From e1e85214ccfedbe03f7015b94c720a88357380de Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 4 Mar 2021 16:33:36 -0800 Subject: [PATCH 1/4] Resolve sales tax code issue on payables IO-738 --- server/accounting/qbxml/qbxml-payables.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/accounting/qbxml/qbxml-payables.js b/server/accounting/qbxml/qbxml-payables.js index 622315936..a0bbfaa27 100644 --- a/server/accounting/qbxml/qbxml-payables.js +++ b/server/accounting/qbxml/qbxml-payables.js @@ -122,7 +122,10 @@ const findTaxCode = (billLine, taxcode) => { applicable_taxes: { local, state, federal }, } = billLine; const t = taxcode.filter( - (t) => t.local === local && t.state === state && t.federal === federal + (t) => + !!t.local === !!local && + !!t.state === !!state && + !!t.federal === !!federal ); if (t.length === 1) { console.log(t); From c0403b6ea931905012244b63c163ad6fa922d1cf Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 4 Mar 2021 16:47:45 -0800 Subject: [PATCH 2/4] Payables bug fixes for class & bill number IO-742 --- server/accounting/qbxml/qbxml-payables.js | 15 ++++++++------- server/graphql-client/queries.js | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/accounting/qbxml/qbxml-payables.js b/server/accounting/qbxml/qbxml-payables.js index a0bbfaa27..1c2dc3d2a 100644 --- a/server/accounting/qbxml/qbxml-payables.js +++ b/server/accounting/qbxml/qbxml-payables.js @@ -63,12 +63,16 @@ const generateBill = (bill) => { TxnDate: moment(bill.date).format("YYYY-MM-DD"), DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"), - RefNumber: bill.bill_number, + RefNumber: bill.invoice_number, Memo: `RO ${bill.job.ro_number || ""} OWNER ${ bill.job.ownr_fn || "" } ${bill.job.ownr_ln || ""} ${bill.job.ownr_co_nm || ""}`, ExpenseLineAdd: bill.billlines.map((il) => - generateBillLine(il, bill.job.bodyshop.md_responsibility_centers) + generateBillLine( + il, + bill.job.bodyshop.md_responsibility_centers, + bill.job.class + ) ), }, }, @@ -90,11 +94,7 @@ const generateBill = (bill) => { return billQbxml_Full; }; -const generateBillLine = (billLine, responsibilityCenters) => { - console.log( - " findTaxCode(billLine, responsibilityCenters.sales_tax_codes)", - findTaxCode(billLine, responsibilityCenters.sales_tax_codes) - ); +const generateBillLine = (billLine, responsibilityCenters, jobClass) => { return { AccountRef: { FullName: responsibilityCenters.costs.find( @@ -104,6 +104,7 @@ const generateBillLine = (billLine, responsibilityCenters) => { Amount: Dinero({ amount: Math.round(billLine.actual_cost * 100), }).toFormat(DineroQbFormat), + ...(jobClass ? { ClassRef: { FullName: jobClass } } : {}), SalesTaxCodeRef: { FullName: findTaxCode(billLine, responsibilityCenters.sales_tax_codes), }, diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index 867dc7b3b..742fc34a3 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -118,6 +118,7 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) { federal_tax_rate invoice_number is_credit_memo + invoice_number job { id ro_number @@ -125,6 +126,7 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) { ownr_fn ownr_ln ownr_co_nm + class bodyshop{ md_responsibility_centers } From 86cb1e1feeeb83c76e7345a581b03e9af2446243 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 4 Mar 2021 17:14:18 -0800 Subject: [PATCH 3/4] Resolve 2 tier by source exporting IO-740 --- server/accounting/qbxml/qbxml-payments.js | 28 ++++++++++------ server/accounting/qbxml/qbxml-receivables.js | 33 ++++++++++++++----- server/accounting/qbxml/qbxml-utils.js | 34 +++++++++++++++----- 3 files changed, 69 insertions(+), 26 deletions(-) diff --git a/server/accounting/qbxml/qbxml-payments.js b/server/accounting/qbxml/qbxml-payments.js index f9d75f842..522fad375 100644 --- a/server/accounting/qbxml/qbxml-payments.js +++ b/server/accounting/qbxml/qbxml-payments.js @@ -74,7 +74,7 @@ exports.default = async (req, res) => { QbXmlToExecute.push({ id: i.id, okStatusCodes: ["0"], - qbxml: generatePayment(i), + qbxml: generatePayment(i, isThreeTier, twoTierPref), }); }); @@ -85,7 +85,7 @@ exports.default = async (req, res) => { } }; -const generatePayment = (payment) => { +const generatePayment = (payment, isThreeTier, twoTierPref) => { console.log("generatePayment -> payment", payment); let paymentQbxmlObj; if (payment.amount > 0) { @@ -99,11 +99,15 @@ const generatePayment = (payment) => { FullName: payment.job.bodyshop.accountingconfig.tiers === 3 ? `${generateSourceTier(payment.job)}:${generateOwnerTier( - payment.job + payment.job, + isThreeTier, + twoTierPref )}:${generateJobTier(payment.job)}` - : `${generateOwnerTier(payment.job)}:${generateJobTier( - payment.job - )}`, + : `${generateOwnerTier( + payment.job, + isThreeTier, + twoTierPref + )}:${generateJobTier(payment.job)}`, }, ARAccountRef: { FullName: @@ -142,11 +146,15 @@ const generatePayment = (payment) => { FullName: payment.job.bodyshop.accountingconfig.tiers === 3 ? `${generateSourceTier(payment.job)}:${generateOwnerTier( - payment.job + payment.job, + isThreeTier, + twoTierPref )}:${generateJobTier(payment.job)}` - : `${generateOwnerTier(payment.job)}:${generateJobTier( - payment.job - )}`, + : `${generateOwnerTier( + payment.job, + isThreeTier, + twoTierPref + )}:${generateJobTier(payment.job)}`, }, ARAccountRef: { FullName: diff --git a/server/accounting/qbxml/qbxml-receivables.js b/server/accounting/qbxml/qbxml-receivables.js index 39914b5df..bc5cc2eb4 100644 --- a/server/accounting/qbxml/qbxml-receivables.js +++ b/server/accounting/qbxml/qbxml-receivables.js @@ -39,6 +39,7 @@ exports.default = async (req, res) => { const isThreeTier = bodyshop.accountingconfig.tiers === 3; const twoTierPref = bodyshop.accountingconfig.twotierpref; + //This is the Insurance Company tier IF 3 tier is selected. if (isThreeTier) { QbXmlToExecute.push({ id: jobs_by_pk.id, @@ -47,6 +48,8 @@ exports.default = async (req, res) => { }); } + //If 3 tier, this should be the customer. + //If 2 tier, this should be based on the pref. QbXmlToExecute.push({ id: jobs_by_pk.id, okStatusCodes: ["0", "3100"], @@ -59,6 +62,7 @@ exports.default = async (req, res) => { ), }); + //This is always going to be the job. QbXmlToExecute.push({ id: jobs_by_pk.id, okStatusCodes: ["0", "3100"], @@ -74,7 +78,12 @@ exports.default = async (req, res) => { QbXmlToExecute.push({ id: jobs_by_pk.id, okStatusCodes: ["0"], - qbxml: generateInvoiceQbxml(jobs_by_pk, bodyshop), + qbxml: generateInvoiceQbxml( + jobs_by_pk, + bodyshop, + isThreeTier, + twoTierPref + ), }); }); @@ -130,19 +139,20 @@ const generateJobQbxml = ( let ParentRefName; if (tierLevel === 2) { - Name = generateOwnerTier(jobs_by_pk); + Name = generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref); ParentRefName = isThreeTier ? generateSourceTier(jobs_by_pk) : null; } else if (tierLevel === 3) { Name = generateJobTier(jobs_by_pk); ParentRefName = isThreeTier - ? `${jobs_by_pk.ins_co_nm}:${generateOwnerTier(jobs_by_pk)}` - : generateOwnerTier(jobs_by_pk); + ? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(jobs_by_pk)}` + : generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref); } const jobQbxmlObj = { QBXML: { QBXMLMsgsRq: { "@onError": "continueOnError", + CustomerAddRq: { CustomerAdd: { Name: Name, @@ -170,7 +180,12 @@ const generateJobQbxml = ( return jobQbxml_Full; }; exports.generateJobQbxml = generateJobQbxml; -const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => { +const generateInvoiceQbxml = ( + jobs_by_pk, + bodyshop, + isThreeTier, + twoTierPref +) => { //Build the Invoice XML file. const InvoiceLineAdd = []; const responsibilityCenters = bodyshop.md_responsibility_centers; @@ -302,9 +317,11 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => { ? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier( jobs_by_pk )}:${generateJobTier(jobs_by_pk)}` - : `${generateOwnerTier(jobs_by_pk)}:${generateJobTier( - jobs_by_pk - )}`, + : `${generateOwnerTier( + jobs_by_pk, + isThreeTier, + twoTierPref + )}:${generateJobTier(jobs_by_pk)}`, }, ...(jobs_by_pk.class diff --git a/server/accounting/qbxml/qbxml-utils.js b/server/accounting/qbxml/qbxml-utils.js index 7b8020bbb..cd47eced8 100644 --- a/server/accounting/qbxml/qbxml-utils.js +++ b/server/accounting/qbxml/qbxml-utils.js @@ -13,12 +13,30 @@ exports.generateJobTier = (jobs_by_pk) => { return jobs_by_pk.ro_number; }; -exports.generateOwnerTier = (jobs_by_pk) => { - return jobs_by_pk.ownr_co_nm - ? `${jobs_by_pk.ownr_co_nm} - ${jobs_by_pk.ownr_ln || ""} ${ - jobs_by_pk.ownr_fn || "" - } #${jobs_by_pk.owner.accountingid || ""}` - : `${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""} #${ - jobs_by_pk.owner.accountingid || "" - }`; +exports.generateOwnerTier = (jobs_by_pk, isThreeTier, twotierpref) => { + if (isThreeTier) { + //It's always gonna be the owner now. Same as 2 tier by name + return jobs_by_pk.ownr_co_nm + ? `${jobs_by_pk.ownr_co_nm} - ${jobs_by_pk.ownr_ln || ""} ${ + jobs_by_pk.ownr_fn || "" + } #${jobs_by_pk.owner.accountingid || ""}` + : `${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""} #${ + jobs_by_pk.owner.accountingid || "" + }`; + } else { + //What's the 2 tier pref? + if (twotierpref === "source") { + return this.generateSourceTier(jobs_by_pk); + //It should be the insurance co. + } else { + //Same as 3 tier + return jobs_by_pk.ownr_co_nm + ? `${jobs_by_pk.ownr_co_nm} - ${jobs_by_pk.ownr_ln || ""} ${ + jobs_by_pk.ownr_fn || "" + } #${jobs_by_pk.owner.accountingid || ""}` + : `${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""} #${ + jobs_by_pk.owner.accountingid || "" + }`; + } + } }; From af949f8d6b07a6a1b7b7b5f50b3ca6464dcc9358 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 4 Mar 2021 17:15:12 -0800 Subject: [PATCH 4/4] Payments table null check. --- .../accounting-payments-table.component.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx index 1b32eba04..77b68c145 100644 --- a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx +++ b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx @@ -66,12 +66,12 @@ export default function AccountingPayablesTableComponent({ return record.job.owner ? ( {`${record.job.ownr_fn || ""} ${record.job.ownr_ln || ""} ${ - record.job.ownr_co_nm + record.job.ownr_co_nm || "" }`} ) : ( {`${record.job.ownr_fn || ""} ${record.job.ownr_ln || ""} ${ - record.job.ownr_co_nm + record.job.ownr_co_nm || "" }`} ); },