This commit is contained in:
efrilm 2025-10-08 17:06:23 +07:00
parent 1fbacae1f4
commit 290360674f
4 changed files with 114 additions and 5 deletions

View File

@ -280,6 +280,114 @@ Future<void> onPrint(
}
}
Future<void> onPrintBill(
BuildContext context, {
required List<ProductQuantity> productQuantity,
required Order order,
}) async {
final outlet = await OutletLocalDatasource().get();
final settings = await SettingsLocalDatasource().getTax();
final authData = await AuthLocalDataSource().getAuthData();
if (outlet.businessType == BusinessType.restaurant) {
final receiptPrinter =
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
if (receiptPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printOrderV4(
order,
authData.user?.name ?? "",
'',
0,
0,
settings.value,
receiptPrinter.paper.toIntegerFromText,
order.orderType ?? "",
outlet,
productQuantity);
await PrinterService()
.printWithPrinter(receiptPrinter, printValue, context);
} catch (e, stackTrace) {
FirebaseCrashlytics.instance.recordError(
e,
stackTrace,
reason: 'Print receipt failed',
information: [
'Order ID: ${order.id}',
'Printer: ${receiptPrinter.name}',
],
);
log("Error printing receipt order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing receipt order: $e')),
);
}
} else {
FirebaseCrashlytics.instance.recordError(
'Receipt printer not found',
null,
reason:
'Receipt printer not found / Printer not setting in printer page',
information: [
'Order ID: ${order.id}',
],
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Anda belum menghubungkan printer receipt')),
);
}
}
if (outlet.businessType == BusinessType.ticketing) {
final ticketPrinter =
await PrinterLocalDatasource.instance.getPrinterByCode('ticket');
final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? "");
if (ticketPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printTicket(
order.totalAmount ?? 0,
barcode,
ticketPrinter.paper.toIntegerFromText,
);
await PrinterService()
// ignore: use_build_context_synchronously
.printWithPrinter(ticketPrinter, printValue, context);
} catch (e, stackTrace) {
FirebaseCrashlytics.instance.recordError(
e,
stackTrace,
reason: 'Error printing ticket ${ticketPrinter.name}',
information: [
'Printer: ticket',
'data: ${ticketPrinter.toMap()}',
],
);
log("Error printing ticket: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing ticket: $e')),
);
}
} else {
FirebaseCrashlytics.instance.recordError(
'Ticket printer not found',
null,
reason:
'Ticket printer not found / Printer not setting in printer page',
information: [
'Order ID: ${order.id}',
],
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Anda belum menghubungkan printer ticket')),
);
}
}
}
Future<void> onPrintRecipt(
context, {
required Order order,

View File

@ -371,8 +371,8 @@ class _PaymentPageState extends State<PaymentPage> {
orElse: () {},
success: (data) {
context.pushReplacement(SuccessPaymentPage(
productQuantity: widget.order.orderItems
?.map(
productQuantity: getOrderItemPending()
.map(
(item) => ProductQuantity(
product: Product(
name: item.productName,
@ -443,6 +443,7 @@ class _PaymentPageState extends State<PaymentPage> {
final itemPending = widget.order.orderItems
?.where((item) => item.status == "pending")
.toList();
if (widget.isSplit == false) {
final request = PaymentRequestModel(
amount: widget.order.totalAmount ?? 0,

View File

@ -274,7 +274,7 @@ class _SalesPageState extends State<SalesPage> {
.toProductQuantities(),
);
} else {
onPrint(
onPrintBill(
context,
productQuantity: orderDetail!.orderItems!
.toProductQuantities(),
@ -282,7 +282,7 @@ class _SalesPageState extends State<SalesPage> {
);
}
},
label: 'Print',
label: 'Print Bill',
icon: Icon(
Icons.print,
),

View File

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.2+5
version: 1.0.2+6
environment:
sdk: ">=3.2.4 <4.0.0"