fix split bill

This commit is contained in:
efrilm
2025-11-21 19:53:02 +07:00
parent e585cf4292
commit 96387c08f4
7 changed files with 1471 additions and 57 deletions
+263
View File
@@ -1843,4 +1843,267 @@ class PrintDataoutputs {
return allBytes;
}
Future<List<int>> printSplitBill(
Order order,
String chashierName,
int paper,
Outlet outlet,
) 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(outlet.name ?? "",
styles: const PosStyles(
bold: true,
align: PosAlign.center,
height: PosTextSize.size1,
width: PosTextSize.size1,
));
bytes += generator.text(outlet.address ?? "",
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(outlet.phoneNumber ?? "",
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
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: 'Receipt Number',
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: 'Order ID',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: Random().nextInt(100000).toString(),
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Bill Name',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: order.metadata?['customer_name'] ?? '',
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Collected By',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: chashierName,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
if (order.payments != null) {
bytes += generator.row([
PosColumn(
text: 'Payment',
width: 8,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: order.payments?.last.paymentMethodName ?? '-',
width: 4,
styles: const PosStyles(align: PosAlign.right),
),
]);
}
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(order.orderType ?? '-',
styles: const PosStyles(bold: true, align: PosAlign.center));
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text("SPLIT",
styles: const PosStyles(bold: true, align: PosAlign.center));
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
for (final item in (order.orderItems ?? <OrderItem>[])) {
bytes += generator.row([
PosColumn(
text: '${item.quantity} x ${item.productName}',
width: 8,
styles: const PosStyles(bold: true, align: PosAlign.left),
),
PosColumn(
text: (((item.unitPrice ?? 0) * (item.quantity ?? 0)))
.currencyFormatRpV2,
width: 4,
styles: const PosStyles(bold: true, align: PosAlign.right),
),
]);
if (item.notes != '') {
bytes += generator.row([
PosColumn(
text: 'Note',
width: 4,
styles: const PosStyles(bold: false, align: PosAlign.left),
),
PosColumn(
text: item.notes ?? "-",
width: 8,
styles: const PosStyles(bold: false, align: PosAlign.right),
),
]);
}
}
if (order.orderItems?.isNotEmpty ?? false) {
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
}
bytes += generator.row([
PosColumn(
text: 'Subtotal',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Discount',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: (order.discountAmount ?? 0).currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
// Only show tax if it's greater than 0
if ((order.taxAmount ?? 0) > 0) {
bytes += generator.row([
PosColumn(
text: 'Tax PB1 (${order.taxAmount}%)',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: (order.taxAmount ?? 0).currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
}
// Only show service charge if it's greater than 0
// if (serviceCharge > 0) {
// bytes += generator.row([
// PosColumn(
// text: 'Service Charge($serviceChargePercentage%)',
// width: 6,
// styles: const PosStyles(align: PosAlign.left),
// ),
// PosColumn(
// text: serviceCharge.currencyFormatRpV2,
// width: 6,
// styles: const PosStyles(align: PosAlign.right),
// ),
// ]);
// }
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.row([
PosColumn(
text: 'Total',
width: 6,
styles: const PosStyles(bold: true, align: PosAlign.left),
),
PosColumn(
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
width: 6,
styles: const PosStyles(bold: true, align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Dibayar',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
bytes += generator.cut();
return bytes;
}
}
@@ -401,3 +401,103 @@ extension OrderItemListExtension on List<OrderItem> {
quantity: e.quantity ?? 0,
)).toList();
}
extension OrderCopyWith on Order {
Order copyWith({
String? id,
String? orderNumber,
String? outletId,
String? userId,
String? tableNumber,
String? orderType,
String? status,
int? subtotal,
int? taxAmount,
int? discountAmount,
int? totalAmount,
num? totalCost,
int? remainingAmount,
String? paymentStatus,
int? refundAmount,
bool? isVoid,
bool? isRefund,
String? notes,
Map<String, dynamic>? metadata,
DateTime? createdAt,
DateTime? updatedAt,
List<OrderItem>? orderItems,
List<Payment>? payments,
int? totalPaid,
int? paymentCount,
String? splitType,
}) {
return Order(
id: id ?? this.id,
orderNumber: orderNumber ?? this.orderNumber,
outletId: outletId ?? this.outletId,
userId: userId ?? this.userId,
tableNumber: tableNumber ?? this.tableNumber,
orderType: orderType ?? this.orderType,
status: status ?? this.status,
subtotal: subtotal ?? this.subtotal,
taxAmount: taxAmount ?? this.taxAmount,
discountAmount: discountAmount ?? this.discountAmount,
totalAmount: totalAmount ?? this.totalAmount,
totalCost: totalCost ?? this.totalCost,
remainingAmount: remainingAmount ?? this.remainingAmount,
paymentStatus: paymentStatus ?? this.paymentStatus,
refundAmount: refundAmount ?? this.refundAmount,
isVoid: isVoid ?? this.isVoid,
isRefund: isRefund ?? this.isRefund,
notes: notes ?? this.notes,
metadata: metadata ?? this.metadata,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
orderItems: orderItems ?? this.orderItems,
payments: payments ?? this.payments,
totalPaid: totalPaid ?? this.totalPaid,
paymentCount: paymentCount ?? this.paymentCount,
splitType: splitType ?? this.splitType,
);
}
}
extension OrderItemCopyWith on OrderItem {
OrderItem copyWith({
String? id,
String? orderId,
String? productId,
String? productName,
String? productVariantId,
String? productVariantName,
int? quantity,
int? unitPrice,
int? totalPrice,
List<dynamic>? modifiers,
String? notes,
String? status,
DateTime? createdAt,
DateTime? updatedAt,
String? printerType,
int? paidQuantity,
}) {
return OrderItem(
id: id ?? this.id,
orderId: orderId ?? this.orderId,
productId: productId ?? this.productId,
productName: productName ?? this.productName,
productVariantId: productVariantId ?? this.productVariantId,
productVariantName: productVariantName ?? this.productVariantName,
quantity: quantity ?? this.quantity,
unitPrice: unitPrice ?? this.unitPrice,
totalPrice: totalPrice ?? this.totalPrice,
modifiers: modifiers ?? this.modifiers,
notes: notes ?? this.notes,
status: status ?? this.status,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
printerType: printerType ?? this.printerType,
paidQuantity: paidQuantity ?? this.paidQuantity,
);
}
}