From 84f9dd642a7cece1066c2e36b73b242a6921de90 Mon Sep 17 00:00:00 2001 From: sheenazien8 Date: Sun, 23 Jun 2024 11:11:44 +0700 Subject: [PATCH] feature(selling-detail): adjust the detail to show discount --- .../transactions/selling_detail.dart | 11 +++ lib/screens/menu_screen.dart | 4 + .../printers/add_printer_page_screen.dart | 3 +- .../transactions/history/detail_screen.dart | 75 ++++++++++--------- .../transactions/history/history_screen.dart | 2 +- lib/widgets/detail_transaction.dart | 9 ++- 6 files changed, 63 insertions(+), 41 deletions(-) diff --git a/lib/api/responses/transactions/selling_detail.dart b/lib/api/responses/transactions/selling_detail.dart index 50b8e9e..f1d9f52 100644 --- a/lib/api/responses/transactions/selling_detail.dart +++ b/lib/api/responses/transactions/selling_detail.dart @@ -36,4 +36,15 @@ class SellingDetail { : null, ); } + + String buildRowPrice() { + var priceText = "${formatPrice(price, isSymbol: false)} x $quantity"; + + if (discountPrice != 0) { + priceText = + "($priceText) -\n${formatPrice(discountPrice, isSymbol: false)} "; + } + + return priceText; + } } diff --git a/lib/screens/menu_screen.dart b/lib/screens/menu_screen.dart index 93bf05d..f0bfe33 100644 --- a/lib/screens/menu_screen.dart +++ b/lib/screens/menu_screen.dart @@ -4,6 +4,7 @@ import 'package:heroicons/heroicons.dart'; import 'package:lakasir/controllers/auths/auth_controller.dart'; import 'package:lakasir/controllers/profiles/profile_controller.dart'; import 'package:lakasir/controllers/setting_controller.dart'; +import 'package:lakasir/controllers/settings/print_controller.dart'; import 'package:lakasir/utils/colors.dart'; import 'package:lakasir/widgets/layout.dart'; import 'package:lakasir/widgets/my_card_list.dart'; @@ -68,17 +69,20 @@ class _MenuScreenState extends State { SettingController settingController = Get.put(SettingController()); final AuthController _authController = Get.put(AuthController()); final ProfileController _profileController = Get.put(ProfileController()); + final PrintController _printController = Get.put(PrintController()); @override void initState() { super.initState(); _authController.fetchPermissions(); + _printController.fetchPrinters(); } @override void dispose() { super.dispose(); _authController.fetchPermissions(); + _printController.fetchPrinters(); } @override diff --git a/lib/screens/setting/printers/add_printer_page_screen.dart b/lib/screens/setting/printers/add_printer_page_screen.dart index 406f4bd..c816dd8 100644 --- a/lib/screens/setting/printers/add_printer_page_screen.dart +++ b/lib/screens/setting/printers/add_printer_page_screen.dart @@ -226,7 +226,8 @@ class _AddPrinterPageScreenState extends State { Container( margin: const EdgeInsets.only(bottom: 10), child: MyTextField( - textInputAction: TextInputAction.none, + keyboardType: TextInputType.multiline, + textInputAction: TextInputAction.newline, maxLines: 4, controller: _printerController.footerController, label: 'field_footer'.tr, diff --git a/lib/screens/transactions/history/detail_screen.dart b/lib/screens/transactions/history/detail_screen.dart index bc6f934..5fd55bb 100644 --- a/lib/screens/transactions/history/detail_screen.dart +++ b/lib/screens/transactions/history/detail_screen.dart @@ -54,6 +54,8 @@ class _HistoryDetailScreenState extends State { }); } }); + } else { + show("printer_error".tr, color: error); } } @@ -137,16 +139,17 @@ class _HistoryDetailScreenState extends State { (e) => DetailTransactionItem( discountPrice: formatPrice(e.discountPrice), productName: e.product!.name, - quantity: "${e.quantity} x ${formatPrice(e.price / e.quantity)}", - subTotal: formatPrice(e.price), + quantity: e.buildRowPrice(), + subTotal: formatPrice(e.discountPrice), ), ) .toList(), tax: "${history.tax!}%", + discount: "(${formatPrice(history.totalDiscount)})", subTotal: formatPrice( history.totalPrice! - (history.totalPrice! * history.tax! / 100), ), - total: formatPrice(history.totalPrice!), + total: formatPrice(history.grandTotalPrice!), payedMoney: formatPrice(history.payedMoney!), change: formatPrice(history.moneyChange!), note: history.note, @@ -158,42 +161,44 @@ class _HistoryDetailScreenState extends State { Widget build(BuildContext context) { return Layout( title: "transaction_detail".tr, - child: ListView( - children: [ - _detailTransaction(), - const SizedBox(height: 20), - Row( - children: [ - Flexible( - child: MyFilledButton( - color: grey, - isLoading: sharedLoading, - onPressed: captureAndShareWidget, - child: Row( - children: [ - Text("share".tr), - const SizedBox(width: 10), - const Icon(Icons.share), - ], + child: SingleChildScrollView( + child: Column( + children: [ + _detailTransaction(), + const SizedBox(height: 20), + Row( + children: [ + Flexible( + child: MyFilledButton( + color: grey, + isLoading: sharedLoading, + onPressed: captureAndShareWidget, + child: Row( + children: [ + Text("share".tr), + const SizedBox(width: 10), + const Icon(Icons.share), + ], + ), ), ), - ), - const SizedBox(width: 10), - Flexible( - child: MyFilledButton( - onPressed: rePrint, - child: Row( - children: [ - Text("re-print".tr), - const SizedBox(width: 10), - const Icon(Icons.print), - ], + const SizedBox(width: 10), + Flexible( + child: MyFilledButton( + onPressed: rePrint, + child: Row( + children: [ + Text("re-print".tr), + const SizedBox(width: 10), + const Icon(Icons.print), + ], + ), ), ), - ), - ], - ), - ], + ], + ), + ], + ), ), ); } diff --git a/lib/screens/transactions/history/history_screen.dart b/lib/screens/transactions/history/history_screen.dart index c9df047..5ed3191 100644 --- a/lib/screens/transactions/history/history_screen.dart +++ b/lib/screens/transactions/history/history_screen.dart @@ -286,7 +286,7 @@ class CardList extends StatelessWidget { ), const SizedBox(height: 10), Text( - "Total Price: ${formatPrice(history.totalPrice!, isSymbol: false)}", + "Total Price: ${formatPrice(history.grandTotalPrice!, isSymbol: false)}", style: const TextStyle( fontWeight: FontWeight.w400, ), diff --git a/lib/widgets/detail_transaction.dart b/lib/widgets/detail_transaction.dart index 50abcd4..84af74c 100644 --- a/lib/widgets/detail_transaction.dart +++ b/lib/widgets/detail_transaction.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:lakasir/controllers/auths/auth_controller.dart'; +import 'package:lakasir/utils/utils.dart'; class DetailTransaction extends StatefulWidget { const DetailTransaction({ @@ -136,15 +137,15 @@ class _DetailTransactionState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("Subtotal".tr, style: _normalStyle), - Text(widget.subTotal, style: _boldStyle) + Text("discount".tr, style: _normalStyle), + Text(widget.discount, style: _boldStyle) ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("discount".tr, style: _normalStyle), - Text(widget.discount, style: _boldStyle) + Text("Subtotal".tr, style: _normalStyle), + Text(widget.subTotal, style: _boldStyle) ], ), Row(