IO-1297 Adjust Job Costing after Invoicing
This commit is contained in:
@@ -215,7 +215,7 @@ const generateInvoiceQbxml = (
|
|||||||
jobs_by_pk.joblines.map((jobline) => {
|
jobs_by_pk.joblines.map((jobline) => {
|
||||||
//Parts Lines
|
//Parts Lines
|
||||||
if (jobline.db_ref === "936008") {
|
if (jobline.db_ref === "936008") {
|
||||||
//If either of these DB REFs change, they also need to change in job-totals calculations.
|
//If either of these DB REFs change, they also need to change in job-totals/job-costing calculations.
|
||||||
hasMapaLine = true;
|
hasMapaLine = true;
|
||||||
}
|
}
|
||||||
if (jobline.db_ref === "936007") {
|
if (jobline.db_ref === "936007") {
|
||||||
|
|||||||
@@ -751,6 +751,7 @@ exports.QUERY_JOB_COSTING_DETAILS = ` query QUERY_JOB_COSTING_DETAILS($id: uuid!
|
|||||||
ca_customer_gst
|
ca_customer_gst
|
||||||
joblines(where: { removed: { _eq: false } }) {
|
joblines(where: { removed: { _eq: false } }) {
|
||||||
id
|
id
|
||||||
|
db_ref
|
||||||
unq_seq
|
unq_seq
|
||||||
line_ind
|
line_ind
|
||||||
tax_part
|
tax_part
|
||||||
@@ -852,6 +853,7 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT
|
|||||||
ca_customer_gst
|
ca_customer_gst
|
||||||
joblines(where: {removed: {_eq: false}}) {
|
joblines(where: {removed: {_eq: false}}) {
|
||||||
id
|
id
|
||||||
|
db_ref
|
||||||
unq_seq
|
unq_seq
|
||||||
line_ind
|
line_ind
|
||||||
tax_part
|
tax_part
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ async function JobCosting(req, res) {
|
|||||||
.request(queries.QUERY_JOB_COSTING_DETAILS, {
|
.request(queries.QUERY_JOB_COSTING_DETAILS, {
|
||||||
id: jobid,
|
id: jobid,
|
||||||
});
|
});
|
||||||
console.timeEnd("querydata");
|
|
||||||
|
|
||||||
console.time(`generatecostingdata-${resp.jobs_by_pk.id}`);
|
console.time(`generatecostingdata-${resp.jobs_by_pk.id}`);
|
||||||
const ret = GenerateCostingData(resp.jobs_by_pk);
|
const ret = GenerateCostingData(resp.jobs_by_pk);
|
||||||
@@ -242,12 +241,22 @@ function GenerateCostingData(job) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const materialsHours = { mapaHrs: 0, mashHrs: 0 };
|
const materialsHours = { mapaHrs: 0, mashHrs: 0 };
|
||||||
|
let hasMapaLine = false;
|
||||||
|
let hasMashLine = false;
|
||||||
|
|
||||||
//Massage the data.
|
//Massage the data.
|
||||||
const jobLineTotalsByProfitCenter =
|
const jobLineTotalsByProfitCenter =
|
||||||
job &&
|
job &&
|
||||||
job.joblines.reduce(
|
job.joblines.reduce(
|
||||||
(acc, val) => {
|
(acc, val) => {
|
||||||
|
//Parts Lines
|
||||||
|
if (val.db_ref === "936008") {
|
||||||
|
//If either of these DB REFs change, they also need to change in job-totals/job-costing calculations.
|
||||||
|
hasMapaLine = true;
|
||||||
|
}
|
||||||
|
if (val.db_ref === "936007") {
|
||||||
|
hasMashLine = true;
|
||||||
|
}
|
||||||
if (val.mod_lbr_ty) {
|
if (val.mod_lbr_ty) {
|
||||||
const laborProfitCenter =
|
const laborProfitCenter =
|
||||||
val.profitcenter_labor || defaultProfits[val.mod_lbr_ty] || "?";
|
val.profitcenter_labor || defaultProfits[val.mod_lbr_ty] || "?";
|
||||||
@@ -265,32 +274,11 @@ function GenerateCostingData(job) {
|
|||||||
acc.labor[laborProfitCenter].add(laborAmount);
|
acc.labor[laborProfitCenter].add(laborAmount);
|
||||||
|
|
||||||
if (val.mod_lbr_ty === "LAR") {
|
if (val.mod_lbr_ty === "LAR") {
|
||||||
if (!acc.parts[defaultProfits["MAPA"]])
|
|
||||||
acc.parts[defaultProfits["MAPA"]] = Dinero();
|
|
||||||
|
|
||||||
materialsHours.mapaHrs += val.mod_lb_hrs || 0;
|
materialsHours.mapaHrs += val.mod_lb_hrs || 0;
|
||||||
acc.parts[defaultProfits["MAPA"]] = acc.parts[
|
|
||||||
defaultProfits["MAPA"]
|
|
||||||
].add(
|
|
||||||
Dinero({
|
|
||||||
amount: Math.round((job.rate_mapa || 0) * 100),
|
|
||||||
}).multiply(val.mod_lb_hrs || 0)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (!acc.parts[defaultProfits["MASH"]])
|
|
||||||
acc.parts[defaultProfits["MASH"]] = Dinero();
|
|
||||||
|
|
||||||
if (val.mod_lbr_ty !== "LAR") {
|
if (val.mod_lbr_ty !== "LAR") {
|
||||||
acc.parts[defaultProfits["MASH"]] = acc.parts[
|
|
||||||
defaultProfits["MASH"]
|
|
||||||
].add(
|
|
||||||
Dinero({
|
|
||||||
amount: Math.round((job.rate_mash || 0) * 100),
|
|
||||||
}).multiply(val.mod_lb_hrs || 0)
|
|
||||||
);
|
|
||||||
materialsHours.mashHrs += val.mod_lb_hrs || 0;
|
materialsHours.mashHrs += val.mod_lb_hrs || 0;
|
||||||
}
|
}
|
||||||
//If labor line, add to paint and shop materials.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val.part_type && val.part_type !== "PAE") {
|
if (val.part_type && val.part_type !== "PAE") {
|
||||||
@@ -358,6 +346,27 @@ function GenerateCostingData(job) {
|
|||||||
{ parts: {}, labor: {} }
|
{ parts: {}, labor: {} }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!hasMapaLine) {
|
||||||
|
if (!jobLineTotalsByProfitCenter.parts[defaultProfits["MAPA"]])
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MAPA"]] = Dinero();
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MAPA"]] =
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MAPA"]].add(
|
||||||
|
Dinero({
|
||||||
|
amount: Math.round((job.rate_mapa || 0) * 100),
|
||||||
|
}).multiply(materialsHours.mapaHrs || 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!hasMashLine) {
|
||||||
|
if (!jobLineTotalsByProfitCenter.parts[defaultProfits["MASH"]])
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MASH"]] = Dinero();
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MASH"]] =
|
||||||
|
jobLineTotalsByProfitCenter.parts[defaultProfits["MASH"]].add(
|
||||||
|
Dinero({
|
||||||
|
amount: Math.round((job.rate_mash || 0) * 100),
|
||||||
|
}).multiply(materialsHours.mashHrs || 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const billTotalsByCostCenters = job.bills.reduce((bill_acc, bill_val) => {
|
const billTotalsByCostCenters = job.bills.reduce((bill_acc, bill_val) => {
|
||||||
//At the bill level.
|
//At the bill level.
|
||||||
bill_val.billlines.map((line_val) => {
|
bill_val.billlines.map((line_val) => {
|
||||||
@@ -603,17 +612,15 @@ const formatGpPercent = (gppercent) => {
|
|||||||
|
|
||||||
//Verify that this stays in line with jobs-close-auto-allocate logic from the application.
|
//Verify that this stays in line with jobs-close-auto-allocate logic from the application.
|
||||||
const getAdditionalCostCenter = (jl, profitCenters) => {
|
const getAdditionalCostCenter = (jl, profitCenters) => {
|
||||||
console.log("Checking additional cost center", jl.line_desc);
|
|
||||||
if (!jl.part_type && !jl.mod_lbr_ty) {
|
if (!jl.part_type && !jl.mod_lbr_ty) {
|
||||||
const lineDesc = jl.line_desc.toLowerCase();
|
const lineDesc = jl.line_desc.toLowerCase();
|
||||||
//This logic is covered prior and assigned based on the labor type of the lines
|
console.log("Checking additional cost center", lineDesc);
|
||||||
// if (lineDesc.includes("shop materials")) {
|
|
||||||
// return profitCenters["MASH"];
|
if (lineDesc.includes("shop mat")) {
|
||||||
// } else if (lineDesc.includes("paint/materials")) {
|
return profitCenters["MASH"];
|
||||||
// return profitCenters["MAPA"];
|
} else if (lineDesc.includes("paint/mat")) {
|
||||||
// } else
|
return profitCenters["MAPA"];
|
||||||
//End covered logic
|
} else if (lineDesc.includes("ats amount")) {
|
||||||
if (lineDesc.includes("ats amount")) {
|
|
||||||
return profitCenters["ATS"];
|
return profitCenters["ATS"];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user