From 290360674f3b42c8bc6e51a25f54b42dfab0f9f3 Mon Sep 17 00:00:00 2001 From: efrilm Date: Wed, 8 Oct 2025 17:06:23 +0700 Subject: [PATCH] update --- lib/core/function/app_function.dart | 108 ++++++++++++++++++ .../payment/pages/payment_page.dart | 5 +- lib/presentation/sales/pages/sales_page.dart | 4 +- pubspec.yaml | 2 +- 4 files changed, 114 insertions(+), 5 deletions(-) diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index b02676a..d6c5bf7 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -280,6 +280,114 @@ Future onPrint( } } +Future onPrintBill( + BuildContext context, { + required List productQuantity, + required Order order, +}) async { + final outlet = await OutletLocalDatasource().get(); + final settings = await SettingsLocalDatasource().getTax(); + final authData = await AuthLocalDataSource().getAuthData(); + + if (outlet.businessType == BusinessType.restaurant) { + final receiptPrinter = + await PrinterLocalDatasource.instance.getPrinterByCode('receipt'); + + if (receiptPrinter != null) { + try { + final printValue = await PrintDataoutputs.instance.printOrderV4( + order, + authData.user?.name ?? "", + '', + 0, + 0, + settings.value, + receiptPrinter.paper.toIntegerFromText, + order.orderType ?? "", + outlet, + productQuantity); + await PrinterService() + .printWithPrinter(receiptPrinter, printValue, context); + } catch (e, stackTrace) { + FirebaseCrashlytics.instance.recordError( + e, + stackTrace, + reason: 'Print receipt failed', + information: [ + 'Order ID: ${order.id}', + 'Printer: ${receiptPrinter.name}', + ], + ); + log("Error printing receipt order: $e"); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Error printing receipt order: $e')), + ); + } + } else { + FirebaseCrashlytics.instance.recordError( + 'Receipt printer not found', + null, + reason: + 'Receipt printer not found / Printer not setting in printer page', + information: [ + 'Order ID: ${order.id}', + ], + ); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Anda belum menghubungkan printer receipt')), + ); + } + } + + if (outlet.businessType == BusinessType.ticketing) { + final ticketPrinter = + await PrinterLocalDatasource.instance.getPrinterByCode('ticket'); + + final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? ""); + + if (ticketPrinter != null) { + try { + final printValue = await PrintDataoutputs.instance.printTicket( + order.totalAmount ?? 0, + barcode, + ticketPrinter.paper.toIntegerFromText, + ); + + await PrinterService() + // ignore: use_build_context_synchronously + .printWithPrinter(ticketPrinter, printValue, context); + } catch (e, stackTrace) { + FirebaseCrashlytics.instance.recordError( + e, + stackTrace, + reason: 'Error printing ticket ${ticketPrinter.name}', + information: [ + 'Printer: ticket', + 'data: ${ticketPrinter.toMap()}', + ], + ); + log("Error printing ticket: $e"); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Error printing ticket: $e')), + ); + } + } else { + FirebaseCrashlytics.instance.recordError( + 'Ticket printer not found', + null, + reason: + 'Ticket printer not found / Printer not setting in printer page', + information: [ + 'Order ID: ${order.id}', + ], + ); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Anda belum menghubungkan printer ticket')), + ); + } + } +} + Future onPrintRecipt( context, { required Order order, diff --git a/lib/presentation/payment/pages/payment_page.dart b/lib/presentation/payment/pages/payment_page.dart index 4c99448..a66445b 100644 --- a/lib/presentation/payment/pages/payment_page.dart +++ b/lib/presentation/payment/pages/payment_page.dart @@ -371,8 +371,8 @@ class _PaymentPageState extends State { orElse: () {}, success: (data) { context.pushReplacement(SuccessPaymentPage( - productQuantity: widget.order.orderItems - ?.map( + productQuantity: getOrderItemPending() + .map( (item) => ProductQuantity( product: Product( name: item.productName, @@ -443,6 +443,7 @@ class _PaymentPageState extends State { final itemPending = widget.order.orderItems ?.where((item) => item.status == "pending") .toList(); + if (widget.isSplit == false) { final request = PaymentRequestModel( amount: widget.order.totalAmount ?? 0, diff --git a/lib/presentation/sales/pages/sales_page.dart b/lib/presentation/sales/pages/sales_page.dart index 8b7dbdd..147a264 100644 --- a/lib/presentation/sales/pages/sales_page.dart +++ b/lib/presentation/sales/pages/sales_page.dart @@ -274,7 +274,7 @@ class _SalesPageState extends State { .toProductQuantities(), ); } else { - onPrint( + onPrintBill( context, productQuantity: orderDetail!.orderItems! .toProductQuantities(), @@ -282,7 +282,7 @@ class _SalesPageState extends State { ); } }, - label: 'Print', + label: 'Print Bill', icon: Icon( Icons.print, ), diff --git a/pubspec.yaml b/pubspec.yaml index b4d40c8..ff47ccb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.2+5 +version: 1.0.2+6 environment: sdk: ">=3.2.4 <4.0.0"