This commit is contained in:
parent
a6ac12c36a
commit
7b12793618
@ -23,6 +23,9 @@ Future<void> onPrint(
|
|||||||
required Order order,
|
required Order order,
|
||||||
}) async {
|
}) async {
|
||||||
final outlet = await OutletLocalDatasource().get();
|
final outlet = await OutletLocalDatasource().get();
|
||||||
|
final settings = await SettingsLocalDatasource().getTax();
|
||||||
|
final authData = await AuthLocalDataSource().getAuthData();
|
||||||
|
|
||||||
if (outlet.businessType == BusinessType.restaurant) {
|
if (outlet.businessType == BusinessType.restaurant) {
|
||||||
final checkerPrinter =
|
final checkerPrinter =
|
||||||
await ProductLocalDatasource.instance.getPrinterByCode('checker');
|
await ProductLocalDatasource.instance.getPrinterByCode('checker');
|
||||||
@ -30,18 +33,59 @@ Future<void> onPrint(
|
|||||||
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
|
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
|
||||||
final barPrinter =
|
final barPrinter =
|
||||||
await ProductLocalDatasource.instance.getPrinterByCode('bar');
|
await ProductLocalDatasource.instance.getPrinterByCode('bar');
|
||||||
|
final receiptPrinter =
|
||||||
|
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
|
||||||
|
|
||||||
final authData = await AuthLocalDataSource().getAuthData();
|
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')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Checker printer
|
// Checker printer
|
||||||
if (checkerPrinter != null) {
|
if (checkerPrinter != null) {
|
||||||
try {
|
try {
|
||||||
final productByPrinter = productQuantity
|
|
||||||
.where((item) => item.product.printerType == 'checker')
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final printValue = await PrintDataoutputs.instance.printChecker(
|
final printValue = await PrintDataoutputs.instance.printChecker(
|
||||||
productByPrinter,
|
productQuantity,
|
||||||
order.tableNumber ?? "",
|
order.tableNumber ?? "",
|
||||||
order.orderNumber ?? "",
|
order.orderNumber ?? "",
|
||||||
authData.user?.name ?? "",
|
authData.user?.name ?? "",
|
||||||
@ -50,7 +94,7 @@ Future<void> onPrint(
|
|||||||
order.orderType ?? "",
|
order.orderType ?? "",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (productByPrinter.isNotEmpty) {
|
if (productQuantity.isNotEmpty) {
|
||||||
await PrinterService()
|
await PrinterService()
|
||||||
// ignore: use_build_context_synchronously
|
// ignore: use_build_context_synchronously
|
||||||
.printWithPrinter(checkerPrinter, printValue, context);
|
.printWithPrinter(checkerPrinter, printValue, context);
|
||||||
@ -70,6 +114,19 @@ Future<void> onPrint(
|
|||||||
SnackBar(content: Text('Error printing checker: $e')),
|
SnackBar(content: Text('Error printing checker: $e')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
FirebaseCrashlytics.instance.recordError(
|
||||||
|
'Checker printer not found',
|
||||||
|
null,
|
||||||
|
reason:
|
||||||
|
'Checker 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 checker')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kitchen printer
|
// Kitchen printer
|
||||||
@ -107,6 +164,19 @@ Future<void> onPrint(
|
|||||||
SnackBar(content: Text('Error printing kitchen order: $e')),
|
SnackBar(content: Text('Error printing kitchen order: $e')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
FirebaseCrashlytics.instance.recordError(
|
||||||
|
'Kitchen printer not found',
|
||||||
|
null,
|
||||||
|
reason:
|
||||||
|
'Kitchen 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 kitchen')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bar printer
|
// Bar printer
|
||||||
@ -145,6 +215,18 @@ Future<void> onPrint(
|
|||||||
SnackBar(content: Text('Error printing bar order: $e')),
|
SnackBar(content: Text('Error printing bar order: $e')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
FirebaseCrashlytics.instance.recordError(
|
||||||
|
'Bar printer not found',
|
||||||
|
null,
|
||||||
|
reason: 'Bar 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 bar')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +262,19 @@ Future<void> onPrint(
|
|||||||
SnackBar(content: Text('Error printing ticket: $e')),
|
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')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +324,18 @@ Future<void> onPrintRecipt(
|
|||||||
SnackBar(content: Text('Error printing receipt order: $e')),
|
SnackBar(content: Text('Error printing receipt order: $e')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
FirebaseCrashlytics.instance.recordError(
|
||||||
|
'Kitchen printer not found',
|
||||||
|
null,
|
||||||
|
reason: 'Kitchen 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 kitchen')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
|
|
||||||
class DioClient {
|
class DioClient {
|
||||||
static final Dio _dio = Dio(BaseOptions(
|
static final Dio _dio = Dio(BaseOptions(
|
||||||
connectTimeout: const Duration(seconds: 10),
|
connectTimeout: const Duration(minutes: 1),
|
||||||
receiveTimeout: const Duration(seconds: 10),
|
receiveTimeout: const Duration(minutes: 1),
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
|
|||||||
@ -534,7 +534,7 @@ class PrintDataoutputs {
|
|||||||
styles: const PosStyles(align: PosAlign.left),
|
styles: const PosStyles(align: PosAlign.left),
|
||||||
),
|
),
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
||||||
width: 6,
|
width: 6,
|
||||||
styles: const PosStyles(align: PosAlign.right),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
),
|
),
|
||||||
@ -799,7 +799,7 @@ class PrintDataoutputs {
|
|||||||
styles: const PosStyles(align: PosAlign.left),
|
styles: const PosStyles(align: PosAlign.left),
|
||||||
),
|
),
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
text: DateFormat('yyyyMMddhhmm').format(DateTime.now()),
|
||||||
width: 6,
|
width: 6,
|
||||||
styles: const PosStyles(align: PosAlign.right),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
),
|
),
|
||||||
@ -841,18 +841,20 @@ class PrintDataoutputs {
|
|||||||
styles: const PosStyles(align: PosAlign.right),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
bytes += generator.row([
|
if (paymentMethod != '') {
|
||||||
PosColumn(
|
bytes += generator.row([
|
||||||
text: 'Pembayaran',
|
PosColumn(
|
||||||
width: 8,
|
text: 'Payment',
|
||||||
styles: const PosStyles(align: PosAlign.left),
|
width: 8,
|
||||||
),
|
styles: const PosStyles(align: PosAlign.left),
|
||||||
PosColumn(
|
),
|
||||||
text: paymentMethod,
|
PosColumn(
|
||||||
width: 4,
|
text: paymentMethod,
|
||||||
styles: const PosStyles(align: PosAlign.right),
|
width: 4,
|
||||||
),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
]);
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
bytes += generator.text(
|
bytes += generator.text(
|
||||||
paper == 80
|
paper == 80
|
||||||
@ -866,7 +868,7 @@ class PrintDataoutputs {
|
|||||||
? '------------------------------------------------'
|
? '------------------------------------------------'
|
||||||
: '--------------------------------',
|
: '--------------------------------',
|
||||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||||
for (final product in (products ?? <ProductQuantity>[])) {
|
for (final product in (products)) {
|
||||||
bytes += generator.row([
|
bytes += generator.row([
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: '${product.quantity} x ${product.product.name}',
|
text: '${product.quantity} x ${product.product.name}',
|
||||||
@ -1057,7 +1059,7 @@ class PrintDataoutputs {
|
|||||||
styles: const PosStyles(align: PosAlign.left),
|
styles: const PosStyles(align: PosAlign.left),
|
||||||
),
|
),
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
||||||
width: 6,
|
width: 6,
|
||||||
styles: const PosStyles(align: PosAlign.right),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
),
|
),
|
||||||
@ -1112,7 +1114,7 @@ class PrintDataoutputs {
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (final product in (productItemVoid ?? <OrderItem>[])) {
|
for (final product in (productItemVoid)) {
|
||||||
bytes += generator.row([
|
bytes += generator.row([
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: '${product.quantity} x ${product.productName}',
|
text: '${product.quantity} x ${product.productName}',
|
||||||
@ -1326,7 +1328,7 @@ class PrintDataoutputs {
|
|||||||
styles: const PosStyles(align: PosAlign.left),
|
styles: const PosStyles(align: PosAlign.left),
|
||||||
),
|
),
|
||||||
PosColumn(
|
PosColumn(
|
||||||
text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
text: '${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
|
||||||
width: 6,
|
width: 6,
|
||||||
styles: const PosStyles(align: PosAlign.right),
|
styles: const PosStyles(align: PosAlign.right),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -217,37 +217,35 @@ class _SuccessPaymentPageState extends State<SuccessPaymentPage> {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
// Order Details
|
// Order Details
|
||||||
Expanded(
|
Column(
|
||||||
child: Column(
|
children: [
|
||||||
children: [
|
_buildInfoRow(
|
||||||
_buildInfoRow(
|
icon: Icons.receipt_long_outlined,
|
||||||
icon: Icons.receipt_long_outlined,
|
label: 'No. Pesanan',
|
||||||
label: 'No. Pesanan',
|
value: order.orderNumber ?? "-",
|
||||||
value: order.orderNumber ?? "-",
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 12),
|
_buildInfoRow(
|
||||||
_buildInfoRow(
|
icon: Icons.receipt_long_outlined,
|
||||||
icon: Icons.receipt_long_outlined,
|
label: 'Metode Pembayaran',
|
||||||
label: 'Metode Pembayaran',
|
value: widget.paymentMethod,
|
||||||
value: widget.paymentMethod,
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 12),
|
_buildInfoRow(
|
||||||
_buildInfoRow(
|
icon: Icons.access_time_rounded,
|
||||||
icon: Icons.access_time_rounded,
|
label: 'Waktu',
|
||||||
label: 'Waktu',
|
value: (order.createdAt ?? DateTime.now())
|
||||||
value: (order.createdAt ?? DateTime.now())
|
.toFormattedDate3(),
|
||||||
.toFormattedDate3(),
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 12),
|
_buildInfoRow(
|
||||||
_buildInfoRow(
|
icon: Icons.check_circle_outline,
|
||||||
icon: Icons.check_circle_outline,
|
label: 'Status Pembayaran',
|
||||||
label: 'Status Pembayaran',
|
value: 'Lunas',
|
||||||
value: 'Lunas',
|
valueColor: Colors.green,
|
||||||
valueColor: Colors.green,
|
showBadge: true,
|
||||||
showBadge: true,
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user