diff --git a/server/data/autohouse.js b/server/data/autohouse.js index 1a442485a..2297ac21f 100644 --- a/server/data/autohouse.js +++ b/server/data/autohouse.js @@ -123,12 +123,12 @@ exports.default = async (req, res) => { } } - // for (const xmlObj of allxmlsToUpload) { - // fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); - // } + for (const xmlObj of allxmlsToUpload) { + fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); + } - // res.json(allxmlsToUpload); - // return; + res.json(allxmlsToUpload); + return; let sftp = new Client(); sftp.on("error", (errors) => @@ -227,7 +227,7 @@ const CreateRepairOrderTag = (job, errorCallback) => { InsuredorClaimantFlag: null, }, VehicleInformation: { - Year: job.v_model_yr || "", + Year: parseInt(job.v_model_yr.match(/\d/g).join(""), 10) || "", Make: job.v_make_desc || "", Model: job.v_model_desc || "", VIN: job.v_vin || "", @@ -575,10 +575,12 @@ const CreateRepairOrderTag = (job, errorCallback) => { .add(Dinero(job.job_totals.totals.federal_tax)) .toFormat(AHDineroFormat), SalesTaxTotalCost: 0, - GrossTotal: Dinero(job.job_totals.totals.net_repairs).toFormat( + GrossTotal: Dinero(job.job_totals.totals.total_repairs).toFormat( AHDineroFormat ), - DeductibleTotal: job.ded_amt || 0, + DeductibleTotal: Dinero({ + amount: Math.round((job.ded_amt || 0) * 100), + }).toFormat(AHDineroFormat), DepreciationTotal: Dinero( job.job_totals.totals.custPayable.dep_taxes ).toFormat(AHDineroFormat), @@ -588,7 +590,9 @@ const CreateRepairOrderTag = (job, errorCallback) => { CustomerPay: Dinero(job.job_totals.totals.custPayable.total).toFormat( AHDineroFormat ), - InsurancePay: 0, + InsurancePay: Dinero(job.job_totals.totals.total_repairs) + .subtract(Dinero(job.job_totals.totals.custPayable)) + .toFormat(AHDineroFormat), Deposit: 0, AmountDue: 0, }, @@ -634,7 +638,7 @@ const CreateRepairOrderTag = (job, errorCallback) => { DetailLine: job.joblines.length > 0 ? job.joblines.map((jl) => - GenerateDetailLines(jl, job.bodyshop.md_order_statuses) + GenerateDetailLines(job, jl, job.bodyshop.md_order_statuses) ) : [generateNullDetailLine()], }, @@ -718,7 +722,10 @@ const CreateCosts = (job) => { return { PartsTotalCost: Object.keys(billTotalsByCostCenters).reduce((acc, key) => { - return acc.add(billTotalsByCostCenters[key]); + if (key !== defaultCosts.PAS && key !== defaultCosts.PASL) + return acc.add(billTotalsByCostCenters[key]); + + return acc; }, Dinero()), PartsOemCost: (billTotalsByCostCenters[defaultCosts.PAN] || Dinero()).add( billTotalsByCostCenters[defaultCosts.PAP] || Dinero() @@ -728,7 +735,9 @@ const CreateCosts = (job) => { billTotalsByCostCenters[defaultCosts.PAM] || Dinero(), PartsRecycledCost: billTotalsByCostCenters[defaultCosts.PAL] || Dinero(), PartsOtherCost: billTotalsByCostCenters[defaultCosts.PAO] || Dinero(), - SubletTotalCost: billTotalsByCostCenters[defaultCosts.PAS] || Dinero(), + SubletTotalCost: + billTotalsByCostCenters[defaultCosts.PAS] || + Dinero(billTotalsByCostCenters[defaultCosts.PASL] || Dinero()), BodyLaborTotalCost: ticketTotalsByCostCenter[defaultCosts.LAB] || Dinero(), RefinishLaborTotalCost: ticketTotalsByCostCenter[defaultCosts.LAR] || Dinero(), @@ -781,10 +790,15 @@ const StatusMapping = (status, md_ro_statuses) => { // default: return "UNDEFINED" }; -const GenerateDetailLines = (line, statuses) => { +const GenerateDetailLines = (job, line, statuses) => { const ret = { BackOrdered: line.status === statuses.default_bo ? "1" : "0", - Cost: (line.billlines[0] && line.billlines[0].actual_cost.toFixed(2)) || 0, + Cost: + (line.billlines[0] && + (line.billlines[0].actual_cost * line.billlines[0].quantity).toFixed( + 2 + )) || + 0, //Critical: null, Description: line.line_desc || "", DiscountMarkup: line.prt_dsmk_m || 0, @@ -811,11 +825,7 @@ const GenerateDetailLines = (line, statuses) => { Vendor: (line.billlines[0] && line.billlines[0].bill.vendor.name) || "", VendorPaid: null, VendorPrice: - (line.billlines[0] && - (line.billlines[0].actual_price * line.billlines[0].quantity).toFixed( - 2 - )) || - 0, + (line.billlines[0] && line.billlines[0].actual_price.toFixed(2)) || 0, Deleted: null, ExpectedOn: null, ReceivedOn: diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index aa8823623..6284de616 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -639,7 +639,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop job_totals driveable parts_tax_rates - + ded_amt joblines(where: {removed: {_eq: false}}) { id line_no