From 4bb5d1a7bc6b8b750a1d6a9e610fde1947506aa1 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 25 Feb 2025 16:11:53 +0100 Subject: [PATCH 1/5] bugfix: tax rate showing always as 0 --- .../sections/components/InvoicePreview.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx index 6ba2c554e..a9ffe80f7 100644 --- a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx +++ b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx @@ -97,10 +97,11 @@ export const InvoicePreview = ({ const getApplicableTaxRate = ( item: CreateReceivablesFormBeforeValidationLineItemProps ): number => { - if (item.price?.currency === 'EUR') { - return item.vat_rate_value || 0; + if (isNonVatSupported) { + return item.tax_rate_value || 0; } - return item.tax_rate_value || 0; + + return item.vat_rate_value || 0; }; const groupItemsByTaxRate = ( @@ -314,9 +315,9 @@ export const InvoicePreview = ({ )} - {((item.price.currency === 'EUR' - ? item.vat_rate_value - : item.tax_rate_value) || 0) / 100} + {((isNonVatSupported + ? item.tax_rate_value + : item.vat_rate_value) || 0) / 100} % From b3fc060bb5619cdb79b11d1fafec6fb4de7b494f Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 25 Feb 2025 16:12:48 +0100 Subject: [PATCH 2/5] docs(changeset): bugfix invoice previeww: tax rate shoowin always as zerog as zero --- .changeset/giant-insects-drum.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/giant-insects-drum.md diff --git a/.changeset/giant-insects-drum.md b/.changeset/giant-insects-drum.md new file mode 100644 index 000000000..570eff6a8 --- /dev/null +++ b/.changeset/giant-insects-drum.md @@ -0,0 +1,5 @@ +--- +'@monite/sdk-react': minor +--- + +bugfix invoice previeww: tax rate shoowin always as zerog as zero From 307529ab1779968954fa5fbf6f74a36f6cb81326 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 25 Feb 2025 16:57:57 +0100 Subject: [PATCH 3/5] bugfix: tax divided by 100 unnecessarily --- .../sections/components/InvoicePreview.tsx | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx index a9ffe80f7..6e174f432 100644 --- a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx +++ b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx @@ -104,11 +104,22 @@ export const InvoicePreview = ({ return item.vat_rate_value || 0; }; + const formatTaxRate = ( + item: CreateReceivablesFormBeforeValidationLineItemProps + ): number => { + const taxRate = getApplicableTaxRate(item); + if (taxRate < 100) { + //when the tax value is 19, it should be displayed as 19 + return taxRate; + } + return taxRate / 100; //when the tax value is 1900 it should be displayed as 19 + }; + const groupItemsByTaxRate = ( items: Array ): Record => { return items.reduce((acc, item) => { - const taxRate = getApplicableTaxRate(item); + const taxRate = formatTaxRate(item); if (taxRate === 0) { return acc; } @@ -131,10 +142,10 @@ export const InvoicePreview = ({ const items = groupedItems[taxRate]; const totalTax = items.reduce((sum, item) => { const itemPrice = item.price?.value || 0; - const itemTax = (itemPrice * item.quantity * taxRate) / 10000; + const itemTax = (itemPrice * item.quantity * taxRate) / 100; return sum + itemTax; }, 0); - return { taxRate: taxRate / 100, totalTax }; + return { taxRate, totalTax }; }); }; @@ -297,8 +308,8 @@ export const InvoicePreview = ({ - {items.length > 0 ? ( - items.map((item) => ( + {sanitizedItems.length > 0 ? ( + sanitizedItems.map((item) => ( {item?.name} {item?.quantity} @@ -314,12 +325,7 @@ export const InvoicePreview = ({ false )} - - {((isNonVatSupported - ? item.tax_rate_value - : item.vat_rate_value) || 0) / 100} - % - + {formatTaxRate(item)}% )) ) : ( From c46aa05edeb7a2f6a9a31df5a3d242cf78ab5030 Mon Sep 17 00:00:00 2001 From: Cristina Santana <13103893+cristinafrombr@users.noreply.github.com> Date: Tue, 25 Feb 2025 16:58:49 +0100 Subject: [PATCH 4/5] Update giant-insects-drum.md --- .changeset/giant-insects-drum.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/giant-insects-drum.md b/.changeset/giant-insects-drum.md index 570eff6a8..596741713 100644 --- a/.changeset/giant-insects-drum.md +++ b/.changeset/giant-insects-drum.md @@ -2,4 +2,4 @@ '@monite/sdk-react': minor --- -bugfix invoice previeww: tax rate shoowin always as zerog as zero +bugfix invoice previeww: tax rate showing always as zero, sometimes divided by 100 unnecessarily From c68870d018a1275b6f89ab203b27811f24cbc2e6 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 25 Feb 2025 17:07:12 +0100 Subject: [PATCH 5/5] lint fix --- .../CreateReceivable/sections/components/InvoicePreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx index 6e174f432..73012c023 100644 --- a/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx +++ b/packages/sdk-react/src/components/receivables/InvoiceDetails/CreateReceivable/sections/components/InvoicePreview.tsx @@ -17,7 +17,7 @@ import { isValid } from 'date-fns'; import { useCreateInvoiceProductsTable } from '../../components/useCreateInvoiceProductsTable'; import { CreateReceivablesFormProps } from '../../validation'; -// @ts-ignore +// @ts-expect-error import invoicePreviewStyles from './InvoicePreview.css'; interface InvoicePreviewProps {