print order
This commit is contained in:
@@ -11,6 +11,7 @@ import '../application/outlet/outlet_loader/outlet_loader_bloc.dart';
|
||||
import '../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../application/printer/bluetooth/bluetooth_connect/bluetooth_connect_bloc.dart';
|
||||
import '../application/printer/bluetooth/bluetooth_loader/bluetooth_loader_bloc.dart';
|
||||
import '../application/printer/print_struck/print_struck_bloc.dart';
|
||||
import '../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../application/product/product_loader/product_loader_bloc.dart';
|
||||
@@ -53,6 +54,7 @@ class _AppWidgetState extends State<AppWidget> {
|
||||
BlocProvider(create: (context) => getIt<BluetoothConnectBloc>()),
|
||||
BlocProvider(create: (context) => getIt<PrinterFormBloc>()),
|
||||
BlocProvider(create: (context) => getIt<PrinterLoaderBloc>()),
|
||||
BlocProvider(create: (context) => getIt<PrintStruckBloc>()),
|
||||
],
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
@@ -105,7 +105,9 @@ class PrintUi {
|
||||
orderNumber: order.orderNumber,
|
||||
customerName: order.metadata['customer_name'] ?? 'John Doe',
|
||||
cashierName: cashierName,
|
||||
paymentMethod: order.payments.last.paymentMethodName,
|
||||
paymentMethod: order.payments.isEmpty
|
||||
? ''
|
||||
: order.payments.last.paymentMethodName,
|
||||
tableNumber: order.tableNumber,
|
||||
);
|
||||
|
||||
@@ -280,4 +282,70 @@ class PrintUi {
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<List<int>> printCashier({
|
||||
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.isEmpty
|
||||
? null
|
||||
: 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(message: 'Kasir');
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../application/order/order_loader/order_loader_bloc.dart';
|
||||
import '../../../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||
import '../../../../../common/theme/theme.dart';
|
||||
import '../../../../../domain/order/order.dart';
|
||||
import '../../../../../injection.dart';
|
||||
import '../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../components/spaces/space.dart';
|
||||
import '../../../../components/toast/flushbar.dart';
|
||||
import 'widgets/success_order_left_panel.dart';
|
||||
import 'widgets/success_order_right_panel.dart';
|
||||
|
||||
@@ -18,32 +20,47 @@ class SuccessOrderPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.background,
|
||||
body: SafeArea(
|
||||
child: BlocBuilder<OrderLoaderBloc, OrderLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetchingById) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
return BlocListener<PrintStruckBloc, PrintStruckState>(
|
||||
listenWhen: (previous, current) =>
|
||||
previous.failureOrPrintStruck != current.failureOrPrintStruck,
|
||||
listener: (context, state) {
|
||||
state.failureOrPrintStruck.fold(
|
||||
() {},
|
||||
(either) => either.fold(
|
||||
(f) => AppFlushbar.showPrinterFailureToast(context, f),
|
||||
(success) {
|
||||
AppFlushbar.showSuccess(context, "Struck berhasil dicetak");
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColor.background,
|
||||
body: SafeArea(
|
||||
child: BlocBuilder<OrderLoaderBloc, OrderLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetchingById) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 35,
|
||||
child: SuccessOrderLeftPanel(order: state.order),
|
||||
),
|
||||
SpaceWidth(16),
|
||||
Expanded(
|
||||
flex: 65,
|
||||
child: SuccessOrderRightPanel(order: state.order),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 35,
|
||||
child: SuccessOrderLeftPanel(order: state.order),
|
||||
),
|
||||
SpaceWidth(16),
|
||||
Expanded(
|
||||
flex: 65,
|
||||
child: SuccessOrderRightPanel(order: state.order),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+5
-16
@@ -1,6 +1,8 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||
import '../../../../../../common/extension/extension.dart';
|
||||
import '../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../domain/order/order.dart';
|
||||
@@ -169,22 +171,9 @@ class SuccessOrderLeftPanel extends StatelessWidget {
|
||||
Expanded(
|
||||
child: AppElevatedButton.filled(
|
||||
onPressed: () {
|
||||
// onPrintRecipt(
|
||||
// context,
|
||||
// order: widget.order,
|
||||
// paymentMethod: widget.paymentMethod,
|
||||
// nominalBayar: widget.paymentMethod == "Cash"
|
||||
// ? widget.nominalBayar
|
||||
// : widget.order.totalAmount ?? 0,
|
||||
// kembalian: widget.nominalBayar -
|
||||
// (widget.order.totalAmount ?? 0),
|
||||
// productQuantity: widget.productQuantity,
|
||||
// );
|
||||
// onPrint(
|
||||
// context,
|
||||
// productQuantity: widget.productQuantity,
|
||||
// order: widget.order,
|
||||
// );
|
||||
context.read<PrintStruckBloc>().add(
|
||||
PrintStruckEvent.order(order),
|
||||
);
|
||||
},
|
||||
label: 'Cetak Struk',
|
||||
icon: Icon(Icons.print_rounded, color: AppColor.white),
|
||||
|
||||
Reference in New Issue
Block a user