diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index 122b574..1eccb86 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -23,6 +23,9 @@ Future onPrint( 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 checkerPrinter = await ProductLocalDatasource.instance.getPrinterByCode('checker'); @@ -30,18 +33,59 @@ Future onPrint( await ProductLocalDatasource.instance.getPrinterByCode('kitchen'); final barPrinter = await ProductLocalDatasource.instance.getPrinterByCode('bar'); + final receiptPrinter = + await ProductLocalDatasource.instance.getPrinterByCode('receipt'); - final authData = await AuthLocalDataSource().getAuthData(); + 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')), + ); + } // Checker printer if (checkerPrinter != null) { try { - final productByPrinter = productQuantity - .where((item) => item.product.printerType == 'checker') - .toList(); - final printValue = await PrintDataoutputs.instance.printChecker( - productByPrinter, + productQuantity, order.tableNumber ?? "", order.orderNumber ?? "", authData.user?.name ?? "", @@ -50,7 +94,7 @@ Future onPrint( order.orderType ?? "", ); - if (productByPrinter.isNotEmpty) { + if (productQuantity.isNotEmpty) { await PrinterService() // ignore: use_build_context_synchronously .printWithPrinter(checkerPrinter, printValue, context); @@ -70,6 +114,19 @@ Future onPrint( SnackBar(content: Text('Error printing checker: $e')), ); } + } else { + FirebaseCrashlytics.instance.recordError( + 'Checker printer not found', + null, + reason: + 'Checker 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 checker')), + ); } // Kitchen printer @@ -107,6 +164,19 @@ Future onPrint( SnackBar(content: Text('Error printing kitchen order: $e')), ); } + } else { + FirebaseCrashlytics.instance.recordError( + 'Kitchen printer not found', + null, + reason: + 'Kitchen 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 kitchen')), + ); } // Bar printer @@ -145,6 +215,18 @@ Future onPrint( SnackBar(content: Text('Error printing bar order: $e')), ); } + } else { + FirebaseCrashlytics.instance.recordError( + 'Bar printer not found', + null, + reason: 'Bar 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 bar')), + ); } } @@ -180,6 +262,19 @@ Future onPrint( 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')), + ); } } } @@ -229,6 +324,18 @@ Future onPrintRecipt( SnackBar(content: Text('Error printing receipt order: $e')), ); } + } else { + FirebaseCrashlytics.instance.recordError( + 'Kitchen printer not found', + null, + reason: 'Kitchen 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 kitchen')), + ); } } diff --git a/lib/core/network/dio_client.dart b/lib/core/network/dio_client.dart index 309d3b5..cf50c2c 100644 --- a/lib/core/network/dio_client.dart +++ b/lib/core/network/dio_client.dart @@ -7,8 +7,8 @@ import 'package:shared_preferences/shared_preferences.dart'; class DioClient { static final Dio _dio = Dio(BaseOptions( - connectTimeout: const Duration(seconds: 10), - receiveTimeout: const Duration(seconds: 10), + connectTimeout: const Duration(minutes: 1), + receiveTimeout: const Duration(minutes: 1), headers: { 'Accept': 'application/json', }, diff --git a/lib/data/dataoutputs/print_dataoutputs.dart b/lib/data/dataoutputs/print_dataoutputs.dart index 1620e51..b7c7d9e 100644 --- a/lib/data/dataoutputs/print_dataoutputs.dart +++ b/lib/data/dataoutputs/print_dataoutputs.dart @@ -534,7 +534,7 @@ class PrintDataoutputs { styles: const PosStyles(align: PosAlign.left), ), PosColumn( - text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', + text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', width: 6, styles: const PosStyles(align: PosAlign.right), ), @@ -799,7 +799,7 @@ class PrintDataoutputs { styles: const PosStyles(align: PosAlign.left), ), PosColumn( - text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', + text: DateFormat('yyyyMMddhhmm').format(DateTime.now()), width: 6, styles: const PosStyles(align: PosAlign.right), ), @@ -841,18 +841,20 @@ class PrintDataoutputs { styles: const PosStyles(align: PosAlign.right), ), ]); - bytes += generator.row([ - PosColumn( - text: 'Pembayaran', - width: 8, - styles: const PosStyles(align: PosAlign.left), - ), - PosColumn( - text: paymentMethod, - width: 4, - styles: const PosStyles(align: PosAlign.right), - ), - ]); + if (paymentMethod != '') { + bytes += generator.row([ + PosColumn( + text: 'Payment', + width: 8, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: paymentMethod, + width: 4, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + } bytes += generator.text( paper == 80 @@ -866,7 +868,7 @@ class PrintDataoutputs { ? '------------------------------------------------' : '--------------------------------', styles: const PosStyles(bold: false, align: PosAlign.center)); - for (final product in (products ?? [])) { + for (final product in (products)) { bytes += generator.row([ PosColumn( text: '${product.quantity} x ${product.product.name}', @@ -1057,7 +1059,7 @@ class PrintDataoutputs { styles: const PosStyles(align: PosAlign.left), ), PosColumn( - text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', + text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', width: 6, styles: const PosStyles(align: PosAlign.right), ), @@ -1112,7 +1114,7 @@ class PrintDataoutputs { ), ]); - for (final product in (productItemVoid ?? [])) { + for (final product in (productItemVoid)) { bytes += generator.row([ PosColumn( text: '${product.quantity} x ${product.productName}', @@ -1326,7 +1328,7 @@ class PrintDataoutputs { styles: const PosStyles(align: PosAlign.left), ), PosColumn( - text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', + text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}', width: 6, styles: const PosStyles(align: PosAlign.right), ), diff --git a/lib/presentation/success/pages/success_payment_page.dart b/lib/presentation/success/pages/success_payment_page.dart index d183539..59da85a 100644 --- a/lib/presentation/success/pages/success_payment_page.dart +++ b/lib/presentation/success/pages/success_payment_page.dart @@ -217,37 +217,35 @@ class _SuccessPaymentPageState extends State { const SizedBox(height: 16), // Order Details - Expanded( - child: Column( - children: [ - _buildInfoRow( - icon: Icons.receipt_long_outlined, - label: 'No. Pesanan', - value: order.orderNumber ?? "-", - ), - const SizedBox(height: 12), - _buildInfoRow( - icon: Icons.receipt_long_outlined, - label: 'Metode Pembayaran', - value: widget.paymentMethod, - ), - const SizedBox(height: 12), - _buildInfoRow( - icon: Icons.access_time_rounded, - label: 'Waktu', - value: (order.createdAt ?? DateTime.now()) - .toFormattedDate3(), - ), - const SizedBox(height: 12), - _buildInfoRow( - icon: Icons.check_circle_outline, - label: 'Status Pembayaran', - value: 'Lunas', - valueColor: Colors.green, - showBadge: true, - ), - ], - ), + Column( + children: [ + _buildInfoRow( + icon: Icons.receipt_long_outlined, + label: 'No. Pesanan', + value: order.orderNumber ?? "-", + ), + const SizedBox(height: 12), + _buildInfoRow( + icon: Icons.receipt_long_outlined, + label: 'Metode Pembayaran', + value: widget.paymentMethod, + ), + const SizedBox(height: 12), + _buildInfoRow( + icon: Icons.access_time_rounded, + label: 'Waktu', + value: (order.createdAt ?? DateTime.now()) + .toFormattedDate3(), + ), + const SizedBox(height: 12), + _buildInfoRow( + icon: Icons.check_circle_outline, + label: 'Status Pembayaran', + value: 'Lunas', + valueColor: Colors.green, + showBadge: true, + ), + ], ), ], ),