Additional changes for CCC calculations.

This commit is contained in:
Patrick Fic
2023-01-19 08:58:23 -08:00
parent 392b405978
commit cccd007ba6
10 changed files with 242 additions and 103 deletions

View File

@@ -11,37 +11,46 @@ export default function JobCalculateTotals({ job, disabled }) {
const [updateJob] = useMutation(UPDATE_JOB);
const handleCalculate = async () => {
setLoading(true);
const newTotals = (
await Axios.post("/job/totals", {
job: job,
})
).data;
try {
setLoading(true);
const newTotals = (
await Axios.post("/job/totals", {
job: job,
})
).data;
const result = await updateJob({
refetchQueries: ["GET_JOB_BY_PK"],
awaitRefetchQueries: true,
variables: {
jobId: job.id,
job: {
job_totals: newTotals,
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat(
"0.00"
),
const result = await updateJob({
refetchQueries: ["GET_JOB_BY_PK"],
awaitRefetchQueries: true,
variables: {
jobId: job.id,
job: {
job_totals: newTotals,
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat(
"0.00"
),
},
},
},
});
if (!!!result.errors) {
notification["success"]({ message: t("jobs.successes.updated") });
} else {
});
if (!!!result.errors) {
notification["success"]({ message: t("jobs.successes.updated") });
} else {
notification["error"]({
message: t("jobs.errors.updating", {
error: JSON.stringify(result.errors),
}),
});
}
} catch (error) {
notification["error"]({
message: t("jobs.errors.updating", {
error: JSON.stringify(result.errors),
error: JSON.stringify(error),
}),
});
} finally {
setLoading(false);
}
setLoading(false);
};
return (