diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index b6075c2..b02676a 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -135,7 +135,8 @@ Future onPrint( final productByPrinter = productQuantity .where((item) => item.product.printerType == 'kitchen') .toList(); - final printValue = await PrintDataoutputs.instance.printKitchen( + final printValue = + await PrintDataoutputs.instance.printKitchenPerProduct( productByPrinter, order.tableNumber ?? "", order.orderNumber ?? "", diff --git a/lib/data/dataoutputs/print_dataoutputs.dart b/lib/data/dataoutputs/print_dataoutputs.dart index fb08f90..441d36b 100644 --- a/lib/data/dataoutputs/print_dataoutputs.dart +++ b/lib/data/dataoutputs/print_dataoutputs.dart @@ -1419,138 +1419,6 @@ class PrintDataoutputs { return bytes; } - Future> printKitchen( - List products, - String tableNumber, - String draftName, - String cashierName, - String customerName, - int paper, - String orderType) async { - List bytes = []; - - final profile = await CapabilityProfile.load(); - final generator = - Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile); - - bytes += generator.reset(); - - bytes += generator.text('Table Kitchen', - styles: const PosStyles( - bold: true, - align: PosAlign.center, - height: PosTextSize.size2, - width: PosTextSize.size2, - )); - bytes += generator.feed(1); - if (tableNumber.isNotEmpty) { - bytes += generator.text(tableNumber, - styles: const PosStyles( - bold: true, - align: PosAlign.center, - height: PosTextSize.size2, - width: PosTextSize.size2, - )); - bytes += generator.feed(1); - } - - bytes += generator.row([ - PosColumn( - text: 'Date', - width: 6, - styles: const PosStyles(align: PosAlign.left), - ), - PosColumn( - text: DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now()), - width: 6, - styles: const PosStyles(align: PosAlign.right), - ), - ]); - // bytes += generator.text( - // 'Date: ${DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now())}', - // styles: const PosStyles(bold: false, align: PosAlign.left)); - //reciept number - bytes += generator.row([ - PosColumn( - text: 'Receipt', - width: 6, - styles: const PosStyles(align: PosAlign.left), - ), - PosColumn( - text: DateFormat('yyyyMMddhhmm').format(DateTime.now()), - width: 6, - styles: const PosStyles(align: PosAlign.right), - ), - ]); - bytes += generator.row([ - PosColumn( - text: 'Cashier', - width: 6, - styles: const PosStyles(align: PosAlign.left), - ), - PosColumn( - text: cashierName, - width: 6, - styles: const PosStyles(align: PosAlign.right), - ), - ]); - bytes += generator.row([ - PosColumn( - text: '$customerName - $draftName', - width: 6, - styles: const PosStyles(align: PosAlign.left), - ), - PosColumn( - text: orderType, - width: 6, - styles: const PosStyles(align: PosAlign.right, bold: true), - ), - ]); - - //---- - bytes += generator.text( - paper == 80 - ? '------------------------------------------------' - : '--------------------------------', - styles: const PosStyles(bold: false, align: PosAlign.center)); - bytes += generator.feed(1); - final kitchenProducts = - products.where((p) => p.product.printerType == 'kitchen'); - for (final product in kitchenProducts) { - bytes += generator.text('${product.quantity} x ${product.product.name}', - styles: const PosStyles( - align: PosAlign.left, - bold: false, - height: PosTextSize.size2, - width: PosTextSize.size1, - )); - if (product.notes.isNotEmpty) { - bytes += generator.text(' Notes: ${product.notes}', - styles: const PosStyles( - align: PosAlign.left, - bold: false, - height: PosTextSize.size1, - width: PosTextSize.size1, - fontType: PosFontType.fontA, - )); - } - } - - bytes += generator.feed(1); - bytes += generator.text( - paper == 80 - ? '------------------------------------------------' - : '--------------------------------', - styles: const PosStyles(bold: false, align: PosAlign.center)); - paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1); - //cut - if (paper == 80) { - bytes += generator.cut(); - } - - return bytes; - } - Future> printBar( List products, String tableNumber, @@ -1717,4 +1585,262 @@ class PrintDataoutputs { return bytes; } + + Future> printKitchenAllItem( + List products, + String tableNumber, + String draftName, + String cashierName, + String customerName, + int paper, + String orderType) async { + List bytes = []; + + final profile = await CapabilityProfile.load(); + final generator = + Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile); + + bytes += generator.reset(); + + bytes += generator.text('Table Kitchen', + styles: const PosStyles( + bold: true, + align: PosAlign.center, + height: PosTextSize.size2, + width: PosTextSize.size2, + )); + bytes += generator.feed(1); + if (tableNumber.isNotEmpty) { + bytes += generator.text(tableNumber, + styles: const PosStyles( + bold: true, + align: PosAlign.center, + height: PosTextSize.size2, + width: PosTextSize.size2, + )); + bytes += generator.feed(1); + } + + bytes += generator.row([ + PosColumn( + text: 'Date', + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now()), + width: 6, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + // bytes += generator.text( + // 'Date: ${DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now())}', + // styles: const PosStyles(bold: false, align: PosAlign.left)); + //reciept number + bytes += generator.row([ + PosColumn( + text: 'Receipt', + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: DateFormat('yyyyMMddhhmm').format(DateTime.now()), + width: 6, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + bytes += generator.row([ + PosColumn( + text: 'Cashier', + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: cashierName, + width: 6, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + bytes += generator.row([ + PosColumn( + text: '$customerName - $draftName', + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: orderType, + width: 6, + styles: const PosStyles(align: PosAlign.right, bold: true), + ), + ]); + + //---- + bytes += generator.text( + paper == 80 + ? '------------------------------------------------' + : '--------------------------------', + styles: const PosStyles(bold: false, align: PosAlign.center)); + bytes += generator.feed(1); + final kitchenProducts = + products.where((p) => p.product.printerType == 'kitchen'); + for (final product in kitchenProducts) { + bytes += generator.text('${product.quantity} x ${product.product.name}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size2, + width: PosTextSize.size1, + )); + if (product.notes.isNotEmpty) { + bytes += generator.text(' Notes: ${product.notes}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size1, + width: PosTextSize.size1, + fontType: PosFontType.fontA, + )); + } + } + + bytes += generator.feed(1); + bytes += generator.text( + paper == 80 + ? '------------------------------------------------' + : '--------------------------------', + styles: const PosStyles(bold: false, align: PosAlign.center)); + paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1); + //cut + if (paper == 80) { + bytes += generator.cut(); + } + + return bytes; + } + + Future> printKitchenPerProduct( + List products, + String tableNumber, + String draftName, + String cashierName, + String customerName, + int paper, + String orderType) async { + List allBytes = []; + + final profile = await CapabilityProfile.load(); + final generator = + Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile); + + // Loop untuk setiap produk - print terpisah + for (final product in products) { + List bytes = []; + + bytes += generator.reset(); + + bytes += generator.text('Table Kitchen', + styles: const PosStyles( + bold: true, + align: PosAlign.center, + height: PosTextSize.size2, + width: PosTextSize.size2, + )); + bytes += generator.feed(1); + + if (tableNumber.isNotEmpty) { + bytes += generator.text(tableNumber, + styles: const PosStyles( + bold: true, + align: PosAlign.center, + height: PosTextSize.size2, + width: PosTextSize.size2, + )); + bytes += generator.feed(1); + } + + bytes += generator.row([ + PosColumn( + text: DateFormat('dd MMM yyyy').format(DateTime.now()), + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: DateFormat('HH:mm').format(DateTime.now()), + width: 6, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + + bytes += generator.row([ + PosColumn( + text: draftName, + width: 8, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: '', + width: 4, + styles: const PosStyles(align: PosAlign.right), + ), + ]); + + bytes += generator.row([ + PosColumn( + text: customerName, + width: 6, + styles: const PosStyles(align: PosAlign.left), + ), + PosColumn( + text: orderType, + width: 6, + styles: const PosStyles(align: PosAlign.right, bold: true), + ), + ]); + + bytes += generator.text( + paper == 80 + ? '------------------------------------------------' + : '--------------------------------', + styles: const PosStyles(bold: false, align: PosAlign.center)); + bytes += generator.feed(1); + + // Print hanya 1 produk per struk + bytes += generator.text('${product.quantity} x ${product.product.name}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size2, + width: PosTextSize.size1, + )); + + if (product.notes.isNotEmpty) { + bytes += generator.text(' Notes: ${product.notes}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size1, + width: PosTextSize.size1, + fontType: PosFontType.fontA, + )); + } + + bytes += generator.feed(1); + bytes += generator.text( + paper == 80 + ? '------------------------------------------------' + : '--------------------------------', + styles: const PosStyles(bold: false, align: PosAlign.center)); + + paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1); + + if (paper == 80) { + bytes += generator.cut(); + } + + // Tambahkan ke allBytes + allBytes += bytes; + } + + return allBytes; + } } diff --git a/lib/presentation/setting/widgets/kitchen_printer_page.dart b/lib/presentation/setting/widgets/kitchen_printer_page.dart index 592b5ce..bf9be74 100644 --- a/lib/presentation/setting/widgets/kitchen_printer_page.dart +++ b/lib/presentation/setting/widgets/kitchen_printer_page.dart @@ -175,7 +175,7 @@ class _KitchenPrinterPageState extends State { // Generate test print data final testPrintData = await PrintDataoutputs .instance - .printKitchen( + .printKitchenAllItem( [], // Empty product list for test 'Test Table', 'Test Order', diff --git a/pubspec.yaml b/pubspec.yaml index 442e126..ce3a0dc 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.1+2 +version: 1.0.1+4 environment: sdk: ">=3.2.4 <4.0.0"