FIX_1, dashboard partner tab particular download based on date 2,soft delete implemented

This commit is contained in:
sanjeev.p 2026-02-02 17:07:46 +05:30
parent 1f34df0d2e
commit 4227ce34d7
5 changed files with 336 additions and 133 deletions

File diff suppressed because one or more lines are too long

View File

@ -176,6 +176,25 @@ class ApiService {
}
Future<Map<String, dynamic>> softDeletePolicyApi(String policyId) async {
// Ensure token is available
if (_token == null) {
await _initializeToken();
}
// Define the endpoint with query parameter
final url = Uri.parse('${Env.apiUrl}policy/softdelete?policy_id=$policyId');
final headers = {
'Authorization': 'Bearer $_token', // Removed null-coalesce as _token is checked above
'app-signature': Env.App_Signature,
};
// Using your standard helper for consistency and error handling
final response = await _makeGetRequest(url, headers);
return response;
}
Future<Map<String, dynamic>> CheckDuplicate(
BuildContext context,
@ -416,6 +435,8 @@ class ApiService {
{DateTime? toDate, DateTime? fromDate}
) async {
print('Sq getxl 1 - $path');
print('Sq toDate - $toDate');
print('Sq fromDate - $fromDate');
dynamic pathVal;
// if (path == 'Insurer') {
@ -1411,7 +1432,7 @@ class ApiService {
} else if (role == 'Accounts') {
query = 'manager_id=$managerId';
if (selectedStatus != null) { query += '&show_policy_report=${Uri.encodeComponent(selectedStatus)}'; }
if (selectedInsurer != null) { query += '&insurer_id=$selectedInsurer'; }
if (selectedInsurer != null && selectedInsurer.toString().trim().isNotEmpty) { query += '&insurer_id=$selectedInsurer'; }
} else if (role == 'staff') {
query = 'staff_id=$id';
} else if (role == 'handler') {

View File

@ -182,7 +182,7 @@ class _PartnerDashboardState extends ConsumerState<PartnerDashboard> {
isLoading = true;
});
// dynamic id = widget.policyNumber;
print('getBusinessDshID - $id');
print('getBusinessDshID - $id - $fromDate - $toDate');
try {
final response = await apiService.findPartnerDashboardData(id,fromDate,toDate);
@ -350,6 +350,9 @@ class _PartnerDashboardState extends ConsumerState<PartnerDashboard> {
if (managerId == null) return;
// Print to verify state before calling API
print("Search Triggered: $fromDate to $toDate");
// OPTIONAL: validation
if (fromDate != null && toDate != null && fromDate!.isAfter(toDate!)) {
ToastHelper.showWarningToast(context, 'From date cannot be after To date');
@ -558,6 +561,8 @@ class _PartnerDashboardState extends ConsumerState<PartnerDashboard> {
isPerfomingAgntPolicy,
apiService: apiService,
managerId: managerId,
fromDate: fromDate,
toDate: toDate,
),
),
],
@ -665,6 +670,8 @@ class _PartnerDashboardState extends ConsumerState<PartnerDashboard> {
isNonPerfomingAgntPolicy,
apiService: apiService,
managerId: managerId,
fromDate: fromDate,
toDate: toDate,
),
),
],

View File

@ -10,6 +10,7 @@ import 'package:nhance_partner/presentation/screens/staff/assignStaff.dart';
import '../../../../core/routing/routes.dart';
import '../../../../core/services/api_service.dart';
import '../../../../data/utils/Pagination.dart';
import '../../../../data/utils/toastNotification.dart';
import '../../../layouts/main_layout.dart';
import '../../../layouts/responsive_layout.dart';
import '../../../providers/manager_provider.dart';
@ -20,6 +21,7 @@ import '../../../widgets/custom_Stdate_EnDate_Filter.dart';
import '../../../widgets/custom_action_popup.dart';
import '../../Enquiry/enquiry/policy_popup.dart';
import '../../Enquiry/policy_claims_endros/sub_claims.dart';
// import '../../../../data/utils/toastNotification.dart';
class policylist extends ConsumerStatefulWidget {
const policylist({super.key});
@ -34,7 +36,7 @@ class policylistState extends ConsumerState<policylist> {
dynamic userId;
dynamic managerId;
dynamic SelectedStatus;
dynamic selectedInsurer;
dynamic SelectedInsurer;
dynamic SelectedStaffId;
// List<Map<String, dynamic>> dataVal = [];
List<Map<String, dynamic>> getStaffData = [];
@ -56,6 +58,7 @@ class policylistState extends ConsumerState<policylist> {
void initState() {
super.initState();
SelectedStatus = 'All';
SelectedInsurer = '';
apiService = ApiService();
for (String field in tabHeader) {
@ -231,7 +234,7 @@ class policylistState extends ConsumerState<policylist> {
print('filterDateRange 1s');
print('manager - $managerId - userID -$userId - roledId -$roleId');
getStaffList(managerId!, userId, roleId, selectedStatus : SelectedStatus ?? 'All', selectedInsurer:selectedInsurer??'');
getStaffList(managerId!, userId, roleId, selectedStatus : SelectedStatus ?? 'All', selectedInsurer:SelectedInsurer??'');
}
print('filterDateRange 1');
}
@ -242,13 +245,13 @@ class policylistState extends ConsumerState<policylist> {
controllers['startDate']!.clear();
controllers['endDate']!.clear();
SelectedStatus ='All';
selectedInsurer = null;
SelectedInsurer = '';
controllers['startDate']?.text = '';
controllers['endDate']?.text = '';
// Reset the FormField validation
_formKey.currentState?.reset();
});
getStaffList(managerId, userId, roleId, selectedStatus : SelectedStatus ?? 'All',selectedInsurer:selectedInsurer??'');
getStaffList(managerId, userId, roleId, selectedStatus : SelectedStatus ?? 'All',selectedInsurer:SelectedInsurer??'');
}
void filterData(String query) {
@ -311,7 +314,7 @@ class policylistState extends ConsumerState<policylist> {
toDate,
searchValue,
SelectedStatus ?? 'All',
selectedInsurer ?? '',
SelectedInsurer ?? '',
);
// Map your controllers and IDs to the API parameters
// final String fromDate = controllers['startDate']!.text; // "11-01-2025"
@ -438,7 +441,7 @@ class policylistState extends ConsumerState<policylist> {
startController: controllers['startDate']!,
endController: controllers['endDate']!,
selectedStatusVal: SelectedStatus,
selectedInsurerVal : selectedInsurer,
selectedInsurerVal : SelectedInsurer,
onStatusChanged: (val) {
setState(() {
SelectedStatus = val; // update parent
@ -446,7 +449,7 @@ class policylistState extends ConsumerState<policylist> {
},
onInsurerChanged: (val) {
setState(() {
selectedInsurer = val; // update parent
SelectedInsurer = val; // update parent
});
},
formKey: _formKey,
@ -483,6 +486,7 @@ class policylistState extends ConsumerState<policylist> {
startController: controllers['startDate']!,
endController: controllers['endDate']!,
selectedStatusVal: SelectedStatus,
selectedInsurerVal : SelectedInsurer,
onStatusChanged: (val) {
setState(() {
SelectedStatus = val; // update parent
@ -490,7 +494,7 @@ class policylistState extends ConsumerState<policylist> {
},
onInsurerChanged: (val) {
setState(() {
selectedInsurer = val; // update parent
SelectedInsurer = val; // update parent
});
},
formKey: _formKey,
@ -631,7 +635,7 @@ class policylistState extends ConsumerState<policylist> {
child: Text('BDS Pushed', style: _headerStyle),
),
Expanded(flex: 2, child: Text('Action', style: _headerStyle)),
Expanded(flex: 3, child: Text('Action', style: _headerStyle)),
],
),
),
@ -757,7 +761,6 @@ class policylistState extends ConsumerState<policylist> {
style: _dataBold,
),
),
Expanded(
flex: 2,
child: Text(
@ -816,131 +819,222 @@ class policylistState extends ConsumerState<policylist> {
maxLines: 3,
),
),
// Expanded(
// flex: 3,
// child: Row(
// children: [
// Tooltip(
// message: 'Download',
// // color: Colors.white,
// child: Row(
// mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// InkWell(
// onTap: () => apiService.downloadFile(
// apiUrl:
// 'policy/downloadPolicyFile?policy_id=$policyId&file_type=policy_pdf',
// apiId: policyId,
// localFile: null,
// fileName: fileName,
// ),
//
// child: Container(
// padding: const EdgeInsets.symmetric(
// horizontal: 5,
// vertical: 3,
// ),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(5),
// // color: Color(0xFF425B5B),
// // color: const Color(0xFF2E7D6E),
// color: Colors.green,
// ),
// child: Row(
// children: const [
// Icon(
// Icons.download,
// size: 12,
// color: Colors.white,
// ),
// ],
// ),
// ),
// ),
// SizedBox(width: 10),
// InkWell(
// onTap: () {
// showAuditHistoryModal(context, item['policy_id']);
// },
// child: Container(
// padding: EdgeInsets.all(5.4),
// decoration: BoxDecoration(
// color: const Color(0xFF2E7D6E),
// // color: Color(0xFF425B5B),
// borderRadius: BorderRadius.circular(8.0),
// ),
// child: Row(
// // mainAxisSize: MainAxisSize.min,
// children: [
// Tooltip(
// message: 'Audit History Information',
// child: Icon(
// Icons.file_open_outlined,
// color: Colors.white,
// size: 12,
// ),
// ),
// ],
// ),
// ),
// ),
// ],
// ),
// ),
// if (roleId == 'Accounts') ...[
// const SizedBox(width: 5),
// Tooltip(
// message: '',
// child: InkWell(
// onTap: () {
// context.push(AppRoutes.policyValidation, extra: item);
// },
// child: Tooltip(
// message: item['is_data_accuracy_checked'] == '1'
// ? 'Verified'
// : 'To Verify',
// child: Container(
// width: 30, // FIXED WIDTH Equal in both states
// padding: const EdgeInsets.symmetric(
// horizontal: 8,
// vertical: 4,
// ),
// decoration: BoxDecoration(
// color: item['is_data_accuracy_checked'] == '1'
// ? const Color(0xFF2E7D6E)
// : Colors.redAccent,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment
// .spaceEvenly, // Center content
// children: [
// Icon(
// item['is_data_accuracy_checked'] == '1'
// ? Icons.check_circle
// : Icons.error,
// size: 12,
// color: Colors.white,
// ),
// // const SizedBox(width: 1),
// // Text(
// // item['is_data_accuracy_checked'] == '1'
// // ? 'Verified'
// // : 'To Verify',
// // style: GoogleFonts.poppins(
// // color: Colors.white,
// // fontSize: 10,
// // fontWeight: FontWeight.w500,
// // ),
// // ),
// ],
// ),
// ),
// ),
// ),
// ),
// // New Delete Iconic Button
// if (item['is_data_accuracy_checked'] == '1') ...[
// const SizedBox(width: 8), // Gap between checkmark and delete
// Tooltip(
// message: 'Delete',
// child: InkWell(
// onTap: () => _handleSoftDeleteFromList(item['policy_id'].toString()), // Pass the item here
// child: Container(
// width: 30,
// height: 24, // Matches your existing vertical padding feel
// decoration: BoxDecoration(
// color: Colors.red, // Red background
// borderRadius: BorderRadius.circular(5),
// ),
// child: const Icon(
// Icons.delete_outline,
// size: 16,
// color: Colors.white,
// ),
// ),
// ),
// ),
// ],
// ],
// ],
// ),
// ),
Expanded(
flex: 2,
flex: 3,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Tooltip(
message: 'Download',
// color: Colors.white,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () => apiService.downloadFile(
apiUrl:
'policy/downloadPolicyFile?policy_id=$policyId&file_type=policy_pdf',
apiId: policyId,
localFile: null,
fileName: fileName,
),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 3,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
// color: Color(0xFF425B5B),
// color: const Color(0xFF2E7D6E),
color: Colors.green,
),
child: Row(
children: const [
Icon(
Icons.download,
size: 12,
color: Colors.white,
),
],
),
),
),
SizedBox(width: 10),
InkWell(
onTap: () {
showAuditHistoryModal(context, item['policy_id']);
},
child: Container(
padding: EdgeInsets.all(5.4),
decoration: BoxDecoration(
color: const Color(0xFF2E7D6E),
// color: Color(0xFF425B5B),
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
// mainAxisSize: MainAxisSize.min,
children: [
Tooltip(
message: 'Audit History Information',
child: Icon(
Icons.file_open_outlined,
color: Colors.white,
size: 12,
),
),
],
),
),
),
],
// DOWNLOAD
actionButton(
icon: Icons.download,
color: Colors.green,
tooltip: 'Download',
onTap: () => apiService.downloadFile(
apiUrl: 'policy/downloadPolicyFile?policy_id=$policyId&file_type=policy_pdf',
apiId: policyId,
localFile: null,
fileName: fileName,
),
),
const SizedBox(width: 8),
// AUDIT
actionButton(
icon: Icons.file_open_outlined,
color: const Color(0xFF2E7D6E),
tooltip: 'Audit History',
onTap: () {
showAuditHistoryModal(context, item['policy_id']);
},
),
if (roleId == 'Accounts') ...[
const SizedBox(width: 5),
Tooltip(
message: '',
child: InkWell(
onTap: () {
context.push(AppRoutes.policyValidation, extra: item);
},
child: Tooltip(
message: item['is_data_accuracy_checked'] == '1'
? 'Verified'
: 'To Verify',
child: Container(
width: 30, // FIXED WIDTH Equal in both states
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: item['is_data_accuracy_checked'] == '1'
? const Color(0xFF2E7D6E)
: Colors.redAccent,
borderRadius: BorderRadius.circular(5),
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment
.spaceEvenly, // Center content
children: [
Icon(
item['is_data_accuracy_checked'] == '1'
? Icons.check_circle
: Icons.error,
size: 12,
color: Colors.white,
),
// const SizedBox(width: 1),
// Text(
// item['is_data_accuracy_checked'] == '1'
// ? 'Verified'
// : 'To Verify',
// style: GoogleFonts.poppins(
// color: Colors.white,
// fontSize: 10,
// fontWeight: FontWeight.w500,
// ),
// ),
],
),
),
const SizedBox(width: 8),
// VERIFY / TO VERIFY
actionButton(
icon: item['is_data_accuracy_checked'] == '1'
? Icons.check_circle
: Icons.error,
color: item['is_data_accuracy_checked'] == '1'
? const Color(0xFF2E7D6E)
: Colors.redAccent,
tooltip: item['is_data_accuracy_checked'] == '1'
? 'Verified'
: 'To Verify',
onTap: () {
context.push(AppRoutes.policyValidation, extra: item);
},
),
// DELETE (only if verified)
if (item['is_data_accuracy_checked'] == '0') ...[
const SizedBox(width: 8),
actionButton(
icon: Icons.delete_outline,
color: Colors.red,
tooltip: 'Delete',
onTap: () => _handleSoftDeleteFromList(
item['policy_id'].toString(),
),
),
),
],
],
],
),
@ -1136,6 +1230,89 @@ class policylistState extends ConsumerState<policylist> {
);
}
Widget actionButton({
required IconData icon,
required Color color,
required VoidCallback onTap,
String? tooltip,
}) {
return Tooltip(
message: tooltip ?? '',
child: InkWell(
onTap: onTap,
child: Container(
width: 26, // SIZE MATCH
height: 22, // SIZE MATCH
alignment: Alignment.center,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(5), // RADIUS
),
child: Icon(
icon,
size: 12, // ICON SIZE
color: Colors.white,
),
),
),
);
}
Future<void> _handleSoftDeleteFromList(String policyId) async {
// 1. Confirmation Dialog
bool confirm = await showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text("Confirm Delete"),
content: const Text("Are you sure you want to remove this policy?"),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text("Cancel")),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text("Delete", style: TextStyle(color: Colors.red)),
),
],
),
) ?? false;
if (!confirm) return;
// 2. Start Loading
setState(() => isLoading = true);
try {
final response = await apiService.softDeletePolicyApi(policyId);
// If status is 'success' or 'not exists' (expired/deleted)
if (response['status'] == 'success' || response['status'] == 'not exists') {
ToastHelper.showSuccessToast(
context,
response['message']?.toString() ?? 'Policy deleted successfully',
);
// 3. Refresh the List using your existing refresh()
refresh();
} else {
// Handle the 'exists' status from your PHP
ToastHelper.showErrorToast(
context,
response['message']?.toString() ?? 'Unable to delete policy',
);
}
} catch (e) {
ToastHelper.showErrorToast(
context,
'Connection Error: ${e.toString()}',
);
} finally {
if (mounted) {
setState(() => isLoading = false);
}
}
}
static final _dataBold = GoogleFonts.inter(
fontSize: 11,

View File

@ -55,6 +55,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
bool highlightDocBroker = false;
String? enqBroker; // Stores the NAME of the enquiry broker
final ValueNotifier<bool> brokerMismatchNotifier = ValueNotifier<bool>(false);
final ValueNotifier<bool> isDeletingNotifier = ValueNotifier<bool>(false);
// --- Controllers (all editable fields)
final List<String> controllerKeys = [
@ -1164,7 +1165,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
print('_fetchCommision OUT');
}
Widget buildVehicleType(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -1388,8 +1388,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
);
}
Widget buildBrokerAsPerEnquiry(BuildContext context, String EnqID) {
// 1. Find the currently selected broker object from your list
final Map<String, dynamic>? selectedBrokers = selectedBroker != null
@ -1591,6 +1589,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
],
);
}
Widget buildVehicleTypeAsPerEnquiry(BuildContext context) {
final Map<String, dynamic>? selectedVehicle =
selectedVehicleTypeForEnquiryID != null
@ -1814,7 +1813,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
);
}
Widget _sectionHeader(String title, {IconData icon = Icons.info , String? rightTitle,}) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),