Resolve non-updated form on bill enter. IO-739
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { useApolloClient, useMutation } from "@apollo/client";
|
import { useApolloClient, useMutation } from "@apollo/client";
|
||||||
import { Button, Form, Modal, notification } from "antd";
|
import { Button, Form, Modal, notification } from "antd";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState, useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
@@ -197,9 +197,28 @@ function BillEnterModalContainer({
|
|||||||
if (enterAgain) form.submit();
|
if (enterAgain) form.submit();
|
||||||
}, [enterAgain, form]);
|
}, [enterAgain, form]);
|
||||||
|
|
||||||
|
const formValues = useMemo(() => {
|
||||||
|
return {
|
||||||
|
...billEnterModal.context.bill,
|
||||||
|
jobid:
|
||||||
|
(billEnterModal.context.job && billEnterModal.context.job.id) || null,
|
||||||
|
federal_tax_rate:
|
||||||
|
(bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.federal_tax_rate) ||
|
||||||
|
0,
|
||||||
|
state_tax_rate:
|
||||||
|
(bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.state_tax_rate) ||
|
||||||
|
0,
|
||||||
|
local_tax_rate:
|
||||||
|
(bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.local_tax_rate) ||
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
}, [billEnterModal, bodyshop]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (billEnterModal.visible) form.resetFields();
|
if (billEnterModal.visible) {
|
||||||
}, [billEnterModal.visible, form]);
|
form.setFieldsValue(formValues);
|
||||||
|
}
|
||||||
|
}, [billEnterModal.visible, form, formValues]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -239,24 +258,7 @@ function BillEnterModalContainer({
|
|||||||
onFinishFailed={() => {
|
onFinishFailed={() => {
|
||||||
setEnterAgain(false);
|
setEnterAgain(false);
|
||||||
}}
|
}}
|
||||||
initialValues={{
|
initialValues={formValues}
|
||||||
...billEnterModal.context.bill,
|
|
||||||
jobid:
|
|
||||||
(billEnterModal.context.job && billEnterModal.context.job.id) ||
|
|
||||||
null,
|
|
||||||
federal_tax_rate:
|
|
||||||
(bodyshop.bill_tax_rates &&
|
|
||||||
bodyshop.bill_tax_rates.federal_tax_rate) ||
|
|
||||||
0,
|
|
||||||
state_tax_rate:
|
|
||||||
(bodyshop.bill_tax_rates &&
|
|
||||||
bodyshop.bill_tax_rates.state_tax_rate) ||
|
|
||||||
0,
|
|
||||||
local_tax_rate:
|
|
||||||
(bodyshop.bill_tax_rates &&
|
|
||||||
bodyshop.bill_tax_rates.local_tax_rate) ||
|
|
||||||
0,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<BillFormContainer
|
<BillFormContainer
|
||||||
form={form}
|
form={form}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
Select,
|
Select,
|
||||||
|
Space,
|
||||||
Switch,
|
Switch,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@@ -48,6 +49,7 @@ export function BillEnterModalLinesComponent({
|
|||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
<LayoutFormRow style={{ flex: 1 }} grow>
|
<LayoutFormRow style={{ flex: 1 }} grow>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
span={8}
|
||||||
label={t("billlines.fields.jobline")}
|
label={t("billlines.fields.jobline")}
|
||||||
key={`${index}joblinename`}
|
key={`${index}joblinename`}
|
||||||
name={[field.name, "joblineid"]}
|
name={[field.name, "joblineid"]}
|
||||||
@@ -154,37 +156,38 @@ export function BillEnterModalLinesComponent({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<div>
|
||||||
label={t("billlines.fields.actual_cost")}
|
<Form.Item
|
||||||
key={`${index}actual_cost`}
|
label={t("billlines.fields.actual_cost")}
|
||||||
name={[field.name, "actual_cost"]}
|
key={`${index}actual_cost`}
|
||||||
rules={[
|
name={[field.name, "actual_cost"]}
|
||||||
{
|
rules={[
|
||||||
required: true,
|
{
|
||||||
message: t("general.validation.required"),
|
required: true,
|
||||||
},
|
message: t("general.validation.required"),
|
||||||
]}
|
},
|
||||||
>
|
]}
|
||||||
<CurrencyInput min={0} disabled={disabled} />
|
>
|
||||||
</Form.Item>
|
<CurrencyInput min={0} disabled={disabled} />
|
||||||
<Form.Item shouldUpdate>
|
</Form.Item>
|
||||||
{() => {
|
<Form.Item shouldUpdate>
|
||||||
const line = getFieldsValue(["billlines"]).billlines[
|
{() => {
|
||||||
index
|
const line = getFieldsValue(["billlines"])
|
||||||
];
|
.billlines[index];
|
||||||
if (!!!line) return null;
|
if (!!!line) return null;
|
||||||
const lineDiscount = (
|
const lineDiscount = (
|
||||||
1 -
|
1 -
|
||||||
Math.round(
|
Math.round(
|
||||||
(line.actual_cost / line.actual_price) * 100
|
(line.actual_cost / line.actual_price) * 100
|
||||||
) /
|
) /
|
||||||
100
|
100
|
||||||
).toPrecision(2);
|
).toPrecision(2);
|
||||||
|
|
||||||
if (lineDiscount - discount === 0) return <div />;
|
if (lineDiscount - discount === 0) return <div />;
|
||||||
return <WarningOutlined style={{ color: "red" }} />;
|
return <WarningOutlined style={{ color: "red" }} />;
|
||||||
}}
|
}}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
</div>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("billlines.fields.cost_center")}
|
label={t("billlines.fields.cost_center")}
|
||||||
key={`${index}cost_center`}
|
key={`${index}cost_center`}
|
||||||
@@ -204,30 +207,45 @@ export function BillEnterModalLinesComponent({
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Space flex>
|
||||||
|
<Form.Item
|
||||||
|
label={t("billlines.fields.federal_tax_applicable")}
|
||||||
|
key={`${index}fedtax`}
|
||||||
|
initialValue={true}
|
||||||
|
valuePropName="checked"
|
||||||
|
name={[field.name, "applicable_taxes", "federal"]}
|
||||||
|
>
|
||||||
|
<Switch disabled={disabled} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label={t("billlines.fields.state_tax_applicable")}
|
||||||
|
key={`${index}statetax`}
|
||||||
|
valuePropName="checked"
|
||||||
|
name={[field.name, "applicable_taxes", "state"]}
|
||||||
|
>
|
||||||
|
<Switch disabled={disabled} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label={t("billlines.fields.local_tax_applicable")}
|
||||||
|
key={`${index}localtax`}
|
||||||
|
valuePropName="checked"
|
||||||
|
name={[field.name, "applicable_taxes", "local"]}
|
||||||
|
>
|
||||||
|
<Switch disabled={disabled} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("billlines.fields.federal_tax_applicable")}
|
label={t("billlines.fields.location")}
|
||||||
key={`${index}fedtax`}
|
key={`${index}location`}
|
||||||
initialValue={true}
|
name={[field.name, "location"]}
|
||||||
valuePropName="checked"
|
|
||||||
name={[field.name, "applicable_taxes", "federal"]}
|
|
||||||
>
|
>
|
||||||
<Switch disabled={disabled} />
|
<Select style={{ width: "10rem" }} disabled={disabled}>
|
||||||
</Form.Item>
|
{bodyshop.md_parts_locations.map((loc, idx) => (
|
||||||
<Form.Item
|
<Select.Option key={idx} value={loc}>
|
||||||
label={t("billlines.fields.state_tax_applicable")}
|
{loc}
|
||||||
key={`${index}statetax`}
|
</Select.Option>
|
||||||
valuePropName="checked"
|
))}
|
||||||
name={[field.name, "applicable_taxes", "state"]}
|
</Select>
|
||||||
>
|
|
||||||
<Switch disabled={disabled} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label={t("billlines.fields.local_tax_applicable")}
|
|
||||||
key={`${index}localtax`}
|
|
||||||
valuePropName="checked"
|
|
||||||
name={[field.name, "applicable_taxes", "local"]}
|
|
||||||
>
|
|
||||||
<Switch disabled={disabled} />
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("billlines.labels.deductfromlabor")}
|
label={t("billlines.labels.deductfromlabor")}
|
||||||
@@ -335,19 +353,6 @@ export function BillEnterModalLinesComponent({
|
|||||||
return <span />;
|
return <span />;
|
||||||
}}
|
}}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
|
||||||
label={t("billlines.fields.location")}
|
|
||||||
key={`${index}location`}
|
|
||||||
name={[field.name, "location"]}
|
|
||||||
>
|
|
||||||
<Select style={{ width: "10rem" }} disabled={disabled}>
|
|
||||||
{bodyshop.md_parts_locations.map((loc, idx) => (
|
|
||||||
<Select.Option key={idx} value={loc}>
|
|
||||||
{loc}
|
|
||||||
</Select.Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
</LayoutFormRow>
|
</LayoutFormRow>
|
||||||
<FormListMoveArrows
|
<FormListMoveArrows
|
||||||
move={move}
|
move={move}
|
||||||
|
|||||||
@@ -46,23 +46,17 @@ const BillLineSearchSelect = (
|
|||||||
line_desc={item.line_desc}
|
line_desc={item.line_desc}
|
||||||
part_qty={item.part_qty}
|
part_qty={item.part_qty}
|
||||||
>
|
>
|
||||||
<Row justify="center" align="middle">
|
<div className="imex-flex-row">
|
||||||
<Col span={12}>{item.line_desc}</Col>
|
<div style={{ flex: 1 }}>{item.line_desc}</div>
|
||||||
<Col span={8}>
|
{item.oem_partno ? (
|
||||||
{item.oem_partno ? (
|
<Tag color="blue">{item.oem_partno}</Tag>
|
||||||
<Tag color="blue">{item.oem_partno}</Tag>
|
) : null}
|
||||||
) : null}
|
{item.act_price ? (
|
||||||
</Col>
|
<Tag color="green">
|
||||||
<Col span={4}>
|
<CurrencyFormatter>{item.act_price || 0}</CurrencyFormatter>
|
||||||
{item.act_price ? (
|
</Tag>
|
||||||
<Tag color="green">
|
) : null}
|
||||||
<CurrencyFormatter>
|
</div>
|
||||||
{item.act_price || 0}
|
|
||||||
</CurrencyFormatter>
|
|
||||||
</Tag>
|
|
||||||
) : null}
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</Option>
|
</Option>
|
||||||
))
|
))
|
||||||
: null}
|
: null}
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ export default function TimeTicketModalComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function LaborAllocationContainer({ jobid }) {
|
function LaborAllocationContainer({ jobid }) {
|
||||||
console.log("jobid", jobid);
|
|
||||||
const { loading, data: lineTicketData } = useQuery(GET_LINE_TICKET_BY_PK, {
|
const { loading, data: lineTicketData } = useQuery(GET_LINE_TICKET_BY_PK, {
|
||||||
variables: { id: jobid },
|
variables: { id: jobid },
|
||||||
skip: !jobid,
|
skip: !jobid,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Col, Row, Select, Tag } from "antd";
|
|
||||||
import React, { useEffect, useState, forwardRef } from "react";
|
|
||||||
import { HeartOutlined } from "@ant-design/icons";
|
import { HeartOutlined } from "@ant-design/icons";
|
||||||
|
import { Select, Tag } from "antd";
|
||||||
|
import React, { forwardRef, useEffect, useState } from "react";
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
||||||
//To be used as a form element only.
|
//To be used as a form element only.
|
||||||
@@ -45,31 +45,22 @@ const VendorSearchSelect = (
|
|||||||
name={o.name}
|
name={o.name}
|
||||||
discount={o.discount}
|
discount={o.discount}
|
||||||
>
|
>
|
||||||
<Row>
|
<div className="imex-flex-row">
|
||||||
<Col span={16}>{o.name}</Col>
|
<div style={{ flex: 1 }}>{o.name}</div>
|
||||||
<Col span={4}>
|
<HeartOutlined />
|
||||||
<HeartOutlined />
|
<Tag color="green">{`${o.discount * 100}%`}</Tag>
|
||||||
</Col>
|
</div>
|
||||||
{o.discount && (
|
|
||||||
<Col span={4}>
|
|
||||||
<Tag color="green">{`${o.discount * 100}%`}</Tag>
|
|
||||||
</Col>
|
|
||||||
)}
|
|
||||||
</Row>
|
|
||||||
</Option>
|
</Option>
|
||||||
))
|
))
|
||||||
: null}
|
: null}
|
||||||
{options
|
{options
|
||||||
? options.map((o) => (
|
? options.map((o) => (
|
||||||
<Option key={o.id} value={o.id} name={o.name} discount={o.discount}>
|
<Option key={o.id} value={o.id} name={o.name} discount={o.discount}>
|
||||||
<Row>
|
<div className="imex-flex-row" style={{ width: "100%" }}>
|
||||||
<Col span={20}>{o.name}</Col>
|
<div style={{ flex: 1 }}>{o.name}</div>
|
||||||
{o.discount && (
|
|
||||||
<Col span={4}>
|
<Tag color="green">{`${o.discount * 100}%`}</Tag>
|
||||||
<Tag color="green">{`${o.discount * 100}%`}</Tag>
|
</div>
|
||||||
</Col>
|
|
||||||
)}
|
|
||||||
</Row>
|
|
||||||
</Option>
|
</Option>
|
||||||
))
|
))
|
||||||
: null}
|
: null}
|
||||||
|
|||||||
@@ -153,8 +153,6 @@ const { Content, Header } = Layout;
|
|||||||
|
|
||||||
const stripePromise = new Promise((resolve, reject) => {
|
const stripePromise = new Promise((resolve, reject) => {
|
||||||
client.query({ query: QUERY_STRIPE_ID }).then((resp) => {
|
client.query({ query: QUERY_STRIPE_ID }).then((resp) => {
|
||||||
console.log(resp);
|
|
||||||
|
|
||||||
resolve(
|
resolve(
|
||||||
loadStripe(process.env.REACT_APP_STRIPE_PUBLIC_KEY, {
|
loadStripe(process.env.REACT_APP_STRIPE_PUBLIC_KEY, {
|
||||||
stripeAccount:
|
stripeAccount:
|
||||||
|
|||||||
Reference in New Issue
Block a user