diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index 33a82db..5c4bd37 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -5,6 +5,7 @@ import 'package:enaklo_pos/core/utils/printer_service.dart'; import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; import 'package:flutter/material.dart'; @@ -21,6 +22,8 @@ Future onPrint( final barPrinter = await ProductLocalDatasource.instance.getPrinterByCode('bar'); + final authData = await AuthLocalDataSource().getAuthData(); + // Checker printer if (checkerPrinter != null) { try { @@ -28,7 +31,7 @@ Future onPrint( productQuantity, order.tableNumber ?? "", order.orderNumber ?? "", - 'kasir', + authData.user?.name ?? "", checkerPrinter.paper.toIntegerFromText, order.orderType ?? "", ); @@ -51,7 +54,7 @@ Future onPrint( productQuantity, order.tableNumber!, order.orderNumber ?? "", - 'kasir', + authData.user?.name ?? "", kitchenPrinter.paper.toIntegerFromText, order.orderType ?? "", ); @@ -73,7 +76,7 @@ Future onPrint( productQuantity, order.tableNumber ?? "", order.orderNumber ?? "", - 'kasir', + authData.user?.name ?? "", barPrinter.paper.toIntegerFromText, order.orderType ?? "", ); @@ -94,11 +97,11 @@ Future onPrintRecipt( required String paymentMethod, required int nominalBayar, required int kembalian, - required int taxPercentage, }) async { final receiptPrinter = await ProductLocalDatasource.instance.getPrinterByCode('receipt'); final authData = await AuthLocalDataSource().getAuthData(); + final settings = await SettingsLocalDatasource().getTax(); if (receiptPrinter != null) { try { @@ -108,7 +111,7 @@ Future onPrintRecipt( paymentMethod, nominalBayar, kembalian, - taxPercentage, + settings.value, receiptPrinter.paper.toIntegerFromText, ); await PrinterService() diff --git a/lib/presentation/payment/pages/payment_page.dart b/lib/presentation/payment/pages/payment_page.dart index 7725631..c8cd64f 100644 --- a/lib/presentation/payment/pages/payment_page.dart +++ b/lib/presentation/payment/pages/payment_page.dart @@ -375,6 +375,8 @@ class _PaymentPageState extends State { .toList() ?? [], payment: data, + paymentMethod: selectedPaymentMethod?.name ?? '', + nominalBayar: totalPriceController.text.toIntegerFromText, )); }, error: (message) { diff --git a/lib/presentation/sales/dialog/payment_dialog.dart b/lib/presentation/sales/dialog/payment_dialog.dart index 6c9932f..d035ae7 100644 --- a/lib/presentation/sales/dialog/payment_dialog.dart +++ b/lib/presentation/sales/dialog/payment_dialog.dart @@ -343,6 +343,8 @@ class _PaymentDialogState extends State { .toList() ?? [], payment: data, + paymentMethod: selectedPaymentMethod?.name ?? "", + nominalBayar: totalPriceController.text.toIntegerFromText, )); }, error: (message) { diff --git a/lib/presentation/success/pages/success_order_page.dart b/lib/presentation/success/pages/success_order_page.dart index 7253aea..9ad041a 100644 --- a/lib/presentation/success/pages/success_order_page.dart +++ b/lib/presentation/success/pages/success_order_page.dart @@ -1005,10 +1005,11 @@ class _SuccessOrderPageState extends State context, order: widget.order, paymentMethod: widget.paymentMethod, - nominalBayar: widget.nominalBayar, + nominalBayar: widget.paymentMethod == "Cash" + ? widget.nominalBayar + : widget.order.totalAmount ?? 0, kembalian: widget.nominalBayar - (widget.order.totalAmount ?? 0), - taxPercentage: widget.taxPercentage, ); onPrint( context, diff --git a/lib/presentation/success/pages/success_payment_page.dart b/lib/presentation/success/pages/success_payment_page.dart index 27bdd75..67e0431 100644 --- a/lib/presentation/success/pages/success_payment_page.dart +++ b/lib/presentation/success/pages/success_payment_page.dart @@ -14,8 +14,15 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class SuccessPaymentPage extends StatefulWidget { final List productQuantity; final PaymentData payment; - const SuccessPaymentPage( - {super.key, required this.payment, required this.productQuantity}); + final String paymentMethod; + final int nominalBayar; + const SuccessPaymentPage({ + super.key, + required this.payment, + required this.productQuantity, + required this.paymentMethod, + required this.nominalBayar, + }); @override State createState() => _SuccessPaymentPageState(); @@ -781,10 +788,15 @@ class _SuccessPaymentPageState extends State { child: InkWell( borderRadius: BorderRadius.circular(16), onTap: () async { - onPrint( + onPrintRecipt( context, - productQuantity: widget.productQuantity, order: order, + paymentMethod: widget.paymentMethod, + nominalBayar: widget.paymentMethod == "Cash" + ? widget.nominalBayar + : order.totalAmount ?? 0, + kembalian: + widget.nominalBayar - (order.totalAmount ?? 0), ); }, child: const Row(