update printer checker

This commit is contained in:
Efril
2026-05-27 16:13:12 +07:00
parent ea29c62af1
commit beb86f6259
5 changed files with 86 additions and 62 deletions
@@ -149,6 +149,26 @@ class Order with _$Order {
categoryId: 'CAT-002',
categoryName: 'Makanan',
),
OrderItem(
id: 'ITEM-003',
orderId: 'ORD-001',
productId: 'PROD-003',
productName: 'Pasta',
productVariantId: 'VAR-002',
productVariantName: '',
quantity: 1,
unitPrice: 50000,
totalPrice: 50000,
modifiers: [],
notes: '',
status: 'Served',
createdAt: DateTime.now().subtract(const Duration(hours: 1)),
updatedAt: DateTime.now(),
printerType: 'Kitchen',
paidQuantity: 1,
categoryId: 'CAT-002',
categoryName: 'Makanan',
),
],
payments: [
Payment(
@@ -102,6 +102,7 @@ class PrintUi {
orderNumber: order.orderNumber,
orderType: order.orderType,
cashierName: cashierName,
customerName: order.metadata['customer_name'] ?? '-',
);
bytes += builder.separator();
@@ -146,7 +147,7 @@ class PrintUi {
bytes += generator.reset();
// Header
bytes += builder.row2Columns('Kitchen', order.orderType, bold: true);
bytes += builder.row2Columns('Kitchen', order.orderType.toUpperCase(), bold: true);
bytes += builder.separator();
bytes += builder.textCenter(
'Table : ${order.tableNumber.isNotEmpty ? order.tableNumber : '-'}',
@@ -9,26 +9,26 @@ class ReceiptComponentBuilder {
ReceiptComponentBuilder({required this.generator, this.paperSize = 58});
/// Helper: returns size2 for 80mm paper, size1 for 58mm
PosTextSize get _titleSize =>
paperSize == 80 ? PosTextSize.size3 : PosTextSize.size1;
/// Font type per paper size — easy to change here
/// 58mm → fontA, 80mm → fontA
PosFontType get _font =>
paperSize == 80 ? PosFontType.fontA : PosFontType.fontA;
paperSize == 80 ? PosFontType.fontB : PosFontType.fontA;
/// Text size for body — height size2 for 80mm to appear taller, size1 for 58mm
PosTextSize get _bodySize =>
PosTextSize get _bodyHeight =>
paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
/// Body width stays size1 always to prevent overflow
PosTextSize get _bodyWidth => PosTextSize.size1;
PosTextSize get _bodyWidth => paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
/// Characters per line based on paper size (always size1 font)
String get _separatorLine => paperSize == 80
? '------------------------------------------------'
: '--------------------------------';
/// Characters per line based on paper size and font
String get _separatorLine {
if (paperSize == 80) {
return _font == PosFontType.fontB
? '----------------------------------------------------------------'
: '------------------------------------------------';
} else {
return _font == PosFontType.fontB
? '------------------------------------------'
: '--------------------------------';
}
}
// ---------------------------------------------------------------------------
// Basic text
@@ -37,17 +37,18 @@ class ReceiptComponentBuilder {
List<int> textCenter(
String text, {
bool bold = false,
PosTextSize height = PosTextSize.size1,
PosTextSize width = PosTextSize.size1,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
return generator.text(
text,
styles: PosStyles(
bold: bold,
align: PosAlign.center,
height: height,
width: width,
fontType: _font,
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
),
);
}
@@ -59,7 +60,7 @@ class ReceiptComponentBuilder {
bold: bold,
align: PosAlign.left,
fontType: _font,
height: _bodySize,
height: _bodyHeight,
width: _bodyWidth,
),
);
@@ -72,7 +73,7 @@ class ReceiptComponentBuilder {
bold: bold,
align: PosAlign.right,
fontType: _font,
height: _bodySize,
height: _bodyHeight,
width: _bodyWidth,
),
);
@@ -110,8 +111,6 @@ class ReceiptComponentBuilder {
align: PosAlign.left,
bold: bold,
fontType: _font,
height: _bodySize,
width: _bodyWidth,
),
),
PosColumn(
@@ -121,8 +120,6 @@ class ReceiptComponentBuilder {
align: PosAlign.right,
bold: bold,
fontType: _font,
height: _bodySize,
width: _bodyWidth,
),
),
]);
@@ -163,8 +160,8 @@ class ReceiptComponentBuilder {
bold: bold,
align: PosAlign.left,
fontType: _font,
height: PosTextSize.size2,
width: PosTextSize.size2,
height: _bodyHeight,
width: _bodyWidth,
),
);
}
@@ -184,7 +181,7 @@ class ReceiptComponentBuilder {
required String phoneNumber,
}) {
List<int> bytes = [];
bytes += textCenter(outletName, bold: true, height: _titleSize, width: _titleSize);
bytes += textCenter(outletName, bold: true);
bytes += textCenter(address);
bytes += textCenter(phoneNumber);
bytes += separator();
@@ -193,7 +190,7 @@ class ReceiptComponentBuilder {
/// Centered printer type label (e.g. KITCHEN, BAR)
List<int> printerType({required String printerType}) {
return textCenter(printerType, bold: true, height: _titleSize, width: _titleSize);
return textCenter(printerType, bold: true);
}
/// Date + time row (receipt style)
@@ -209,15 +206,21 @@ class ReceiptComponentBuilder {
required String orderNumber,
String? orderType,
required String cashierName,
String? customerName,
}) {
List<int> bytes = [];
final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now());
bytes += textLeft('Order : $orderNumber');
bytes += textLeft('Date : $dateStr');
if(orderType != null) {
bytes += textLeft('Purpose : $orderType');
bytes += textLeft('Order : $orderNumber');
bytes += textLeft('Date : $dateStr');
if(customerName != null) {
bytes += textLeft('Customer : $customerName');
}
bytes += textLeft('Waiter : $cashierName');
if(orderType != null) {
bytes += textLeft('Purpose : ${orderType.toUpperCase()}');
}
bytes += textLeft('Waiter : $cashierName');
return bytes;
}
@@ -250,7 +253,7 @@ class ReceiptComponentBuilder {
List<int> orderType(String type) {
List<int> bytes = [];
bytes += separator();
bytes += textCenter(type, bold: true, height: _titleSize, width: _titleSize);
bytes += textCenter(type, bold: true);
bytes += separator();
return bytes;
}
@@ -268,8 +271,8 @@ class ReceiptComponentBuilder {
final displayName = (variantName != null && variantName.isNotEmpty)
? '$productName ($variantName)'
: productName;
bytes += textLeft(displayName, bold: paperSize == 80);
bytes += row2Columns('$quantity x $unitPrice', totalPrice, leftWidth: 8, rightWidth: 4);
bytes += textLeft(displayName, bold: true);
bytes += row2Columns('${quantity}x $unitPrice', totalPrice);
if (notes != null && notes.isNotEmpty) {
bytes += row2Columns('Note', notes, leftWidth: 4, rightWidth: 8);
}
@@ -303,7 +306,7 @@ class ReceiptComponentBuilder {
List<int> footer({String message = 'Terima kasih'}) {
List<int> bytes = [];
bytes += emptyLines(2);
bytes += textCenter(message, bold: true, height: _titleSize, width: _titleSize);
bytes += textCenter(message, bold: true);
if (kDebugMode) {
bytes += textCenter('$paperSize MM');
}