BOD-62 creation of totals utility class + base calculations.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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 {
|
||||
CalculateRatesTotals,
|
||||
CalculatePartsTotals,
|
||||
CalculateCustPayable
|
||||
} from "./job-totals.utility";
|
||||
|
||||
export default function JobTotalsTableContainer({ jobId }) {
|
||||
const { loading, error, data } = useQuery(QUERY_JOB_FINANCIALS, {
|
||||
variables: { jobId: jobId }
|
||||
});
|
||||
|
||||
const [totals, setTotals] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
if (!!data) {
|
||||
setTotals({
|
||||
parts: CalculatePartsTotals(data.jobs_by_pk.joblines),
|
||||
rates: CalculateRatesTotals(data.jobs_by_pk),
|
||||
custPayable: CalculateCustPayable(data.jobs_by_pk)
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
console.log("totals", totals);
|
||||
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent message={error.message} type='error' />;
|
||||
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user