From 783d2ef4339c31546c6913924e1e23a143305316 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 5 May 2020 18:03:07 -0700 Subject: [PATCH] BOD-63 Prevent render of invoice detail when not selected --- bodyshop_translations.babel | 21 ++++++++++++++++ .../invoice-detail-edit.container.jsx | 4 +++- .../invoice-form/invoice-form.component.jsx | 4 ++-- .../invoice-form/invoice-form.container.jsx | 24 ++++++++++--------- .../invoice-form.totals.utility.js | 12 +++++----- client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index c2860aed7..4aefc114b 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -5541,6 +5541,27 @@ + + noneselected + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + state_tax false diff --git a/client/src/components/invoice-detail-edit/invoice-detail-edit.container.jsx b/client/src/components/invoice-detail-edit/invoice-detail-edit.container.jsx index 7fb1a4682..534b86335 100644 --- a/client/src/components/invoice-detail-edit/invoice-detail-edit.container.jsx +++ b/client/src/components/invoice-detail-edit/invoice-detail-edit.container.jsx @@ -11,6 +11,7 @@ import { selectBodyshop } from "../../redux/user/user.selectors"; import AlertComponent from "../alert/alert.component"; import InvoiceFormContainer from "../invoice-form/invoice-form.container"; import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component"; +import { useTranslation } from "react-i18next"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -18,7 +19,7 @@ const mapStateToProps = createStructuredSelector({ export function InvoiceDetailEditContainer({ bodyshop }) { const search = queryString.parse(useLocation().search); - + const { t } = useTranslation(); const [form] = Form.useForm(); const { loading, error, data } = useQuery(QUERY_INVOICE_BY_PK, { @@ -37,6 +38,7 @@ export function InvoiceDetailEditContainer({ bodyshop }) { }, [form, search.invoiceid]); if (error) return ; + if (!!!search.invoiceid) return
{t("invoices.labels.noneseleced")}
; return (
+
+ +
); } export default connect(mapStateToProps, null)(InvoiceFormContainer); diff --git a/client/src/components/invoice-form/invoice-form.totals.utility.js b/client/src/components/invoice-form/invoice-form.totals.utility.js index 13dbdb551..b8f74e623 100644 --- a/client/src/components/invoice-form/invoice-form.totals.utility.js +++ b/client/src/components/invoice-form/invoice-form.totals.utility.js @@ -8,20 +8,20 @@ export const CalculateInvoiceTotal = (invoice) => { local_tax_rate, state_tax_rate, } = invoice; - + //TODO Determine why this recalculates so many times. + console.log("Calculating invoice total..."); let subtotal = Dinero({ amount: 0 }); let federalTax = Dinero({ amount: 0 }); let stateTax = Dinero({ amount: 0 }); let localTax = Dinero({ amount: 0 }); if (!!!invoicelines) return null; - invoicelines.map((i) => { + invoicelines.forEach((i) => { if (!!i) { - const itemTotal = Dinero({ amount: i.actual_cost * 100 || 0 }).multiply( - i.quantity || 1 - ); + const itemTotal = Dinero({ + amount: Math.round((i.actual_cost || 0) * 100) || 0, + }).multiply(i.quantity || 1); subtotal = subtotal.add(itemTotal); if (i.applicable_taxes.federal) { - console.log("Adding fed tax."); federalTax = federalTax.add( itemTotal.percentage(federal_tax_rate || 0) ); diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 786cfa273..c5022acd9 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -381,6 +381,7 @@ "invoice_total": "Invoice Total Amount", "local_tax": "Local Tax", "new": "New Invoice", + "noneselected": "No invoice selected.F", "state_tax": "State Tax", "subtotal": "Subtotal" }, diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 1d785339e..11e74e98c 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -381,6 +381,7 @@ "invoice_total": "", "local_tax": "", "new": "", + "noneselected": "", "state_tax": "", "subtotal": "" }, diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index f702fff46..8ef0e9b0a 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -381,6 +381,7 @@ "invoice_total": "", "local_tax": "", "new": "", + "noneselected": "", "state_tax": "", "subtotal": "" },