BOD-62 WIP total calculations. PST rates is still missing.
This commit is contained in:
@@ -4,30 +4,27 @@ 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 {
|
||||
CalculateRatesTotals,
|
||||
CalculatePartsTotals,
|
||||
CalculateCustPayable
|
||||
} from "./job-totals.utility";
|
||||
import { CalculateJob } from "./job-totals.utility";
|
||||
|
||||
export default function JobTotalsTableContainer({ jobId }) {
|
||||
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({});
|
||||
const [totals, setTotals] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!!data) {
|
||||
setTotals({
|
||||
parts: CalculatePartsTotals(data.jobs_by_pk.joblines),
|
||||
rates: CalculateRatesTotals(data.jobs_by_pk),
|
||||
custPayable: CalculateCustPayable(data.jobs_by_pk)
|
||||
});
|
||||
setTotals(CalculateJob(data.jobs_by_pk, bodyshop.shoprates));
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
console.log("totals", totals);
|
||||
}, [data, setTotals, bodyshop.shoprates]);
|
||||
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type='error' />;
|
||||
@@ -35,22 +32,8 @@ export default function JobTotalsTableContainer({ jobId }) {
|
||||
return (
|
||||
<div>
|
||||
<JobTotalsTableComponent totals={totals} />
|
||||
<div>
|
||||
<div>STL Data</div>
|
||||
<div>
|
||||
{data
|
||||
? JSON.stringify(data.jobs_by_pk.cieca_stl.data, null, 2)
|
||||
: null}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div>ttl Data</div>
|
||||
<div>
|
||||
{data
|
||||
? JSON.stringify(data.jobs_by_pk.cieca_ttl.data, null, 2)
|
||||
: null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(JobTotalsTableContainer);
|
||||
|
||||
Reference in New Issue
Block a user