fix printer
This commit is contained in:
@@ -53,28 +53,32 @@ class ReceiptComponentBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
List<int> textLeft(String text, {bool bold = false}) {
|
||||
List<int> textLeft(String text, {bool bold = false, PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,}) {
|
||||
return generator.text(
|
||||
text,
|
||||
styles: PosStyles(
|
||||
bold: bold,
|
||||
align: PosAlign.left,
|
||||
fontType: _font,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<int> textRight(String text, {bool bold = false}) {
|
||||
List<int> textRight(String text, {bool bold = false, PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,}) {
|
||||
return generator.text(
|
||||
text,
|
||||
styles: PosStyles(
|
||||
bold: bold,
|
||||
align: PosAlign.right,
|
||||
fontType: _font,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -102,6 +106,9 @@ class ReceiptComponentBuilder {
|
||||
bool bold = false,
|
||||
int leftWidth = 6,
|
||||
int rightWidth = 6,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
return generator.row([
|
||||
PosColumn(
|
||||
@@ -110,9 +117,9 @@ class ReceiptComponentBuilder {
|
||||
styles: PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: bold,
|
||||
fontType: _font,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
),
|
||||
),
|
||||
PosColumn(
|
||||
@@ -121,9 +128,9 @@ class ReceiptComponentBuilder {
|
||||
styles: PosStyles(
|
||||
align: PosAlign.right,
|
||||
bold: bold,
|
||||
fontType: _font,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
),
|
||||
),
|
||||
]);
|
||||
@@ -183,14 +190,17 @@ class ReceiptComponentBuilder {
|
||||
required String outletName,
|
||||
required String address,
|
||||
required String phoneNumber,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
bytes += textCenter(outletName, bold: true);
|
||||
bytes += textCenter(address);
|
||||
bytes += textCenter(phoneNumber);
|
||||
bytes += textCenter(outletName, height: PosTextSize.size2, width: PosTextSize.size2, fontType: fontType, bold: true);
|
||||
bytes += textCenter(address, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += textCenter(phoneNumber, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += separator();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/// Centered printer type label (e.g. KITCHEN, BAR)
|
||||
List<int> printerType({required String printerType}) {
|
||||
@@ -198,10 +208,16 @@ class ReceiptComponentBuilder {
|
||||
}
|
||||
|
||||
/// Date + time row (receipt style)
|
||||
List<int> dateTime(DateTime dateTime) {
|
||||
List<int> dateTime(DateTime dateTime, { PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
return row2Columns(
|
||||
DateFormat('dd MMM yyyy').format(dateTime),
|
||||
DateFormat('HH:mm').format(dateTime),
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -235,29 +251,48 @@ class ReceiptComponentBuilder {
|
||||
required String cashierName,
|
||||
String? paymentMethod,
|
||||
String? tableNumber,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now());
|
||||
bytes += textLeft('Order : $orderNumber');
|
||||
bytes += textLeft('Date : $dateStr');
|
||||
bytes += textLeft('Order : $orderNumber', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += textLeft('Date : $dateStr', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
if (tableNumber != null && tableNumber.isNotEmpty) {
|
||||
bytes += textLeft('Table : $tableNumber');
|
||||
bytes += textLeft('Table : $tableNumber', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
}
|
||||
bytes += textLeft('Waiter : $cashierName');
|
||||
bytes += textLeft('Customer : $customerName');
|
||||
bytes += textLeft('Waiter : $cashierName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += textLeft('Customer : $customerName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
|
||||
if (paymentMethod != null) {
|
||||
bytes += textLeft('Payment : $paymentMethod');
|
||||
bytes += textLeft('Payment : $paymentMethod', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// Order type banner (separator + type + separator)
|
||||
List<int> orderType(String type) {
|
||||
List<int> orderType(String type, {
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
bytes += separator();
|
||||
bytes += textCenter(type, bold: true);
|
||||
bytes += textCenter(type.toUpperCase(), fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, bold: true);
|
||||
bytes += separator();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
List<int> tableName(String table, {
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
bytes += separator();
|
||||
bytes += textCenter( 'Table : ${table.isNotEmpty ? table : '-'}', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, bold: true);
|
||||
bytes += separator();
|
||||
return bytes;
|
||||
}
|
||||
@@ -270,15 +305,18 @@ class ReceiptComponentBuilder {
|
||||
required String totalPrice,
|
||||
String? variantName,
|
||||
String? notes,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
final displayName = (variantName != null && variantName.isNotEmpty)
|
||||
? '$productName ($variantName)'
|
||||
: productName;
|
||||
bytes += textLeft(displayName, bold: true);
|
||||
bytes += row2Columns('${quantity}x $unitPrice', totalPrice);
|
||||
bytes += textLeft(displayName, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
|
||||
bytes += row2Columns('${quantity}x $unitPrice', totalPrice, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
if (notes != null && notes.isNotEmpty) {
|
||||
bytes += row2Columns('Note', notes, leftWidth: 4, rightWidth: 8);
|
||||
bytes += row2Columns('Note', notes, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, leftWidth: 4, rightWidth: 8);
|
||||
}
|
||||
bytes += emptyLines(1);
|
||||
return bytes;
|
||||
@@ -291,17 +329,20 @@ class ReceiptComponentBuilder {
|
||||
required String discount,
|
||||
required String total,
|
||||
required String paid,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
bytes += separator();
|
||||
if (totalItems > 0) {
|
||||
bytes += row2Columns('Total Item', totalItems.toString());
|
||||
bytes += row2Columns('Total Item', totalItems.toString(), fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
}
|
||||
bytes += row2Columns('Subtotal', subtotal);
|
||||
bytes += row2Columns('Diskon', discount);
|
||||
bytes += row2Columns('Subtotal', subtotal, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
bytes += row2Columns('Diskon', discount, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
bytes += separator();
|
||||
bytes += row2Columns('Total', total, bold: true);
|
||||
bytes += row2Columns('Bayar', paid);
|
||||
bytes += row2Columns('Total', total, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
bytes += row2Columns('Bayar', paid, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
|
||||
bytes += separator();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user