diff --git a/lib/data/models/request/payment_request.dart b/lib/data/models/request/payment_request.dart index 818e238..37f6e55 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 amount; + final int quantity; SplitItem({ required this.orderItemId, - required this.amount, + required this.quantity, }); Map toJson() { return { 'order_item_id': orderItemId, - 'amount': amount, + 'quantity': quantity, }; } } diff --git a/lib/data/models/response/order_response_model.dart b/lib/data/models/response/order_response_model.dart index 3c2d26d..075f12c 100644 --- a/lib/data/models/response/order_response_model.dart +++ b/lib/data/models/response/order_response_model.dart @@ -244,6 +244,7 @@ class OrderItem { DateTime? createdAt; DateTime? updatedAt; String? printerType; + int? paidQuantity; OrderItem({ this.id, @@ -261,6 +262,7 @@ class OrderItem { this.createdAt, this.updatedAt, this.printerType, + this.paidQuantity, }); factory OrderItem.fromMap(Map map) { @@ -281,6 +283,7 @@ class OrderItem { createdAt: DateTime.parse(map['created_at']), updatedAt: DateTime.parse(map['updated_at']), printerType: map['printer_type'], + paidQuantity: map['paid_quantity'], ); } @@ -301,6 +304,7 @@ class OrderItem { 'created_at': createdAt?.toIso8601String(), 'updated_at': updatedAt?.toIso8601String(), 'printer_type': printerType, + 'paid_quantity': paidQuantity, }; } } diff --git a/lib/presentation/payment/pages/payment_page.dart b/lib/presentation/payment/pages/payment_page.dart index b02b2c2..4c99448 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 ?? "", - amount: item.unitPrice ?? 0, + quantity: item.quantity ?? 0, )) .toList() ?? [], diff --git a/lib/presentation/sales/widgets/sales_list_order.dart b/lib/presentation/sales/widgets/sales_list_order.dart index 055680e..8cc32ce 100644 --- a/lib/presentation/sales/widgets/sales_list_order.dart +++ b/lib/presentation/sales/widgets/sales_list_order.dart @@ -271,6 +271,57 @@ class SalesListOrder extends StatelessWidget { ), ], ), + if (order?.splitType == 'ITEM' && order?.status == 'pending') ...[ + SpaceHeight(6), + Align( + alignment: Alignment.centerRight, + child: Container( + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 4), + decoration: BoxDecoration( + color: AppColors.primary.withOpacity(0.2), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: AppColors.primary), + ), + child: RichText( + text: TextSpan( + children: [ + TextSpan( + text: '${product.paidQuantity} ', + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: AppColors.primary, + ), + ), + TextSpan( + text: 'dari ', + style: const TextStyle( + fontSize: 12, + color: AppColors.primary, + ), + ), + TextSpan( + text: '${product.quantity} ', + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: AppColors.primary, + ), + ), + TextSpan( + text: 'kuantiti telah dibayar.', + style: const TextStyle( + fontSize: 12, + color: AppColors.primary, + ), + ), + ], + ), + ), + ), + ) + ], ], ), ), diff --git a/lib/presentation/split_bill/pages/split_bill_page.dart b/lib/presentation/split_bill/pages/split_bill_page.dart index 1fb6ac3..3d5b6c5 100644 --- a/lib/presentation/split_bill/pages/split_bill_page.dart +++ b/lib/presentation/split_bill/pages/split_bill_page.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:enaklo_pos/core/components/flushbar.dart'; +import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; import 'package:enaklo_pos/data/models/response/customer_response_model.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; @@ -176,6 +177,50 @@ class _SplitBillPageState extends State { ), SizedBox(height: 8), ], + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Total terbayar', + style: TextStyle( + fontSize: 14, + color: AppColorSplitBill.textPrimary, + fontWeight: FontWeight.w600, + ), + ), + Text( + 'Rp ${_formatCurrency(widget.order.totalPaid ?? 0)}', + style: TextStyle( + fontSize: 14, + color: AppColorSplitBill.textPrimary, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + SizedBox(height: 2), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Sisa Tagihan', + style: TextStyle( + fontSize: 14, + color: Colors.red, + fontWeight: FontWeight.w600, + ), + ), + Text( + 'Rp ${_formatCurrency(widget.order.remainingAmount ?? 0)}', + style: TextStyle( + fontSize: 14, + color: Colors.red, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + SizedBox(height: 2), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -313,48 +358,103 @@ class _SplitBillPageState extends State { Widget _buildOrderItem(OrderItem item) { return Container( padding: EdgeInsets.symmetric(vertical: 12), - child: Row( + child: Column( children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - item.productName ?? '', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: AppColorSplitBill.textPrimary, - ), - ), - if (item.productVariantName != null && - item.productVariantName!.isNotEmpty) - Text( - item.productVariantName!, - style: TextStyle( - fontSize: 14, - color: AppColorSplitBill.textSecondary, - fontStyle: FontStyle.italic, + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + item.productName ?? '', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: AppColorSplitBill.textPrimary, + ), ), - ), - Text( - 'Qty: ${item.quantity} x Rp ${_formatCurrency(item.unitPrice ?? 0)}', - style: TextStyle( - fontSize: 14, - color: AppColorSplitBill.textSecondary, + if (item.productVariantName != null && + item.productVariantName!.isNotEmpty) + Text( + item.productVariantName!, + style: TextStyle( + fontSize: 14, + color: AppColorSplitBill.textSecondary, + fontStyle: FontStyle.italic, + ), + ), + Text( + 'Qty: ${item.quantity} x Rp ${_formatCurrency(item.unitPrice ?? 0)}', + style: TextStyle( + fontSize: 14, + color: AppColorSplitBill.textSecondary, + ), + ), + ], + ), + ), + Text( + 'Rp ${_formatCurrency(item.totalPrice ?? 0)}', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: AppColorSplitBill.textPrimary, + ), + ), + ], + ), + if ((item.paidQuantity ?? 0) > 1) ...[ + SpaceHeight(6), + Align( + alignment: Alignment.centerRight, + child: Container( + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 4), + decoration: BoxDecoration( + color: AppColorSplitBill.primary.withOpacity(0.2), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: AppColorSplitBill.primary), + ), + child: RichText( + text: TextSpan( + children: [ + TextSpan( + text: '${item.paidQuantity} ', + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: AppColorSplitBill.primary, + ), + ), + TextSpan( + text: 'dari ', + style: const TextStyle( + fontSize: 12, + color: AppColorSplitBill.primary, + ), + ), + TextSpan( + text: '${item.quantity} ', + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: AppColorSplitBill.primary, + ), + ), + TextSpan( + text: 'kuantiti telah dibayar.', + style: const TextStyle( + fontSize: 12, + color: AppColorSplitBill.primary, + ), + ), + ], ), ), - ], - ), - ), - Text( - 'Rp ${_formatCurrency(item.totalPrice ?? 0)}', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: AppColorSplitBill.textPrimary, - ), - ), + ), + ) + ], ], ), ); @@ -468,7 +568,7 @@ class _SplitBillPageState extends State { Widget _buildProductSplitItem(OrderItem item) { int selectedQty = selectedProducts[item.id] ?? 0; - int maxQty = item.quantity ?? 0; + int maxQty = (item.quantity ?? 0) - (item.paidQuantity ?? 0); return Container( margin: EdgeInsets.only(bottom: 12),