split struct

This commit is contained in:
efrilm
2025-11-10 13:28:18 +07:00
parent c5673a147c
commit f5256fb33d
10 changed files with 405 additions and 56 deletions
@@ -414,4 +414,62 @@ class PrintUi {
return bytes;
}
Future<List<int>> printSplit({
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('Split');
bytes += builder.row2Columns(
'Split',
'${order.payments.last.splitNumber} / ${order.payments.last.splitTotal}',
);
bytes += builder.summary(
totalItems: 0,
subtotal: order.payments.last.amount.currencyFormatRpV2,
discount: 0.currencyFormatRpV2,
total: order.payments.last.amount.currencyFormatRpV2,
paid: order.payments.last.amount.currencyFormatRpV2,
);
bytes += builder.footer(message: 'Kasir');
return bytes;
}
}
@@ -241,7 +241,9 @@ class ReceiptComponentBuilder {
List<int> bytes = [];
bytes += separator();
bytes += row2Columns('Total Item', totalItems.toString());
if (totalItems > 0) {
bytes += row2Columns('Total Item', totalItems.toString());
}
bytes += row2Columns('Subtotal', subtotal);
bytes += row2Columns('Diskon', discount);
bytes += separator();
@@ -3,10 +3,12 @@ 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 '../../../../../injection.dart';
import '../../../../components/error/order_loader_error_state_widget.dart';
import '../../../../components/loader/loader_with_text.dart';
import '../../../../components/toast/flushbar.dart';
import 'widgets/payment_success_split_bill_left_panel.dart';
import 'widgets/payment_success_split_bill_right_panel.dart';
@@ -18,49 +20,64 @@ class PaymentSuccessSplitBillPage extends StatelessWidget
@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 state.failureOptionGetById.fold(
() => Container(
padding: const EdgeInsets.all(24.0),
child: Row(
children: [
// Left Panel - Success Message & Order Info
Expanded(
flex: 35,
child: PaymentSuccessSplitBillLeftPanel(
order: state.order,
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 state.failureOptionGetById.fold(
() => Container(
padding: const EdgeInsets.all(24.0),
child: Row(
children: [
// Left Panel - Success Message & Order Info
Expanded(
flex: 35,
child: PaymentSuccessSplitBillLeftPanel(
order: state.order,
),
),
),
const SizedBox(width: 16),
const SizedBox(width: 16),
// Right Panel - Order Details
Expanded(
flex: 65,
child: PaymentSuccessSplitBillRightPanel(
order: state.order,
// Right Panel - Order Details
Expanded(
flex: 65,
child: PaymentSuccessSplitBillRightPanel(
order: state.order,
),
),
),
],
],
),
),
),
(f) => OrderLoaderErrorStateWidget(
failure: f,
onRefresh: () {
context.read<OrderLoaderBloc>().add(
OrderLoaderEvent.getById(orderId),
);
},
),
);
},
(f) => OrderLoaderErrorStateWidget(
failure: f,
onRefresh: () {
context.read<OrderLoaderBloc>().add(
OrderLoaderEvent.getById(orderId),
);
},
),
);
},
),
),
),
);
@@ -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';
@@ -166,22 +168,9 @@ class PaymentSuccessSplitBillLeftPanel 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.splitBill(order),
);
},
label: 'Cetak Struk',
icon: Icon(Icons.print_rounded, color: AppColor.white),
@@ -193,7 +193,11 @@ class PaymentSuccessSplitBillRightPanel extends StatelessWidget {
],
),
child: Text(
(order.payments.last.amount).toString().currencyFormatRpV2,
order.payments.isNotEmpty
? (order.payments.last.amount)
.toString()
.currencyFormatRpV2
: 0.currencyFormatRpV2,
style: AppStyle.xl.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,