diff --git a/lib/core/services/api_service.dart b/lib/core/services/api_service.dart index 97ab947..02f0e24 100644 --- a/lib/core/services/api_service.dart +++ b/lib/core/services/api_service.dart @@ -154,7 +154,11 @@ class ApiService { } } - Future getPdfDownload(BuildContext context,String path, String id) async { + Future getPdfDownload( + BuildContext context, + String path, + String id, + ) async { print('getPdfDownload 1'); print('getPdfDownload 1 - $path'); @@ -176,39 +180,40 @@ class ApiService { final response = await _makeGethttpRequest(url, headers); print('getPdfDownload 3'); - if (response.statusCode == 200) { final contentType = response.headers['content-type'] ?? ''; if (contentType.contains('application/json')) { final jsonResponse = jsonDecode(response.body); - if (jsonResponse['code'] == 404 || jsonResponse['code'] == 500) - { ToastHelper.showInfoToast(context, 'File Not Found'); } - else { ToastHelper.showInfoToast(context, 'No File Found'); } + if (jsonResponse['code'] == 404 || jsonResponse['code'] == 500) { + ToastHelper.showInfoToast(context, 'File Not Found'); + } else { + ToastHelper.showInfoToast(context, 'No File Found'); + } return; - }else{ - final blob = html.Blob([response.bodyBytes]); - final blobUrl = html.Url.createObjectUrlFromBlob(blob); - print('getPdfDownload $blobUrl'); - // --- filename resolution --- - String fileName = 'download_$id'; - print('getPdfDownloadfileName $fileName'); - final contentDisp = response.headers['content-disposition']; - print('getPdfDownloadcontentDisp $contentDisp'); - if (contentDisp != null && contentDisp.contains('filename=')) { - print('getPdfDownloadcontentDisp..1'); - fileName = contentDisp.split('filename=')[1].replaceAll('"', ''); - print('getPdfDownloadcontentDisp..2'); } else { - print('getPdfDownloadcontentDisp..3'); - // fallback: URL or id - fileName = path.split('/').last; - if (id != null) fileName = '${id}_$fileName'; - } - final anchor = html.AnchorElement(href: blobUrl) - ..setAttribute('download', fileName) - ..click(); - print('getPdfDownloadcontentDisp..4'); - html.Url.revokeObjectUrl(blobUrl); + final blob = html.Blob([response.bodyBytes]); + final blobUrl = html.Url.createObjectUrlFromBlob(blob); + print('getPdfDownload $blobUrl'); + // --- filename resolution --- + String fileName = 'download_$id'; + print('getPdfDownloadfileName $fileName'); + final contentDisp = response.headers['content-disposition']; + print('getPdfDownloadcontentDisp $contentDisp'); + if (contentDisp != null && contentDisp.contains('filename=')) { + print('getPdfDownloadcontentDisp..1'); + fileName = contentDisp.split('filename=')[1].replaceAll('"', ''); + print('getPdfDownloadcontentDisp..2'); + } else { + print('getPdfDownloadcontentDisp..3'); + // fallback: URL or id + fileName = path.split('/').last; + if (id != null) fileName = '${id}_$fileName'; + } + final anchor = html.AnchorElement(href: blobUrl) + ..setAttribute('download', fileName) + ..click(); + print('getPdfDownloadcontentDisp..4'); + html.Url.revokeObjectUrl(blobUrl); } } else if (response.statusCode == 404) { showDialog( @@ -256,7 +261,7 @@ class ApiService { } else if (apiUrl != null) { print("Download from API: $apiUrl"); print("Download from API: $apiId!"); - await getPdfDownload(context,apiUrl, apiId!); + await getPdfDownload(context, apiUrl, apiId!); } else { print("⚠️ No file available to download"); } @@ -470,7 +475,7 @@ class ApiService { // ----------------------------------- ENQUIRY ------------------------------------------------- - Future> fetchEnquiryList(int id, role) async { + Future> fetchEnquiryList1(int id, role) async { // print(_token); if (_token == null) { await _initializeToken(); @@ -479,11 +484,17 @@ class ApiService { final url; if (role == 'manager') { - url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?manager_id=$id'); + url = Uri.parse( + '${Env.apiUrl}enquiry/enquiryList?manager_id=$id&from_date=&to_date=', + ); } else if (role == 'staff') { - url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?staff_id=$id'); + url = Uri.parse( + '${Env.apiUrl}enquiry/enquiryList?staff_id=$id&from_date=&to_date=', + ); } else { - url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?agent_id=$id'); + url = Uri.parse( + '${Env.apiUrl}enquiry/enquiryList?agent_id=$id&from_date=&to_date=', + ); } // final url = Uri.parse( // 'https://venbait.in/nhance/partner/dev/api/agent/agentList?manager_id=${managerId}', @@ -496,6 +507,39 @@ class ApiService { return response; } + Future> fetchEnquiryList( + int id, + String role, { + String? fromDate, + String? toDate, + }) async { + if (_token == null) { + await _initializeToken(); + } + + final String query; + + if (role == 'manager') { + query = 'manager_id=$id'; + } else if (role == 'staff') { + query = 'staff_id=$id'; + } else { + query = 'agent_id=$id'; + } + + final url = Uri.parse( + '${Env.apiUrl}enquiry/enquiryList?$query&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}', + ); + + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'App-Signature': 'nhance-partner-2025-signature-35468846JRhH551HK', + }; + + final response = await _makeGetRequest(url, headers); + return response; + } + Future> findSingleEnquiryData(id) async { // print(_token); if (_token == null) { diff --git a/lib/presentation/screens/Enquiry/enquiry/enquiry_tab.dart b/lib/presentation/screens/Enquiry/enquiry/enquiry_tab.dart index 228c84f..2727411 100644 --- a/lib/presentation/screens/Enquiry/enquiry/enquiry_tab.dart +++ b/lib/presentation/screens/Enquiry/enquiry/enquiry_tab.dart @@ -326,24 +326,24 @@ class EnquiryTabState extends ConsumerState { final dataSet = dataDetails(); // check RC file - if ((docUploadedRCFile == null || - (docUploadedRCFile?.bytes == null && - docUploadedRCFile?.path == null)) && - (rcFileUrlFromApi == null || rcFileUrlFromApi!.isEmpty)) { - setState(() => isSaving = false); // reset button - ToastHelper.showErrorToast(context, "Please upload RC Document"); - return; - } - - // check ID proof - if ((docUploadedIDProof == null || - (docUploadedIDProof?.bytes == null && - docUploadedIDProof?.path == null)) && - (idProofFileUrlFromApi == null || idProofFileUrlFromApi!.isEmpty)) { - setState(() => isSaving = false); // reset button - ToastHelper.showErrorToast(context, "Please upload ID Proof"); - return; - } + // if ((docUploadedRCFile == null || + // (docUploadedRCFile?.bytes == null && + // docUploadedRCFile?.path == null)) && + // (rcFileUrlFromApi == null || rcFileUrlFromApi!.isEmpty)) { + // setState(() => isSaving = false); // reset button + // ToastHelper.showErrorToast(context, "Please upload RC Document"); + // return; + // } + // + // // check ID proof + // if ((docUploadedIDProof == null || + // (docUploadedIDProof?.bytes == null && + // docUploadedIDProof?.path == null)) && + // (idProofFileUrlFromApi == null || idProofFileUrlFromApi!.isEmpty)) { + // setState(() => isSaving = false); // reset button + // ToastHelper.showErrorToast(context, "Please upload ID Proof"); + // return; + // } try { await createUserData(dataSet); // API call @@ -358,7 +358,7 @@ class EnquiryTabState extends ConsumerState { TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('OK'), - ) + ), ], ), ); @@ -1032,7 +1032,7 @@ class EnquiryTabState extends ConsumerState { Widget buildUploadRCDocument(BuildContext context) { return buildResponsiveUploadField( - label: "Upload RC Document *", + label: "Upload RC Document ", hintText: selectedRCFile, onFileSelected: (fileName, file) { setState(() { @@ -1063,7 +1063,7 @@ class EnquiryTabState extends ConsumerState { Widget buildUploadIDDocument(BuildContext context) { return buildResponsiveUploadField( - label: "Upload ID Proof *", + label: "Upload ID Proof", hintText: selectedIdProof, onFileSelected: (fileName, file) { setState(() { diff --git a/lib/presentation/screens/Enquiry/enquiryList.dart b/lib/presentation/screens/Enquiry/enquiryList.dart index 96429d0..1302f01 100644 --- a/lib/presentation/screens/Enquiry/enquiryList.dart +++ b/lib/presentation/screens/Enquiry/enquiryList.dart @@ -29,6 +29,9 @@ class EnquiryListState extends ConsumerState { int currentPage = 1; int itemsPerPage = 10; late ApiService apiService; + dynamic roleId; + dynamic userId; + final _formKey = GlobalKey(); // List> dataVal = []; List> getStaffData = []; @@ -50,8 +53,8 @@ class EnquiryListState extends ConsumerState { Future.microtask(() { final id = ref.read(managerIdProvider); - final roleId = ref.read(userRoleProvider); - final userId = ref.read(userIdProvider); + roleId = ref.read(userRoleProvider); + userId = ref.read(userIdProvider); print("A56 => r : $roleId | mId: $id | uId: $userId "); @@ -60,40 +63,120 @@ class EnquiryListState extends ConsumerState { // Agent - venba2026@gmail.com - T E S T A - 5 evarkku 8th id is manager // so here i used userId - if (userId != null) { getStaffList(userId, roleId); } - + if (userId != null) { + getStaffList(userId, roleId); + } }); } - void filterDateRange() {} - void refrshfilterDateRange() {} + void filterDateRange() { + print("filterDateRange"); + // if (!_formKey.currentState!.validate()) return; - Future getStaffList(int managerId, role) async { + // final fromDate = controllers['startDate']?.text ?? ''; + // final toDate = controllers['endDate']?.text ?? ''; + print("filterDateRange1"); + // Call with selected dates + getStaffList(userId, roleId); + } + + void refrshfilterDateRange() { + setState(() { + controllers['startDate']!.clear(); + controllers['endDate']!.clear(); + + controllers['startDate']?.text = ''; + controllers['endDate']?.text = ''; + }); + getStaffList(userId, roleId); + } + + // Future getStaffList(int managerId, role) async { + // print('A72 => Fns called => $managerId | $role'); + // setState(() { + // isLoading = true; + // }); + // + // try { + // final response = await apiService.fetchEnquiryList(managerId, role); + // + // if (response['status'] == 'success') { + // final data = response['data']; + // final fromDate = response['from_date'] ?? ''; + // final toDate = response['to_date'] ?? ''; + // print('FromDAte : $fromDate'); + // print('ToDAte : $toDate'); + // + // print('A82 => getStaffListData => ${response['data']}'); + // setState(() { + // controllers['startDate']?.text = fromDate; + // controllers['endDate']?.text = toDate; + // if (data is List) { + // // Already a list of maps + // getStaffData = List>.from(data); + // } else if (data is Map) { + // // Single object, wrap in a list + // getStaffData = [Map.from(data)]; + // } else { + // getStaffData = []; + // } + // // getStaffData = List>.from(response['data']); + // originalData = getStaffData; + // filteredData = List.from(originalData); + // // print('originalData - $getClaimPolicies'); + // }); + // } else { + // getStaffData = []; + // originalData = []; + // } + // } catch (e) { + // print('Exception occurred: $e'); + // } finally { + // setState(() { + // isLoading = false; + // }); + // } + // } + + Future getStaffList( + int managerId, + role, { + String fromDate = '', + String toDate = '', + }) async { print('A72 => Fns called => $managerId | $role'); setState(() { isLoading = true; }); try { - final response = await apiService.fetchEnquiryList(managerId, role); + final response = await apiService.fetchEnquiryList( + managerId, + role, + fromDate: controllers['startDate']?.text ?? '', + toDate: controllers['endDate']?.text ?? '', + ); if (response['status'] == 'success') { final data = response['data']; - print('A82 => getStaffListData => ${response['data']}'); + final fromDate = response['from_date'] ?? ''; + final toDate = response['to_date'] ?? ''; + + print('FromDate : $fromDate'); + print('ToDate : $toDate'); + setState(() { + controllers['startDate']?.text = fromDate; + controllers['endDate']?.text = toDate; if (data is List) { - // Already a list of maps getStaffData = List>.from(data); } else if (data is Map) { - // Single object, wrap in a list getStaffData = [Map.from(data)]; } else { getStaffData = []; } - // getStaffData = List>.from(response['data']); originalData = getStaffData; filteredData = List.from(originalData); - // print('originalData - $getClaimPolicies'); }); } else { getStaffData = []; @@ -180,7 +263,9 @@ class EnquiryListState extends ConsumerState { (item['status'] ?? '-').toLowerCase().contains( query.toLowerCase(), ) || - (item['remarks'] ?? '-').toLowerCase().contains(query.toLowerCase()); + (item['remarks'] ?? '-').toLowerCase().contains( + query.toLowerCase(), + ); }).toList(); }); } @@ -274,6 +359,50 @@ class EnquiryListState extends ConsumerState { padding: EdgeInsets.all(8.0), child: Column( children: [ + if (ResponsiveLayout.isMobile(context)) ...[ + Container( + padding: EdgeInsets.all(8.0), + color: Color(0xffD9EBE8), + child: Form( + key: _formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + buildStartDate(context), + SizedBox(height: 10), + buildEndDate(context), + // SizedBox(height: 10), + Row( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: GestureDetector( + onTap: filterDateRange, + child: Icon( + Icons.filter_list_outlined, + size: 18, + ), + ), + ), + + Padding( + padding: const EdgeInsets.all(8.0), + child: GestureDetector( + onTap: refrshfilterDateRange, + child: Icon(Icons.refresh, size: 18), + ), + ), + ], + ), + ], + ), + ), + ), + ], + Container( // height: 40, // color: Colors.pink, @@ -281,26 +410,29 @@ class EnquiryListState extends ConsumerState { crossAxisAlignment: CrossAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.start, children: [ - // buildStartDate(context), - // SizedBox(width: 10), - // buildEndDate(context), - // SizedBox(width: 10), - // - // Padding( - // padding: const EdgeInsets.all(8.0), - // child: GestureDetector( - // onTap: filterDateRange, - // child: Icon(Icons.filter_list_outlined), - // ), - // ), - // - // Padding( - // padding: const EdgeInsets.all(8.0), - // child: GestureDetector( - // onTap: refrshfilterDateRange, - // child: Icon(Icons.refresh), - // ), - // ), + if (!ResponsiveLayout.isMobile(context)) ...[ + buildStartDate(context), + SizedBox(width: 10), + buildEndDate(context), + SizedBox(width: 10), + + Padding( + padding: const EdgeInsets.all(8.0), + child: GestureDetector( + onTap: filterDateRange, + child: Icon(Icons.filter_list_outlined), + ), + ), + + Padding( + padding: const EdgeInsets.all(8.0), + child: GestureDetector( + onTap: refrshfilterDateRange, + child: Icon(Icons.refresh), + ), + ), + Spacer(), + ], ThemedSearchField( hintText: 'Search', backgroundColor: Color(0xFFF6F8F8), @@ -311,8 +443,6 @@ class EnquiryListState extends ConsumerState { : MediaQuery.of(context).size.width * 0.2, ), - Spacer(), - SizedBox(width: 10), ExportBtn( @@ -411,17 +541,11 @@ class EnquiryListState extends ConsumerState { ), Expanded( flex: 2, - child: Text( - 'Created Date', - style: _headerStyle, - ), + child: Text('Created Date', style: _headerStyle), ), Expanded( flex: 2, - child: Text( - 'Updated Date', - style: _headerStyle, - ), + child: Text('Updated Date', style: _headerStyle), ), Expanded( flex: 1, @@ -795,7 +919,7 @@ class EnquiryListState extends ConsumerState { txtwidth: ResponsiveLayout.isMobile(context) ? null : MediaQuery.of(context).size.width * 0.16, - txtheight: 50, + // txtheight: 50, // backgroundColor: const Color(0xFFECECEC), // validator: (value) => Validators.requiredField(value, "date"), controller: controllers['startDate']!, @@ -823,7 +947,7 @@ class EnquiryListState extends ConsumerState { txtwidth: ResponsiveLayout.isMobile(context) ? null : MediaQuery.of(context).size.width * 0.16, - txtheight: 50, + // txtheight: 50, // backgroundColor: const Color(0xFFECECEC), // validator: (value) => Validators.requiredField(value, "date"), controller: controllers['endDate']!, diff --git a/lib/presentation/screens/Enquiry/policy_claims_endros/claims.dart b/lib/presentation/screens/Enquiry/policy_claims_endros/claims.dart index 7dfba2b..14fad8b 100644 --- a/lib/presentation/screens/Enquiry/policy_claims_endros/claims.dart +++ b/lib/presentation/screens/Enquiry/policy_claims_endros/claims.dart @@ -45,8 +45,9 @@ class claimListState extends ConsumerState { final roleId = ref.read(userRoleProvider); final userId = ref.read(userIdProvider); print("G47 => r : $roleId | mId: $id | uId: $userId "); - if (userId != null) { getStaffList(userId, roleId); } - + if (userId != null) { + getStaffList(userId, roleId); + } }); } @@ -248,6 +249,7 @@ class claimListState extends ConsumerState { "policy_end_date", "claim_number", "claim_type_value", + 'claim_status_value', ], ), @@ -336,10 +338,10 @@ class claimListState extends ConsumerState { flex: 2, child: Text('Claim No.', style: _headerStyle), ), - // Expanded( - // flex: 1, - // child: Text('Action', style: _headerStyle), - // ), + Expanded( + flex: 2, + child: Text('Status', style: _headerStyle), + ), ], ), ), @@ -470,6 +472,13 @@ class claimListState extends ConsumerState { style: _dataBold, ), ), + Expanded( + flex: 2, + child: Text( + item['claim_status_value'] ?? '-', // fallback + style: _dataBold, + ), + ), // Expanded( // flex: 1, @@ -528,6 +537,7 @@ class claimListState extends ConsumerState { item['reg_no'] != null ? _formatDate(item['reg_no']) : '-', style: _headerStyle, ), + // PopupMenuButton( // color: Colors.white, // padding: EdgeInsets.zero, @@ -627,6 +637,27 @@ class claimListState extends ConsumerState { ), ], ), + const SizedBox(height: 15), + + // Created On + Remarks + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + //date and time + Text("Status", style: _cardheaderStyle), + Text( + item['claim_status_value'] ?? '-', + style: _cardBodyStyle, + ), + ], + ), + ), + ], + ), ], ), ); diff --git a/lib/presentation/screens/staff/policy/policy_list.dart b/lib/presentation/screens/staff/policy/policy_list.dart index 3ae37d1..fb6ff39 100644 --- a/lib/presentation/screens/staff/policy/policy_list.dart +++ b/lib/presentation/screens/staff/policy/policy_list.dart @@ -156,8 +156,9 @@ class policylistState extends ConsumerState { ) || (item['policy_number'] ?? '-').toLowerCase().contains( query.toLowerCase(), - ) || - (item['status'] ?? '-').toLowerCase().contains(query.toLowerCase()); + ) + // || + // (item['status'] ?? '-').toLowerCase().contains(query.toLowerCase()); ; }).toList(); }); @@ -378,7 +379,6 @@ class policylistState extends ConsumerState { "payment_mode", "updated_on", "policy_number", - "status", ], ), @@ -473,10 +473,6 @@ class policylistState extends ConsumerState { child: Text('Policy Number', style: _headerStyle), ), - Expanded( - flex: 3, - child: Text('Status', style: _headerStyle), - ), // Expanded( // flex: 1, // child: Text('Action', style: _headerStyle), @@ -637,50 +633,6 @@ class policylistState extends ConsumerState { maxLines: 3, ), ), - - Expanded( - flex: 3, - child: Text(item['status'] ?? '-', style: _dataBold), - ), - - // Expanded( - // flex: 1, - // child: Row( - // children: [ - // PopupMenuButton( - // color: Colors.white, - // padding: EdgeInsets.zero, - // offset: Offset(0, 30), - // icon: Icon( - // Icons.more_vert, - // color: Color(0xFF475569), - // size: 14, - // ), - // itemBuilder: (context) => [ - // CustomPopupMenuEntry( - // child: Container( - // padding: EdgeInsets.symmetric( - // horizontal: 8, - // vertical: 8, - // ), - // child: Column( - // mainAxisSize: MainAxisSize.min, - // mainAxisAlignment: MainAxisAlignment.start, - // crossAxisAlignment: CrossAxisAlignment.start, - // children: _buildPopupMenuActions( - // context, - // item, - // item['id'], - // item['reg_no'], - // ), - // ), - // ), - // ), - // ], - // ), - // ], - // ), - // ), ], ), ); @@ -741,16 +693,16 @@ class policylistState extends ConsumerState { ], ), ), - const SizedBox(width: 5), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text("Status", style: _cardheaderStyle), - Text(item['status'] ?? '-', style: _cardBodyStyle), - ], - ), - ), + // const SizedBox(width: 5), + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Text("Status", style: _cardheaderStyle), + // Text(item['status'] ?? '-', style: _cardBodyStyle), + // ], + // ), + // ), ], ), const SizedBox(height: 15), diff --git a/lib/presentation/widgets/drawer_menu.dart b/lib/presentation/widgets/drawer_menu.dart index 9e02419..34f82cd 100644 --- a/lib/presentation/widgets/drawer_menu.dart +++ b/lib/presentation/widgets/drawer_menu.dart @@ -268,29 +268,32 @@ class DrawerMenuState extends ConsumerState { DrawerLabel("User"), ], - Builder( - builder: (itemContext) { - return MouseRegion( - // onEnter: (_) => _showPopup(itemContext), - onEnter: (_) { - final renderBox = itemContext.findRenderObject() as RenderBox; - final offset = renderBox.localToGlobal(Offset.zero); - final size = renderBox.size; - final key = "Reports"; - _showPopup(context, offset, size, key); - }, + if (roleId != 'staff') ...[ + Builder( + builder: (itemContext) { + return MouseRegion( + // onEnter: (_) => _showPopup(itemContext), + onEnter: (_) { + final renderBox = + itemContext.findRenderObject() as RenderBox; + final offset = renderBox.localToGlobal(Offset.zero); + final size = renderBox.size; + final key = "Reports"; + _showPopup(context, offset, size, key); + }, - child: DrawerContentWrapper( - child: Image.asset( - "assets/drawer/drawerImg2.png", - height: 25, - width: 25, + child: DrawerContentWrapper( + child: Image.asset( + "assets/drawer/drawerImg2.png", + height: 25, + width: 25, + ), ), - ), - ); - }, - ), - DrawerLabel("Reports"), + ); + }, + ), + DrawerLabel("Reports"), + ], ], ), );