IO-791 Bill Edit with Labor Adjustments confirmation

This commit is contained in:
Patrick Fic
2021-03-22 17:29:39 -07:00
parent af30651d7b
commit 43a266c463
9 changed files with 108 additions and 23 deletions

View File

@@ -1338,7 +1338,7 @@
<name>labels</name> <name>labels</name>
<children> <children>
<concept_node> <concept_node>
<name>deductfromlabor</name> <name>deductedfromlbr</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>
<description></description> <description></description>
<comment></comment> <comment></comment>
@@ -2160,6 +2160,27 @@
</translation> </translation>
</translations> </translations>
</concept_node> </concept_node>
<concept_node>
<name>editadjwarning</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node> <concept_node>
<name>entered_total</name> <name>entered_total</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>

View File

@@ -1,5 +1,5 @@
import { useMutation, useQuery } from "@apollo/client"; import { useMutation, useQuery } from "@apollo/client";
import { Button, Form } from "antd"; import { Button, Form, Popconfirm } from "antd";
import moment from "moment"; import moment from "moment";
import queryString from "query-string"; import queryString from "query-string";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
@@ -19,6 +19,7 @@ export default function BillDetailEditcontainer() {
const search = queryString.parse(useLocation().search); const search = queryString.parse(useLocation().search);
const { t } = useTranslation(); const { t } = useTranslation();
const [form] = Form.useForm(); const [form] = Form.useForm();
const [visible, setVisible] = useState(false);
const [updateLoading, setUpdateLoading] = useState(false); const [updateLoading, setUpdateLoading] = useState(false);
const [update_bill] = useMutation(UPDATE_BILL); const [update_bill] = useMutation(UPDATE_BILL);
const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES); const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES);
@@ -29,6 +30,15 @@ export default function BillDetailEditcontainer() {
skip: !!!search.billid, skip: !!!search.billid,
}); });
const handleSave = () => {
//It's got a previously deducted bill line!
if (data.bills_by_pk.billlines.filter((b) => b.deductedfromlbr).length > 0)
setVisible(true);
else {
form.submit();
}
};
const handleFinish = async (values) => { const handleFinish = async (values) => {
setUpdateLoading(true); setUpdateLoading(true);
//let adjustmentsToInsert = {}; //let adjustmentsToInsert = {};
@@ -42,7 +52,7 @@ export default function BillDetailEditcontainer() {
); );
billlines.forEach((billline) => { billlines.forEach((billline) => {
const { deductfromlabor, ...il } = billline; const { deductedfromlbr, ...il } = billline;
delete il.__typename; delete il.__typename;
//Need to compare this line to the previous version of the line to see if there is a change in the adjustments. //Need to compare this line to the previous version of the line to see if there is a change in the adjustments.
@@ -52,7 +62,7 @@ export default function BillDetailEditcontainer() {
if (theOldBillLine) { if (theOldBillLine) {
//It was there! Need to change the diff. //It was there! Need to change the diff.
if (theOldBillLine.deductfromlabor !== deductfromlabor) { if (theOldBillLine.deductedfromlbr !== deductedfromlbr) {
//There's a different //There's a different
} }
} }
@@ -64,7 +74,7 @@ export default function BillDetailEditcontainer() {
billLineId: il.id, billLineId: il.id,
billLine: { billLine: {
...il, ...il,
deductedfromlbr: deductfromlabor, deductedfromlbr: deductedfromlbr,
joblineid: il.joblineid === "noline" ? null : il.joblineid, joblineid: il.joblineid === "noline" ? null : il.joblineid,
}, },
}, },
@@ -78,7 +88,7 @@ export default function BillDetailEditcontainer() {
billLines: [ billLines: [
{ {
...il, ...il,
deductedfromlbr: deductfromlabor, deductedfromlbr: deductedfromlbr,
billid: search.billid, billid: search.billid,
joblineid: il.joblineid === "noline" ? null : il.joblineid, joblineid: il.joblineid === "noline" ? null : il.joblineid,
}, },
@@ -93,6 +103,7 @@ export default function BillDetailEditcontainer() {
await refetch(); await refetch();
form.resetFields(); form.resetFields();
form.resetFields(); form.resetFields();
setVisible(false);
setUpdateLoading(false); setUpdateLoading(false);
}; };
@@ -109,19 +120,28 @@ export default function BillDetailEditcontainer() {
return ( return (
<LoadingSkeleton loading={loading}> <LoadingSkeleton loading={loading}>
<Form <Popconfirm
form={form} visible={visible}
onFinish={handleFinish} onConfirm={() => form.submit()}
initialValues={transformData(data)} onCancel={() => setVisible(false)}
okButtonProps={{ loading: updateLoading }}
title={t("bills.labels.editadjwarning")}
> >
<Button <Button
htmlType="submit" htmlType="submit"
disabled={exported} disabled={exported}
onClick={handleSave}
loading={updateLoading} loading={updateLoading}
type="primary" type="primary"
> >
{t("general.actions.save")} {t("general.actions.save")}
</Button> </Button>
</Popconfirm>
<Form
form={form}
onFinish={handleFinish}
initialValues={transformData(data)}
>
<BillFormContainer form={form} billEdit disabled={exported} /> <BillFormContainer form={form} billEdit disabled={exported} />
<JobDocumentsGallery <JobDocumentsGallery
jobId={data ? data.bills_by_pk.jobid : null} jobId={data ? data.bills_by_pk.jobid : null}

View File

@@ -59,20 +59,20 @@ function BillEnterModalContainer({
remainingValues.billlines && remainingValues.billlines &&
remainingValues.billlines.map((i) => { remainingValues.billlines.map((i) => {
const { const {
deductfromlabor, deductedfromlbr,
lbr_adjustment, lbr_adjustment,
location: lineLocation, location: lineLocation,
...restI ...restI
} = i; } = i;
if (deductfromlabor) { if (deductedfromlbr) {
adjustmentsToInsert[lbr_adjustment.mod_lbr_ty] = adjustmentsToInsert[lbr_adjustment.mod_lbr_ty] =
(adjustmentsToInsert[lbr_adjustment.mod_lbr_ty] || 0) - (adjustmentsToInsert[lbr_adjustment.mod_lbr_ty] || 0) -
restI.actual_price / lbr_adjustment.rate; restI.actual_price / lbr_adjustment.rate;
} }
return { return {
...restI, ...restI,
deductedfromlbr: deductfromlabor, deductedfromlbr: deductedfromlbr,
joblineid: i.joblineid === "noline" ? null : i.joblineid, joblineid: i.joblineid === "noline" ? null : i.joblineid,
}; };
}), }),

View File

@@ -248,19 +248,19 @@ export function BillEnterModalLinesComponent({
</Select> </Select>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("billlines.labels.deductfromlabor")} label={t("billlines.labels.deductedfromlbr")}
key={`${index}deductfromlabor`} key={`${index}deductedfromlbr`}
valuePropName="checked" valuePropName="checked"
name={[field.name, "deductfromlabor"]} name={[field.name, "deductedfromlbr"]}
> >
<Switch disabled={disabled} /> <Switch disabled={disabled} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
shouldUpdate={(prev, cur) => shouldUpdate={(prev, cur) =>
prev.billlines[index] && prev.billlines[index] &&
prev.billlines[index].deductfromlabor !== prev.billlines[index].deductedfromlbr !==
cur.billlines[index] && cur.billlines[index] &&
cur.billlines[index].deductfromlabor cur.billlines[index].deductedfromlbr
} }
> >
{() => { {() => {
@@ -268,7 +268,7 @@ export function BillEnterModalLinesComponent({
getFieldValue([ getFieldValue([
"billlines", "billlines",
field.name, field.name,
"deductfromlabor", "deductedfromlbr",
]) ])
) )
return ( return (

View File

@@ -136,6 +136,46 @@ export function JobsDetailRatesParts({ jobRO, expanded, required = true }) {
<InputNumber min={0} max={1} precision={2} disabled={jobRO} /> <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
</Form.Item> </Form.Item>
</LayoutFormRow> </LayoutFormRow>
<LayoutFormRow header={t("joblines.fields.part_types.PAG")}>
<Form.Item
label={t("jobs.fields.parts_tax_rates.prt_discp")}
name={["parts_tax_rates", "PAG", "prt_discp"]}
>
<InputNumber min={0} max={1} precision={2} disabled={jobRO} />
</Form.Item>
<Form.Item
label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
name={["parts_tax_rates", "PAG", "prt_mktyp"]}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
name={["parts_tax_rates", "PAG", "prt_mkupp"]}
>
<InputNumber min={0} max={1} precision={2} disabled={jobRO} />
</Form.Item>
<Form.Item
label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
name={["parts_tax_rates", "PAG", "prt_tax_in"]}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
name={["parts_tax_rates", "PAG", "prt_tax_rt"]}
rules={[
{
required: required,
message: t("general.validation.required"),
},
]}
>
<InputNumber min={0} max={1} precision={2} disabled={jobRO} />
</Form.Item>
</LayoutFormRow>
<LayoutFormRow header={t("joblines.fields.part_types.PAM")}> <LayoutFormRow header={t("joblines.fields.part_types.PAM")}>
<Form.Item <Form.Item
label={t("jobs.fields.parts_tax_rates.prt_discp")} label={t("jobs.fields.parts_tax_rates.prt_discp")}

View File

@@ -166,6 +166,7 @@ export const QUERY_BILL_BY_PK = gql`
quantity quantity
joblineid joblineid
applicable_taxes applicable_taxes
deductedfromlbr
} }
documents { documents {
id id

View File

@@ -98,7 +98,7 @@
"state_tax_applicable": "St. Tax?" "state_tax_applicable": "St. Tax?"
}, },
"labels": { "labels": {
"deductfromlabor": "Deduct from Labor?", "deductedfromlbr": "Deduct from Labor?",
"entered": "Entered", "entered": "Entered",
"from": "From", "from": "From",
"other": "-- Not On Estimate --", "other": "-- Not On Estimate --",
@@ -142,10 +142,11 @@
"billcmtotal": "Retail Total of Credit Memos", "billcmtotal": "Retail Total of Credit Memos",
"bills": "Bills", "bills": "Bills",
"dedfromlbr": "Deducted from Labor", "dedfromlbr": "Deducted from Labor",
"deleteconfirm": "Are you sure you want to delete this bill? It cannot be undone.", "deleteconfirm": "Are you sure you want to delete this bill? It cannot be undone. If this bill has deductions from labors, manual changes may be required.",
"discrepancy": "Discrepancy", "discrepancy": "Discrepancy",
"discrepwithcms": "Discrepancy including Credit Memos", "discrepwithcms": "Discrepancy including Credit Memos",
"discrepwithlbradj": "Discrepancy including Lbr. Adj.", "discrepwithlbradj": "Discrepancy including Lbr. Adj.",
"editadjwarning": "This bill had lines which resulted in labor adjustments. Manual correction to adjustments may be required.",
"entered_total": "Total of Entered Lines", "entered_total": "Total of Entered Lines",
"enteringcreditmemo": "You are entering a credit memo. Please ensure you are also entering positive values.", "enteringcreditmemo": "You are entering a credit memo. Please ensure you are also entering positive values.",
"federal_tax": "Federal Tax", "federal_tax": "Federal Tax",

View File

@@ -98,7 +98,7 @@
"state_tax_applicable": "" "state_tax_applicable": ""
}, },
"labels": { "labels": {
"deductfromlabor": "", "deductedfromlbr": "",
"entered": "", "entered": "",
"from": "", "from": "",
"other": "", "other": "",
@@ -146,6 +146,7 @@
"discrepancy": "", "discrepancy": "",
"discrepwithcms": "", "discrepwithcms": "",
"discrepwithlbradj": "", "discrepwithlbradj": "",
"editadjwarning": "",
"entered_total": "", "entered_total": "",
"enteringcreditmemo": "", "enteringcreditmemo": "",
"federal_tax": "", "federal_tax": "",

View File

@@ -98,7 +98,7 @@
"state_tax_applicable": "" "state_tax_applicable": ""
}, },
"labels": { "labels": {
"deductfromlabor": "", "deductedfromlbr": "",
"entered": "", "entered": "",
"from": "", "from": "",
"other": "", "other": "",
@@ -146,6 +146,7 @@
"discrepancy": "", "discrepancy": "",
"discrepwithcms": "", "discrepwithcms": "",
"discrepwithlbradj": "", "discrepwithlbradj": "",
"editadjwarning": "",
"entered_total": "", "entered_total": "",
"enteringcreditmemo": "", "enteringcreditmemo": "",
"federal_tax": "", "federal_tax": "",