added validation for payment request in and expense reumbersemrnt bottomsheet

This commit is contained in:
Vaibhav Surve 2025-11-12 11:23:13 +05:30
parent be2f97cc0e
commit 5db53c29df
5 changed files with 392 additions and 184 deletions

View File

@ -142,6 +142,10 @@ class ExpenseDetailController extends GetxController {
required String reimburseDate, required String reimburseDate,
required String reimburseById, required String reimburseById,
required String statusId, required String statusId,
double? baseAmount,
double? taxAmount,
double? tdsPercent,
double? netPayable,
}) async { }) async {
final success = await _apiCallWrapper( final success = await _apiCallWrapper(
() => ApiService.updateExpenseStatusApi( () => ApiService.updateExpenseStatusApi(
@ -151,13 +155,16 @@ class ExpenseDetailController extends GetxController {
reimburseTransactionId: reimburseTransactionId, reimburseTransactionId: reimburseTransactionId,
reimburseDate: reimburseDate, reimburseDate: reimburseDate,
reimbursedById: reimburseById, reimbursedById: reimburseById,
baseAmount: baseAmount,
taxAmount: taxAmount,
tdsPercent: tdsPercent,
netPayable: netPayable,
), ),
"submit reimbursement", "submit reimbursement",
); );
if (success == true) { if (success == true) {
// Explicitly check for true as _apiCallWrapper returns T? await fetchExpenseDetails();
await fetchExpenseDetails(); // Refresh details after successful update
return true; return true;
} else { } else {
errorMessage.value = "Failed to submit reimbursement."; errorMessage.value = "Failed to submit reimbursement.";

View File

@ -1705,34 +1705,32 @@ class ApiService {
String? reimburseTransactionId, String? reimburseTransactionId,
String? reimburseDate, String? reimburseDate,
String? reimbursedById, String? reimbursedById,
double? baseAmount,
double? taxAmount,
double? tdsPercent,
double? netPayable,
}) async { }) async {
final Map<String, dynamic> payload = { final Map<String, dynamic> payload = {
"expenseId": expenseId, "expenseId": expenseId,
"statusId": statusId, "statusId": statusId,
}; };
if (comment != null) { if (comment != null) payload["comment"] = comment;
payload["comment"] = comment; if (reimburseTransactionId != null)
}
if (reimburseTransactionId != null) {
payload["reimburseTransactionId"] = reimburseTransactionId; payload["reimburseTransactionId"] = reimburseTransactionId;
} if (reimburseDate != null) payload["reimburseDate"] = reimburseDate;
if (reimburseDate != null) { if (reimbursedById != null) payload["reimburseById"] = reimbursedById;
payload["reimburseDate"] = reimburseDate; if (baseAmount != null) payload["baseAmount"] = baseAmount;
} if (taxAmount != null) payload["taxAmount"] = taxAmount;
if (reimbursedById != null) { if (tdsPercent != null) payload["tdsPercent"] = tdsPercent;
payload["reimburseById"] = reimbursedById; if (netPayable != null) payload["netPayable"] = netPayable;
}
const endpoint = ApiEndpoints.updateExpenseStatus; const endpoint = ApiEndpoints.updateExpenseStatus;
logSafe("Updating expense status with payload: $payload"); logSafe("Updating expense status with payload: $payload");
try { try {
final response = await _postRequest( final response =
endpoint, await _postRequest(endpoint, payload, customTimeout: extendedTimeout);
payload,
customTimeout: extendedTimeout,
);
if (response == null) { if (response == null) {
logSafe("Update expense status failed: null response", logSafe("Update expense status failed: null response",

View File

@ -20,6 +20,10 @@ class ReimbursementBottomSheet extends StatefulWidget {
required String reimburseDate, required String reimburseDate,
required String reimburseById, required String reimburseById,
required String statusId, required String statusId,
required double baseAmount,
required double taxAmount,
required double tdsPercent,
required double netPayable,
}) onSubmit; }) onSubmit;
const ReimbursementBottomSheet({ const ReimbursementBottomSheet({
@ -41,15 +45,44 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
final TextEditingController commentCtrl = TextEditingController(); final TextEditingController commentCtrl = TextEditingController();
final TextEditingController txnCtrl = TextEditingController(); final TextEditingController txnCtrl = TextEditingController();
final TextEditingController baseAmountCtrl = TextEditingController();
final TextEditingController gstAmountCtrl = TextEditingController();
final TextEditingController tdsCtrl = TextEditingController(text: '0');
final RxString dateStr = ''.obs; final RxString dateStr = ''.obs;
final RxDouble tdsAmount = 0.0.obs;
final RxDouble netPayable = 0.0.obs;
@override
void initState() {
super.initState();
baseAmountCtrl.addListener(_recalculate);
gstAmountCtrl.addListener(_recalculate);
tdsCtrl.addListener(_recalculate);
}
@override @override
void dispose() { void dispose() {
commentCtrl.dispose(); commentCtrl.dispose();
txnCtrl.dispose(); txnCtrl.dispose();
baseAmountCtrl.dispose();
gstAmountCtrl.dispose();
tdsCtrl.dispose();
super.dispose(); super.dispose();
} }
void _recalculate() {
final double base = double.tryParse(baseAmountCtrl.text.trim()) ?? 0.0;
final double gst = double.tryParse(gstAmountCtrl.text.trim()) ?? 0.0;
final double tdsPercent = double.tryParse(tdsCtrl.text.trim()) ?? 0.0;
final double calculatedTds = (base * tdsPercent) / 100;
final double net = (base + gst) - calculatedTds;
tdsAmount.value = double.parse(calculatedTds.toStringAsFixed(2));
netPayable.value = double.parse(net.toStringAsFixed(2));
}
void _showEmployeeList() async { void _showEmployeeList() async {
await showModalBottomSheet( await showModalBottomSheet(
context: context, context: context,
@ -67,7 +100,6 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
), ),
); );
// Optional cleanup
controller.employeeSearchController.clear(); controller.employeeSearchController.clear();
controller.employeeSearchResults.clear(); controller.employeeSearchResults.clear();
} }
@ -94,6 +126,29 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
); );
} }
Widget _readOnlyValueBox(String label, String value, Color color) {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 16),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
border: Border.all(color: color.withOpacity(0.3)),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyText.labelMedium(label),
MyText.bodyMedium(
"$value",
color: color,
fontWeight: 700,
),
],
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Obx(() { return Obx(() {
@ -105,31 +160,73 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
Navigator.pop(context); Navigator.pop(context);
}, },
onSubmit: () async { onSubmit: () async {
final expenseTransactionDateStr =
controller.expense.value?.transactionDate;
DateTime? expenseTransactionDate;
if (expenseTransactionDateStr != null) {
try {
expenseTransactionDate =
DateTime.parse(expenseTransactionDateStr);
} catch (_) {}
}
if (commentCtrl.text.trim().isEmpty || if (commentCtrl.text.trim().isEmpty ||
txnCtrl.text.trim().isEmpty ||
dateStr.value.isEmpty || dateStr.value.isEmpty ||
controller.selectedReimbursedBy.value == null) { controller.selectedReimbursedBy.value == null ||
baseAmountCtrl.text.trim().isEmpty ||
gstAmountCtrl.text.trim().isEmpty) {
showAppSnackbar( showAppSnackbar(
title: "Incomplete", title: "Incomplete",
message: "Please fill all fields", message: "Please fill all required fields",
type: SnackbarType.warning, type: SnackbarType.warning,
); );
return; return;
} }
// Validate reimbursement date
final DateTime? selectedDate = DateTime.tryParse(dateStr.value);
if (selectedDate != null) {
final now = DateTime.now();
if (selectedDate.isAfter(now)) {
showAppSnackbar(
title: "Invalid Date",
message: "Reimbursement date cannot be in the future.",
type: SnackbarType.warning,
);
return;
}
if (expenseTransactionDate != null &&
selectedDate.isBefore(expenseTransactionDate)) {
showAppSnackbar(
title: "Invalid Date",
message:
"Reimbursement date cannot be before the transaction date (${DateFormat('yyyy-MM-dd').format(expenseTransactionDate)}).",
type: SnackbarType.warning,
);
return;
}
}
final success = await widget.onSubmit( final success = await widget.onSubmit(
comment: commentCtrl.text.trim(), comment: commentCtrl.text.trim(),
reimburseTransactionId: txnCtrl.text.trim(), reimburseTransactionId: txnCtrl.text
.trim(),
reimburseDate: dateStr.value, reimburseDate: dateStr.value,
reimburseById: controller.selectedReimbursedBy.value!.id, reimburseById: controller.selectedReimbursedBy.value!.id,
statusId: widget.statusId, statusId: widget.statusId,
baseAmount: double.tryParse(baseAmountCtrl.text.trim()) ?? 0,
taxAmount: double.tryParse(gstAmountCtrl.text.trim()) ?? 0,
tdsPercent: double.tryParse(tdsCtrl.text.trim()) ?? 0,
netPayable: netPayable.value,
); );
if (success) { if (success) {
Get.back(); Get.back();
showAppSnackbar( showAppSnackbar(
title: "Success", title: "Success",
message: "Reimbursement submitted", message: "Reimbursement submitted successfully",
type: SnackbarType.success, type: SnackbarType.success,
); );
} else { } else {
@ -140,76 +237,152 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
); );
} }
}, },
child: Column( child: SingleChildScrollView(
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
MyText.labelMedium("Comment"), children: [
MySpacing.height(8), MyText.labelMedium("Transaction ID*"),
TextField( MySpacing.height(8),
controller: commentCtrl, TextField(
decoration: _inputDecoration("Enter comment"), controller: txnCtrl,
), decoration: _inputDecoration("Enter transaction ID"),
MySpacing.height(16), ),
MyText.labelMedium("Transaction ID"), MySpacing.height(16),
MySpacing.height(8), MyText.labelMedium("Reimbursement Date*"),
TextField( MySpacing.height(8),
controller: txnCtrl, GestureDetector(
decoration: _inputDecoration("Enter transaction ID"), onTap: () async {
), // Get transaction date from expense
MySpacing.height(16), DateTime? transactionDate;
MyText.labelMedium("Reimbursement Date"), if (controller.expense.value?.transactionDate != null) {
MySpacing.height(8), try {
GestureDetector( transactionDate = DateTime.parse(
onTap: () async { controller.expense.value!.transactionDate);
final picked = await showDatePicker( } catch (_) {
context: context, transactionDate = null;
initialDate: dateStr.value.isEmpty }
? DateTime.now() }
: DateFormat('yyyy-MM-dd').parse(dateStr.value),
firstDate: DateTime(2020), final DateTime now = DateTime.now();
lastDate: DateTime(2100), final DateTime firstDate =
); transactionDate ?? DateTime(2020); // fallback if null
if (picked != null) { final DateTime lastDate = now;
dateStr.value = DateFormat('yyyy-MM-dd').format(picked);
} final picked = await showDatePicker(
}, context: context,
child: AbsorbPointer( initialDate: now.isBefore(firstDate)
child: TextField( ? firstDate
controller: TextEditingController(text: dateStr.value), : now, // initial date inside the range
decoration: _inputDecoration("Select Date").copyWith( firstDate: firstDate,
suffixIcon: const Icon(Icons.calendar_today), lastDate: lastDate,
);
if (picked != null) {
dateStr.value = DateFormat('yyyy-MM-dd').format(picked);
}
},
child: AbsorbPointer(
child: TextField(
controller: TextEditingController(text: dateStr.value),
decoration: _inputDecoration("Select Date").copyWith(
suffixIcon: const Icon(Icons.calendar_today),
),
), ),
), ),
), ),
), MySpacing.height(16),
MySpacing.height(16), MyText.labelMedium("Reimbursed By*"),
MyText.labelMedium("Reimbursed By"), MySpacing.height(8),
MySpacing.height(8), GestureDetector(
GestureDetector( onTap: _showEmployeeList,
onTap: _showEmployeeList, child: Container(
child: Container( padding:
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
const EdgeInsets.symmetric(horizontal: 16, vertical: 14), decoration: BoxDecoration(
decoration: BoxDecoration( color: Colors.grey.shade100,
color: Colors.grey.shade100, borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(12), border: Border.all(color: Colors.grey.shade300),
border: Border.all(color: Colors.grey.shade300), ),
), child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [ Text(
Text( controller.selectedReimbursedBy.value == null
controller.selectedReimbursedBy.value == null ? "Select Paid By"
? "Select Paid By" : '${controller.selectedReimbursedBy.value?.firstName ?? ''} ${controller.selectedReimbursedBy.value?.lastName ?? ''}',
: '${controller.selectedReimbursedBy.value?.firstName ?? ''} ${controller.selectedReimbursedBy.value?.lastName ?? ''}', style: const TextStyle(fontSize: 14),
style: const TextStyle(fontSize: 14), ),
), const Icon(Icons.arrow_drop_down, size: 22),
const Icon(Icons.arrow_drop_down, size: 22), ],
], ),
), ),
), ),
), MySpacing.height(16),
], MyText.labelMedium("Base Amount*"),
MySpacing.height(8),
TextField(
controller: baseAmountCtrl,
keyboardType: TextInputType.number,
decoration: _inputDecoration("Enter Base Amount"),
),
MySpacing.height(16),
MyText.labelMedium("GST Amount*"),
MySpacing.height(8),
TextField(
controller: gstAmountCtrl,
keyboardType: TextInputType.number,
decoration: _inputDecoration("Enter GST Amount"),
),
MySpacing.height(16),
MyText.labelMedium("TDS Percent"),
MySpacing.height(8),
TextField(
controller: tdsCtrl,
keyboardType: TextInputType.number,
decoration: _inputDecoration("Enter TDS Percent").copyWith(
suffixIcon: Padding(
padding: const EdgeInsets.only(right: 12),
child: Icon(Icons.percent,
size: 20, color: Colors.grey.shade600),
),
suffixIconConstraints:
const BoxConstraints(minWidth: 0, minHeight: 0),
),
onChanged: (_) => _recalculate(),
),
MySpacing.height(4),
MyText.bodySmall(
"TDS is applied on base amount only.",
color: Colors.grey.shade600,
),
MySpacing.height(16),
Obx(() => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_readOnlyValueBox(
"TDS Amount",
tdsAmount.value.toStringAsFixed(2),
Colors.orange,
),
MySpacing.height(12),
_readOnlyValueBox(
"Net Payable",
netPayable.value.toStringAsFixed(2),
Colors.green,
),
],
)),
MySpacing.height(16),
MyText.labelMedium("Comment*"),
MySpacing.height(8),
TextField(
controller: commentCtrl,
maxLines: 2,
decoration: _inputDecoration("Enter comment"),
),
MySpacing.height(16),
],
),
), ),
); );
}); });

