feat: make statusId dynamic in reimbursement handling and update related components
This commit is contained in:
parent
9d49f2a92d
commit
adf5e1437e
@ -81,6 +81,7 @@ class ExpenseDetailController extends GetxController {
|
|||||||
required String reimburseTransactionId,
|
required String reimburseTransactionId,
|
||||||
required String reimburseDate,
|
required String reimburseDate,
|
||||||
required String reimburseById,
|
required String reimburseById,
|
||||||
|
required String statusId, // ✅ dynamic
|
||||||
}) async {
|
}) async {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
errorMessage.value = '';
|
errorMessage.value = '';
|
||||||
@ -90,7 +91,7 @@ class ExpenseDetailController extends GetxController {
|
|||||||
|
|
||||||
final success = await ApiService.updateExpenseStatusApi(
|
final success = await ApiService.updateExpenseStatusApi(
|
||||||
expenseId: expenseId,
|
expenseId: expenseId,
|
||||||
statusId: 'reimbursed',
|
statusId: statusId, // ✅ now dynamic
|
||||||
comment: comment,
|
comment: comment,
|
||||||
reimburseTransactionId: reimburseTransactionId,
|
reimburseTransactionId: reimburseTransactionId,
|
||||||
reimburseDate: reimburseDate,
|
reimburseDate: reimburseDate,
|
||||||
|
|||||||
@ -6,14 +6,14 @@ import 'package:marco/helpers/widgets/my_text.dart';
|
|||||||
|
|
||||||
class ReimbursementBottomSheet extends StatefulWidget {
|
class ReimbursementBottomSheet extends StatefulWidget {
|
||||||
final String expenseId;
|
final String expenseId;
|
||||||
final String statusId;
|
final String statusId;
|
||||||
final void Function() onClose;
|
final void Function() onClose;
|
||||||
final Future<bool> Function({
|
final Future<bool> Function({
|
||||||
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,
|
||||||
}) onSubmit;
|
}) onSubmit;
|
||||||
|
|
||||||
const ReimbursementBottomSheet({
|
const ReimbursementBottomSheet({
|
||||||
@ -21,16 +21,17 @@ class ReimbursementBottomSheet extends StatefulWidget {
|
|||||||
required this.expenseId,
|
required this.expenseId,
|
||||||
required this.onClose,
|
required this.onClose,
|
||||||
required this.onSubmit,
|
required this.onSubmit,
|
||||||
required this.statusId,
|
required this.statusId,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ReimbursementBottomSheet> createState() => _ReimbursementBottomSheetState();
|
State<ReimbursementBottomSheet> createState() =>
|
||||||
|
_ReimbursementBottomSheetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
||||||
final ExpenseDetailController controller = Get.find<ExpenseDetailController>();
|
final ExpenseDetailController controller =
|
||||||
|
Get.find<ExpenseDetailController>();
|
||||||
|
|
||||||
final TextEditingController commentCtrl = TextEditingController();
|
final TextEditingController commentCtrl = TextEditingController();
|
||||||
final TextEditingController txnCtrl = TextEditingController();
|
final TextEditingController txnCtrl = TextEditingController();
|
||||||
@ -47,13 +48,15 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||||
builder: (_) {
|
builder: (_) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 300,
|
height: 300,
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
final employees = controller.allEmployees;
|
final employees = controller.allEmployees;
|
||||||
if (employees.isEmpty) return const Center(child: Text("No employees found"));
|
if (employees.isEmpty)
|
||||||
|
return const Center(child: Text("No employees found"));
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: employees.length,
|
itemCount: employees.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
@ -113,7 +116,8 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
children: [
|
children: [
|
||||||
_buildInputField(label: 'Comment', controller: commentCtrl),
|
_buildInputField(label: 'Comment', controller: commentCtrl),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_buildInputField(label: 'Transaction ID', controller: txnCtrl),
|
_buildInputField(
|
||||||
|
label: 'Transaction ID', controller: txnCtrl),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_buildDatePickerField(),
|
_buildDatePickerField(),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
@ -130,12 +134,14 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildInputField({required String label, required TextEditingController controller}) {
|
Widget _buildInputField(
|
||||||
|
{required String label, required TextEditingController controller}) {
|
||||||
return TextField(
|
return TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: label,
|
labelText: label,
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
@ -163,7 +169,8 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
child: InputDecorator(
|
child: InputDecorator(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Reimbursement Date',
|
labelText: 'Reimbursement Date',
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
@ -194,7 +201,8 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
child: InputDecorator(
|
child: InputDecorator(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Reimbursed By',
|
labelText: 'Reimbursed By',
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
@ -206,7 +214,9 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
: '${controller.selectedReimbursedBy.value?.firstName ?? ''} ${controller.selectedReimbursedBy.value?.lastName ?? ''}',
|
: '${controller.selectedReimbursedBy.value?.firstName ?? ''} ${controller.selectedReimbursedBy.value?.lastName ?? ''}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: controller.selectedReimbursedBy.value == null ? Colors.grey : Colors.black,
|
color: controller.selectedReimbursedBy.value == null
|
||||||
|
? Colors.grey
|
||||||
|
: Colors.black,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -224,11 +234,13 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
Get.back();
|
Get.back();
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.close, color: Colors.white),
|
icon: const Icon(Icons.close, color: Colors.white),
|
||||||
label: MyText.bodyMedium("Cancel", color: Colors.white, fontWeight: 600),
|
label: MyText.bodyMedium("Cancel",
|
||||||
|
color: Colors.white, fontWeight: 600),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 14),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 7),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -251,7 +263,9 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
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,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@ -269,8 +283,10 @@ class _ReimbursementBottomSheetState extends State<ReimbursementBottomSheet> {
|
|||||||
),
|
),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.indigo,
|
backgroundColor: Colors.indigo,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 14),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 5, vertical: 7),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -90,22 +90,28 @@ class ExpenseDetailScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
|
// Show error snackbar only once after frame render
|
||||||
|
if (controller.errorMessage.isNotEmpty) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
Get.snackbar(
|
||||||
|
"Error",
|
||||||
|
controller.errorMessage.value,
|
||||||
|
backgroundColor: Colors.red.withOpacity(0.9),
|
||||||
|
colorText: Colors.white,
|
||||||
|
);
|
||||||
|
controller.errorMessage.value = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (controller.isLoading.value) {
|
if (controller.isLoading.value) {
|
||||||
return _buildLoadingSkeleton();
|
return _buildLoadingSkeleton();
|
||||||
}
|
}
|
||||||
if (controller.errorMessage.isNotEmpty) {
|
|
||||||
return Center(
|
|
||||||
child: MyText.bodyMedium(
|
|
||||||
controller.errorMessage.value,
|
|
||||||
color: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final expense = controller.expense.value;
|
final expense = controller.expense.value;
|
||||||
if (expense == null) {
|
if (expense == null) {
|
||||||
return Center(
|
return Center(
|
||||||
child: MyText.bodyMedium("No expense details found."));
|
child: MyText.bodyMedium("No expense details found."),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final statusColor = getStatusColor(expense.status.name,
|
final statusColor = getStatusColor(expense.status.name,
|
||||||
@ -116,8 +122,14 @@ class ExpenseDetailScreen extends StatelessWidget {
|
|||||||
decimalDigits: 2,
|
decimalDigits: 2,
|
||||||
).format(expense.amount);
|
).format(expense.amount);
|
||||||
|
|
||||||
|
// === CHANGE: Add proper bottom padding to always keep content away from device nav bar ===
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
8,
|
||||||
|
8,
|
||||||
|
8,
|
||||||
|
16 + MediaQuery.of(context).padding.bottom, // KEY LINE
|
||||||
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: const BoxConstraints(maxWidth: 520),
|
constraints: const BoxConstraints(maxWidth: 520),
|
||||||
@ -199,13 +211,13 @@ class ExpenseDetailScreen extends StatelessWidget {
|
|||||||
builder: (context) => ReimbursementBottomSheet(
|
builder: (context) => ReimbursementBottomSheet(
|
||||||
expenseId: expense.id,
|
expenseId: expense.id,
|
||||||
statusId: next.id,
|
statusId: next.id,
|
||||||
onClose:
|
onClose: () {},
|
||||||
() {}, // <-- This is the missing required parameter
|
|
||||||
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,
|
||||||
}) async {
|
}) async {
|
||||||
final success = await controller
|
final success = await controller
|
||||||
.updateExpenseStatusWithReimbursement(
|
.updateExpenseStatusWithReimbursement(
|
||||||
@ -214,6 +226,7 @@ class ExpenseDetailScreen extends StatelessWidget {
|
|||||||
reimburseTransactionId: reimburseTransactionId,
|
reimburseTransactionId: reimburseTransactionId,
|
||||||
reimburseDate: reimburseDate,
|
reimburseDate: reimburseDate,
|
||||||
reimburseById: reimburseById,
|
reimburseById: reimburseById,
|
||||||
|
statusId: statusId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user