From 31963ca7aa9a5ea46f7bdba4349cc4f6066443a0 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 4 Oct 2022 11:23:18 +0300 Subject: [PATCH] Use company currency for purchase order --- lib/ui/app/invoice/invoice_item_view.dart | 13 +++++--- lib/ui/invoice/edit/invoice_edit_desktop.dart | 16 ++++++--- .../edit/invoice_edit_items_desktop.dart | 32 +++++++++++++----- .../invoice/view/invoice_view_overview.dart | 33 +++++++++++-------- .../purchase_order_presenter.dart | 6 ++-- lib/ui/reports/purchase_order_report.dart | 14 +++++--- 6 files changed, 74 insertions(+), 40 deletions(-) diff --git a/lib/ui/app/invoice/invoice_item_view.dart b/lib/ui/app/invoice/invoice_item_view.dart index fc226ec7a..ecc59cecf 100644 --- a/lib/ui/app/invoice/invoice_item_view.dart +++ b/lib/ui/app/invoice/invoice_item_view.dart @@ -27,9 +27,11 @@ class InvoiceItemListTile extends StatelessWidget { @override Widget build(BuildContext context) { final String cost = formatNumber(invoiceItem.cost, context, - clientId: invoice.clientId, roundToPrecision: false); + clientId: invoice.isPurchaseOrder ? null : invoice.clientId, + roundToPrecision: false); final String qty = formatNumber(invoiceItem.quantity, context, - clientId: invoice.clientId, formatNumberType: FormatNumberType.double); + clientId: invoice.isPurchaseOrder ? null : invoice.clientId, + formatNumberType: FormatNumberType.double); final localization = AppLocalization.of(context); final store = StoreProvider.of(context); @@ -44,10 +46,10 @@ class InvoiceItemListTile extends StatelessWidget { subtitle += ' • ${localization.discount} '; if (invoice.isAmountDiscount) { subtitle += formatNumber(invoiceItem.discount, context, - clientId: invoice.clientId); + clientId: invoice.isPurchaseOrder ? null : invoice.clientId); } else { subtitle += formatNumber(invoiceItem.discount, context, - clientId: invoice.clientId, + clientId: invoice.isPurchaseOrder ? null : invoice.clientId, formatNumberType: FormatNumberType.percent); } } @@ -115,7 +117,8 @@ class InvoiceItemListTile extends StatelessWidget { Expanded(child: Text(invoiceItem.productKey)), Text(formatNumber( invoiceItem.total(invoice, precision), context, - clientId: invoice.clientId)), + clientId: + invoice.isPurchaseOrder ? null : invoice.clientId)), ], ), subtitle: Row( diff --git a/lib/ui/invoice/edit/invoice_edit_desktop.dart b/lib/ui/invoice/edit/invoice_edit_desktop.dart index 2cdf8e26b..24ab6c271 100644 --- a/lib/ui/invoice/edit/invoice_edit_desktop.dart +++ b/lib/ui/invoice/edit/invoice_edit_desktop.dart @@ -847,7 +847,9 @@ class InvoiceEditDesktopState extends State precision: precisionForInvoice(state, invoice)), context, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), ), if (invoice.isOld && (invoice.isInvoice || invoice.isQuote)) @@ -861,7 +863,9 @@ class InvoiceEditDesktopState extends State '__invoice_paid_to_date_${invoice.paidToDate}_${invoice.clientId}__'), initialValue: formatNumber( invoice.paidToDate, context, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), ), if (company.hasCustomSurcharge) CustomSurcharges( @@ -941,7 +945,9 @@ class InvoiceEditDesktopState extends State state, invoice)) - invoice.paidToDate, context, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), ), if (invoice.partial != 0) TextFormField( @@ -954,7 +960,9 @@ class InvoiceEditDesktopState extends State '__invoice_total_${invoice.partial}_${invoice.clientId}__'), initialValue: formatNumber( invoice.partial, context, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), ), ]), ], diff --git a/lib/ui/invoice/edit/invoice_edit_items_desktop.dart b/lib/ui/invoice/edit/invoice_edit_items_desktop.dart index 656171e80..668e7945e 100644 --- a/lib/ui/invoice/edit/invoice_edit_items_desktop.dart +++ b/lib/ui/invoice/edit/invoice_edit_items_desktop.dart @@ -435,7 +435,9 @@ class _InvoiceEditItemsDesktopState extends State { formatNumber(item.cost, context, formatNumberType: FormatNumberType.inputMoney, - clientId: invoice.clientId) ?? + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId) ?? '', textAlign: TextAlign.right, ); @@ -444,7 +446,9 @@ class _InvoiceEditItemsDesktopState extends State { formatNumber(item.quantity, context, formatNumberType: FormatNumberType.inputAmount, - clientId: invoice.clientId) ?? + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId) ?? '', textAlign: TextAlign.right, ); @@ -453,7 +457,9 @@ class _InvoiceEditItemsDesktopState extends State { formatNumber(item.discount, context, formatNumberType: FormatNumberType.inputAmount, - clientId: invoice.clientId) ?? + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId) ?? '', textAlign: TextAlign.right, ); @@ -470,7 +476,9 @@ class _InvoiceEditItemsDesktopState extends State { Expanded( child: Text( formatNumber(item.total(invoice, precision), context, - clientId: invoice.clientId) ?? + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId) ?? '', textAlign: TextAlign.right, ), @@ -955,7 +963,9 @@ class _InvoiceEditItemsDesktopState extends State { initialValue: formatNumber( lineItems[index].cost, context, formatNumberType: FormatNumberType.inputMoney, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), onChanged: (value) => _onChanged( lineItems[index].rebuild( (b) => b..cost = parseDouble(value)), @@ -983,7 +993,9 @@ class _InvoiceEditItemsDesktopState extends State { lineItems[index].quantity, context, formatNumberType: FormatNumberType.inputAmount, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), onChanged: (value) => _onChanged( lineItems[index].rebuild( (b) => b..quantity = parseDouble(value)), @@ -1011,7 +1023,9 @@ class _InvoiceEditItemsDesktopState extends State { lineItems[index].discount, context, formatNumberType: FormatNumberType.inputAmount, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), onChanged: (value) => _onChanged( lineItems[index].rebuild( (b) => b..discount = parseDouble(value)), @@ -1034,7 +1048,9 @@ class _InvoiceEditItemsDesktopState extends State { enabled: false, initialValue: formatNumber( lineItems[index].total(invoice, precision), context, - clientId: invoice.clientId), + clientId: invoice.isPurchaseOrder + ? null + : invoice.clientId), textAlign: TextAlign.right, ), ), diff --git a/lib/ui/invoice/view/invoice_view_overview.dart b/lib/ui/invoice/view/invoice_view_overview.dart index 380e009a1..c48dc9957 100644 --- a/lib/ui/invoice/view/invoice_view_overview.dart +++ b/lib/ui/invoice/view/invoice_view_overview.dart @@ -102,8 +102,8 @@ class InvoiceOverview extends StatelessWidget { : invoice.isQuote ? localization.quoteAmount : localization.invoiceAmount, - value: - formatNumber(invoice.amount, context, clientId: invoice.clientId), + value: formatNumber(invoice.amount, context, + clientId: invoice.isPurchaseOrder ? null : invoice.clientId), secondLabel: invoice.isCredit ? localization.creditRemaining : (invoice.isQuote || invoice.isRecurringInvoice) @@ -112,7 +112,7 @@ class InvoiceOverview extends StatelessWidget { secondValue: [EntityType.invoice, EntityType.credit].contains(invoice.entityType) ? formatNumber(invoice.balanceOrAmount, context, - clientId: invoice.clientId) + clientId: invoice.isPurchaseOrder ? null : invoice.clientId) : null, ), ListDivider(), @@ -158,11 +158,12 @@ class InvoiceOverview extends StatelessWidget { if (invoice.isInvoice && !invoice.isPaid) InvoiceFields.nextSendDate: formatDate(invoice.nextSendDate, context), InvoiceFields.partial: formatNumber(invoice.partial, context, - clientId: invoice.clientId, zeroIsNull: true), + clientId: invoice.isPurchaseOrder ? null : invoice.clientId, + zeroIsNull: true), InvoiceFields.partialDueDate: formatDate(invoice.partialDueDate, context), InvoiceFields.poNumber: invoice.poNumber, InvoiceFields.discount: formatNumber(invoice.discount, context, - clientId: invoice.clientId, + clientId: invoice.isPurchaseOrder ? null : invoice.clientId, zeroIsNull: true, formatNumberType: invoice.isAmountDiscount ? FormatNumberType.money @@ -306,11 +307,12 @@ class InvoiceOverview extends StatelessWidget { paymentMap.entries.forEach((entry) { final payment = entry.value; final paymentable = entry.key; - String amount = - formatNumber(paymentable.amount, context, clientId: client.id); + String amount = formatNumber(paymentable.amount, context, + clientId: invoice.isPurchaseOrder ? null : client.id); if (paymentable.amount != payment.amount) { - amount += - '/' + formatNumber(payment.amount, context, clientId: client.id); + amount += '/' + + formatNumber(payment.amount, context, + clientId: invoice.isPurchaseOrder ? null : client.id); } widgets.add( @@ -327,11 +329,12 @@ class InvoiceOverview extends StatelessWidget { creditMap.entries.forEach((entry) { final credit = entry.value; final paymentable = entry.key; - String amount = - formatNumber(paymentable.amount, context, clientId: client.id); + String amount = formatNumber(paymentable.amount, context, + clientId: invoice.isPurchaseOrder ? null : client.id); if (paymentable.amount != credit.amount) { - amount += - '/' + formatNumber(credit.amount, context, clientId: client.id); + amount += '/' + + formatNumber(credit.amount, context, + clientId: invoice.isPurchaseOrder ? null : client.id); } widgets.add( @@ -389,7 +392,9 @@ class InvoiceOverview extends StatelessWidget { child: Align( alignment: Alignment.centerRight, child: Text( - formatNumber(amount, context, clientId: invoice.clientId), + formatNumber(amount, context, + clientId: + invoice.isPurchaseOrder ? null : invoice.clientId), style: Theme.of(context).textTheme.subtitle1, ), ), diff --git a/lib/ui/purchase_order/purchase_order_presenter.dart b/lib/ui/purchase_order/purchase_order_presenter.dart index 68e552594..79990d107 100644 --- a/lib/ui/purchase_order/purchase_order_presenter.dart +++ b/lib/ui/purchase_order/purchase_order_presenter.dart @@ -85,8 +85,7 @@ class PurchaseOrderPresenter extends EntityPresenter { case PurchaseOrderFields.amount: return Align( alignment: Alignment.centerRight, - child: Text(formatNumber(purchaseOrder.amount, context, - clientId: purchaseOrder.clientId)), + child: Text(formatNumber(purchaseOrder.amount, context)), ); case PurchaseOrderFields.dueDate: return Text(formatDate(purchaseOrder.dueDate, context)); @@ -105,8 +104,7 @@ class PurchaseOrderPresenter extends EntityPresenter { case PurchaseOrderFields.discount: return Text(purchaseOrder.isAmountDiscount ? formatNumber(purchaseOrder.discount, context, - formatNumberType: FormatNumberType.money, - clientId: purchaseOrder.clientId) + formatNumberType: FormatNumberType.money) : formatNumber(purchaseOrder.discount, context, formatNumberType: FormatNumberType.percent)); case PurchaseOrderFields.poNumber: diff --git a/lib/ui/reports/purchase_order_report.dart b/lib/ui/reports/purchase_order_report.dart index 9c3546c47..2319b4f4e 100644 --- a/lib/ui/reports/purchase_order_report.dart +++ b/lib/ui/reports/purchase_order_report.dart @@ -1,7 +1,6 @@ // Package imports: import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/redux/reports/reports_selectors.dart'; -import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:memoize/memoize.dart'; // Project imports: @@ -15,7 +14,7 @@ import 'package:invoiceninja_flutter/utils/enums.dart'; enum PurchaseOrderReportFields { id, amount, - converted_amount, + //converted_amount, vendor, vendor_number, //vendor_balance, @@ -158,10 +157,12 @@ ReportResult purchaseOrderReport( case PurchaseOrderReportFields.amount: value = purchaseOrder.amount; break; + /* case PurchaseOrderReportFields.converted_amount: value = round(purchaseOrder.amount * 1 / purchaseOrder.exchangeRate, 2); break; + */ case PurchaseOrderReportFields.number: value = purchaseOrder.number; break; @@ -300,8 +301,9 @@ ReportResult purchaseOrderReport( value = vendor.city; break; case PurchaseOrderReportFields.currency: - value = - staticState.currencyMap[vendor.currencyId]?.listDisplayName ?? ''; + value = staticState.currencyMap[userCompany.company.currencyId] + ?.listDisplayName ?? + ''; break; case PurchaseOrderReportFields.is_viewed: value = purchaseOrder.isViewed; @@ -367,15 +369,17 @@ ReportResult purchaseOrderReport( if (value.runtimeType == bool) { row.add(purchaseOrder.getReportBool(value: value)); } else if (value.runtimeType == double || value.runtimeType == int) { + /* String currencyId = vendor.currencyId; if ([ PurchaseOrderReportFields.converted_amount, ].contains(column)) { currencyId = userCompany.company.currencyId; } + */ row.add(purchaseOrder.getReportDouble( value: value, - currencyId: currencyId, + currencyId: userCompany.company.currencyId, exchangeRate: purchaseOrder.exchangeRate, )); } else {