import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:generp/Models/crmModels/GetSegmentOnTeamResponse.dart'; import 'package:generp/Models/crmModels/GetSourceOnReferenceResponse.dart'; import 'package:generp/Models/crmModels/LeadListViewResponse.dart'; import 'package:generp/Models/crmModels/SubmitLeadListFilterResponse.dart'; import 'package:provider/provider.dart'; import '../../Models/crmModels/GetDistrictOnStateResponse.dart'; import '../../Models/crmModels/GetSubLocOnDistrictResponse.dart'; import '../../Models/crmModels/LeadListContactPopUpResponse.dart' show Contacts; import '../../services/api_calling.dart'; import '../HomeScreenNotifier.dart'; class Leadlistprovider extends ChangeNotifier { TextEditingController sLeadIDController = TextEditingController(); TextEditingController mobileNumberController = TextEditingController(); TextEditingController companyNameController = TextEditingController( text: "a", ); bool _isLoading = true; List _sourcesList = []; List _teamsList = []; List _statesList = []; List _employeesList = []; List _referencesList = []; List _segmentsList = []; List _districtsList = []; List _subLocationsList = []; List _contactsList = []; List _crmLeadList = []; List _leadStatusList = []; List _openStatusList = []; List _alphabetList = []; Sources? _selectedSources; Teams? _selectedTeams; States? _selectedStates; Employees? _selectedEmployees; References? _selectedReferences; Segments? _selectedSegments; Districts? _selectedDistricts; SubLocations? _selectedSubLocations; Contacts? _selectedContacts; String? _selectedLeadStatus; String? _selectedOpenStatus; String? _selectedAlphabet; String? _selectedSourceId; String? _selectedSourceValue; String? _selectedTeamId; String? _selectedTeamValue; String? _selectedStateId; String? _selectedStateValue; String? _selectedEmployeeId; String? _selectedEmployeeValue; String? _selectedReferenceId; String? _selectedReferenceValue; String? _selectedSegmentId; String? _selectedSegmentValue; String? _selectedDistrictId; String? _selectedDistrictValue; String? _selectedSubLocationId; String? _selectedSubLocationValue; String? _selectedContactId; String? _selectedContactValue; bool get isLoading => _isLoading; List get sourcesList => _sourcesList; List get teamsList => _teamsList; List get statesList => _statesList; List get employeesList => _employeesList; List get referencesList => _referencesList; List get segmentsList => _segmentsList; List get districtsList => _districtsList; List get subLocationsList => _subLocationsList; List get contactsList => _contactsList; List get crmLeadList => _crmLeadList; List get leadStatusList => _leadStatusList; List get alphabetList => _alphabetList; List get openStatusList => _openStatusList; Sources? get selectedSource => _selectedSources; Teams? get selectedTeam => _selectedTeams; States? get selectedStates => _selectedStates; Employees? get selectedEmployee => _selectedEmployees; References? get selectedReference => _selectedReferences; Segments? get selectedSegment => _selectedSegments; Districts? get selectedDistricts => _selectedDistricts; SubLocations? get selectedSubLocations => _selectedSubLocations; Contacts? get selectedContacts => _selectedContacts; String? get selectedLeadStatus => _selectedLeadStatus; String? get selectedOpenStatus => _selectedOpenStatus; String? get selectedSourceId => _selectedSourceId; String? get selectedSourceValue => _selectedSourceValue; String? get selectedTeamId => _selectedTeamId; String? get selectedTeamValue => _selectedTeamValue; String? get selectedStateId => _selectedStateId; String? get selectedStateValue => _selectedStateValue; String? get selectedEmployeeId => _selectedEmployeeId; String? get selectedEmployeeValue => _selectedEmployeeValue; String? get selectedReferenceId => _selectedReferenceId; String? get selectedReferenceValue => _selectedReferenceValue; String? get selectedSegmentId => _selectedSegmentId; String? get selectedSegmentValue => _selectedSegmentValue; String? get selectedDistrictId => _selectedDistrictId; String? get selectedDistrictValue => _selectedDistrictValue; String? get selectedSubLocationId => _selectedSubLocationId; String? get selectedSubLocationValue => _selectedSubLocationValue; String? get selectedContactId => _selectedContactId; String? get selectedContactValue => _selectedContactValue; String? get selectedAlphabet => _selectedAlphabet; set isLoading(bool value) { _isLoading = value; notifyListeners(); } set selectedAlphabet(String? value){ _selectedAlphabet = value; notifyListeners(); } set selectedSource(Sources? value) { _selectedSources = value; _selectedSourceId = value!.id!; _selectedSourceValue = value!.name!; notifyListeners(); } set selectedTeam(Teams? value) { _selectedTeams = value; _selectedTeamId = value!.id!; _selectedTeamValue = value.name; notifyListeners(); } set selectedStates(States? value) { _selectedStates = value; _selectedStateId = value!.id!; _selectedStateValue = value.name; notifyListeners(); } set selectedEmployee(Employees? value) { _selectedEmployees = value; _selectedEmployeeId = value!.id!; _selectedEmployeeValue = value.name; notifyListeners(); } set selectedReference(References? value) { _selectedReferences = value; _selectedReferenceId = value!.id!; _selectedReferenceValue = value.name; notifyListeners(); } set selectedSegment(Segments? value) { _selectedSegments = value; _selectedSegmentId = value!.id!; _selectedSegmentValue = value.name; notifyListeners(); } set selectedDistricts(Districts? value) { _selectedDistricts = value; _selectedDistrictId = value!.id!; _selectedDistrictValue = value.district; notifyListeners(); } set selectedSubLocations(SubLocations? value) { _selectedSubLocations = value; _selectedSubLocationId = value!.id!; _selectedSubLocationValue = value.subLocality; notifyListeners(); } set selectedContacts(Contacts? value) { _selectedContacts = value; _selectedContactId = value!.id!; _selectedContactValue = value.name; notifyListeners(); } set selectedLeadStatus(String? value) { _selectedLeadStatus = value; notifyListeners(); } set selectedOpenStatus(String? value) { _selectedOpenStatus = value; notifyListeners(); } set selectedSourceId(String? value) { _selectedSourceId = value; notifyListeners(); } set selectedSourceValue(String? value) { _selectedSourceValue = value; notifyListeners(); } set selectedTeamId(String? value) { _selectedTeamId = value; notifyListeners(); } set selectedTeamValue(String? value) { _selectedTeamValue = value; notifyListeners(); } set selectedStateId(String? value) { _selectedStateId = value; notifyListeners(); } set selectedStateValue(String? value) { _selectedStateValue = value; notifyListeners(); } set selectedEmployeeId(String? value) { _selectedEmployeeId = value; notifyListeners(); } set selectedEmployeeValue(String? value) { _selectedEmployeeValue = value; notifyListeners(); } set selectedReferenceId(String? value) { _selectedReferenceId = value; notifyListeners(); } set selectedReferenceValue(String? value) { _selectedReferenceValue = value; notifyListeners(); } set selectedSegmentId(String? value) { _selectedSegmentId = value; notifyListeners(); } set selectedSegmentValue(String? value) { _selectedSegmentValue = value; notifyListeners(); } set selectedDistrictId(String? value) { _selectedDistrictId = value; notifyListeners(); } set selectedDistrictValue(String? value) { _selectedDistrictValue = value; notifyListeners(); } set selectedSubLocationId(String? value) { _selectedSubLocationId = value; notifyListeners(); } set selectedSubLocationValue(String? value) { _selectedSubLocationValue = value; notifyListeners(); } set selectedContactId(String? value) { _selectedContactId = value; notifyListeners(); } set selectedContactValue(String? value) { _selectedContactValue = value; notifyListeners(); } Future crmLeadListViewAPIFunction(context, mode) async { try { var HomeProv = Provider.of(context, listen: false); final data = await ApiCalling.crmLeadListViewAPI( HomeProv.empId, HomeProv.session, mode, ); if (data != null) { print(data.error); if (data.error == "0") { // print("as"); _leadStatusList = [ "all", "Hot", "Warm", "Cold", "Order Gain", "Order Lost", ]; _alphabetList = List.generate(26, (index) => String.fromCharCode(index + 65)); _openStatusList = ["open", "Closed", "All"]; _sourcesList = data.sources!; _teamsList = data.teams!; _statesList = data.states!; _employeesList = data.employees!; checkDropDownValues(); // print(_leadStatusList); notifyListeners(); } } } catch (e, s) {} } Future crmLeadListSourceOnReferenceAPIFunction( context, mode, sourceID, ) async { try { var prov = Provider.of(context, listen: false); final data = await ApiCalling.crmLeadListSourceOnReferenceAPI( prov.empId, prov.session, sourceID, ); if (data != null) { if (data.error == "0") { _referencesList = data.references!; notifyListeners(); } } } catch (e, s) {} } Future crmLeadListSegmentOnTeamAPIFunction( context, mode, teamID, ) async { try { var prov = Provider.of(context, listen: false); final data = await ApiCalling.crmLeadListSegmentOnTeamAPI( prov.empId, prov.session, teamID, ); if (data != null) { if (data.error == "0") { _segmentsList = data.segments!; notifyListeners(); } } } catch (e, s) {} } Future crmLeadListDistrictsOnStateAPIFunction( context, mode, stateID, ) async { try { var prov = Provider.of(context, listen: false); final data = await ApiCalling.crmDistrictsOnStateAPI( prov.empId, prov.session, stateID, ); if (data != null) { if (data.error == "0") { _districtsList = data.districts!; notifyListeners(); } } } catch (e, s) {} } Future crmLeadListSubLocOnDistrictAPIFunction( context, mode, districtID, ) async { try { var prov = Provider.of(context, listen: false); final data = await ApiCalling.crmSubLocOnDistrictAPI( prov.empId, prov.session, districtID, ); if (data != null) { if (data.error == "0") { _subLocationsList = data.subLocations!; notifyListeners(); } } } catch (e, s) {} } Future crmLeadListContactPopUpAPIFunction( context, mode, accountID, ) async { try { var prov = Provider.of(context, listen: false); final data = await ApiCalling.crmLeadListContactPopUpAPI( prov.empId, prov.session, accountID, ); if (data != null) { if (data.error == "0") { _contactsList = data.contacts!; notifyListeners(); } } } catch (e, s) {} } Future crmLeadListAPIFunction( context, mode, leadStatus, openStatus, sourceID, referenceID, teamID, segmentID, alphabet ) async { try { _isLoading = true; _crmLeadList.clear(); notifyListeners(); var HomeProv = Provider.of(context, listen: false); final data = await ApiCalling.crmLeadListFilterSubmitAPI( HomeProv.empId, HomeProv.session, mode, leadStatus, openStatus, mobileNumberController.text, companyNameController.text, sourceID, referenceID, teamID, segmentID, alphabet ); if (data != null) { _isLoading = true; notifyListeners(); if (data.error == "0") { _crmLeadList = data.leadList!; _isLoading = false; checkDropDownValues(); notifyListeners(); } else { _isLoading = false; notifyListeners(); } } else { _isLoading = false; notifyListeners(); } } catch (e, s) { _isLoading = false; notifyListeners(); } } onChangedLeadId(value) { notifyListeners(); } onChangedMobileNum(value) { notifyListeners(); } onChangedCompanyName(value) { notifyListeners(); } void resetForm() { _isLoading = false; sLeadIDController.clear(); mobileNumberController.clear(); companyNameController.clear(); companyNameController.text = "a"; _selectedEmployees = null; _selectedSources = null; _selectedReferences = null; _selectedSegments = null; _selectedTeams = null; _selectedDistricts = null; _selectedStates = null; _selectedSubLocations = null; _selectedLeadStatus = null; _selectedOpenStatus = null; _selectedEmployeeId = null; _selectedSourceId = null; _selectedReferenceId = null; _selectedTeamId = null; _selectedSegmentId = null; _selectedStateId = null; _selectedDistrictId = null; _selectedSubLocationId = null; _selectedEmployeeValue = null; _selectedSourceValue = null; _selectedReferenceValue = null; _selectedTeamValue = null; _selectedSegmentValue = null; _selectedDistrictValue = null; _selectedStateValue = null; _selectedSubLocationValue = null; checkDropDownValues(); notifyListeners(); } void checkDropDownValues() { if (!_employeesList.contains(_selectedEmployees) && _selectedEmployees != null) { _selectedEmployeeId = null; _selectedEmployeeValue = null; } if (!_sourcesList.contains(_selectedSources) && _selectedSources != null) { _selectedSourceId = null; _selectedSourceValue = null; } if (!_referencesList.contains(_selectedReferences) && _selectedReferences != null) { _selectedReferenceId = null; _selectedReferenceValue = null; } if (!_segmentsList.contains(_selectedSegments) && _selectedSegments != null) { _selectedTeamId = null; _selectedTeamValue = null; } if (!_teamsList.contains(_selectedTeams) && _selectedTeams != null) { _selectedSegmentId = null; _selectedSegmentValue = null; } if (!_districtsList.contains(_selectedDistricts) && _selectedDistricts != null) { _selectedDistrictId = null; _selectedDistrictValue = null; } if (!_statesList.contains(_selectedStates) && _selectedStates != null) { _selectedStateId = null; _selectedStateValue = null; } if (!_subLocationsList.contains(_selectedSubLocations) && _selectedSubLocations != null) { _selectedSubLocationId = null; _selectedSubLocationValue = null; } notifyListeners(); } }