fixed wrong list display due to date format , and added tds calculation in the payment proceed sheet
This commit is contained in:
parent
af5bfcaa59
commit
cffa4456b9
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import 'package:marco/controller/finance/payment_request_detail_controller.dart';
|
import 'package:marco/controller/finance/payment_request_detail_controller.dart';
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
@ -24,10 +23,10 @@ class UpdatePaymentRequestWithReimbursement extends StatefulWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
State<UpdatePaymentRequestWithReimbursement> createState() =>
|
State<UpdatePaymentRequestWithReimbursement> createState() =>
|
||||||
_UpdatePaymentRequestWithReimbursement();
|
_UpdatePaymentRequestWithReimbursementState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UpdatePaymentRequestWithReimbursement
|
class _UpdatePaymentRequestWithReimbursementState
|
||||||
extends State<UpdatePaymentRequestWithReimbursement> {
|
extends State<UpdatePaymentRequestWithReimbursement> {
|
||||||
final PaymentRequestDetailController controller =
|
final PaymentRequestDetailController controller =
|
||||||
Get.find<PaymentRequestDetailController>();
|
Get.find<PaymentRequestDetailController>();
|
||||||
@ -37,7 +36,18 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
final TextEditingController tdsCtrl = TextEditingController(text: '0');
|
final TextEditingController tdsCtrl = TextEditingController(text: '0');
|
||||||
final TextEditingController baseAmountCtrl = TextEditingController();
|
final TextEditingController baseAmountCtrl = TextEditingController();
|
||||||
final TextEditingController taxAmountCtrl = TextEditingController();
|
final TextEditingController taxAmountCtrl = TextEditingController();
|
||||||
|
|
||||||
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(_recalculateTds);
|
||||||
|
taxAmountCtrl.addListener(_recalculateTds);
|
||||||
|
tdsCtrl.addListener(_recalculateTds);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -49,7 +59,21 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Employee selection bottom sheet
|
void _recalculateTds() {
|
||||||
|
final double base = double.tryParse(baseAmountCtrl.text.trim()) ?? 0.0;
|
||||||
|
final double gst = double.tryParse(taxAmountCtrl.text.trim()) ?? 0.0;
|
||||||
|
final double tdsPercent = double.tryParse(tdsCtrl.text.trim()) ?? 0.0;
|
||||||
|
|
||||||
|
final double calculatedTds = (base * tdsPercent) / 100;
|
||||||
|
final double roundedTds = double.parse(calculatedTds.toStringAsFixed(2));
|
||||||
|
|
||||||
|
final double net = (base + gst) - roundedTds;
|
||||||
|
final double roundedNet = double.parse(net.toStringAsFixed(2));
|
||||||
|
|
||||||
|
tdsAmount.value = roundedTds;
|
||||||
|
netPayable.value = roundedNet;
|
||||||
|
}
|
||||||
|
|
||||||
void _showEmployeeList() async {
|
void _showEmployeeList() async {
|
||||||
await showModalBottomSheet(
|
await showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
@ -67,7 +91,6 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Optional cleanup
|
|
||||||
controller.employeeSearchController.clear();
|
controller.employeeSearchController.clear();
|
||||||
controller.employeeSearchResults.clear();
|
controller.employeeSearchResults.clear();
|
||||||
}
|
}
|
||||||
@ -94,6 +117,29 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,7 +151,6 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
onSubmit: () async {
|
onSubmit: () async {
|
||||||
// Mandatory fields validation
|
|
||||||
if (commentCtrl.text.trim().isEmpty ||
|
if (commentCtrl.text.trim().isEmpty ||
|
||||||
txnCtrl.text.trim().isEmpty ||
|
txnCtrl.text.trim().isEmpty ||
|
||||||
dateStr.value.isEmpty ||
|
dateStr.value.isEmpty ||
|
||||||
@ -120,27 +165,24 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse inputs
|
|
||||||
final parsedDate =
|
final parsedDate =
|
||||||
DateFormat('dd-MM-yyyy').parse(dateStr.value, true);
|
DateFormat('dd-MM-yyyy').parse(dateStr.value, true);
|
||||||
final baseAmount = double.tryParse(baseAmountCtrl.text.trim()) ?? 0;
|
final baseAmt = double.tryParse(baseAmountCtrl.text.trim()) ?? 0;
|
||||||
final taxAmount = double.tryParse(taxAmountCtrl.text.trim()) ?? 0;
|
final taxAmt = double.tryParse(taxAmountCtrl.text.trim()) ?? 0;
|
||||||
final tdsPercentage =
|
final tdsPercentage =
|
||||||
tdsCtrl.text.trim().isEmpty ? null : tdsCtrl.text.trim();
|
tdsCtrl.text.trim().isEmpty ? null : tdsCtrl.text.trim();
|
||||||
|
|
||||||
// Call API
|
|
||||||
final success = await controller.updatePaymentRequestStatus(
|
final success = await controller.updatePaymentRequestStatus(
|
||||||
statusId: widget.statusId,
|
statusId: widget.statusId,
|
||||||
comment: commentCtrl.text.trim(),
|
comment: commentCtrl.text.trim(),
|
||||||
paidTransactionId: txnCtrl.text.trim(),
|
paidTransactionId: txnCtrl.text.trim(),
|
||||||
paidById: controller.selectedReimbursedBy.value?.id,
|
paidById: controller.selectedReimbursedBy.value?.id,
|
||||||
paidAt: parsedDate,
|
paidAt: parsedDate,
|
||||||
baseAmount: baseAmount,
|
baseAmount: baseAmt,
|
||||||
taxAmount: taxAmount,
|
taxAmount: taxAmt,
|
||||||
tdsPercentage: tdsPercentage,
|
tdsPercentage: tdsPercentage,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Show snackbar
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: success ? 'Success' : 'Error',
|
title: success ? 'Success' : 'Error',
|
||||||
message: success
|
message: success
|
||||||
@ -150,12 +192,11 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// Ensure bottom sheet closes and callback is called
|
widget.onClose();
|
||||||
widget.onClose(); // optional callback for parent refresh
|
|
||||||
if (Navigator.canPop(context)) {
|
if (Navigator.canPop(context)) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
} else {
|
} else {
|
||||||
Get.close(1); // fallback if Navigator can't pop
|
Get.close(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
@ -167,103 +208,141 @@ class _UpdatePaymentRequestWithReimbursement
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Column(
|
child: SingleChildScrollView(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
MyText.labelMedium("Transaction ID*"),
|
children: [
|
||||||
MySpacing.height(8),
|
MyText.labelMedium("Transaction ID*"),
|
||||||
TextField(
|
MySpacing.height(8),
|
||||||
controller: txnCtrl,
|
TextField(
|
||||||
decoration: _inputDecoration("Enter transaction ID"),
|
controller: txnCtrl,
|
||||||
),
|
decoration: _inputDecoration("Enter transaction ID"),
|
||||||
MySpacing.height(16),
|
),
|
||||||
MyText.labelMedium("Transaction Date*"),
|
MySpacing.height(16),
|
||||||
MySpacing.height(8),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
final today = DateTime.now();
|
|
||||||
final firstDate = DateTime(2020);
|
|
||||||
final lastDate = today;
|
|
||||||
|
|
||||||
final picked = await showDatePicker(
|
MyText.labelMedium("Transaction Date*"),
|
||||||
context: context,
|
MySpacing.height(8),
|
||||||
initialDate: today,
|
GestureDetector(
|
||||||
firstDate: firstDate,
|
onTap: () async {
|
||||||
lastDate: lastDate,
|
final picked = await showDatePicker(
|
||||||
);
|
context: context,
|
||||||
|
initialDate: DateTime.now(),
|
||||||
if (picked != null) {
|
firstDate: DateTime(2020),
|
||||||
dateStr.value = DateFormat('dd-MM-yyyy').format(picked);
|
lastDate: DateTime.now(),
|
||||||
}
|
);
|
||||||
},
|
if (picked != null) {
|
||||||
child: AbsorbPointer(
|
dateStr.value = DateFormat('dd-MM-yyyy').format(picked);
|
||||||
child: TextField(
|
}
|
||||||
controller: TextEditingController(text: dateStr.value),
|
},
|
||||||
decoration: _inputDecoration("Select Date").copyWith(
|
child: AbsorbPointer(
|
||||||
suffixIcon: const Icon(Icons.calendar_today),
|
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("Paid By (Optional)"),
|
MyText.labelMedium("Paid By (Optional)"),
|
||||||
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),
|
||||||
MySpacing.height(16),
|
|
||||||
MyText.labelMedium("TDS Percentage (Optional)"),
|
MyText.labelMedium("Base Amount"),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
TextField(
|
TextField(
|
||||||
controller: tdsCtrl,
|
controller: baseAmountCtrl,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: _inputDecoration("Enter TDS Percentage"),
|
decoration: _inputDecoration("Enter Base Amount"),
|
||||||
),
|
),
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
MyText.labelMedium("Base Amount*"),
|
|
||||||
MySpacing.height(8),
|
MyText.labelMedium("GST Amount"),
|
||||||
TextField(
|
MySpacing.height(8),
|
||||||
controller: baseAmountCtrl,
|
TextField(
|
||||||
keyboardType: TextInputType.number,
|
controller: taxAmountCtrl,
|
||||||
decoration: _inputDecoration("Enter Base Amount"),
|
keyboardType: TextInputType.number,
|
||||||
),
|
decoration: _inputDecoration("Enter GST Amount"),
|
||||||
MySpacing.height(16),
|
),
|
||||||
MyText.labelMedium("Tax Amount*"),
|
MySpacing.height(16),
|
||||||
MySpacing.height(8),
|
|
||||||
TextField(
|
MyText.labelMedium("TDS Percent"),
|
||||||
controller: taxAmountCtrl,
|
MySpacing.height(8),
|
||||||
keyboardType: TextInputType.number,
|
TextField(
|
||||||
decoration: _inputDecoration("Enter Tax Amount"),
|
controller: tdsCtrl,
|
||||||
),
|
keyboardType: TextInputType.number,
|
||||||
MySpacing.height(16),
|
decoration: _inputDecoration("Enter TDS Percent").copyWith(
|
||||||
MyText.labelMedium("Comment*"),
|
suffixIcon: Padding(
|
||||||
MySpacing.height(8),
|
padding: const EdgeInsets.only(right: 12),
|
||||||
TextField(
|
child: Icon(Icons.percent,
|
||||||
controller: commentCtrl,
|
size: 20, color: Colors.grey.shade600),
|
||||||
decoration: _inputDecoration("Enter comment"),
|
),
|
||||||
),
|
suffixIconConstraints:
|
||||||
],
|
const BoxConstraints(minWidth: 0, minHeight: 0),
|
||||||
|
),
|
||||||
|
onChanged: (_) => _recalculateTds(),
|
||||||
|
),
|
||||||
|
|
||||||
|
MySpacing.height(4),
|
||||||
|
MyText.bodySmall(
|
||||||
|
"TDS is applied on base amount only.",
|
||||||
|
color: Colors.grey.shade600,
|
||||||
|
),
|
||||||
|
MySpacing.height(16),
|
||||||
|
|
||||||
|
// ✅ Proper display section for TDS and Net Payable
|
||||||
|
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(20),
|
||||||
|
|
||||||
|
MyText.labelMedium("Comment*"),
|
||||||
|
MySpacing.height(8),
|
||||||
|
TextField(
|
||||||
|
controller: commentCtrl,
|
||||||
|
maxLines: 2,
|
||||||
|
decoration: _inputDecoration("Enter comment"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -76,11 +76,10 @@ class _PaymentRequestMainScreenState extends State<PaymentRequestMainScreen>
|
|||||||
|
|
||||||
return isHistory
|
return isHistory
|
||||||
? filtered
|
? filtered
|
||||||
.where((e) => e.dueDate.isBefore(DateTime(now.year, now.month)))
|
.where((e) => e.dueDate.isBefore(DateTime(now.year, now.month, 1)))
|
||||||
.toList()
|
.toList()
|
||||||
: filtered
|
: filtered
|
||||||
.where((e) =>
|
.where((e) => e.dueDate.isAfter(DateTime(now.year, now.month, 0)))
|
||||||
e.dueDate.month == now.month && e.dueDate.year == now.year)
|
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user