From 11ab7cd67effde073eda08811a0a77fdc341516b Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 22 Nov 2024 09:18:09 -0800 Subject: [PATCH] IO-3001 Null Coalesce for some items for better handling. --- server/accounting/qb-receivables-lines.js | 18 +++++++++--------- server/job/job-costing.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/accounting/qb-receivables-lines.js b/server/accounting/qb-receivables-lines.js index c257cd944..bed94f1d7 100644 --- a/server/accounting/qb-receivables-lines.js +++ b/server/accounting/qb-receivables-lines.js @@ -548,7 +548,7 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes } } - if (jobs_by_pk.job_totals.totals.ttl_adjustment) { + if (jobs_by_pk.job_totals.totals?.ttl_adjustment) { // Do not need to check for ImEX or Rome because ImEX uses a different totals calculation that will never set this field. if (qbo) { const taxAccountCode = findTaxCode( @@ -571,11 +571,11 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes InvoiceLineAdd.push({ DetailType: "SalesItemLineDetail", - Amount: Dinero(jobs_by_pk.job_totals.totals.ttl_adjustment).toFormat(DineroQbFormat), + Amount: Dinero(jobs_by_pk.job_totals.totals?.ttl_adjustment).toFormat(DineroQbFormat), SalesItemLineDetail: { ...(jobs_by_pk.class ? { ClassRef: { value: classes[jobs_by_pk.class] } } : {}), ItemRef: { - value: items[responsibilityCenters.ttl_adjustment.accountitem] + value: items[responsibilityCenters.ttl_adjustment?.accountitem] }, TaxCodeRef: { value: QboTaxId @@ -586,11 +586,11 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes } else { InvoiceLineAdd.push({ ItemRef: { - FullName: responsibilityCenters.ttl_adjustment.accountitem + FullName: responsibilityCenters.ttl_adjustment?.accountitem }, Desc: "Adjustment", Quantity: 1, - Amount: Dinero(jobs_by_pk.job_totals.totals.ttl_adjustment).toFormat(DineroQbFormat), + Amount: Dinero(jobs_by_pk.job_totals.totals?.ttl_adjustment).toFormat(DineroQbFormat), SalesTaxCodeRef: InstanceManager({ imex: { FullName: "E" @@ -902,11 +902,11 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes InvoiceLineAdd.push({ DetailType: "SalesItemLineDetail", - Amount: Dinero(jobs_by_pk.job_totals.totals.ttl_tax_adjustment).toFormat(DineroQbFormat), + Amount: Dinero(jobs_by_pk.job_totals.totals?.ttl_tax_adjustment).toFormat(DineroQbFormat), SalesItemLineDetail: { ...(jobs_by_pk.class ? { ClassRef: { value: classes[jobs_by_pk.class] } } : {}), ItemRef: { - value: items[responsibilityCenters.ttl_tax_adjustment.accountitem] + value: items[responsibilityCenters.ttl_tax_adjustment?.accountitem] }, TaxCodeRef: { value: QboTaxId @@ -917,11 +917,11 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes } else { InvoiceLineAdd.push({ ItemRef: { - FullName: responsibilityCenters.ttl_tax_adjustment.accountitem + FullName: responsibilityCenters.ttl_tax_adjustment?.accountitem }, Desc: "Tax Adjustment", Quantity: 1, - Amount: Dinero(jobs_by_pk.job_totals.totals.ttl_tax_adjustment).toFormat(DineroQbFormat), + Amount: Dinero(jobs_by_pk.job_totals.totals?.ttl_tax_adjustment).toFormat(DineroQbFormat), SalesTaxCodeRef: InstanceManager({ imex: { FullName: "E" diff --git a/server/job/job-costing.js b/server/job/job-costing.js index 6c107ce8d..4e7af7f86 100644 --- a/server/job/job-costing.js +++ b/server/job/job-costing.js @@ -850,7 +850,7 @@ function GenerateCostingData(job) { }); } //Push adjustments to bottom line. - if (job.job_totals.totals.ttl_adjustment) { + if (job.job_totals?.totals?.ttl_adjustment) { //Add to totals. const Adjustment = Dinero(job.job_totals.totals.ttl_adjustment); //Need to invert, since this is being assigned as a cost. summaryData.totalAdditionalSales = summaryData.totalAdditionalSales.add(Adjustment);