Added server side job calculation. BOD-267
This commit is contained in:
@@ -26,6 +26,20 @@ export function JobsTotalsTableComponent({ bodyshop, job }) {
|
||||
setTotals(CalculateJob(job, bodyshop.shoprates));
|
||||
}, [bodyshop, job]);
|
||||
|
||||
// useEffect(() => {
|
||||
// const Calculate = async () => {
|
||||
// const newTotals = (
|
||||
// await Axios.post("/job/totals", {
|
||||
// job: job,
|
||||
// shoprates: bodyshop.shoprates,
|
||||
// })
|
||||
// ).data;
|
||||
// setTotals(newTotals);
|
||||
// };
|
||||
|
||||
// Calculate();
|
||||
// }, [bodyshop, job]);
|
||||
|
||||
if (!!!totals) {
|
||||
return <LoadingSkeleton />;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export function JobsDetailHeader({
|
||||
bodyshop,
|
||||
updateJobStatus,
|
||||
setScheduleContext,
|
||||
loading,
|
||||
form,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
@@ -79,6 +80,7 @@ export function JobsDetailHeader({
|
||||
<JobsDetailHeaderActions key="actions" job={job} refetch={refetch} />
|
||||
<Button
|
||||
type="primary"
|
||||
loading={loading}
|
||||
className="imex-flex-row__margin"
|
||||
onClick={() => form.submit()}
|
||||
>
|
||||
|
||||
@@ -6,9 +6,11 @@ import Icon, {
|
||||
ToolFilled,
|
||||
} from "@ant-design/icons";
|
||||
import { Form, notification, Tabs } from "antd";
|
||||
import Axios from "axios";
|
||||
import Dinero from "dinero.js";
|
||||
import moment from "moment";
|
||||
import queryString from "query-string";
|
||||
import React, { lazy, Suspense } from "react";
|
||||
import React, { lazy, Suspense, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FaHardHat,
|
||||
@@ -20,7 +22,6 @@ import { connect } from "react-redux";
|
||||
import { useHistory, useLocation } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import FormFieldsChanged from "../../components/form-fields-changed-alert/form-fields-changed-alert.component";
|
||||
import { CalculateJob } from "../../components/job-totals-table/job-totals.utility";
|
||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
|
||||
@@ -89,7 +90,7 @@ export function JobsDetailPage({
|
||||
const { t } = useTranslation();
|
||||
const [form] = Form.useForm();
|
||||
const history = useHistory();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const search = queryString.parse(useLocation().search);
|
||||
const formItemLayout = {
|
||||
layout: "vertical",
|
||||
@@ -97,16 +98,23 @@ export function JobsDetailPage({
|
||||
};
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
const newTotals = CalculateJob({ ...job, ...values }, bodyshop.shoprates);
|
||||
setLoading(true);
|
||||
//const newTotals = CalculateJob({ ...job, ...values }, bodyshop.shoprates);
|
||||
const newTotals = (
|
||||
await Axios.post("/job/totals", {
|
||||
job: { ...job, ...values },
|
||||
shoprates: bodyshop.shoprates,
|
||||
})
|
||||
).data;
|
||||
|
||||
const result = await mutationUpdateJob({
|
||||
variables: {
|
||||
jobId: job.id,
|
||||
job: {
|
||||
...values,
|
||||
clm_total: newTotals.totals.total_repairs.toFormat("0.00"),
|
||||
owner_owing: newTotals.custPayable.total.toFormat("0.00"),
|
||||
job_totals: JSON.stringify(newTotals),
|
||||
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
|
||||
owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
|
||||
job_totals: newTotals, //JSON.stringify(newTotals),
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -119,6 +127,7 @@ export function JobsDetailPage({
|
||||
form.resetFields();
|
||||
form.resetFields();
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -147,6 +156,7 @@ export function JobsDetailPage({
|
||||
refetch={refetch}
|
||||
handleSubmit={handleSubmit}
|
||||
updateJobStatus={updateJobStatus}
|
||||
loading={loading}
|
||||
/>
|
||||
<Tabs
|
||||
defaultActiveKey={search.tab}
|
||||
|
||||
Reference in New Issue
Block a user