diff --git a/lib/data/models/request/payment_request.dart b/lib/data/models/request/payment_request.dart index 37f6e55..818e238 100644 --- a/lib/data/models/request/payment_request.dart +++ b/lib/data/models/request/payment_request.dart @@ -121,17 +121,17 @@ class PaymentSplitBillRequest { class SplitItem { final String orderItemId; - final int quantity; + final int amount; SplitItem({ required this.orderItemId, - required this.quantity, + required this.amount, }); Map toJson() { return { 'order_item_id': orderItemId, - 'quantity': quantity, + 'amount': amount, }; } } diff --git a/lib/presentation/payment/pages/payment_page.dart b/lib/presentation/payment/pages/payment_page.dart index 4c99448..b02b2c2 100644 --- a/lib/presentation/payment/pages/payment_page.dart +++ b/lib/presentation/payment/pages/payment_page.dart @@ -468,7 +468,7 @@ class _PaymentPageState extends State { items: itemPending ?.map((item) => SplitItem( orderItemId: item.id ?? "", - quantity: item.quantity ?? 0, + amount: item.unitPrice ?? 0, )) .toList() ?? [], diff --git a/lib/presentation/sales/widgets/sales_list_order.dart b/lib/presentation/sales/widgets/sales_list_order.dart index e21fefe..055680e 100644 --- a/lib/presentation/sales/widgets/sales_list_order.dart +++ b/lib/presentation/sales/widgets/sales_list_order.dart @@ -285,8 +285,8 @@ class SalesListOrder extends StatelessWidget { switch (status) { case "pending": - backgroundColor = Colors.orange.withOpacity(0.1); - textColor = Colors.orange.shade700; + backgroundColor = Colors.white; + textColor = Colors.white; displayText = "Pending"; icon = Icons.access_time; break; diff --git a/lib/presentation/sales/widgets/sales_payment.dart b/lib/presentation/sales/widgets/sales_payment.dart index 3d96463..6c83d51 100644 --- a/lib/presentation/sales/widgets/sales_payment.dart +++ b/lib/presentation/sales/widgets/sales_payment.dart @@ -1,6 +1,7 @@ import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/int_ext.dart'; +import 'package:enaklo_pos/core/extensions/string_ext.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; @@ -31,29 +32,18 @@ class SalesPayment extends StatelessWidget { color: AppColors.primary, ), ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), - decoration: BoxDecoration( - color: Colors.amber.shade100, - borderRadius: BorderRadius.circular(4), - ), - child: Text( - order?.paymentStatus ?? "", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.bold, - color: Colors.amber.shade800, - ), - ), - ), + _buildPaymentStatus(), ], ), const SpaceHeight(12), ...List.generate( order?.payments?.length ?? 0, - (index) => _buildPaymentItem(order?.payments?[index] ?? Payment()), + (index) => Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: _buildPaymentItem(order?.payments?[index] ?? Payment()), + ), ), - const SpaceHeight(12), + const SpaceHeight(4), const Divider(), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -96,6 +86,43 @@ class SalesPayment extends StatelessWidget { ); } + Container _buildPaymentStatus() { + switch (order?.paymentStatus) { + case 'completed': + return Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + decoration: BoxDecoration( + color: AppColors.green.withOpacity(0.2), + borderRadius: BorderRadius.circular(4), + ), + child: Text( + (order?.paymentStatus ?? "").toTitleCase(), + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.bold, + color: AppColors.green, + ), + ), + ); + default: + return Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + decoration: BoxDecoration( + color: Colors.amber.shade100, + borderRadius: BorderRadius.circular(4), + ), + child: Text( + (order?.paymentStatus ?? "").toTitleCase(), + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.bold, + color: Colors.amber.shade800, + ), + ), + ); + } + } + Row _buildPaymentItem(Payment payment) { return Row( children: [ diff --git a/lib/presentation/split_bill/pages/split_bill_page.dart b/lib/presentation/split_bill/pages/split_bill_page.dart index e194559..1fb6ac3 100644 --- a/lib/presentation/split_bill/pages/split_bill_page.dart +++ b/lib/presentation/split_bill/pages/split_bill_page.dart @@ -39,6 +39,7 @@ class _SplitBillPageState extends State { // Per Amount Split Data TextEditingController amountController = TextEditingController(); int splitAmount = 0; + int remainingAmount = 0; List getOrderItemPending() => widget.order.orderItems @@ -46,9 +47,24 @@ class _SplitBillPageState extends State { .toList() ?? []; + init() { + setState(() { + remainingAmount = + (widget.order.totalAmount ?? 0) - (widget.order.totalPaid ?? 0); + selectedSplitType = widget.order.splitType == 'AMOUNT' ? 1 : 0; + }); + } + + @override + void initState() { + init(); + super.initState(); + } + @override void dispose() { amountController.dispose(); + super.dispose(); } @@ -210,13 +226,7 @@ class _SplitBillPageState extends State { SizedBox(height: 24), // Split Type Selection - Row( - children: [ - _buildSplitTypeButton('Per Produk', 0), - SizedBox(width: 16), - _buildSplitTypeButton('Per Jumlah', 1), - ], - ), + _buildRowButtonSplit(), SizedBox(height: 32), @@ -263,6 +273,23 @@ class _SplitBillPageState extends State { ); } + Widget _buildRowButtonSplit() { + switch (widget.order.splitType) { + case 'AMOUNT': + return _buildSplitTypeButton('Per Jumlah', 1); + case 'ITEM': + return _buildSplitTypeButton('Per Produk', 0); + default: + return Row( + children: [ + _buildSplitTypeButton('Per Produk', 0), + SizedBox(width: 16), + _buildSplitTypeButton('Per Jumlah', 1), + ], + ); + } + } + Widget _buildCustomer(BuildContext context) { return Container( padding: EdgeInsets.all(16), @@ -681,7 +708,7 @@ class _SplitBillPageState extends State { ), ), Text( - 'Rp ${_formatCurrency((widget.order.totalAmount ?? 0) - splitAmount)}', + 'Rp ${_formatCurrency((remainingAmount) - splitAmount)}', style: TextStyle( fontSize: 14, color: AppColorSplitBill.textSecondary, @@ -797,7 +824,8 @@ class _SplitBillPageState extends State { } } else { // Per Amount Split - int totalAmount = widget.order.totalAmount ?? 0; + int totalAmount = + (widget.order.totalAmount ?? 0) - (widget.order.totalPaid ?? 0); if (splitAmount > 0 && splitAmount <= totalAmount) { // Create split order object with the specified amount