View File

@ -117,6 +117,21 @@ class _UpdatePaymentRequestWithReimbursementState
); );
} }
Widget _requiredLabel(String label) {
return RichText(
text: TextSpan(
text: label,
style: MyTextStyle.labelMedium(),
children: const [
TextSpan(
text: ' *',
style: TextStyle(color: Colors.red),
),
],
),
);
}
Widget _readOnlyValueBox(String label, String value, Color color) { Widget _readOnlyValueBox(String label, String value, Color color) {
return Container( return Container(
width: double.infinity, width: double.infinity,
@ -151,11 +166,11 @@ class _UpdatePaymentRequestWithReimbursementState
Navigator.pop(context); Navigator.pop(context);
}, },
onSubmit: () async { onSubmit: () async {
if (commentCtrl.text.trim().isEmpty || if (txnCtrl.text.trim().isEmpty ||
txnCtrl.text.trim().isEmpty ||
dateStr.value.isEmpty || dateStr.value.isEmpty ||
baseAmountCtrl.text.trim().isEmpty || baseAmountCtrl.text.trim().isEmpty ||
taxAmountCtrl.text.trim().isEmpty) { taxAmountCtrl.text.trim().isEmpty ||
commentCtrl.text.trim().isEmpty) {
showAppSnackbar( showAppSnackbar(
title: "Incomplete", title: "Incomplete",
message: "Please fill all mandatory fields", message: "Please fill all mandatory fields",
@ -199,8 +214,7 @@ class _UpdatePaymentRequestWithReimbursementState
Get.close(1); Get.close(1);
} }
} }
} catch (e, st) { } catch (e) {
print("Error updating payment: $e\n$st");
showAppSnackbar( showAppSnackbar(
title: 'Error', title: 'Error',
message: 'Something went wrong. Please try again.', message: 'Something went wrong. Please try again.',
@ -212,7 +226,7 @@ class _UpdatePaymentRequestWithReimbursementState
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
MyText.labelMedium("Transaction ID*"), _requiredLabel("Transaction ID"),
MySpacing.height(8), MySpacing.height(8),
TextField( TextField(
controller: txnCtrl, controller: txnCtrl,
@ -220,16 +234,24 @@ class _UpdatePaymentRequestWithReimbursementState
), ),
MySpacing.height(16), MySpacing.height(16),
MyText.labelMedium("Transaction Date*"), _requiredLabel("Transaction Date"),
MySpacing.height(8), MySpacing.height(8),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
final DateTime submittedDate =
controller.paymentRequest.value?.createdAt ??
DateTime.now();
final DateTime today = DateTime.now();
final picked = await showDatePicker( final picked = await showDatePicker(
context: context, context: context,
initialDate: DateTime.now(), initialDate:
firstDate: DateTime(2020), today.isBefore(submittedDate) ? submittedDate : today,
lastDate: DateTime.now(), firstDate: submittedDate,
lastDate: today,
helpText: 'Select Transaction Date',
); );
if (picked != null) { if (picked != null) {
dateStr.value = DateFormat('dd-MM-yyyy').format(picked); dateStr.value = DateFormat('dd-MM-yyyy').format(picked);
} }
@ -273,7 +295,7 @@ class _UpdatePaymentRequestWithReimbursementState
), ),
MySpacing.height(16), MySpacing.height(16),
MyText.labelMedium("Base Amount"), _requiredLabel("Base Amount"),
MySpacing.height(8), MySpacing.height(8),
TextField( TextField(
controller: baseAmountCtrl, controller: baseAmountCtrl,
@ -282,7 +304,7 @@ class _UpdatePaymentRequestWithReimbursementState
), ),
MySpacing.height(16), MySpacing.height(16),
MyText.labelMedium("GST Amount"), _requiredLabel("GST Amount"),
MySpacing.height(8), MySpacing.height(8),
TextField( TextField(
controller: taxAmountCtrl, controller: taxAmountCtrl,
@ -307,7 +329,6 @@ class _UpdatePaymentRequestWithReimbursementState
), ),
onChanged: (_) => _recalculateTds(), onChanged: (_) => _recalculateTds(),
), ),
MySpacing.height(4), MySpacing.height(4),
MyText.bodySmall( MyText.bodySmall(
"TDS is applied on base amount only.", "TDS is applied on base amount only.",
@ -315,7 +336,6 @@ class _UpdatePaymentRequestWithReimbursementState
), ),
MySpacing.height(16), MySpacing.height(16),
// Proper display section for TDS and Net Payable
Obx(() => Column( Obx(() => Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -334,7 +354,7 @@ class _UpdatePaymentRequestWithReimbursementState
)), )),
MySpacing.height(20), MySpacing.height(20),
MyText.labelMedium("Comment*"), _requiredLabel("Comment"),
MySpacing.height(8), MySpacing.height(8),
TextField( TextField(
controller: commentCtrl, controller: commentCtrl,

View File

@ -31,10 +31,11 @@ class ExpenseDetailScreen extends StatefulWidget {
State<ExpenseDetailScreen> createState() => _ExpenseDetailScreenState(); State<ExpenseDetailScreen> createState() => _ExpenseDetailScreenState();
} }
class _ExpenseDetailScreenState extends State<ExpenseDetailScreen> with UIMixin { class _ExpenseDetailScreenState extends State<ExpenseDetailScreen>
with UIMixin {
final controller = Get.put(ExpenseDetailController()); final controller = Get.put(ExpenseDetailController());
final projectController = Get.find<ProjectController>(); final projectController = Get.find<ProjectController>();
final permissionController = Get.put(PermissionController()); final permissionController = Get.put(PermissionController());
EmployeeInfo? employeeInfo; EmployeeInfo? employeeInfo;
final RxBool canSubmit = false.obs; final RxBool canSubmit = false.obs;
@ -198,8 +199,8 @@ final permissionController = Get.put(PermissionController());
}, },
backgroundColor: contentTheme.primary, backgroundColor: contentTheme.primary,
icon: const Icon(Icons.edit), icon: const Icon(Icons.edit),
label: MyText.bodyMedium( label: MyText.bodyMedium("Edit Expense",
"Edit Expense", fontWeight: 600, color: Colors.white), fontWeight: 600, color: Colors.white),
); );
}), }),
bottomNavigationBar: Obx(() { bottomNavigationBar: Obx(() {
@ -278,87 +279,96 @@ final permissionController = Get.put(PermissionController());
const reimbursementId = 'f18c5cfd-7815-4341-8da2-2c2d65778e27'; const reimbursementId = 'f18c5cfd-7815-4341-8da2-2c2d65778e27';
if (expense.status.id == reimbursementId) { if (expense.status.id == reimbursementId) {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(5))), borderRadius: BorderRadius.vertical(top: Radius.circular(5))),
builder: (context) => ReimbursementBottomSheet( builder: (context) => ReimbursementBottomSheet(
expenseId: expense.id, expenseId: expense.id,
statusId: next.id, statusId: next.id,
onClose: () {}, onClose: () {},
onSubmit: ({ onSubmit: ({
required String comment, required String comment,
required String reimburseTransactionId, required String reimburseTransactionId,
required String reimburseDate, required String reimburseDate,
required String reimburseById, required String reimburseById,
required String statusId, required String statusId,
}) async { required double baseAmount,
final transactionDate = DateTime.tryParse( required double taxAmount,
controller.expense.value?.transactionDate ?? ''); required double tdsPercent,
final selectedReimburseDate = required double netPayable,
DateTime.tryParse(reimburseDate); }) async {
final today = DateTime.now(); final transactionDate = DateTime.tryParse(
controller.expense.value?.transactionDate ?? '');
final selectedReimburseDate =
DateTime.tryParse(reimburseDate);
final today = DateTime.now();
if (transactionDate == null || if (transactionDate == null ||
selectedReimburseDate == null) { selectedReimburseDate == null) {
showAppSnackbar( showAppSnackbar(
title: 'Invalid date', title: 'Invalid Date',
message: message:
'Could not parse transaction or reimbursement date.', 'Could not parse transaction or reimbursement date.',
type: SnackbarType.error, type: SnackbarType.error,
); );
return false; return false;
} }
if (onlyDate(selectedReimburseDate) if (onlyDate(selectedReimburseDate)
.isBefore(onlyDate(transactionDate))) { .isBefore(onlyDate(transactionDate))) {
showAppSnackbar( showAppSnackbar(
title: 'Invalid Date', title: 'Invalid Date',
message: message:
'Reimbursement date cannot be before the transaction date.', 'Reimbursement date cannot be before the transaction date.',
type: SnackbarType.error, type: SnackbarType.error,
); );
return false; return false;
} }
if (onlyDate(selectedReimburseDate) if (onlyDate(selectedReimburseDate)
.isAfter(onlyDate(today))) { .isAfter(onlyDate(today))) {
showAppSnackbar( showAppSnackbar(
title: 'Invalid Date', title: 'Invalid Date',
message: 'Reimbursement date cannot be in the future.', message:
type: SnackbarType.error, 'Reimbursement date cannot be in the future.',
); type: SnackbarType.error,
return false; );
} return false;
}
final success = final success =
await controller.updateExpenseStatusWithReimbursement( await controller.updateExpenseStatusWithReimbursement(
comment: comment, comment: comment,
reimburseTransactionId: reimburseTransactionId, reimburseTransactionId: reimburseTransactionId,
reimburseDate: reimburseDate, reimburseDate: reimburseDate,
reimburseById: reimburseById, reimburseById: reimburseById,
statusId: statusId, statusId: statusId,
); baseAmount: baseAmount,
taxAmount: taxAmount,
tdsPercent: tdsPercent,
netPayable: netPayable,
);
if (success) { if (success) {
Navigator.of(context).pop(); Navigator.of(context).pop();
showAppSnackbar( showAppSnackbar(
title: 'Success', title: 'Success',
message: 'Expense reimbursed successfully.', message: 'Expense reimbursed successfully.',
type: SnackbarType.success, type: SnackbarType.success,
); );
await controller.fetchExpenseDetails(); await controller.fetchExpenseDetails();
return true; return true;
} else { } else {
showAppSnackbar( showAppSnackbar(
title: 'Error', title: 'Error',
message: 'Failed to reimburse expense.', message: 'Failed to reimburse expense.',
type: SnackbarType.error, type: SnackbarType.error,
); );
return false; return false;
} }
}), },
); ));
} else { } else {
final comment = await showCommentBottomSheet(context, next.name); final comment = await showCommentBottomSheet(context, next.name);
if (comment == null) return; if (comment == null) return;