FIX_1_IunsurerFilterforPolicyReportAndExportExcelAlso_2_AgentCodeAndAgentNameAddedForPolicyVerifyScreen

This commit is contained in:
sanjeev.p 2026-01-30 15:57:43 +05:30
parent d991ee2a49
commit 2dd4e281d0
6 changed files with 235 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -1392,10 +1392,11 @@ class ApiService {
String? fromDate,
String? toDate,
String? selectedStaffId,
String ? selectedStatus
String ? selectedStatus,
String ? selectedInsurer,
}) async {
print(
"fetchPolicyDataOnlyListAPI - mangerID- $managerId - id - $id - role -$role ",
"fetchPolicyDataOnlyListAPI - mangerID- $managerId - id - $id - role -$role >> selectedInsurer -$selectedInsurer ",
);
if (_token == null) {
await _initializeToken();
@ -1403,15 +1404,14 @@ class ApiService {
final userId = '1';
final String query;
String query = "";
if (role == 'manager') {
query = 'manager_id=$managerId';
} else if (role == 'Accounts') {
// query = 'manager_id=$managerId';
query = selectedStatus != null
? 'manager_id=$managerId&show_policy_report=${Uri.encodeComponent(selectedStatus)}'
: 'manager_id=$managerId';
query = 'manager_id=$managerId';
if (selectedStatus != null) { query += '&show_policy_report=${Uri.encodeComponent(selectedStatus)}'; }
if (selectedInsurer != null) { query += '&insurer_id=$selectedInsurer'; }
} else if (role == 'staff') {
query = 'staff_id=$id';
} else if (role == 'handler') {
@ -1420,8 +1420,11 @@ class ApiService {
query = 'agent_id=$id';
}
// final url = Uri.parse(
// '${Env.apiUrl}enquiry/enquiryList?$query&only_policy_data=true&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}&staff_id=$selectedStaffId',
// );
final url = Uri.parse(
'${Env.apiUrl}enquiry/enquiryList?$query&only_policy_data=true&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}&staff_id=$selectedStaffId',
'http://localhost/nhance_partner_be/enquiry/enquiryList?$query&only_policy_data=true&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}&staff_id=$selectedStaffId',
);
// if (role == 'manager') {
@ -1597,6 +1600,7 @@ class ApiService {
Future<Map<String, dynamic>> fetchMasterDropDown(String val ,[String? type]) async {
// print(_token);
print("*** MasterDropDown *** ");
if (_token == null) {
await _initializeToken();
}
@ -2114,9 +2118,9 @@ class ApiService {
}
}
Future<void> generatePolicyExcel(managerId, fromDate, toDate, searchValue,flag) async {
Future<void> generatePolicyExcel(managerId, fromDate, toDate, searchValue,flag,insurer) async {
final url = Uri.parse(
'${Env.apiUrl}reports/policy-excel?manager_id=$managerId&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}&search=${searchValue ?? ''}&show_policy_report=${flag ?? ''}',
'${Env.apiUrl}reports/policy-excel?manager_id=$managerId&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}&search=${searchValue ?? ''}&show_policy_report=${flag ?? ''}&insurer_id=${insurer ?? ''}',
);
print('getPdfDownload policy-excel - $url');
await _initializeToken();

View File

@ -34,6 +34,7 @@ class policylistState extends ConsumerState<policylist> {
dynamic userId;
dynamic managerId;
dynamic SelectedStatus;
dynamic selectedInsurer;
dynamic SelectedStaffId;
// List<Map<String, dynamic>> dataVal = [];
List<Map<String, dynamic>> getStaffData = [];
@ -104,6 +105,7 @@ class policylistState extends ConsumerState<policylist> {
String fromDate = '',
String toDate = '',
String selectedStatus = 'All',
String selectedInsurer = '',
}) async {
print('D68 => Fns called => $managerId | $role');
setState(() {
@ -138,7 +140,8 @@ class policylistState extends ConsumerState<policylist> {
fromDate: fromDt,
toDate: toDt,
selectedStaffId: SelectedStaffId ?? '',
selectedStatus:selectedStatus
selectedStatus:selectedStatus,
selectedInsurer:selectedInsurer
);
if (response['status'] == 'success') {
@ -228,7 +231,7 @@ class policylistState extends ConsumerState<policylist> {
print('filterDateRange 1s');
print('manager - $managerId - userID -$userId - roledId -$roleId');
getStaffList(managerId!, userId, roleId, selectedStatus : SelectedStatus ?? 'All');
getStaffList(managerId!, userId, roleId, selectedStatus : SelectedStatus ?? 'All', selectedInsurer:selectedInsurer??'');
}
print('filterDateRange 1');
}
@ -239,12 +242,13 @@ class policylistState extends ConsumerState<policylist> {
controllers['startDate']!.clear();
controllers['endDate']!.clear();
SelectedStatus ='All';
selectedInsurer = null;
controllers['startDate']?.text = '';
controllers['endDate']?.text = '';
// Reset the FormField validation
_formKey.currentState?.reset();
});
getStaffList(managerId, userId, roleId, selectedStatus : SelectedStatus ?? 'All');
getStaffList(managerId, userId, roleId, selectedStatus : SelectedStatus ?? 'All',selectedInsurer:selectedInsurer??'');
}
void filterData(String query) {
@ -306,7 +310,8 @@ class policylistState extends ConsumerState<policylist> {
fromDate,
toDate,
searchValue,
SelectedStatus ?? 'All'
SelectedStatus ?? 'All',
selectedInsurer ?? '',
);
// Map your controllers and IDs to the API parameters
// final String fromDate = controllers['startDate']!.text; // "11-01-2025"
@ -433,11 +438,17 @@ class policylistState extends ConsumerState<policylist> {
startController: controllers['startDate']!,
endController: controllers['endDate']!,
selectedStatusVal: SelectedStatus,
selectedInsurerVal : selectedInsurer,
onStatusChanged: (val) {
setState(() {
SelectedStatus = val; // update parent
});
},
onInsurerChanged: (val) {
setState(() {
selectedInsurer = val; // update parent
});
},
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {
@ -477,6 +488,11 @@ class policylistState extends ConsumerState<policylist> {
SelectedStatus = val; // update parent
});
},
onInsurerChanged: (val) {
setState(() {
selectedInsurer = val; // update parent
});
},
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {

View File

@ -95,6 +95,9 @@ class _policyValidationState extends ConsumerState<policyValidation> {
//find Policy
'insurance_plan_type_id',
// agent code and agent name in single.
'agent_code_and_name',
];
late Map<String, TextEditingController> controllers;
String? selectedInsuranceId;
@ -131,6 +134,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
String? selectedBroker;
String? selectedInsurerName;
String? selectedInsurerShortName;
String? selectedPartnerCodeAndName;
final GlobalKey<DropdownSearchState<Map<String, dynamic>>> dropDownKey =
GlobalKey<DropdownSearchState<Map<String, dynamic>>>();
@ -284,6 +288,9 @@ class _policyValidationState extends ConsumerState<policyValidation> {
? controllers["payment_mode"]?.text
: selectedPaymentMode,
"insurance_plan_type_id": selectedInsurancePlanTypeId,
// If there is no data means
"agent_code_and_name" : selectedPartnerCodeAndName,
};
}
@ -321,6 +328,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
"enquiry_reg_no_for_commission": data["enquiry_reg_no_for_commission"],
"enquiry_vehicle_type_id_for_commission": selectedVehicleTypeForEnquiryID,
"payment_mode": pm,
"agent_code_and_name" : selectedPartnerCodeAndName
};
}
@ -773,6 +781,10 @@ class _policyValidationState extends ConsumerState<policyValidation> {
selectedInsurancePlanTypeId = data['insurance_plan_type_id']?.toString();
// 2. Set the Controller (This ensures dataDetails() can pick it up if needed)
controllers["insurance_plan_type_id"]?.text = selectedInsurancePlanTypeId ?? '';
selectedPartnerCodeAndName = safeText(data['agent_code']) + '-' + safeText(data['agent_name']);
controllers["agent_code_and_name"]?.text = selectedPartnerCodeAndName ?? '';
});
debugPrint('findPolicyApi response3:');
@ -1951,6 +1963,18 @@ class _policyValidationState extends ConsumerState<policyValidation> {
),
),
],
),
Row(
children: [
Expanded(
child: _buildInput(
'Partner Code And Name',
controllers['agent_code_and_name']!,
required : false,
// rightLabel: selectedInsurerName,
),
)
],
)
],
),

View File

@ -37,9 +37,11 @@ import '../themes/indicators/input_field_decoration.dart';
class DateFilterRow extends ConsumerStatefulWidget {
final TextEditingController startController;
final String? selectedStatusVal;
final String? selectedInsurerVal;
final String? selectedStaffId;
final TextEditingController endController;
final ValueChanged<String?>? onStatusChanged;
final ValueChanged<String?>? onInsurerChanged;
final ValueChanged<String?>? onFilterStaff;
final String? dataFrom;
final VoidCallback onFilter;
@ -56,9 +58,11 @@ class DateFilterRow extends ConsumerStatefulWidget {
required this.onFilter,
required this.onRefresh,
required this.onStatusChanged,
this.onInsurerChanged,
this.onFilterStaff,
required this.selectedStaffId,
this.selectedStatusVal,
this.selectedInsurerVal,
required this.formKey,
required this.role,
required this.id,
@ -76,12 +80,17 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
late ApiService apiService;
List<Map<String, dynamic>> getStaffDetailsData = [];
List<Map<String, dynamic>> filteredStaffData = [];
Map<String, dynamic>? selectedInsurerData;
List<Map<String, dynamic>> filteredInsurerData = [];
List<Map<String, dynamic>> getInsurerDetailsData = [];
String? selectedInsurer;
String? selectedStaff;
String? selectedStaffName;
dynamic role;
dynamic managerId;
bool isLoadingA = false;
bool isLoading = false;
@override
@ -99,6 +108,8 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
print('hansles');
getStaffDetails(userID);
}
print('***Insurer***');
getInsurerDetails();
});
// Future.microtask(() {
@ -147,6 +158,38 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
}
}
Future<void> getInsurerDetails() async {
setState(() => isLoadingA = true);
try {
final response = await apiService.fetchMasterDropDown('Insurers');
print("***999999999999999999*********** $response");
if (response['status'] == 200) {
print('getInsurerDetails - ${response['data']}');
setState(() {
getInsurerDetailsData =
List<Map<String, dynamic>>.from(response['data']);
filteredInsurerData =
List<Map<String, dynamic>>.from(getInsurerDetailsData);
print("Filtered Insurer Data: $filteredInsurerData");
});
} else {
setState(() {
getInsurerDetailsData = [];
filteredInsurerData = [];
});
}
} catch (e) {
print('Error: $e');
} finally {
setState(() => isLoadingA = false);
}
}
@override
Widget build(BuildContext context) {
final spacing = 5.0;
@ -190,6 +233,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
if (widget.role == 'Accounts' && widget.dataFrom == 'Policy') ...[
buildPolicyReportFlagSearch(context),
SizedBox(width: spacing),
buildSelectInsurer(context),
],
];
@ -783,6 +827,137 @@ class _DateFilterRowState extends ConsumerState<DateFilterRow> {
);
}
Widget buildSelectInsurer(BuildContext context) {
// Ensure this list has data BEFORE building dropdown
final List<Map<String, dynamic>> insurerOptions =
List<Map<String, dynamic>>.from(filteredInsurerData);
// Selected item logic
Map<String, dynamic>? selectedItem;
if (widget.selectedInsurerVal != null &&
widget.selectedInsurerVal.toString().isNotEmpty &&
insurerOptions.isNotEmpty) {
try {
selectedItem = insurerOptions.firstWhere(
(e) =>
e['id'].toString() ==
widget.selectedInsurerVal.toString(),
);
} catch (e) {
selectedItem = null;
}
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 35,
child: Container(
width: ResponsiveLayout.isMobile(context)
? null
: MediaQuery.of(context).size.width * 0.14,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
border: Border.all(color: const Color(0xFFE2E8F0)),
),
child: DropdownSearch<Map<String, dynamic>>(
selectedItem: selectedItem,
items: (filter, infiniteScrollProps) => insurerOptions,
itemAsString: (item) => item['short_name']?.toString() ?? '',
compareFn: (item, selected) {
if (selected == null) return false;
return item['id'].toString() ==
selected['id'].toString();
},
// FIELD UI
dropdownBuilder: (context, selectedItem) {
return Align(
alignment: Alignment.centerLeft,
child: Text(
selectedItem != null
? selectedItem['short_name'].toString()
: '',
style: GoogleFonts.poppins(
fontSize: 11,
color: Colors.black,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
);
},
decoratorProps: DropDownDecoratorProps(
decoration: AppInputDecorations.dropdownDecoration(
label: "Select Insurer",
).copyWith(
filled: true,
fillColor: Colors.white,
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 1,
),
),
),
// POPUP UI
popupProps: PopupProps.menu(
fit: FlexFit.loose,
constraints: const BoxConstraints(maxHeight: 200),
menuProps:
const MenuProps(backgroundColor: Colors.white),
showSearchBox: false,
itemBuilder:
(context, item, isDisabled, isSelected) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
child: Text(
item['short_name'].toString(),
style: GoogleFonts.inter(
fontSize: 13,
color: Colors.black,
),
),
);
},
),
// ON CHANGE
onChanged: (val) {
if (val == null) return;
selectedInsurer = val['id'];
widget.onInsurerChanged?.call(val['id']);
// Safe UI refresh
Future.microtask(() {
widget.onFilter();
});
},
),
),
),
],
);
}
static const _textStyle = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,

View File

@ -16,7 +16,7 @@
-->
<!-- <base href="$FLUTTER_BASE_HREF">-->
<!-- <base href="/partner/"> &lt;!&ndash; Live build: also check env.dart (line 8) &ndash;&gt;-->
<base href="/nhance/partner/app/"> Testing build: also check env.dart (line 9)
<base href="/nhance/partner/app/"> <!-- Testing build: also check env.dart (line 9) -->
<meta charset="UTF-8">