print kitchen update

This commit is contained in:
efrilm 2025-10-02 17:57:48 +07:00
parent 2813011fac
commit 455a6afd70
4 changed files with 262 additions and 135 deletions

View File

@ -135,7 +135,8 @@ Future<void> 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 ?? "",

View File

@ -1419,138 +1419,6 @@ class PrintDataoutputs {
return bytes;
}
Future<List<int>> printKitchen(
List<ProductQuantity> products,
String tableNumber,
String draftName,
String cashierName,
String customerName,
int paper,
String orderType) async {
List<int> 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<List<int>> printBar(
List<ProductQuantity> products,
String tableNumber,
@ -1717,4 +1585,262 @@ class PrintDataoutputs {
return bytes;
}
Future<List<int>> printKitchenAllItem(
List<ProductQuantity> products,
String tableNumber,
String draftName,
String cashierName,
String customerName,
int paper,
String orderType) async {
List<int> 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<List<int>> printKitchenPerProduct(
List<ProductQuantity> products,
String tableNumber,
String draftName,
String cashierName,
String customerName,
int paper,
String orderType) async {
List<int> 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<int> 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;
}
}

View File

@ -175,7 +175,7 @@ class _KitchenPrinterPageState extends State<KitchenPrinterPage> {
// Generate test print data
final testPrintData = await PrintDataoutputs
.instance
.printKitchen(
.printKitchenAllItem(
[], // Empty product list for test
'Test Table',
'Test Order',

View File

@ -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"