BOD-62 Added new job calculations on import + supplement.
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
import { useQuery } from "@apollo/react-hooks";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { QUERY_JOB_FINANCIALS } from "../../graphql/jobs.queries";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||
import JobTotalsTableComponent from "./job-totals-table.component";
|
||||
import { CalculateJob } from "./job-totals.utility";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
|
||||
export function JobTotalsTableContainer({ jobId, bodyshop }) {
|
||||
const { loading, error, data } = useQuery(QUERY_JOB_FINANCIALS, {
|
||||
variables: { jobId: jobId }
|
||||
});
|
||||
|
||||
const [totals, setTotals] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!!data) {
|
||||
setTotals(CalculateJob(data.jobs_by_pk, bodyshop.shoprates));
|
||||
}
|
||||
}, [data, setTotals, bodyshop.shoprates]);
|
||||
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type='error' />;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<JobTotalsTableComponent totals={totals} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(JobTotalsTableContainer);
|
||||
@@ -15,11 +15,10 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
otherTotals.parts.parts.subtotal +
|
||||
otherTotals.parts.sublets.subtotal +
|
||||
otherTotals.rates.subtotal +
|
||||
job.towing_payable +
|
||||
job.storage_payable; //Levies should be included??
|
||||
(job.towing_payable || 0) +
|
||||
(job.storage_payable || 0); //Levies should be included??
|
||||
|
||||
const statePartsTax = job.joblines.reduce((acc, val) => {
|
||||
console.log("val", val);
|
||||
if (!!!val.tax_part) return acc;
|
||||
if (!!job.parts_tax_rates[val.part_type]) {
|
||||
return (
|
||||
@@ -75,82 +74,82 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LA1")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
rate: ratesList.rate_la1,
|
||||
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),
|
||||
rate: ratesList.rate_la2,
|
||||
rate: ratesList.rate_la2 || 0,
|
||||
},
|
||||
rate_la3: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_la4: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_laa: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lab: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lad: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lae: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_laf: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lag: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lam: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lar: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_las: {
|
||||
rate: ratesList.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),
|
||||
},
|
||||
rate_lau: {
|
||||
rate: ratesList.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),
|
||||
@@ -176,13 +175,13 @@ function CalculateRatesTotals(ratesList, shoprates) {
|
||||
: 0,
|
||||
},
|
||||
paint_mat: {
|
||||
rate: ratesList.rate_mapa,
|
||||
rate: ratesList.rate_mapa || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty === "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
},
|
||||
shop_mat: {
|
||||
rate: ratesList.rate_mash,
|
||||
rate: ratesList.rate_mash || 0,
|
||||
hours: jobLines
|
||||
.filter((item) => item.mod_lbr_ty !== "LAR")
|
||||
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
|
||||
|
||||
Reference in New Issue
Block a user