update printer

This commit is contained in:
Efril
2026-05-25 20:35:40 +07:00
parent 56e720e253
commit 6d9377f4ab
8 changed files with 185 additions and 44 deletions
+27 -14
View File
@@ -88,9 +88,9 @@ class PrintUi {
paperSize: paper,
);
for (final item in order.orderItems) {
bytes += generator.reset();
bytes += generator.reset();
for (final item in order.orderItems) {
bytes += builder.separator();
bytes += builder.printerType(printerType: 'CHECKER');
bytes += builder.separator();
@@ -118,11 +118,11 @@ class PrintUi {
variantName: item.productVariantName,
notes: item.notes,
);
bytes += builder.separator();
bytes += builder.footer();
}
bytes += builder.separator();
bytes += builder.cutOnly();
return bytes;
}
@@ -144,7 +144,17 @@ class PrintUi {
paperSize: paper,
);
// Group items by category
final Map<String, List<OrderItem>> groupedItems = {};
for (final item in order.orderItems) {
final key = item.categoryName.isNotEmpty ? item.categoryName : 'Lainnya';
groupedItems.putIfAbsent(key, () => []).add(item);
}
for (final entry in groupedItems.entries) {
final categoryName = entry.key;
final items = entry.value;
bytes += generator.reset();
bytes += builder.separator();
@@ -158,17 +168,20 @@ class PrintUi {
tableNumber: order.tableNumber,
);
bytes += builder.separator();
bytes += builder.orderType(categoryName);
bytes += builder.emptyLines(1);
bytes += builder.orderItem(
productName: item.productName,
quantity: item.quantity,
unitPrice: item.unitPrice.currencyFormatRpV2,
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
);
for (final item in items) {
bytes += builder.orderItem(
productName: item.productName,
quantity: item.quantity,
unitPrice: item.unitPrice.currencyFormatRpV2,
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
);
}
bytes += builder.separator();
bytes += builder.footer();
@@ -9,11 +9,6 @@ class ReceiptComponentBuilder {
ReceiptComponentBuilder({required this.generator, this.paperSize = 58});
/// Get separator line based on paper size
String get _separator => paperSize == 80
? '------------------------------------------------'
: '--------------------------------';
/// Print text centered with custom style
List<int> textCenter(
String text, {
@@ -48,11 +43,21 @@ class ReceiptComponentBuilder {
);
}
/// Characters per line based on paper size (always size1 font)
String get _separatorLine => paperSize == 80
? '------------------------------------------------'
: '--------------------------------';
/// Print separator line
List<int> separator({bool bold = false}) {
return generator.text(
_separator,
styles: PosStyles(bold: bold, align: PosAlign.center),
_separatorLine,
styles: PosStyles(
bold: bold,
align: PosAlign.center,
height: PosTextSize.size1,
width: PosTextSize.size1,
),
);
}
@@ -116,6 +121,10 @@ class ReceiptComponentBuilder {
return generator.feed(count);
}
/// Helper: returns size2 for 80mm paper, size1 for 58mm
PosTextSize get _titleSize =>
paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
/// Print header (outlet info)
List<int> header({
required String outletName,
@@ -127,8 +136,8 @@ class ReceiptComponentBuilder {
bytes += textCenter(
outletName,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
bytes += textCenter(address);
bytes += textCenter(phoneNumber);
@@ -143,8 +152,8 @@ class ReceiptComponentBuilder {
bytes += textCenter(
printerType,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
return bytes;
@@ -168,21 +177,16 @@ class ReceiptComponentBuilder {
}) {
List<int> bytes = [];
bytes += row2Columns('Nomor', orderNumber, leftWidth: 4, rightWidth: 8);
bytes += row2Columns('Nomor', orderNumber);
bytes += row2Columns('Pelanggan', customerName);
bytes += row2Columns('Kasir', cashierName, leftWidth: 4, rightWidth: 8);
bytes += row2Columns('Kasir', cashierName);
if (paymentMethod != null) {
bytes += row2Columns(
'Pembayaran',
paymentMethod,
leftWidth: 8,
rightWidth: 4,
);
bytes += row2Columns('Pembayaran', paymentMethod);
}
if (tableNumber != null && tableNumber.isNotEmpty) {
bytes += row2Columns('Meja', tableNumber, leftWidth: 8, rightWidth: 4);
bytes += row2Columns('Meja', tableNumber);
}
return bytes;
@@ -193,7 +197,7 @@ class ReceiptComponentBuilder {
List<int> bytes = [];
bytes += separator();
bytes += textCenter(type, bold: true);
bytes += textCenter(type, bold: true, height: _titleSize, width: _titleSize);
bytes += separator();
return bytes;
@@ -214,7 +218,7 @@ class ReceiptComponentBuilder {
? '$productName ($variantName)'
: productName;
bytes += textLeft(displayName);
bytes += textLeft(displayName, bold: paperSize == 80);
bytes += row2Columns(
'$quantity x $unitPrice',
totalPrice,
@@ -263,19 +267,27 @@ class ReceiptComponentBuilder {
bytes += textCenter(
message,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
if (kDebugMode) {
bytes += textCenter("$paperSize MM", );
bytes += textCenter("$paperSize MM");
}
bytes += feed(paperSize == 80 ? 3 : 1);
bytes += generator.cut();
return bytes;
}
/// Cut paper without printing footer message
List<int> cutOnly() {
List<int> bytes = [];
bytes += feed(paperSize == 80 ? 3 : 1);
bytes += generator.cut();
return bytes;
}
/// Print QR Code
List<int> qrCode(String data, {PosAlign align = PosAlign.center}) {
return generator.qrcode(data, align: align);