From 0d91d438668a6dd2b6b58e07dd82a4cb965352bd Mon Sep 17 00:00:00 2001 From: efrilm Date: Mon, 1 Sep 2025 22:25:15 +0700 Subject: [PATCH] fix: print split bill --- lib/core/function/app_function.dart | 21 ++++++++++--------- lib/data/dataoutputs/print_dataoutputs.dart | 10 +++++---- lib/presentation/sales/pages/sales_page.dart | 19 +++++++++-------- .../split_bill/pages/split_bill_page.dart | 2 +- .../success/pages/success_order_page.dart | 1 + .../success/pages/success_payment_page.dart | 1 + 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index 908d4ef..7a83f33 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -133,6 +133,7 @@ Future onPrintRecipt( required String paymentMethod, required int nominalBayar, required int kembalian, + required List productQuantity, }) async { final receiptPrinter = await ProductLocalDatasource.instance.getPrinterByCode('receipt'); @@ -143,16 +144,16 @@ Future onPrintRecipt( if (receiptPrinter != null) { try { final printValue = await PrintDataoutputs.instance.printOrderV4( - order, - authData.user?.name ?? "", - paymentMethod, - nominalBayar, - kembalian, - settings.value, - receiptPrinter.paper.toIntegerFromText, - order.orderType ?? "", - outlet, - ); + order, + authData.user?.name ?? "", + paymentMethod, + nominalBayar, + kembalian, + settings.value, + receiptPrinter.paper.toIntegerFromText, + order.orderType ?? "", + outlet, + productQuantity); await PrinterService() .printWithPrinter(receiptPrinter, printValue, context); } catch (e) { diff --git a/lib/data/dataoutputs/print_dataoutputs.dart b/lib/data/dataoutputs/print_dataoutputs.dart index eba8df6..ea619ff 100644 --- a/lib/data/dataoutputs/print_dataoutputs.dart +++ b/lib/data/dataoutputs/print_dataoutputs.dart @@ -751,6 +751,7 @@ class PrintDataoutputs { int paper, String orderType, Outlet outlet, + List products, ) async { List bytes = []; @@ -865,15 +866,16 @@ class PrintDataoutputs { ? '------------------------------------------------' : '--------------------------------', styles: const PosStyles(bold: false, align: PosAlign.center)); - for (final product in (order.orderItems ?? [])) { + for (final product in (products ?? [])) { bytes += generator.row([ PosColumn( - text: '${product.quantity} x ${product.productName}', + text: '${product.quantity} x ${product.product.name}', width: 8, styles: const PosStyles(bold: true, align: PosAlign.left), ), PosColumn( - text: (product.totalPrice ?? 0).currencyFormatRpV2, + text: (((product.product.price ?? 0) * product.quantity)) + .currencyFormatRpV2, width: 4, styles: const PosStyles(bold: true, align: PosAlign.right), ), @@ -887,7 +889,7 @@ class PrintDataoutputs { bytes += generator.row([ PosColumn( - text: 'Subtotal ${order.orderItems?.length ?? "0"} Product', + text: 'Subtotal ${products.length} Product', width: 6, styles: const PosStyles(align: PosAlign.left), ), diff --git a/lib/presentation/sales/pages/sales_page.dart b/lib/presentation/sales/pages/sales_page.dart index 15a89ff..f6d0b72 100644 --- a/lib/presentation/sales/pages/sales_page.dart +++ b/lib/presentation/sales/pages/sales_page.dart @@ -246,15 +246,16 @@ class _SalesPageState extends State { ), ], if (widget.status == 'completed') - Button.outlined( - onPressed: () { - context.push(RefundPage( - selectedOrder: orderDetail!, - )); - }, - label: 'Refund', - icon: Icon(Icons.autorenew), - ), + if (orderDetail?.isRefund == false) + Button.outlined( + onPressed: () { + context.push(RefundPage( + selectedOrder: orderDetail!, + )); + }, + label: 'Refund', + icon: Icon(Icons.autorenew), + ), ], ), Expanded( diff --git a/lib/presentation/split_bill/pages/split_bill_page.dart b/lib/presentation/split_bill/pages/split_bill_page.dart index 3d5b6c5..ccb593f 100644 --- a/lib/presentation/split_bill/pages/split_bill_page.dart +++ b/lib/presentation/split_bill/pages/split_bill_page.dart @@ -932,7 +932,7 @@ class _SplitBillPageState extends State { Order splitOrder = Order( id: widget.order.id, orderNumber: widget.order.orderNumber, - orderItems: getOrderItemPending(), // Keep all items for reference + orderItems: [], // Keep all items for reference subtotal: splitAmount, totalAmount: splitAmount, taxAmount: 0, // You might want to calculate proportional values diff --git a/lib/presentation/success/pages/success_order_page.dart b/lib/presentation/success/pages/success_order_page.dart index b13d54d..9c9c4d6 100644 --- a/lib/presentation/success/pages/success_order_page.dart +++ b/lib/presentation/success/pages/success_order_page.dart @@ -1012,6 +1012,7 @@ class _SuccessOrderPageState extends State : widget.order.totalAmount ?? 0, kembalian: widget.nominalBayar - (widget.order.totalAmount ?? 0), + productQuantity: widget.productQuantity, ); onPrint( context, diff --git a/lib/presentation/success/pages/success_payment_page.dart b/lib/presentation/success/pages/success_payment_page.dart index 5b1d6aa..cfcef39 100644 --- a/lib/presentation/success/pages/success_payment_page.dart +++ b/lib/presentation/success/pages/success_payment_page.dart @@ -798,6 +798,7 @@ class _SuccessPaymentPageState extends State { : order.totalAmount ?? 0, kembalian: widget.nominalBayar - (order.totalAmount ?? 0), + productQuantity: widget.productQuantity, ); }, child: const Row(