From e801a03984c055810d37f7b5bc7aaa4aa9319b46 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Mon, 7 Jun 2021 13:16:31 -0700 Subject: [PATCH] IO-1059 Prevent posting bills to closed jobs. --- bodyshop_translations.babel | 21 +++++++++++++++++++ .../bill-form/bill-form.component.jsx | 20 +++++++++++++++++- .../bill-form/bill-form.container.jsx | 1 + client/src/graphql/jobs-lines.queries.js | 4 ++++ client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + client/src/utils/TemplateConstants.js | 2 +- 8 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index b94370a28..46aa75c86 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -2370,6 +2370,27 @@ + + onlycmforinvoiced + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + retailtotal false diff --git a/client/src/components/bill-form/bill-form.component.jsx b/client/src/components/bill-form/bill-form.component.jsx index e8d8e4387..f74046c61 100644 --- a/client/src/components/bill-form/bill-form.component.jsx +++ b/client/src/components/bill-form/bill-form.component.jsx @@ -41,6 +41,7 @@ export function BillFormComponent({ loadLines, billEdit, disableInvNumber, + job, }) { const { t } = useTranslation(); const client = useApolloClient(); @@ -89,7 +90,7 @@ export function BillFormComponent({ { if (form.getFieldValue("jobid") !== null) { loadLines({ variables: { id: form.getFieldValue("jobid") } }); @@ -187,6 +188,23 @@ export function BillFormComponent({ label={t("bills.fields.is_credit_memo")} name="is_credit_memo" valuePropName="checked" + dependencies={["jobid"]} + rules={[ + ({ getFieldValue }) => ({ + validator(rule, value) { + if ( + (job.status === bodyshop.md_ro_statuses.default_invoiced || + job.status === bodyshop.md_ro_statuses.default_exported || + job.status === bodyshop.md_ro_statuses.default_void) && + (value === false || !value) + ) { + return Promise.reject(t("bills.labels.onlycmforinvoiced")); + } + + return Promise.resolve(); + }, + }), + ]} > diff --git a/client/src/components/bill-form/bill-form.container.jsx b/client/src/components/bill-form/bill-form.container.jsx index f5775eac2..308b4bdb4 100644 --- a/client/src/components/bill-form/bill-form.container.jsx +++ b/client/src/components/bill-form/bill-form.container.jsx @@ -34,6 +34,7 @@ export function BillFormContainer({ } loadLines={loadLines} lineData={lineData ? lineData.joblines : []} + job={lineData ? lineData.jobs_by_pk : null} responsibilityCenters={bodyshop.md_responsibility_centers || null} disableInvNumber={disableInvNumber} /> diff --git a/client/src/graphql/jobs-lines.queries.js b/client/src/graphql/jobs-lines.queries.js index 7f5aadfb2..1b1304653 100644 --- a/client/src/graphql/jobs-lines.queries.js +++ b/client/src/graphql/jobs-lines.queries.js @@ -186,6 +186,10 @@ export const GET_JOB_LINES_TO_ENTER_BILL = gql` lbr_amt op_code_desc } + jobs_by_pk(id: $id) { + id + status + } } `; // oem_partno: { diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 3a1b1b070..62c264f66 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -156,6 +156,7 @@ "markforreexport": "Mark for Re-export", "new": "New Bill", "noneselected": "No bill selected.", + "onlycmforinvoiced": "Only credit memos can be entered for any job that has been invoiced.", "retailtotal": "Bills Retail Total", "state_tax": "Provincial/State Tax", "subtotal": "Subtotal", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index ef40ff1c5..f3ca17de3 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -156,6 +156,7 @@ "markforreexport": "", "new": "", "noneselected": "", + "onlycmforinvoiced": "", "retailtotal": "", "state_tax": "", "subtotal": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 2c2395e5a..1e96195c4 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -156,6 +156,7 @@ "markforreexport": "", "new": "", "noneselected": "", + "onlycmforinvoiced": "", "retailtotal": "", "state_tax": "", "subtotal": "", diff --git a/client/src/utils/TemplateConstants.js b/client/src/utils/TemplateConstants.js index a3e086306..567c484e7 100644 --- a/client/src/utils/TemplateConstants.js +++ b/client/src/utils/TemplateConstants.js @@ -765,7 +765,7 @@ export const TemplateList = (type, context) => { disabled: false, rangeFilter: { object: i18n.t("reportcenter.labels.objects.jobs"), - field: i18n.t("jobs.fields.date_invoiced"), + field: i18n.t("jobs.fields.date_open"), }, }, job_costing_ro_date_summary: {