73 lines
1.9 KiB
Dart
73 lines
1.9 KiB
Dart
|
|
import 'package:esc_pos_utils_plus/esc_pos_utils_plus.dart';
|
||
|
|
|
||
|
|
import '../../../common/extension/extension.dart';
|
||
|
|
import '../../../domain/order/order.dart';
|
||
|
|
import '../../../domain/outlet/outlet.dart';
|
||
|
|
import 'receipt_component_builder.dart';
|
||
|
|
|
||
|
|
class PrintUi {
|
||
|
|
Future<List<int>> printOrder({
|
||
|
|
required Order order,
|
||
|
|
required Outlet outlet,
|
||
|
|
required String cashierName,
|
||
|
|
int paper = 58,
|
||
|
|
}) async {
|
||
|
|
List<int> bytes = [];
|
||
|
|
|
||
|
|
final profile = await CapabilityProfile.load();
|
||
|
|
final generator = Generator(
|
||
|
|
paper == 58 ? PaperSize.mm58 : PaperSize.mm80,
|
||
|
|
profile,
|
||
|
|
);
|
||
|
|
final builder = ReceiptComponentBuilder(
|
||
|
|
generator: generator,
|
||
|
|
paperSize: 58,
|
||
|
|
);
|
||
|
|
|
||
|
|
bytes += generator.reset();
|
||
|
|
|
||
|
|
bytes += builder.header(
|
||
|
|
outletName: outlet.name,
|
||
|
|
address: outlet.address,
|
||
|
|
phoneNumber: outlet.phoneNumber,
|
||
|
|
);
|
||
|
|
|
||
|
|
bytes += builder.dateTime(DateTime.now());
|
||
|
|
|
||
|
|
bytes += builder.orderInfo(
|
||
|
|
orderNumber: order.orderNumber,
|
||
|
|
customerName: order.metadata['customer_name'] ?? 'John Doe',
|
||
|
|
cashierName: cashierName,
|
||
|
|
paymentMethod: order.payments.last.paymentMethodName,
|
||
|
|
tableNumber: order.tableNumber,
|
||
|
|
);
|
||
|
|
|
||
|
|
bytes += builder.orderType(order.orderType);
|
||
|
|
|
||
|
|
bytes += builder.emptyLines(1);
|
||
|
|
|
||
|
|
for (final item in order.orderItems) {
|
||
|
|
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.summary(
|
||
|
|
totalItems: order.orderItems.length,
|
||
|
|
subtotal: order.subtotal.currencyFormatRpV2,
|
||
|
|
discount: order.discountAmount.currencyFormatRpV2,
|
||
|
|
total: order.totalAmount.currencyFormatRpV2,
|
||
|
|
paid: order.totalPaid.currencyFormatRpV2,
|
||
|
|
);
|
||
|
|
|
||
|
|
bytes += builder.footer();
|
||
|
|
|
||
|
|
return bytes;
|
||
|
|
}
|
||
|
|
}
|