FIX_minor issues fixes

This commit is contained in:
sanjeev.p 2025-12-22 18:00:58 +05:30
parent a52b8d6c04
commit 4d9ecae17d
7 changed files with 247 additions and 85 deletions

File diff suppressed because one or more lines are too long

View File

@ -656,7 +656,7 @@ class ApiService {
} else if (role == 'staff') { } else if (role == 'staff') {
url = Uri.parse('${Env.apiUrl}staff/changeStaffStatus'); url = Uri.parse('${Env.apiUrl}staff/changeStaffStatus');
} else { } else {
url = Uri.parse('${Env.apiUrl}/api/agent/changeAgentStatus'); url = Uri.parse('${Env.apiUrl}agent/changeAgentStatus');
} }
// final token = await getToken(); // Fetch token // final token = await getToken(); // Fetch token

View File

@ -219,7 +219,10 @@ class AgentState extends ConsumerState<Agent> {
} }
Future<void> createUserData(Map<String, dynamic> userData) async { Future<void> createUserData(Map<String, dynamic> userData) async {
final bool isUpdating = widget.id != null && widget.id != 'create';
final String cleanedId = widget.id?.toString().replaceAll(' ', '').toUpperCase() ?? '';
final bool isUpdating = cleanedId.isNotEmpty && cleanedId != 'CREATE' && cleanedId != '0';
final id = widget.id; final id = widget.id;
final uri = Uri.parse( final uri = Uri.parse(
// isUpdating // isUpdating

View File

@ -133,6 +133,7 @@ class StaffListState extends ConsumerState<StaffList> {
(item['email'] ?? '').toString().toLowerCase().contains(q) || (item['email'] ?? '').toString().toLowerCase().contains(q) ||
(item['mobile'] ?? '').toString().toLowerCase().contains(q) || (item['mobile'] ?? '').toString().toLowerCase().contains(q) ||
(item['address'] ?? '').toString().toLowerCase().contains(q) || (item['address'] ?? '').toString().toLowerCase().contains(q) ||
(item['role'] ?? '').toString().toLowerCase().contains(q) ||
(item['emp_id'] ?? item['agent_code'] ?? '') (item['emp_id'] ?? item['agent_code'] ?? '')
.toString() .toString()
.toLowerCase() .toLowerCase()

View File

@ -479,9 +479,11 @@ class CreateProposal_QuickFormState
} }
void addQuotationRow() { void addQuotationRow() {
String amountText = controllers["premium_Amount"]?.text ?? "";
double? amount = double.tryParse(amountText);
if (selectedInsurer != null && if (selectedInsurer != null &&
selectedInsPlanType != null && selectedInsPlanType != null &&
controllers["premium_Amount"]?.text.isNotEmpty == true) { amount != null && amount > 0) {
setState(() { setState(() {
quotationList.add({ quotationList.add({
"insurer_id": selectedInsurer, "insurer_id": selectedInsurer,
@ -502,6 +504,10 @@ class CreateProposal_QuickFormState
if (isSingleSave) { if (isSingleSave) {
handleDone(); handleDone();
} }
} else {
print('Please enter a valid Premium Amount greater than 0');
ToastHelper.showErrorToast(context, 'Please enter a valid Premium Amount');
return; // stop execution
} }
} }

View File

@ -1221,46 +1221,48 @@ class AuditHistoryModalState extends ConsumerState<AuditHistoryModal> {
: getAuditHistoryData.isEmpty : getAuditHistoryData.isEmpty
? const Center(child: Text("No Audit History Data Found")) ? const Center(child: Text("No Audit History Data Found"))
: SingleChildScrollView( : SingleChildScrollView(
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
child: Theme( child: SizedBox(
data: Theme.of(context).copyWith( width: double.infinity,
dividerColor: Colors.grey.shade200, child: Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.grey.shade200,
),
child: DataTable(
headingRowColor: WidgetStateProperty.all(Color(0xFFF8FAFC)),
columnSpacing: 20,
columns: [
DataColumn(label: Text("Column Name", style: _headerStyle())),
DataColumn(label: Text("Message", style: _headerStyle())),
DataColumn(label: Text("Changed On", style: _headerStyle())),
DataColumn(label: Text("Changed By", style: _headerStyle())),
],
// Inside your build method's DataTable
rows: getAuditHistoryData.map((data) {
return DataRow(cells: [
DataCell(Text(data['column_name'] ?? "-", style: _cellStyle())),
DataCell(
SizedBox(
width: 300, // Give message more width
child: Text(
data['message'] ?? "-",
style: _cellStyle(),
softWrap: true, // Ensure text wraps to next line
),
)
),
DataCell(Text(
formatIndianDate(data['changed_on'] ?? ""),
style: _cellStyle(),
)),
DataCell(Text(data['changed_by'] ?? "-", style: _cellStyle())),
]);
}).toList(),
),
),
),
), ),
child: DataTable( )
headingRowColor: WidgetStateProperty.all(Color(0xFFF8FAFC)),
columnSpacing: 20,
columns: [
DataColumn(label: Text("Column Name", style: _headerStyle())),
DataColumn(label: Text("Message", style: _headerStyle())),
DataColumn(label: Text("Changed On", style: _headerStyle())),
DataColumn(label: Text("Changed By", style: _headerStyle())),
],
// Inside your build method's DataTable
rows: getAuditHistoryData.map((data) {
return DataRow(cells: [
DataCell(Text(data['column_name'] ?? "-", style: _cellStyle())),
DataCell(
SizedBox(
width: 300, // Give message more width
child: Text(
data['message'] ?? "-",
style: _cellStyle(),
softWrap: true, // Ensure text wraps to next line
),
)
),
DataCell(Text(
formatIndianDate(data['changed_on'] ?? ""),
style: _cellStyle(),
)),
DataCell(Text(data['changed_by'] ?? "-", style: _cellStyle())),
]);
}).toList(),
),
),
),
),
], ],
), ),
), ),

View File

@ -260,8 +260,13 @@ class _policyValidationState extends ConsumerState<policyValidation> {
getFuelType(); getFuelType();
getPolicyFilePath(); getPolicyFilePath();
}); });
controllers['commission_amount']?.addListener(() {
setState(() {});
});
} }
@override @override
void dispose() { void dispose() {
for (final controller in controllers.values) { for (final controller in controllers.values) {
@ -548,9 +553,9 @@ class _policyValidationState extends ConsumerState<policyValidation> {
} }
Future<void> _fetchCommision() async { Future<void> _fetchCommision() async {
print('_fetchCommision'); print('_fetchCommision IN');
final policyId = widget.item?['policy_id']; final policyId = widget.item?['policy_id'];
final payload = buildCommissionPayload();
if (policyId == null) { if (policyId == null) {
ToastHelper.showWarningToast(context, 'Missing policy id'); ToastHelper.showWarningToast(context, 'Missing policy id');
return; return;
@ -573,7 +578,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
// ...dataDetails(), // ...dataDetails(),
// // "insurance_plan_type": // // "insurance_plan_type":
// }; // };
print('_fetchCommision1'); // print('_fetchCommision1');
// setState(() { // setState(() {
// isLoading = true; // isLoading = true;
// payload['insurance_plan_type'] = selectedInsurancPlanType; // payload['insurance_plan_type'] = selectedInsurancPlanType;
@ -583,23 +588,37 @@ class _policyValidationState extends ConsumerState<policyValidation> {
// print('payload2 - ${payload['insurance_plan_type']}'); // print('payload2 - ${payload['insurance_plan_type']}');
// print('payload - $payload'); // print('payload - $payload');
// }); // });
print('_fetchCommision2'); // print('_fetchCommision2');
// 👉 CRITICAL FIX: Set loading to true BEFORE the API call starts
setState(() { isLoading = true; });
try { try {
debugPrint('FINAL SAVE PAYLOAD 1=> $payload');
final payload = buildCommissionPayload();
debugPrint('Payload in fetchCommission: $payload');
final result = await apiService.calculateCommissionRequest(payload); final result = await apiService.calculateCommissionRequest(payload);
debugPrint('updatePolicy result => $result'); debugPrint('Result in fetchCommission: $result');
if (result != null && result['status'] == 'success') { if (result != null && result['status'] == 'success') {
if (!mounted) return; if (!mounted) return;
setState(() => isLoading = false); // setState(() => isLoading = false);
// context.pop(); // context.pop();
ToastHelper.showSuccessToast(context, "Policy updated successfully");
// Extract commission_amount from response // Extract commission_amount from response
final commissionAmount = result['data']?['commission_amount']; final commissionAmount = result['data']?['commission_amount'];
if (commissionAmount != null) {
controllers["commission_amount"]?.text = commissionAmount setState(() {
.toStringAsFixed(2); isLoading = false; // Stop loading
} if (commissionAmount != null) {
// Update controller so the Confirm button becomes active
controllers["commission_amount"]?.text =
double.parse(commissionAmount.toString()).toStringAsFixed(2);
}
});
ToastHelper.showSuccessToast(context, "Commission calculated successfully");
// WidgetsBinding.instance.addPostFrameCallback((_) { // WidgetsBinding.instance.addPostFrameCallback((_) {
// // Now safe to do navigation + provider updates // // Now safe to do navigation + provider updates
@ -612,17 +631,98 @@ class _policyValidationState extends ConsumerState<policyValidation> {
setState(() => isLoading = false); setState(() => isLoading = false);
ToastHelper.showErrorToast( ToastHelper.showErrorToast(
context, context,
result?['message']?.toString() ?? 'Error updating policy', result?['message']?.toString() ?? 'Error calculating commission',
); );
} }
} catch (e, st) { } catch (e, st) {
debugPrint('Exception in updatePolicy: $e\n$st'); debugPrint('Exception in fetchCommission: $e\n$st');
if (!mounted) return; if (!mounted) return;
setState(() => isLoading = false); setState(() => isLoading = false);
ToastHelper.showWarningToast(context, 'Exception: $e'); ToastHelper.showWarningToast(context, 'Exception: $e');
} }
print('_fetchCommision OUT');
} }
// Old Code For Backup purpose
// Future<void> _fetchCommision() async {
// print('_fetchCommision');
// final policyId = widget.item?['policy_id'];
// final payload = buildCommissionPayload();
// if (policyId == null) {
// ToastHelper.showWarningToast(context, 'Missing policy id');
// return;
// }
//
// if (!_formKey.currentState!.validate()) {
// ToastHelper.showWarningToast(context, "Please fill all required fields");
// return;
// }
//
// // if (widget.item?['is_data_accuracy_checked'] == "1") {
// // ToastHelper.showWarningToast(context, "Data already confirmed");
// // return;
// // }
//
// // final payload = {
// // "id": policyId,
// // 'insurance_plan_type': controllers['insurance_plan_type'],
// // "updated_by": userId,
// // ...dataDetails(),
// // // "insurance_plan_type":
// // };
// print('_fetchCommision1');
// // setState(() {
// // isLoading = true;
// // payload['insurance_plan_type'] = selectedInsurancPlanType;
// // payload['insurer_id'] = selectedInsuranceId;
// // payload['id'] = policyId;
// // payload['updated_by'] = userId;
// // print('payload2 - ${payload['insurance_plan_type']}');
// // print('payload - $payload');
// // });// debugPrint('FINAL SAVE PAYLOAD 1=> $payload');
// final result = await apiService.calculateCommissionRequest(payload);
// debugPrint('updatePolicy result => $result');
// print('_fetchCommision2');
// try {
// debugPrint('FINAL SAVE PAYLOAD 1=> $payload');
// final result = await apiService.calculateCommissionRequest(payload);
// debugPrint('updatePolicy result => $result');
//
// if (result != null && result['status'] == 'success') {
// if (!mounted) return;
// setState(() => isLoading = false);
// // context.pop();
// ToastHelper.showSuccessToast(context, "Policy updated successfully");
// // Extract commission_amount from response
// final commissionAmount = result['data']?['commission_amount'];
// if (commissionAmount != null) {
// controllers["commission_amount"]?.text = commissionAmount
// .toStringAsFixed(2);
// }
//
// // WidgetsBinding.instance.addPostFrameCallback((_) {
// // // Now safe to do navigation + provider updates
// // final container = ProviderScope.containerOf(context);
// // container.read(policyDataAcurancyRefreshProvider.notifier).state =
// // true;
// // });
// } else {
// if (!mounted) return;
// setState(() => isLoading = false);
// ToastHelper.showErrorToast(
// context,
// result?['message']?.toString() ?? 'Error updating policy',
// );
// }
// } catch (e, st) {
// debugPrint('Exception in updatePolicy: $e\n$st');
// if (!mounted) return;
// setState(() => isLoading = false);
// ToastHelper.showWarningToast(context, 'Exception: $e');
// }
// }
Widget buildVehicleType(BuildContext context) { Widget buildVehicleType(BuildContext context) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -919,34 +1019,19 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.end, // 👉 move button to right mainAxisAlignment: MainAxisAlignment.end, // 👉 move button to right
children: [ children: [
ElevatedButton(
onPressed: widget.item?['is_data_accuracy_checked'] == '1'
? null
: _fetchCommision,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2E7D6E),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 20, // 👉 smaller width
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'Fetch Commission',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
),
),
SizedBox(width: 10),
ElevatedButton( ElevatedButton(
// onPressed: widget.item?['is_data_accuracy_checked'] == '1' // onPressed: widget.item?['is_data_accuracy_checked'] == '1'
onPressed: // onPressed:
widget.item?['is_data_accuracy_checked'] != '1' || // widget.item?['is_data_accuracy_checked'] != '1' ||
(controllers['commission_amount']?.text.isEmpty ?? true) // (controllers['commission_amount']?.text.isEmpty ?? true)
? null // ? null
: _save, // : _save,
onPressed: (
widget.item?['is_data_accuracy_checked']?.toString() == '0' &&
((double.tryParse(controllers["commission_amount"]?.text ?? '0') ?? 0).floor() >= 1)
)
? _save
: null,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2E7D6E), backgroundColor: const Color(0xFF2E7D6E),
foregroundColor: Colors.white, foregroundColor: Colors.white,
@ -958,11 +1043,57 @@ class _policyValidationState extends ConsumerState<policyValidation> {
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
), ),
child: const Text( child: Text(
'Confirm Data Accuracy', 'Confirm Data Accuracy ',
// '(${controllers["commission_amount"]?.text ?? '0'} | '
// '${widget.item?['is_data_accuracy_checked'] ?? '0'})',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600), style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
), ),
), ),
// ElevatedButton(
// onPressed: widget.item?['is_data_accuracy_checked'] == '1'
// ? null
// : _fetchCommision,
// style: ElevatedButton.styleFrom(
// backgroundColor: const Color(0xFF2E7D6E),
// foregroundColor: Colors.white,
// padding: const EdgeInsets.symmetric(
// vertical: 10,
// horizontal: 20, // 👉 smaller width
// ),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(8),
// ),
// ),
// child: const Text(
// 'Fetch Commission',
// style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
// ),
// ),
// SizedBox(width: 10),
// ElevatedButton(
// // onPressed: widget.item?['is_data_accuracy_checked'] == '1'
// onPressed:
// widget.item?['is_data_accuracy_checked'] != '1' ||
// (controllers['commission_amount']?.text.isEmpty ?? true)
// ? null
// : _save,
// style: ElevatedButton.styleFrom(
// backgroundColor: const Color(0xFF2E7D6E),
// foregroundColor: Colors.white,
// padding: const EdgeInsets.symmetric(
// vertical: 10,
// horizontal: 20, // 👉 smaller width
// ),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(8),
// ),
// ),
// child: const Text(
// 'Confirm Data Accuracy',
// style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
// ),
// ),
], ],
), ),
), ),
@ -1549,6 +1680,25 @@ class _policyValidationState extends ConsumerState<policyValidation> {
), ),
], ],
), ),
Row(
mainAxisAlignment: MainAxisAlignment.end, // Pushes children to the right
children: [
TextButton(
onPressed: (widget.item?['is_data_accuracy_checked'] == '1' || isLoading)
? null // Disable if already checked or currently loading
: _fetchCommision,
child: Text(isLoading ? "Calculating..." : "Calculate",
style: TextStyle(
color: (widget.item?['is_data_accuracy_checked'] == '1' || isLoading)
? Colors.grey
: const Color(0xFF2E7D6E),
fontWeight: FontWeight.bold,
)
),
),
],
)
], ],
), ),
), ),