Autohouse Fixes.

This commit is contained in:
Patrick Fic
2022-02-09 10:34:52 -08:00
parent b4e0dcc395
commit 39998a279e
2 changed files with 30 additions and 20 deletions

View File

@@ -123,12 +123,12 @@ exports.default = async (req, res) => {
} }
} }
// for (const xmlObj of allxmlsToUpload) { for (const xmlObj of allxmlsToUpload) {
// fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
// } }
// res.json(allxmlsToUpload); res.json(allxmlsToUpload);
// return; return;
let sftp = new Client(); let sftp = new Client();
sftp.on("error", (errors) => sftp.on("error", (errors) =>
@@ -227,7 +227,7 @@ const CreateRepairOrderTag = (job, errorCallback) => {
InsuredorClaimantFlag: null, InsuredorClaimantFlag: null,
}, },
VehicleInformation: { VehicleInformation: {
Year: job.v_model_yr || "", Year: parseInt(job.v_model_yr.match(/\d/g).join(""), 10) || "",
Make: job.v_make_desc || "", Make: job.v_make_desc || "",
Model: job.v_model_desc || "", Model: job.v_model_desc || "",
VIN: job.v_vin || "", VIN: job.v_vin || "",
@@ -575,10 +575,12 @@ const CreateRepairOrderTag = (job, errorCallback) => {
.add(Dinero(job.job_totals.totals.federal_tax)) .add(Dinero(job.job_totals.totals.federal_tax))
.toFormat(AHDineroFormat), .toFormat(AHDineroFormat),
SalesTaxTotalCost: 0, SalesTaxTotalCost: 0,
GrossTotal: Dinero(job.job_totals.totals.net_repairs).toFormat( GrossTotal: Dinero(job.job_totals.totals.total_repairs).toFormat(
AHDineroFormat AHDineroFormat
), ),
DeductibleTotal: job.ded_amt || 0, DeductibleTotal: Dinero({
amount: Math.round((job.ded_amt || 0) * 100),
}).toFormat(AHDineroFormat),
DepreciationTotal: Dinero( DepreciationTotal: Dinero(
job.job_totals.totals.custPayable.dep_taxes job.job_totals.totals.custPayable.dep_taxes
).toFormat(AHDineroFormat), ).toFormat(AHDineroFormat),
@@ -588,7 +590,9 @@ const CreateRepairOrderTag = (job, errorCallback) => {
CustomerPay: Dinero(job.job_totals.totals.custPayable.total).toFormat( CustomerPay: Dinero(job.job_totals.totals.custPayable.total).toFormat(
AHDineroFormat AHDineroFormat
), ),
InsurancePay: 0, InsurancePay: Dinero(job.job_totals.totals.total_repairs)
.subtract(Dinero(job.job_totals.totals.custPayable))
.toFormat(AHDineroFormat),
Deposit: 0, Deposit: 0,
AmountDue: 0, AmountDue: 0,
}, },
@@ -634,7 +638,7 @@ const CreateRepairOrderTag = (job, errorCallback) => {
DetailLine: DetailLine:
job.joblines.length > 0 job.joblines.length > 0
? job.joblines.map((jl) => ? job.joblines.map((jl) =>
GenerateDetailLines(jl, job.bodyshop.md_order_statuses) GenerateDetailLines(job, jl, job.bodyshop.md_order_statuses)
) )
: [generateNullDetailLine()], : [generateNullDetailLine()],
}, },
@@ -718,7 +722,10 @@ const CreateCosts = (job) => {
return { return {
PartsTotalCost: Object.keys(billTotalsByCostCenters).reduce((acc, key) => { 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()), }, Dinero()),
PartsOemCost: (billTotalsByCostCenters[defaultCosts.PAN] || Dinero()).add( PartsOemCost: (billTotalsByCostCenters[defaultCosts.PAN] || Dinero()).add(
billTotalsByCostCenters[defaultCosts.PAP] || Dinero() billTotalsByCostCenters[defaultCosts.PAP] || Dinero()
@@ -728,7 +735,9 @@ const CreateCosts = (job) => {
billTotalsByCostCenters[defaultCosts.PAM] || Dinero(), billTotalsByCostCenters[defaultCosts.PAM] || Dinero(),
PartsRecycledCost: billTotalsByCostCenters[defaultCosts.PAL] || Dinero(), PartsRecycledCost: billTotalsByCostCenters[defaultCosts.PAL] || Dinero(),
PartsOtherCost: billTotalsByCostCenters[defaultCosts.PAO] || 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(), BodyLaborTotalCost: ticketTotalsByCostCenter[defaultCosts.LAB] || Dinero(),
RefinishLaborTotalCost: RefinishLaborTotalCost:
ticketTotalsByCostCenter[defaultCosts.LAR] || Dinero(), ticketTotalsByCostCenter[defaultCosts.LAR] || Dinero(),
@@ -781,10 +790,15 @@ const StatusMapping = (status, md_ro_statuses) => {
// default: return "UNDEFINED" // default: return "UNDEFINED"
}; };
const GenerateDetailLines = (line, statuses) => { const GenerateDetailLines = (job, line, statuses) => {
const ret = { const ret = {
BackOrdered: line.status === statuses.default_bo ? "1" : "0", 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, //Critical: null,
Description: line.line_desc || "", Description: line.line_desc || "",
DiscountMarkup: line.prt_dsmk_m || 0, DiscountMarkup: line.prt_dsmk_m || 0,
@@ -811,11 +825,7 @@ const GenerateDetailLines = (line, statuses) => {
Vendor: (line.billlines[0] && line.billlines[0].bill.vendor.name) || "", Vendor: (line.billlines[0] && line.billlines[0].bill.vendor.name) || "",
VendorPaid: null, VendorPaid: null,
VendorPrice: VendorPrice:
(line.billlines[0] && (line.billlines[0] && line.billlines[0].actual_price.toFixed(2)) || 0,
(line.billlines[0].actual_price * line.billlines[0].quantity).toFixed(
2
)) ||
0,
Deleted: null, Deleted: null,
ExpectedOn: null, ExpectedOn: null,
ReceivedOn: ReceivedOn:

View File

@@ -639,7 +639,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
job_totals job_totals
driveable driveable
parts_tax_rates parts_tax_rates
ded_amt
joblines(where: {removed: {_eq: false}}) { joblines(where: {removed: {_eq: false}}) {
id id
line_no line_no