WIP Financial Calculation
This commit is contained in:
@@ -2,7 +2,7 @@ export function CalculateJob(job, shoprates) {
|
||||
let ret = {
|
||||
parts: CalculatePartsTotals(job.joblines),
|
||||
rates: CalculateRatesTotals(job, shoprates),
|
||||
custPayable: CalculateCustPayable(job)
|
||||
custPayable: CalculateCustPayable(job),
|
||||
};
|
||||
|
||||
ret.totals = CalculateTaxesTotals(job, ret);
|
||||
@@ -14,12 +14,35 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
const subtotal =
|
||||
otherTotals.parts.parts.subtotal +
|
||||
otherTotals.parts.sublets.subtotal +
|
||||
otherTotals.rates.subtotal;
|
||||
otherTotals.rates.subtotal +
|
||||
job.towing_payable +
|
||||
job.storage_payable; //Levies should be included??
|
||||
|
||||
console.log("job.parts_tax_rates", job.parts_tax_rates);
|
||||
|
||||
const statePartsTax = job.joblines.reduce((acc, val) => {
|
||||
if (!!!val.part_type) return acc;
|
||||
if (!!job.parts_tax_rates[val.part_type]) {
|
||||
return (
|
||||
acc +
|
||||
(val.act_price * job.parts_tax_rates[val.part_type].prt_tax_rt || 0)
|
||||
);
|
||||
} else {
|
||||
return acc;
|
||||
}
|
||||
}, 0);
|
||||
|
||||
let ret = {
|
||||
subtotal: subtotal,
|
||||
federal_tax: subtotal * job.federal_tax_rate || 0,
|
||||
state_tax: subtotal * job.state_tax_rate || 0,
|
||||
local_tax: subtotal * job.local_tax_rate || 0
|
||||
statePartsTax,
|
||||
state_tax:
|
||||
statePartsTax +
|
||||
(otherTotals.rates.rates_subtotal * job.tax_lbr_rate || 0) +
|
||||
(job.towing_payable || 0 * job.tax_tow_rt || 0) +
|
||||
(job.storage_payable || 0 * job.tax_str_rt || 0) +
|
||||
(otherTotals.rates.paint_mat.subtotal * job.tax_paint_mat_rt || 0),
|
||||
local_tax: subtotal * job.local_tax_rate || 0,
|
||||
};
|
||||
|
||||
ret.total_repairs =
|
||||
@@ -35,93 +58,93 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
let ret = {
|
||||
rate_la1: {
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LA1")
|
||||
.filter((item) => item.mod_lbr_ty === "LA1")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
rate: ratesList.rate_la1
|
||||
rate: ratesList.rate_la1,
|
||||
},
|
||||
rate_la2: {
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LA2")
|
||||
.filter((item) => item.mod_lbr_ty === "LA2")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
rate: ratesList.rate_la2
|
||||
rate: ratesList.rate_la2,
|
||||
},
|
||||
rate_la3: {
|
||||
rate: ratesList.rate_la3,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LA3")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LA3")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_la4: {
|
||||
rate: ratesList.rate_la4,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LA4")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LA4")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_laa: {
|
||||
rate: ratesList.rate_laa,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAA")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAA")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lab: {
|
||||
rate: ratesList.rate_lab,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAB")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAB")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lad: {
|
||||
rate: ratesList.rate_lad,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAD")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAD")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lae: {
|
||||
rate: ratesList.rate_lae,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAE")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAE")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_laf: {
|
||||
rate: ratesList.rate_laf,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAF")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAF")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lag: {
|
||||
rate: ratesList.rate_lag,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAG")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAG")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lam: {
|
||||
rate: ratesList.rate_lam,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAM")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAM")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lar: {
|
||||
rate: ratesList.rate_lar,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_las: {
|
||||
rate: ratesList.rate_las,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAS")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAS")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_lau: {
|
||||
rate: ratesList.rate_lau,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAU")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAU")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
rate_atp: {
|
||||
rate: shoprates.rate_atp || 0,
|
||||
hours: jobLines
|
||||
.filter(
|
||||
item =>
|
||||
(item) =>
|
||||
item.mod_lbr_ty !== "LA1" &&
|
||||
item.mod_lbr_ty !== "LA2" &&
|
||||
item.mod_lbr_ty !== "LA3" &&
|
||||
@@ -131,28 +154,33 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
item.mod_lbr_ty !== "LAS" &&
|
||||
item.mod_lbr_ty !== "LAA"
|
||||
)
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
paint_mat: {
|
||||
rate: ratesList.rate_mapa,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
shop_mat: {
|
||||
rate: ratesList.rate_mash,
|
||||
hours: jobLines
|
||||
.filter(item => item.mod_lbr_ty !== "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
|
||||
}
|
||||
.filter((item) => item.mod_lbr_ty !== "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
};
|
||||
|
||||
let subtotal = 0;
|
||||
let rates_subtotal = 0;
|
||||
for (const property in ret) {
|
||||
ret[property].total = ret[property].hours * ret[property].rate;
|
||||
subtotal = subtotal + ret[property].hours * ret[property].rate;
|
||||
if (property !== "paint_mat" && property !== "shop_mat")
|
||||
rates_subtotal =
|
||||
rates_subtotal + ret[property].hours * ret[property].rate;
|
||||
}
|
||||
ret.subtotal = subtotal;
|
||||
ret.rates_subtotal = rates_subtotal;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -173,9 +201,9 @@ function CalculatePartsTotals(jobLines) {
|
||||
...acc,
|
||||
parts: {
|
||||
...acc.parts,
|
||||
subtotal: acc.parts.subtotal + value.act_price
|
||||
subtotal: acc.parts.subtotal + value.act_price,
|
||||
//TODO Add Adjustments in
|
||||
}
|
||||
},
|
||||
};
|
||||
case "PAS":
|
||||
case "PASL":
|
||||
@@ -183,9 +211,9 @@ function CalculatePartsTotals(jobLines) {
|
||||
...acc,
|
||||
sublets: {
|
||||
...acc.sublets,
|
||||
subtotal: acc.sublets.subtotal + value.act_price
|
||||
subtotal: acc.sublets.subtotal + value.act_price,
|
||||
//TODO Add Adjustments in
|
||||
}
|
||||
},
|
||||
};
|
||||
default:
|
||||
return acc;
|
||||
@@ -193,7 +221,7 @@ function CalculatePartsTotals(jobLines) {
|
||||
},
|
||||
{
|
||||
parts: { subtotal: 0, adjustments: 0, total: 0 },
|
||||
sublets: { subtotal: 0, adjustments: 0, total: 0 }
|
||||
sublets: { subtotal: 0, adjustments: 0, total: 0 },
|
||||
}
|
||||
);
|
||||
|
||||
@@ -201,8 +229,8 @@ function CalculatePartsTotals(jobLines) {
|
||||
parts: { ...ret.parts, total: ret.parts.subtotal + ret.parts.adjustments },
|
||||
sublets: {
|
||||
...ret.sublets,
|
||||
total: ret.sublets.subtotal + ret.sublets.adjustments
|
||||
}
|
||||
total: ret.sublets.subtotal + ret.sublets.adjustments,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -217,6 +245,6 @@ function CalculateCustPayable(job) {
|
||||
0 + job.federal_tax_payable ||
|
||||
0 + job.other_amount_payable ||
|
||||
0 + job.depreciation_taxes ||
|
||||
0
|
||||
0,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user