Further work to refactor job costing + qb posting. BOD-383
This commit is contained in:
@@ -76,11 +76,14 @@ const generatePayment = (payment) => {
|
||||
TotalAmount: Dinero({
|
||||
amount: Math.round(payment.amount * 100),
|
||||
}).toFormat(DineroQbFormat),
|
||||
PaymentMethodRef: {
|
||||
FullName: payment.type,
|
||||
},
|
||||
Memo: `RO ${payment.job.ro_number || ""} OWNER ${
|
||||
payment.job.ownr_fn || ""
|
||||
} ${payment.job.ownr_ln || ""} ${payment.job.ownr_co_nm || ""} ${
|
||||
payment.stripeid
|
||||
}`,
|
||||
payment.stripeid || ""
|
||||
} ${payment.payer ? ` PAID BY ${payment.payer}` : ""}`,
|
||||
IsAutoApply: true,
|
||||
// AppliedToTxnAdd:{
|
||||
// T
|
||||
|
||||
@@ -28,7 +28,6 @@ exports.default = async (req, res) => {
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
|
||||
console.log("result", result);
|
||||
const { jobs } = result;
|
||||
const { bodyshops } = result;
|
||||
const QbXmlToExecute = [];
|
||||
@@ -174,44 +173,74 @@ const generateJobQbxml = (
|
||||
const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
||||
//Build the Invoice XML file.
|
||||
const InvoiceLineAdd = [];
|
||||
const invoice_allocation = jobs_by_pk.invoice_allocation;
|
||||
Object.keys(invoice_allocation.partsAllocations).forEach(
|
||||
(partsAllocationKey) => {
|
||||
if (
|
||||
!!!invoice_allocation.partsAllocations[partsAllocationKey].allocations
|
||||
)
|
||||
return;
|
||||
invoice_allocation.partsAllocations[
|
||||
partsAllocationKey
|
||||
].allocations.forEach((alloc) => {
|
||||
InvoiceLineAdd.push(
|
||||
generateInvoiceLine(
|
||||
jobs_by_pk,
|
||||
alloc,
|
||||
bodyshop.md_responsibility_centers
|
||||
)
|
||||
);
|
||||
const responsibilityCenters = bodyshop.md_responsibility_centers;
|
||||
|
||||
jobs_by_pk.joblines.map((jobline) => {
|
||||
if (jobline.profitcenter_part && jobline.act_price) {
|
||||
const DineroAmount = Dinero({
|
||||
amount: Math.round(jobline.act_price * 100),
|
||||
});
|
||||
}
|
||||
);
|
||||
Object.keys(invoice_allocation.labMatAllocations).forEach((AllocationKey) => {
|
||||
if (!!!invoice_allocation.labMatAllocations[AllocationKey].allocations)
|
||||
return;
|
||||
invoice_allocation.labMatAllocations[AllocationKey].allocations.forEach(
|
||||
(alloc) => {
|
||||
InvoiceLineAdd.push(
|
||||
generateInvoiceLine(
|
||||
jobs_by_pk,
|
||||
alloc,
|
||||
bodyshop.md_responsibility_centers
|
||||
)
|
||||
const account = responsibilityCenters.profits.find(
|
||||
(i) => jobline.profitcenter_part.toLowerCase() === i.name.toLowerCase()
|
||||
);
|
||||
|
||||
if (!!!account) {
|
||||
throw new Error(
|
||||
`A matching account does not exist for the allocation. Center: ${center}`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
InvoiceLineAdd.push({
|
||||
ItemRef: { FullName: account.accountitem },
|
||||
Desc: `${account.accountdesc} - ${jobline.line_desc}`,
|
||||
Quantity: jobline.part_qty,
|
||||
Rate: DineroAmount.toFormat(DineroQbFormat),
|
||||
//Amount: DineroAmount.toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: {
|
||||
FullName: "E",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (
|
||||
jobline.profitcenter_labor &&
|
||||
jobline.mod_lb_hrs &&
|
||||
jobline.mod_lb_hrs > 0
|
||||
) {
|
||||
const DineroAmount = Dinero({
|
||||
amount: Math.round(
|
||||
jobs_by_pk[`rate_${jobline.mod_lbr_ty.toLowerCase()}`] * 100
|
||||
),
|
||||
});
|
||||
console.log(
|
||||
"Rate",
|
||||
jobline.mod_lbr_ty,
|
||||
jobs_by_pk[`rate_${jobline.mod_lbr_ty.toLowerCase()}`]
|
||||
);
|
||||
const account = responsibilityCenters.profits.find(
|
||||
(i) => jobline.profitcenter_labor.toLowerCase() === i.name.toLowerCase()
|
||||
);
|
||||
|
||||
if (!!!account) {
|
||||
throw new Error(
|
||||
`A matching account does not exist for the allocation. Center: ${center}`
|
||||
);
|
||||
}
|
||||
|
||||
InvoiceLineAdd.push({
|
||||
ItemRef: { FullName: account.accountitem },
|
||||
Desc: `${account.accountdesc} - ${jobline.op_code_desc} ${jobline.line_desc}`,
|
||||
Quantity: jobline.mod_lb_hrs,
|
||||
Rate: DineroAmount.toFormat(DineroQbFormat),
|
||||
//Amount: DineroAmount.toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: {
|
||||
FullName: "E",
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Add tax lines
|
||||
const job_totals = JSON.parse(jobs_by_pk.job_totals);
|
||||
const job_totals = jobs_by_pk.job_totals;
|
||||
|
||||
const federal_tax = Dinero(job_totals.totals.federal_tax);
|
||||
const state_tax = Dinero(job_totals.totals.state_tax);
|
||||
@@ -288,31 +317,32 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
||||
.end({ pretty: true });
|
||||
|
||||
const invoiceQbxml_Full = QbXmlUtils.addQbxmlHeader(invoiceQbxml_partial);
|
||||
console.log("invoiceQbxml_Full", invoiceQbxml_Full);
|
||||
|
||||
return invoiceQbxml_Full;
|
||||
};
|
||||
|
||||
const generateInvoiceLine = (job, allocation, responsibilityCenters) => {
|
||||
const { amount, center } = allocation;
|
||||
const DineroAmount = Dinero(amount);
|
||||
const account = responsibilityCenters.profits.find(
|
||||
(i) => i.name.toLowerCase() === center.toLowerCase()
|
||||
);
|
||||
// const generateInvoiceLine = (job, allocation, responsibilityCenters) => {
|
||||
// const { amount, center } = allocation;
|
||||
// const DineroAmount = Dinero(amount);
|
||||
// const account = responsibilityCenters.profits.find(
|
||||
// (i) => i.name.toLowerCase() === center.toLowerCase()
|
||||
// );
|
||||
|
||||
if (!!!account) {
|
||||
throw new Error(
|
||||
`A matching account does not exist for the allocation. Center: ${center}`
|
||||
);
|
||||
}
|
||||
// if (!!!account) {
|
||||
// throw new Error(
|
||||
// `A matching account does not exist for the allocation. Center: ${center}`
|
||||
// );
|
||||
// }
|
||||
|
||||
return {
|
||||
ItemRef: { FullName: account.accountitem },
|
||||
Desc: account.accountdesc,
|
||||
Quantity: 1,
|
||||
//Rate: 100,
|
||||
Amount: DineroAmount.toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: {
|
||||
FullName: "E",
|
||||
},
|
||||
};
|
||||
};
|
||||
// return {
|
||||
// ItemRef: { FullName: account.accountitem },
|
||||
// Desc: account.accountdesc,
|
||||
// Quantity: 1,
|
||||
// //Rate: 100,
|
||||
// Amount: DineroAmount.toFormat(DineroQbFormat),
|
||||
// SalesTaxCodeRef: {
|
||||
// FullName: "E",
|
||||
// },
|
||||
// };
|
||||
// };
|
||||
|
||||
@@ -59,9 +59,45 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($ids: [uuid!]!) {
|
||||
ownr_city
|
||||
ownr_st
|
||||
ins_co_nm
|
||||
job_totals
|
||||
rate_la1
|
||||
rate_la2
|
||||
rate_la3
|
||||
rate_la4
|
||||
rate_laa
|
||||
rate_lab
|
||||
rate_lad
|
||||
rate_lae
|
||||
rate_laf
|
||||
rate_lag
|
||||
rate_lam
|
||||
rate_lar
|
||||
rate_las
|
||||
rate_lau
|
||||
rate_ma2s
|
||||
rate_ma2t
|
||||
rate_ma3s
|
||||
rate_mabl
|
||||
rate_macs
|
||||
rate_mahw
|
||||
rate_mapa
|
||||
rate_mash
|
||||
rate_matd
|
||||
owner {
|
||||
accountingid
|
||||
}
|
||||
joblines{
|
||||
id
|
||||
line_desc
|
||||
part_type
|
||||
act_price
|
||||
mod_lb_hrs
|
||||
mod_lbr_ty
|
||||
part_qty
|
||||
op_code_desc
|
||||
profitcenter_labor
|
||||
profitcenter_part
|
||||
}
|
||||
}
|
||||
bodyshops(where: {associations: {active: {_eq: true}}}) {
|
||||
id
|
||||
@@ -136,6 +172,8 @@ exports.QUERY_PAYMENTS_FOR_EXPORT = `
|
||||
stripeid
|
||||
exportedat
|
||||
stripeid
|
||||
type
|
||||
payer
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user