void struck

This commit is contained in:
efrilm
2025-11-10 13:06:06 +07:00
parent af182b6f5a
commit c5673a147c
8 changed files with 381 additions and 35 deletions
@@ -348,4 +348,70 @@ class PrintUi {
return bytes;
}
Future<List<int>> printVoid({
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('Void');
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;
}
}
@@ -2,9 +2,11 @@ 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 '../../../../../application/void/void_form/void_form_bloc.dart';
import '../../../../../common/theme/theme.dart';
import '../../../../components/spaces/space.dart';
import '../../../../components/toast/flushbar.dart';
import 'widgets/void_success_left_panel.dart';
import 'widgets/void_success_right_panel.dart';
@@ -14,26 +16,44 @@ class VoidSuccessPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.background,
body: BlocBuilder<VoidFormBloc, VoidFormState>(
builder: (context, state) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Row(
children: [
Expanded(flex: 35, child: VoidSuccessLeftPanel(state: state)),
SpaceWidth(16),
Expanded(
flex: 65,
child: VoidSuccessRightPanel(state: state),
),
],
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: BlocBuilder<VoidFormBloc, VoidFormState>(
builder: (context, state) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Row(
children: [
Expanded(
flex: 35,
child: VoidSuccessLeftPanel(state: state),
),
SpaceWidth(16),
Expanded(
flex: 65,
child: VoidSuccessRightPanel(state: state),
),
],
),
),
),
);
},
);
},
),
),
);
}
@@ -2,6 +2,7 @@ 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 '../../../../../../application/void/void_form/void_form_bloc.dart';
import '../../../../../../common/extension/extension.dart';
import '../../../../../../common/theme/theme.dart';
@@ -149,22 +150,21 @@ class VoidSuccessLeftPanel 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.voided(
state.order.copyWith(
orderItems: state.voidType.isAll
? state.order.orderItems
: state.voidItems,
subtotal: state.voidType.isAll
? state.order.totalAmount
: state.totalPriceVoid,
totalAmount: state.voidType.isAll
? state.order.totalAmount
: state.totalPriceVoid,
),
),
);
},
label: 'Cetak Struk',
icon: Icon(Icons.print_rounded, color: AppColor.white),