BOD-72 Refactored calculations to use Dinero library.
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
import { Col, Descriptions, Row, Statistic, Result } from "antd";
|
||||
import React from "react";
|
||||
import { Col, Descriptions, Row, Statistic } from "antd";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import { CalculateJob } from "./job-totals.utility";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export default function JobsTotalsTableComponent({ totals }) {
|
||||
export function JobsTotalsTableComponent({ bodyshop, job }) {
|
||||
const { t } = useTranslation();
|
||||
if (!!!totals)
|
||||
return <Result status='warning' title={t("jobs.errors.nofinancial")} />;
|
||||
const [totals, setTotals] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
setTotals(CalculateJob(job, bodyshop.shoprates));
|
||||
}, [bodyshop, job]);
|
||||
|
||||
if (!!!totals) {
|
||||
console.log("Totals was falsey.");
|
||||
return <LoadingSkeleton />;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<Row>
|
||||
@@ -17,161 +33,161 @@ export default function JobsTotalsTableComponent({ totals }) {
|
||||
title={t("jobs.labels.rates")}>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_laa")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_laa.total}
|
||||
value={totals.rates.rate_laa.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_laa.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_laa.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_laa.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_laa.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lab")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lab.total}
|
||||
value={totals.rates.rate_lab.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lab.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lab.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lab.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lab.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lad")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lad.total}
|
||||
value={totals.rates.rate_lad.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lad.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lad.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lad.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lad.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lae")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lae.total}
|
||||
value={totals.rates.rate_lae.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lae.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lae.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lae.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lae.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_laf")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_laf.total}
|
||||
value={totals.rates.rate_laf.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_laf.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_laf.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_laf.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_laf.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lag")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lag.total}
|
||||
value={totals.rates.rate_lag.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lag.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lag.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lag.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lag.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lam")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lam.total}
|
||||
value={totals.rates.rate_lam.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lam.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lam.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lam.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lam.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lar")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lar.total}
|
||||
value={totals.rates.rate_lar.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lar.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lar.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lar.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lar.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_las")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_las.total}
|
||||
value={totals.rates.rate_las.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_las.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_las.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_las.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_las.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_lau")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_lau.total}
|
||||
value={totals.rates.rate_lau.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_lau.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_lau.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_lau.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_lau.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la1")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la1.total}
|
||||
value={totals.rates.rate_la1.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la1.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_la1.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_la1.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la1.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la2")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la2.total}
|
||||
value={totals.rates.rate_la2.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la2.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_la2.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_la2.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la2.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la3")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la3.total}
|
||||
value={totals.rates.rate_la3.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la3.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_la3.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_la3.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la3.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_la4")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_la4.total}
|
||||
value={totals.rates.rate_la4.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_la4.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_la4.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_la4.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_la4.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.fields.rate_atp")}>
|
||||
<Statistic
|
||||
value={totals.rates.rate_atp.total}
|
||||
value={totals.rates.rate_atp.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.rate_atp.hours.toFixed(2)} @ ${
|
||||
totals.rates.rate_atp.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.rate_atp.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.rate_atp.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.paint_mat")}>
|
||||
<Statistic
|
||||
value={totals.rates.paint_mat.total}
|
||||
value={totals.rates.paint_mat.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.paint_mat.hours.toFixed(2)} @ ${
|
||||
totals.rates.paint_mat.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.paint_mat.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.paint_mat.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.shop_mat")}>
|
||||
<Statistic
|
||||
value={totals.rates.shop_mat.total}
|
||||
value={totals.rates.shop_mat.total.toFormat()}
|
||||
precision={2}
|
||||
suffix={`(${totals.rates.shop_mat.hours.toFixed(2)} @ ${
|
||||
totals.rates.shop_mat.rate
|
||||
})`}
|
||||
suffix={`(${totals.rates.shop_mat.hours.toFixed(
|
||||
2
|
||||
)} @ ${totals.rates.shop_mat.rate})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item
|
||||
style={{ color: "red" }}
|
||||
label={t("jobs.labels.rates_subtotal")}>
|
||||
<Statistic value={totals.rates.subtotal} precision={2} />
|
||||
<Statistic value={totals.rates.subtotal.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Row>
|
||||
@@ -184,16 +200,14 @@ export default function JobsTotalsTableComponent({ totals }) {
|
||||
title={t("jobs.labels.partssubletstotal")}>
|
||||
<Descriptions.Item label={t("jobs.labels.partstotal")}>
|
||||
<Statistic
|
||||
value={totals.parts.parts.total}
|
||||
precision={2}
|
||||
suffix={`(${totals.parts.parts.subtotal} ± ${totals.parts.parts.adjustments})`}
|
||||
value={totals.parts.parts.total.toFormat()}
|
||||
suffix={`(${totals.parts.parts.subtotal.toFormat()} ± ${totals.parts.parts.adjustments.toFormat()})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.subletstotal")}>
|
||||
<Statistic
|
||||
value={totals.parts.sublets.total}
|
||||
precision={2}
|
||||
suffix={`(${totals.parts.sublets.subtotal} ± ${totals.parts.sublets.adjustments})`}
|
||||
value={totals.parts.sublets.total.toFormat()}
|
||||
suffix={`(${totals.parts.sublets.subtotal.toFormat()} ± ${totals.parts.sublets.adjustments.toFormat()})`}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
@@ -206,32 +220,31 @@ export default function JobsTotalsTableComponent({ totals }) {
|
||||
column={1}
|
||||
title={t("jobs.labels.totals")}>
|
||||
<Descriptions.Item label={t("jobs.labels.subtotal")}>
|
||||
<Statistic value={totals.totals.subtotal} precision={2} />
|
||||
<Statistic value={totals.totals.subtotal.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.federal_tax_amt")}>
|
||||
<Statistic value={totals.totals.federal_tax} precision={2} />
|
||||
<Statistic value={totals.totals.federal_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.state_tax_amt")}>
|
||||
<Statistic value={totals.totals.state_tax} precision={2} />
|
||||
<Statistic value={totals.totals.state_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label={t("jobs.labels.local_tax_amt")}>
|
||||
<Statistic value={totals.totals.local_tax_amt} precision={2} />
|
||||
<Statistic value={totals.totals.local_tax.toFormat()} />
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Statistic
|
||||
title={t("jobs.labels.total_repairs")}
|
||||
value={totals.totals.total_repairs}
|
||||
precision={2}
|
||||
value={totals.totals.total_repairs.toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.net_repairs")}
|
||||
value={totals.totals.net_repairs}
|
||||
precision={2}
|
||||
value={totals.totals.net_repairs.toFormat()}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, null)(JobsTotalsTableComponent);
|
||||
|
||||
@@ -6,68 +6,70 @@ export function CalculateJob(job, shoprates) {
|
||||
rates: CalculateRatesTotals(job, shoprates),
|
||||
custPayable: CalculateCustPayable(job),
|
||||
};
|
||||
|
||||
ret.totals = CalculateTaxesTotals(job, ret);
|
||||
|
||||
console.log("CalculateJob -> Final", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function CalculateTaxesTotals(job, otherTotals) {
|
||||
const subtotal =
|
||||
otherTotals.parts.parts.subtotal +
|
||||
otherTotals.parts.sublets.subtotal +
|
||||
otherTotals.rates.subtotal +
|
||||
(job.towing_payable || 0) +
|
||||
(job.storage_payable || 0); //Levies should be included??
|
||||
const subtotal = otherTotals.parts.parts.subtotal
|
||||
.add(otherTotals.parts.sublets.subtotal)
|
||||
.add(otherTotals.rates.subtotal)
|
||||
.add(Dinero({ amount: (job.towing_payable || 0) * 100 }))
|
||||
.add(Dinero({ amount: (job.storage_payable || 0) * 100 }));
|
||||
//TODO Levies should be included??
|
||||
|
||||
const statePartsTax = job.joblines.reduce((acc, val) => {
|
||||
if (!!!val.tax_part) return acc;
|
||||
if (!!job.parts_tax_rates[val.part_type]) {
|
||||
return (
|
||||
acc +
|
||||
val.act_price *
|
||||
val.part_qty *
|
||||
(job.parts_tax_rates[val.part_type].prt_tax_rt || 0)
|
||||
return acc.add(
|
||||
Dinero({ amount: val.act_price * 100 })
|
||||
.multiply(val.part_qty)
|
||||
.percentage(
|
||||
(job.parts_tax_rates[val.part_type].prt_tax_rt || 0) * 100
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return acc;
|
||||
}
|
||||
}, 0);
|
||||
|
||||
// console.log("otherTotals", otherTotals);
|
||||
// console.log("job", job);
|
||||
// console.log("parts pst", statePartsTax);
|
||||
// console.log(
|
||||
// "pst on labor",
|
||||
// otherTotals.rates.rates_subtotal * (job.tax_lbr_rt || 0)
|
||||
// );
|
||||
// console.log(
|
||||
// "pst on mat",
|
||||
// (otherTotals.rates.paint_mat.total + otherTotals.rates.shop_mat.total) *
|
||||
// (job.tax_paint_mat_rt || 0)
|
||||
// );
|
||||
}, Dinero({ amount: 0 }));
|
||||
|
||||
let ret = {
|
||||
subtotal: subtotal,
|
||||
federal_tax: subtotal * (job.federal_tax_rate || 0),
|
||||
federal_tax: subtotal.percentage((job.federal_tax_rate || 0) * 100),
|
||||
statePartsTax,
|
||||
state_tax:
|
||||
statePartsTax +
|
||||
otherTotals.rates.rates_subtotal * (job.tax_lbr_rt || 0) +
|
||||
((job.towing_payable || 0) * job.tax_tow_rt || 0) +
|
||||
((job.storage_payable || 0) * job.tax_str_rt || 0) +
|
||||
(otherTotals.rates.paint_mat.total + otherTotals.rates.shop_mat.total) *
|
||||
(job.tax_paint_mat_rt || 0),
|
||||
local_tax: subtotal * (job.local_tax_rate || 0),
|
||||
state_tax: statePartsTax
|
||||
.add(
|
||||
otherTotals.rates.rates_subtotal.percentage((job.tax_lbr_rt || 0) * 100)
|
||||
)
|
||||
.add(
|
||||
Dinero({ amount: (job.towing_payable || 0) * 100 }).percentage(
|
||||
(job.tax_tow_rt || 0) * 100
|
||||
)
|
||||
)
|
||||
.add(
|
||||
Dinero({ amount: (job.storage_payable || 0) * 100 }).percentage(
|
||||
(job.tax_str_rt || 0) * 100
|
||||
)
|
||||
)
|
||||
.add(
|
||||
otherTotals.rates.paint_mat.total
|
||||
.add(otherTotals.rates.shop_mat.total)
|
||||
.percentage((job.tax_paint_mat_rt || 0) * 100)
|
||||
),
|
||||
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
|
||||
};
|
||||
|
||||
ret.total_repairs =
|
||||
ret.subtotal + ret.federal_tax + ret.state_tax + ret.local_tax;
|
||||
ret.net_repairs = ret.total_repairs - otherTotals.custPayable.total;
|
||||
ret.total_repairs = ret.subtotal
|
||||
.add(ret.federal_tax)
|
||||
.add(ret.state_tax)
|
||||
.add(ret.local_tax);
|
||||
ret.net_repairs = ret.total_repairs.subtract(otherTotals.custPayable.total);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//Rates are multipled by 10 to reduce the errors of rounding.
|
||||
//Adjusted for when adding to total by dividing by 10.
|
||||
function CalculateRatesTotals(ratesList, shoprates) {
|
||||
const jobLines = ratesList.joblines;
|
||||
|
||||
@@ -75,86 +77,86 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
rate_la1: {
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA1")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
rate: ratesList.rate_la1 || 0,
|
||||
},
|
||||
rate_la2: {
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA2")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
rate: ratesList.rate_la2 || 0,
|
||||
},
|
||||
rate_la3: {
|
||||
rate: ratesList.rate_la3 || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA3")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_la4: {
|
||||
rate: ratesList.rate_la4 || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA4")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_laa: {
|
||||
rate: ratesList.rate_laa || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAA")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lab: {
|
||||
rate: ratesList.rate_lab || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAB")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lad: {
|
||||
rate: ratesList.rate_lad || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAD")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lae: {
|
||||
rate: ratesList.rate_lae || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAE")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_laf: {
|
||||
rate: ratesList.rate_laf || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAF")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lag: {
|
||||
rate: ratesList.rate_lag || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAG")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lam: {
|
||||
rate: ratesList.rate_lam || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAM")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lar: {
|
||||
rate: ratesList.rate_lar || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_las: {
|
||||
rate: ratesList.rate_las || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAS")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_lau: {
|
||||
rate: ratesList.rate_lau || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAU")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
rate_atp: {
|
||||
rate: shoprates.rate_atp || 0,
|
||||
@@ -173,38 +175,40 @@ 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 * 10, 0)
|
||||
: 0,
|
||||
},
|
||||
paint_mat: {
|
||||
rate: ratesList.rate_mapa || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
shop_mat: {
|
||||
rate: ratesList.rate_mash || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty !== "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
|
||||
},
|
||||
};
|
||||
|
||||
let subtotal = 0;
|
||||
let rates_subtotal = 0;
|
||||
let subtotal = Dinero({ amount: 0 });
|
||||
let rates_subtotal = Dinero({ amount: 0 });
|
||||
for (const property in ret) {
|
||||
ret[property].total = ret[property].hours * ret[property].rate;
|
||||
subtotal = subtotal + ret[property].hours * ret[property].rate;
|
||||
ret[property].total = Dinero({ amount: ret[property].rate * 100 })
|
||||
.multiply(ret[property].hours)
|
||||
.divide(10);
|
||||
subtotal = subtotal.add(ret[property].total);
|
||||
if (
|
||||
property !== "paint_mat" &&
|
||||
property !== "shop_mat"
|
||||
//&& property !== "rate_atp"
|
||||
)
|
||||
rates_subtotal =
|
||||
rates_subtotal + ret[property].hours * ret[property].rate;
|
||||
rates_subtotal = rates_subtotal.add(ret[property].total);
|
||||
}
|
||||
ret.subtotal = subtotal;
|
||||
ret.rates_subtotal = rates_subtotal;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -225,7 +229,11 @@ function CalculatePartsTotals(jobLines) {
|
||||
...acc,
|
||||
parts: {
|
||||
...acc.parts,
|
||||
subtotal: acc.parts.subtotal + value.act_price * value.part_qty,
|
||||
subtotal: acc.parts.subtotal.add(
|
||||
Dinero({ amount: value.act_price * 100 }).multiply(
|
||||
value.part_qty
|
||||
)
|
||||
),
|
||||
//TODO Add Adjustments in
|
||||
},
|
||||
};
|
||||
@@ -235,7 +243,9 @@ function CalculatePartsTotals(jobLines) {
|
||||
...acc,
|
||||
sublets: {
|
||||
...acc.sublets,
|
||||
subtotal: acc.sublets.subtotal + value.act_price,
|
||||
subtotal: acc.sublets.subtotal.add(
|
||||
Dinero({ amount: value.act_price * 100 })
|
||||
),
|
||||
//TODO Add Adjustments in
|
||||
},
|
||||
};
|
||||
@@ -244,31 +254,46 @@ function CalculatePartsTotals(jobLines) {
|
||||
}
|
||||
},
|
||||
{
|
||||
parts: { subtotal: 0, adjustments: 0, total: 0 },
|
||||
sublets: { subtotal: 0, adjustments: 0, total: 0 },
|
||||
parts: {
|
||||
subtotal: Dinero({ amount: 0 }),
|
||||
adjustments: Dinero({ amount: 0 }),
|
||||
total: Dinero({ amount: 0 }),
|
||||
},
|
||||
sublets: {
|
||||
subtotal: Dinero({ amount: 0 }),
|
||||
adjustments: Dinero({ amount: 0 }),
|
||||
total: Dinero({ amount: 0 }),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
parts: { ...ret.parts, total: ret.parts.subtotal + ret.parts.adjustments },
|
||||
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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function CalculateCustPayable(job) {
|
||||
return {
|
||||
deductible: job.ded_amt || 0,
|
||||
federal_tax: job.federal_tax_payable || 0, //TODO Should this be renamed to make it more clear this is customer GST?
|
||||
other_customer_amount: job.other_amount_payable || 0,
|
||||
dep_taxes: job.depreciation_taxes || 0,
|
||||
total:
|
||||
job.ded_amt ||
|
||||
0 + job.federal_tax_payable ||
|
||||
0 + job.other_amount_payable ||
|
||||
0 + job.depreciation_taxes ||
|
||||
0,
|
||||
let ret = {
|
||||
deductible: Dinero({ amount: (job.ded_amt || 0) * 100 }) || 0,
|
||||
federal_tax: Dinero({ amount: (job.federal_tax_payable || 0) * 100 }), //TODO Should this be renamed to make it more clear this is customer GST?
|
||||
other_customer_amount: Dinero({
|
||||
amount: (job.other_amount_payable || 0) * 100,
|
||||
}),
|
||||
dep_taxes: Dinero({ amount: job.depreciation_taxes || 0 }),
|
||||
};
|
||||
|
||||
ret.total = ret.deductible
|
||||
.add(ret.federal_tax)
|
||||
.add(ret.federal_tax)
|
||||
.add(ret.other_customer_amount)
|
||||
.add(ret.dep_taxes);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -66,12 +66,11 @@ export function JobsAvailableContainer({
|
||||
|
||||
const newJob = {
|
||||
...estData.data.available_jobs_by_pk.est_data,
|
||||
clm_total: newTotals.totals.total_repairs,
|
||||
owner_owing: newTotals.custPayable.total,
|
||||
job_totals: newTotals,
|
||||
clm_total: newTotals.totals.total_repairs.toFormat("0.00"),
|
||||
owner_owing: newTotals.custPayable.total.toFormat("0.00"),
|
||||
job_totals: JSON.stringify(newTotals),
|
||||
};
|
||||
|
||||
console.log("newTotals", newTotals);
|
||||
insertNewJob({
|
||||
variables: {
|
||||
job: selectedOwner
|
||||
|
||||
@@ -97,9 +97,9 @@ export function JobsAvailableSupplementContainer({
|
||||
jobId: selectedJob,
|
||||
job: {
|
||||
...supp,
|
||||
clm_total: newTotals.totals.total_repairs,
|
||||
owner_owing: newTotals.custPayable.total,
|
||||
job_totals: newTotals,
|
||||
clm_total: newTotals.totals.total_repairs.toFormat("0.00"),
|
||||
owner_owing: newTotals.custPayable.total.toFormat("0.00"),
|
||||
job_totals: JSON.stringify(newTotals),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Divider, Form, Input, InputNumber, Row, Col } from "antd";
|
||||
import { Col, Divider, Form, Input, InputNumber, Row } from "antd";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import JobTotalsTable from "../job-totals-table/job-totals-table.component";
|
||||
|
||||
export default function JobsDetailFinancials({ job }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -125,8 +124,9 @@ export default function JobsDetailFinancials({ job }) {
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col offset={1} span={15}>
|
||||
<JobTotalsTable totals={job.job_totals} />
|
||||
{JSON.stringify(job.cieca_ttl, null, "\t")}
|
||||
<JobTotalsTable job={job} />
|
||||
<p>Mitchell: {JSON.stringify(job.cieca_ttl, null, "\t")}</p>
|
||||
<p>Mine:{JSON.stringify(job.job_totals, null, "\t")}</p>
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
|
||||
@@ -109,9 +109,9 @@ export function JobsDetailPage({
|
||||
jobId: job.id,
|
||||
job: {
|
||||
...values,
|
||||
clm_total: newTotals.totals.total_repairs,
|
||||
owner_owing: newTotals.custPayable.total,
|
||||
job_totals: newTotals,
|
||||
clm_total: newTotals.totals.total_repairs.toFormat("0.00"),
|
||||
owner_owing: newTotals.custPayable.total.toFormat("0.00"),
|
||||
job_totals: JSON.stringify(newTotals),
|
||||
},
|
||||
},
|
||||
}).then((r) => {
|
||||
@@ -124,15 +124,21 @@ export function JobsDetailPage({
|
||||
|
||||
return (
|
||||
<Suspense
|
||||
fallback={<LoadingSpinner message={t("general.labels.loadingapp")} />}
|
||||
>
|
||||
fallback={<LoadingSpinner message={t("general.labels.loadingapp")} />}>
|
||||
<ScheduleJobModalContainer />
|
||||
<JobLineUpsertModalContainer />
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
let r = CalculateJob(job, bodyshop.shoprates);
|
||||
console.log("r", r);
|
||||
}}>
|
||||
Calculate
|
||||
</button>
|
||||
<Form
|
||||
form={form}
|
||||
//onFieldsChange={(a, b) => console.log("a,b", a, b)}
|
||||
name="JobDetailForm"
|
||||
name='JobDetailForm'
|
||||
onFinish={handleFinish}
|
||||
{...formItemLayout}
|
||||
autoComplete={"off"}
|
||||
@@ -163,8 +169,7 @@ export function JobsDetailPage({
|
||||
date_invoiced: job.date_invoiced ? moment(job.date_invoiced) : null,
|
||||
date_closed: job.date_closed ? moment(job.date_closed) : null,
|
||||
date_exported: job.date_exported ? moment(job.date_exported) : null,
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
<JobsDetailHeader
|
||||
job={job}
|
||||
mutationConvertJob={mutationConvertJob}
|
||||
@@ -174,8 +179,7 @@ export function JobsDetailPage({
|
||||
/>
|
||||
<Tabs
|
||||
defaultActiveKey={search.tab}
|
||||
onChange={(key) => history.push({ search: `?tab=${key}` })}
|
||||
>
|
||||
onChange={(key) => history.push({ search: `?tab=${key}` })}>
|
||||
<Tabs.TabPane
|
||||
tab={
|
||||
<span>
|
||||
@@ -183,8 +187,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.claimdetail")}
|
||||
</span>
|
||||
}
|
||||
key="claimdetail"
|
||||
>
|
||||
key='claimdetail'>
|
||||
<JobsDetailClaims job={job} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -194,8 +197,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.insurance")}
|
||||
</span>
|
||||
}
|
||||
key="insurance"
|
||||
>
|
||||
key='insurance'>
|
||||
<JobsDetailInsurance job={job} form={form} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -205,8 +207,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.repairdata")}
|
||||
</span>
|
||||
}
|
||||
key="repairdata"
|
||||
>
|
||||
key='repairdata'>
|
||||
<JobsLinesContainer jobId={job.id} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -216,8 +217,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.financials")}
|
||||
</span>
|
||||
}
|
||||
key="financials"
|
||||
>
|
||||
key='financials'>
|
||||
<JobsDetailFinancials job={job} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -227,8 +227,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.partssublet")}
|
||||
</span>
|
||||
}
|
||||
key="partssublet"
|
||||
>
|
||||
key='partssublet'>
|
||||
<JobsDetailPliContainer job={job} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -238,8 +237,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.labor")}
|
||||
</span>
|
||||
}
|
||||
key="labor"
|
||||
>
|
||||
key='labor'>
|
||||
<JobsDetailLaborContainer jobId={job.id} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -249,8 +247,7 @@ export function JobsDetailPage({
|
||||
{t("menus.jobsdetail.dates")}
|
||||
</span>
|
||||
}
|
||||
key="dates"
|
||||
>
|
||||
key='dates'>
|
||||
<JobsDetailDatesComponent job={job} />}
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -260,8 +257,7 @@ export function JobsDetailPage({
|
||||
{t("jobs.labels.documents")}
|
||||
</span>
|
||||
}
|
||||
key="documents"
|
||||
>
|
||||
key='documents'>
|
||||
<JobsDocumentsGalleryContainer jobId={job.id} />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane
|
||||
@@ -271,8 +267,7 @@ export function JobsDetailPage({
|
||||
{t("jobs.labels.notes")}
|
||||
</span>
|
||||
}
|
||||
key="notes"
|
||||
>
|
||||
key='notes'>
|
||||
<JobNotesContainer jobId={job.id} />
|
||||
</Tabs.TabPane>
|
||||
|
||||
@@ -283,8 +278,7 @@ export function JobsDetailPage({
|
||||
{t("jobs.labels.audit")}
|
||||
</span>
|
||||
}
|
||||
key="audit"
|
||||
>
|
||||
key='audit'>
|
||||
<JobsDetailAuditContainer recordId={job.id} />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
|
||||
Reference in New Issue
Block a user