IO-1978 Selection of lines for parts return
This commit is contained in:
@@ -0,0 +1,251 @@
|
|||||||
|
import { useMutation, useQuery } from "@apollo/client";
|
||||||
|
import { Button, Form, PageHeader, Popconfirm, Space } from "antd";
|
||||||
|
import moment from "moment";
|
||||||
|
import queryString from "query-string";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import {
|
||||||
|
DELETE_BILL_LINE,
|
||||||
|
INSERT_NEW_BILL_LINES,
|
||||||
|
UPDATE_BILL_LINE,
|
||||||
|
} from "../../graphql/bill-lines.queries";
|
||||||
|
import { QUERY_BILL_BY_PK, UPDATE_BILL } from "../../graphql/bills.queries";
|
||||||
|
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||||
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||||
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||||
|
import AlertComponent from "../alert/alert.component";
|
||||||
|
import BillFormContainer from "../bill-form/bill-form.container";
|
||||||
|
import BillMarkExportedButton from "../bill-mark-exported-button/bill-mark-exported-button.component";
|
||||||
|
import BillReeportButtonComponent from "../bill-reexport-button/bill-reexport-button.component";
|
||||||
|
import JobDocumentsGallery from "../jobs-documents-gallery/jobs-documents-gallery.container";
|
||||||
|
import JobsDocumentsLocalGallery from "../jobs-documents-local-gallery/jobs-documents-local-gallery.container";
|
||||||
|
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||||
|
import BillDetailEditReturn from "./bill-detail-edit-return.component";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
|
bodyshop: selectBodyshop,
|
||||||
|
});
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
setPartsOrderContext: (context) =>
|
||||||
|
dispatch(setModalContext({ context: context, modal: "partsOrder" })),
|
||||||
|
insertAuditTrail: ({ jobid, operation }) =>
|
||||||
|
dispatch(insertAuditTrail({ jobid, operation })),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(BillDetailEditcontainer);
|
||||||
|
|
||||||
|
export function BillDetailEditcontainer({
|
||||||
|
setPartsOrderContext,
|
||||||
|
insertAuditTrail,
|
||||||
|
bodyshop,
|
||||||
|
}) {
|
||||||
|
const search = queryString.parse(useLocation().search);
|
||||||
|
const history = useHistory();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [updateLoading, setUpdateLoading] = useState(false);
|
||||||
|
const [update_bill] = useMutation(UPDATE_BILL);
|
||||||
|
const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES);
|
||||||
|
const [updateBillLine] = useMutation(UPDATE_BILL_LINE);
|
||||||
|
const [deleteBillLine] = useMutation(DELETE_BILL_LINE);
|
||||||
|
|
||||||
|
const { loading, error, data, refetch } = useQuery(QUERY_BILL_BY_PK, {
|
||||||
|
variables: { billid: search.billid },
|
||||||
|
skip: !!!search.billid,
|
||||||
|
fetchPolicy: "network-only",
|
||||||
|
nextFetchPolicy: "network-only",
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
//It's got a previously deducted bill line!
|
||||||
|
if (
|
||||||
|
data.bills_by_pk.billlines.filter((b) => b.deductedfromlbr).length > 0 ||
|
||||||
|
form.getFieldValue("billlines").filter((b) => b.deductedfromlbr).length >
|
||||||
|
0
|
||||||
|
)
|
||||||
|
setVisible(true);
|
||||||
|
else {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFinish = async (values) => {
|
||||||
|
setUpdateLoading(true);
|
||||||
|
//let adjustmentsToInsert = {};
|
||||||
|
|
||||||
|
const { billlines, upload, ...bill } = values;
|
||||||
|
const updates = [];
|
||||||
|
updates.push(
|
||||||
|
update_bill({
|
||||||
|
variables: { billId: search.billid, bill: bill },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
billlines.forEach((l) => {
|
||||||
|
delete l.selected;
|
||||||
|
});
|
||||||
|
|
||||||
|
//Find bill lines that were deleted.
|
||||||
|
const deletedJobLines = [];
|
||||||
|
|
||||||
|
data.bills_by_pk.billlines.forEach((a) => {
|
||||||
|
const matchingRecord = billlines.find((b) => b.id === a.id);
|
||||||
|
if (!matchingRecord) {
|
||||||
|
deletedJobLines.push(a);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deletedJobLines.forEach((d) => {
|
||||||
|
updates.push(deleteBillLine({ variables: { id: d.id } }));
|
||||||
|
});
|
||||||
|
|
||||||
|
billlines.forEach((billline) => {
|
||||||
|
const { deductedfromlbr, inventories, jobline, ...il } = billline;
|
||||||
|
delete il.__typename;
|
||||||
|
|
||||||
|
if (il.id) {
|
||||||
|
updates.push(
|
||||||
|
updateBillLine({
|
||||||
|
variables: {
|
||||||
|
billLineId: il.id,
|
||||||
|
billLine: {
|
||||||
|
...il,
|
||||||
|
deductedfromlbr: deductedfromlbr,
|
||||||
|
joblineid: il.joblineid === "noline" ? null : il.joblineid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//It's a new line, have to insert it.
|
||||||
|
updates.push(
|
||||||
|
insertBillLine({
|
||||||
|
variables: {
|
||||||
|
billLines: [
|
||||||
|
{
|
||||||
|
...il,
|
||||||
|
deductedfromlbr: deductedfromlbr,
|
||||||
|
billid: search.billid,
|
||||||
|
joblineid: il.joblineid === "noline" ? null : il.joblineid,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(updates);
|
||||||
|
|
||||||
|
insertAuditTrail({
|
||||||
|
jobid: bill.jobid,
|
||||||
|
billid: search.billid,
|
||||||
|
operation: AuditTrailMapping.billupdated(bill.invoice_number),
|
||||||
|
});
|
||||||
|
|
||||||
|
await refetch();
|
||||||
|
form.setFieldsValue(transformData(data));
|
||||||
|
form.resetFields();
|
||||||
|
setVisible(false);
|
||||||
|
setUpdateLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
if (!search.billid) return <></>; //<div>{t("bills.labels.noneselected")}</div>;
|
||||||
|
|
||||||
|
const exported = data && data.bills_by_pk && data.bills_by_pk.exported;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{loading && <LoadingSkeleton />}
|
||||||
|
{data && (
|
||||||
|
<>
|
||||||
|
<PageHeader
|
||||||
|
title={
|
||||||
|
data &&
|
||||||
|
`${data.bills_by_pk.invoice_number} - ${data.bills_by_pk.vendor.name}`
|
||||||
|
}
|
||||||
|
extra={
|
||||||
|
<Space>
|
||||||
|
<BillDetailEditReturn data={data} />
|
||||||
|
|
||||||
|
<Popconfirm
|
||||||
|
visible={visible}
|
||||||
|
onConfirm={() => form.submit()}
|
||||||
|
onCancel={() => setVisible(false)}
|
||||||
|
okButtonProps={{ loading: updateLoading }}
|
||||||
|
title={t("bills.labels.editadjwarning")}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
htmlType="submit"
|
||||||
|
disabled={exported}
|
||||||
|
onClick={handleSave}
|
||||||
|
loading={updateLoading}
|
||||||
|
type="primary"
|
||||||
|
>
|
||||||
|
{t("general.actions.save")}
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
<BillReeportButtonComponent bill={data && data.bills_by_pk} />
|
||||||
|
<BillMarkExportedButton bill={data && data.bills_by_pk} />
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
onFinish={handleFinish}
|
||||||
|
initialValues={transformData(data)}
|
||||||
|
layout="vertical"
|
||||||
|
>
|
||||||
|
<BillFormContainer form={form} billEdit disabled={exported} />
|
||||||
|
|
||||||
|
{bodyshop.uselocalmediaserver ? (
|
||||||
|
<JobsDocumentsLocalGallery
|
||||||
|
job={{ id: data ? data.bills_by_pk.jobid : null }}
|
||||||
|
invoice_number={data ? data.bills_by_pk.invoice_number : null}
|
||||||
|
vendorid={data ? data.bills_by_pk.vendorid : null}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<JobDocumentsGallery
|
||||||
|
jobId={data ? data.bills_by_pk.jobid : null}
|
||||||
|
billId={search.billid}
|
||||||
|
documentsList={data ? data.bills_by_pk.documents : []}
|
||||||
|
billsCallback={refetch}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformData = (data) => {
|
||||||
|
return data
|
||||||
|
? {
|
||||||
|
...data.bills_by_pk,
|
||||||
|
|
||||||
|
billlines: data.bills_by_pk.billlines.map((i) => {
|
||||||
|
return {
|
||||||
|
...i,
|
||||||
|
joblineid: !!i.joblineid ? i.joblineid : "noline",
|
||||||
|
applicable_taxes: {
|
||||||
|
federal:
|
||||||
|
(i.applicable_taxes && i.applicable_taxes.federal) || false,
|
||||||
|
state: (i.applicable_taxes && i.applicable_taxes.state) || false,
|
||||||
|
local: (i.applicable_taxes && i.applicable_taxes.local) || false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
date: data.bills_by_pk ? moment(data.bills_by_pk.date) : null,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
};
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
import { Button, Checkbox, Form, Modal } from "antd";
|
||||||
|
import queryString from "query-string";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||||
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||||
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
|
import ReadOnlyFormItemComponent from "../form-items-formatted/read-only-form-item.component";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
|
bodyshop: selectBodyshop,
|
||||||
|
});
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
setPartsOrderContext: (context) =>
|
||||||
|
dispatch(setModalContext({ context: context, modal: "partsOrder" })),
|
||||||
|
insertAuditTrail: ({ jobid, operation }) =>
|
||||||
|
dispatch(insertAuditTrail({ jobid, operation })),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(BillDetailEditReturn);
|
||||||
|
|
||||||
|
export function BillDetailEditReturn({
|
||||||
|
setPartsOrderContext,
|
||||||
|
insertAuditTrail,
|
||||||
|
bodyshop,
|
||||||
|
data,
|
||||||
|
disabled,
|
||||||
|
}) {
|
||||||
|
const search = queryString.parse(useLocation().search);
|
||||||
|
const history = useHistory();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
|
||||||
|
const handleFinish = ({ billlines }) => {
|
||||||
|
const selectedLines = billlines.filter((l) => l.selected).map((l) => l.id);
|
||||||
|
|
||||||
|
setPartsOrderContext({
|
||||||
|
actions: {},
|
||||||
|
context: {
|
||||||
|
jobId: data.bills_by_pk.jobid,
|
||||||
|
vendorId: data.bills_by_pk.vendorid,
|
||||||
|
returnFromBill: data.bills_by_pk.id,
|
||||||
|
invoiceNumber: data.bills_by_pk.invoice_number,
|
||||||
|
linesToOrder: data.bills_by_pk.billlines
|
||||||
|
.filter((l) => selectedLines.includes(l.id))
|
||||||
|
.map((i) => {
|
||||||
|
return {
|
||||||
|
line_desc: i.line_desc,
|
||||||
|
// db_price: i.actual_price,
|
||||||
|
act_price: i.actual_price,
|
||||||
|
cost: i.actual_cost,
|
||||||
|
quantity: i.quantity,
|
||||||
|
joblineid: i.joblineid,
|
||||||
|
oem_partno: i.jobline && i.jobline.oem_partno,
|
||||||
|
part_type: i.jobline && i.jobline.part_type,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
isReturn: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
delete search.billid;
|
||||||
|
|
||||||
|
history.push({ search: queryString.stringify(search) });
|
||||||
|
setVisible(false);
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (visible === false) form.resetFields();
|
||||||
|
}, [visible, form]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Modal
|
||||||
|
visible={visible}
|
||||||
|
onCancel={() => setVisible(false)}
|
||||||
|
destroyOnClose
|
||||||
|
title={t("bills.actions.return")}
|
||||||
|
onOk={() => form.submit()}
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
initialValues={data && data.bills_by_pk}
|
||||||
|
onFinish={handleFinish}
|
||||||
|
form={form}
|
||||||
|
>
|
||||||
|
<Form.List name={["billlines"]}>
|
||||||
|
{(fields, { add, remove, move }) => {
|
||||||
|
return (
|
||||||
|
<table style={{ tableLayout: "auto", width: "100%" }}>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>{t("billlines.fields.line_desc")}</td>
|
||||||
|
<td>{t("billlines.fields.quantity")}</td>
|
||||||
|
<td>{t("billlines.fields.actual_price")}</td>
|
||||||
|
<td>{t("billlines.fields.actual_cost")}</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{fields.map((field, index) => (
|
||||||
|
<tr key={field.key}>
|
||||||
|
<td>
|
||||||
|
<Form.Item
|
||||||
|
// label={t("joblines.fields.selected")}
|
||||||
|
key={`${index}selected`}
|
||||||
|
name={[field.name, "selected"]}
|
||||||
|
valuePropName="checked"
|
||||||
|
>
|
||||||
|
<Checkbox />
|
||||||
|
</Form.Item>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Form.Item
|
||||||
|
// label={t("joblines.fields.line_desc")}
|
||||||
|
key={`${index}line_desc`}
|
||||||
|
name={[field.name, "line_desc"]}
|
||||||
|
>
|
||||||
|
<ReadOnlyFormItemComponent />
|
||||||
|
</Form.Item>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Form.Item
|
||||||
|
// label={t("joblines.fields.quantity")}
|
||||||
|
key={`${index}quantity`}
|
||||||
|
name={[field.name, "quantity"]}
|
||||||
|
>
|
||||||
|
<ReadOnlyFormItemComponent />
|
||||||
|
</Form.Item>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Form.Item
|
||||||
|
// label={t("joblines.fields.actual_price")}
|
||||||
|
key={`${index}actual_price`}
|
||||||
|
name={[field.name, "actual_price"]}
|
||||||
|
>
|
||||||
|
<ReadOnlyFormItemComponent type="currency" />
|
||||||
|
</Form.Item>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Form.Item
|
||||||
|
// label={t("joblines.fields.actual_cost")}
|
||||||
|
key={`${index}actual_cost`}
|
||||||
|
name={[field.name, "actual_cost"]}
|
||||||
|
>
|
||||||
|
<ReadOnlyFormItemComponent type="currency" />
|
||||||
|
</Form.Item>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Form.List>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
<Button
|
||||||
|
disabled={data.bills_by_pk.is_credit_memo || disabled}
|
||||||
|
onClick={() => {
|
||||||
|
setVisible(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("bills.actions.return")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,68 +1,12 @@
|
|||||||
import { useMutation, useQuery } from "@apollo/client";
|
import { Drawer, Grid } from "antd";
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
Drawer,
|
|
||||||
Form,
|
|
||||||
Grid,
|
|
||||||
PageHeader,
|
|
||||||
Popconfirm,
|
|
||||||
Space,
|
|
||||||
} from "antd";
|
|
||||||
import moment from "moment";
|
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { useHistory, useLocation } from "react-router-dom";
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
import { createStructuredSelector } from "reselect";
|
import BillDetailEditComponent from "./bill-detail-edit-component";
|
||||||
import {
|
|
||||||
DELETE_BILL_LINE,
|
|
||||||
INSERT_NEW_BILL_LINES,
|
|
||||||
UPDATE_BILL_LINE,
|
|
||||||
} from "../../graphql/bill-lines.queries";
|
|
||||||
import { QUERY_BILL_BY_PK, UPDATE_BILL } from "../../graphql/bills.queries";
|
|
||||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
|
||||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
|
||||||
import AlertComponent from "../alert/alert.component";
|
|
||||||
import BillFormContainer from "../bill-form/bill-form.container";
|
|
||||||
import BillMarkExportedButton from "../bill-mark-exported-button/bill-mark-exported-button.component";
|
|
||||||
import BillReeportButtonComponent from "../bill-reexport-button/bill-reexport-button.component";
|
|
||||||
import JobDocumentsGallery from "../jobs-documents-gallery/jobs-documents-gallery.container";
|
|
||||||
import JobsDocumentsLocalGallery from "../jobs-documents-local-gallery/jobs-documents-local-gallery.container";
|
|
||||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
export default function BillDetailEditcontainer() {
|
||||||
bodyshop: selectBodyshop,
|
|
||||||
});
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
|
||||||
setPartsOrderContext: (context) =>
|
|
||||||
dispatch(setModalContext({ context: context, modal: "partsOrder" })),
|
|
||||||
insertAuditTrail: ({ jobid, operation }) =>
|
|
||||||
dispatch(insertAuditTrail({ jobid, operation })),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(
|
|
||||||
mapStateToProps,
|
|
||||||
mapDispatchToProps
|
|
||||||
)(BillDetailEditcontainer);
|
|
||||||
|
|
||||||
export function BillDetailEditcontainer({
|
|
||||||
setPartsOrderContext,
|
|
||||||
insertAuditTrail,
|
|
||||||
bodyshop,
|
|
||||||
}) {
|
|
||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { t } = useTranslation();
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const [visible, setVisible] = useState(false);
|
|
||||||
const [updateLoading, setUpdateLoading] = useState(false);
|
|
||||||
const [update_bill] = useMutation(UPDATE_BILL);
|
|
||||||
const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES);
|
|
||||||
const [updateBillLine] = useMutation(UPDATE_BILL_LINE);
|
|
||||||
const [deleteBillLine] = useMutation(DELETE_BILL_LINE);
|
|
||||||
|
|
||||||
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
|
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
|
||||||
.filter((screen) => !!screen[1])
|
.filter((screen) => !!screen[1])
|
||||||
@@ -80,114 +24,6 @@ export function BillDetailEditcontainer({
|
|||||||
? bpoints[selectedBreakpoint[0]]
|
? bpoints[selectedBreakpoint[0]]
|
||||||
: "100%";
|
: "100%";
|
||||||
|
|
||||||
const { loading, error, data, refetch } = useQuery(QUERY_BILL_BY_PK, {
|
|
||||||
variables: { billid: search.billid },
|
|
||||||
skip: !!!search.billid,
|
|
||||||
fetchPolicy: "network-only",
|
|
||||||
nextFetchPolicy: "network-only",
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSave = () => {
|
|
||||||
//It's got a previously deducted bill line!
|
|
||||||
if (
|
|
||||||
data.bills_by_pk.billlines.filter((b) => b.deductedfromlbr).length > 0 ||
|
|
||||||
form.getFieldValue("billlines").filter((b) => b.deductedfromlbr).length >
|
|
||||||
0
|
|
||||||
)
|
|
||||||
setVisible(true);
|
|
||||||
else {
|
|
||||||
form.submit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFinish = async (values) => {
|
|
||||||
setUpdateLoading(true);
|
|
||||||
//let adjustmentsToInsert = {};
|
|
||||||
|
|
||||||
const { billlines, upload, ...bill } = values;
|
|
||||||
const updates = [];
|
|
||||||
updates.push(
|
|
||||||
update_bill({
|
|
||||||
variables: { billId: search.billid, bill: bill },
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
//Find bill lines that were deleted.
|
|
||||||
const deletedJobLines = [];
|
|
||||||
|
|
||||||
data.bills_by_pk.billlines.forEach((a) => {
|
|
||||||
const matchingRecord = billlines.find((b) => b.id === a.id);
|
|
||||||
if (!matchingRecord) {
|
|
||||||
deletedJobLines.push(a);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
deletedJobLines.forEach((d) => {
|
|
||||||
updates.push(deleteBillLine({ variables: { id: d.id } }));
|
|
||||||
});
|
|
||||||
|
|
||||||
billlines.forEach((billline) => {
|
|
||||||
const { deductedfromlbr, inventories, jobline, ...il } = billline;
|
|
||||||
delete il.__typename;
|
|
||||||
|
|
||||||
if (il.id) {
|
|
||||||
updates.push(
|
|
||||||
updateBillLine({
|
|
||||||
variables: {
|
|
||||||
billLineId: il.id,
|
|
||||||
billLine: {
|
|
||||||
...il,
|
|
||||||
deductedfromlbr: deductedfromlbr,
|
|
||||||
joblineid: il.joblineid === "noline" ? null : il.joblineid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
//It's a new line, have to insert it.
|
|
||||||
updates.push(
|
|
||||||
insertBillLine({
|
|
||||||
variables: {
|
|
||||||
billLines: [
|
|
||||||
{
|
|
||||||
...il,
|
|
||||||
deductedfromlbr: deductedfromlbr,
|
|
||||||
billid: search.billid,
|
|
||||||
joblineid: il.joblineid === "noline" ? null : il.joblineid,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(updates);
|
|
||||||
|
|
||||||
insertAuditTrail({
|
|
||||||
jobid: bill.jobid,
|
|
||||||
billid: search.billid,
|
|
||||||
operation: AuditTrailMapping.billupdated(bill.invoice_number),
|
|
||||||
});
|
|
||||||
|
|
||||||
await refetch();
|
|
||||||
form.setFieldsValue(transformData(data));
|
|
||||||
form.resetFields();
|
|
||||||
setVisible(false);
|
|
||||||
setUpdateLoading(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (search.billid && data) {
|
|
||||||
form.resetFields();
|
|
||||||
}
|
|
||||||
}, [form, search.billid, data]);
|
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
|
||||||
if (!search.billid) return <></>; //<div>{t("bills.labels.noneselected")}</div>;
|
|
||||||
|
|
||||||
const exported = data && data.bills_by_pk && data.bills_by_pk.exported;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
width={drawerPercentage}
|
width={drawerPercentage}
|
||||||
@@ -195,119 +31,10 @@ export function BillDetailEditcontainer({
|
|||||||
delete search.billid;
|
delete search.billid;
|
||||||
history.push({ search: queryString.stringify(search) });
|
history.push({ search: queryString.stringify(search) });
|
||||||
}}
|
}}
|
||||||
|
destroyOnClose
|
||||||
visible={search.billid}
|
visible={search.billid}
|
||||||
>
|
>
|
||||||
{loading && <LoadingSkeleton />}
|
<BillDetailEditComponent />
|
||||||
{!loading && (
|
|
||||||
<>
|
|
||||||
<PageHeader
|
|
||||||
title={
|
|
||||||
data &&
|
|
||||||
`${data.bills_by_pk.invoice_number} - ${data.bills_by_pk.vendor.name}`
|
|
||||||
}
|
|
||||||
extra={
|
|
||||||
<Space>
|
|
||||||
<Button
|
|
||||||
disabled={data.bills_by_pk.is_credit_memo}
|
|
||||||
onClick={() => {
|
|
||||||
delete search.billid;
|
|
||||||
history.push({ search: queryString.stringify(search) });
|
|
||||||
setPartsOrderContext({
|
|
||||||
actions: {},
|
|
||||||
context: {
|
|
||||||
jobId: data.bills_by_pk.jobid,
|
|
||||||
vendorId: data.bills_by_pk.vendorid,
|
|
||||||
returnFromBill: data.bills_by_pk.id,
|
|
||||||
invoiceNumber: data.bills_by_pk.invoice_number,
|
|
||||||
linesToOrder: data.bills_by_pk.billlines.map((i) => {
|
|
||||||
return {
|
|
||||||
line_desc: i.line_desc,
|
|
||||||
// db_price: i.actual_price,
|
|
||||||
act_price: i.actual_price,
|
|
||||||
cost: i.actual_cost,
|
|
||||||
quantity: i.quantity,
|
|
||||||
joblineid: i.joblineid,
|
|
||||||
oem_partno: i.jobline && i.jobline.oem_partno,
|
|
||||||
part_type: i.jobline && i.jobline.part_type,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
isReturn: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("bills.actions.return")}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Popconfirm
|
|
||||||
visible={visible}
|
|
||||||
onConfirm={() => form.submit()}
|
|
||||||
onCancel={() => setVisible(false)}
|
|
||||||
okButtonProps={{ loading: updateLoading }}
|
|
||||||
title={t("bills.labels.editadjwarning")}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
htmlType="submit"
|
|
||||||
disabled={exported}
|
|
||||||
onClick={handleSave}
|
|
||||||
loading={updateLoading}
|
|
||||||
type="primary"
|
|
||||||
>
|
|
||||||
{t("general.actions.save")}
|
|
||||||
</Button>
|
|
||||||
</Popconfirm>
|
|
||||||
<BillReeportButtonComponent bill={data && data.bills_by_pk} />
|
|
||||||
<BillMarkExportedButton bill={data && data.bills_by_pk} />
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Form
|
|
||||||
form={form}
|
|
||||||
onFinish={handleFinish}
|
|
||||||
initialValues={transformData(data)}
|
|
||||||
layout="vertical"
|
|
||||||
>
|
|
||||||
<BillFormContainer form={form} billEdit disabled={exported} />
|
|
||||||
|
|
||||||
{bodyshop.uselocalmediaserver ? (
|
|
||||||
<JobsDocumentsLocalGallery
|
|
||||||
job={{ id: data ? data.bills_by_pk.jobid : null }}
|
|
||||||
invoice_number={data ? data.bills_by_pk.invoice_number : null}
|
|
||||||
vendorid={data ? data.bills_by_pk.vendorid : null}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<JobDocumentsGallery
|
|
||||||
jobId={data ? data.bills_by_pk.jobid : null}
|
|
||||||
billId={search.billid}
|
|
||||||
documentsList={data ? data.bills_by_pk.documents : []}
|
|
||||||
billsCallback={refetch}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Form>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformData = (data) => {
|
|
||||||
return data
|
|
||||||
? {
|
|
||||||
...data.bills_by_pk,
|
|
||||||
|
|
||||||
billlines: data.bills_by_pk.billlines.map((i) => {
|
|
||||||
return {
|
|
||||||
...i,
|
|
||||||
joblineid: !!i.joblineid ? i.joblineid : "noline",
|
|
||||||
applicable_taxes: {
|
|
||||||
federal:
|
|
||||||
(i.applicable_taxes && i.applicable_taxes.federal) || false,
|
|
||||||
state: (i.applicable_taxes && i.applicable_taxes.state) || false,
|
|
||||||
local: (i.applicable_taxes && i.applicable_taxes.local) || false,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
date: data.bills_by_pk ? moment(data.bills_by_pk.date) : null,
|
|
||||||
}
|
|
||||||
: {};
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { DeleteFilled, DollarCircleFilled } from "@ant-design/icons";
|
import { DeleteFilled, DollarCircleFilled } from "@ant-design/icons";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
Checkbox,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { DateFormatter } from "../../utils/DateFormatter";
|
|||||||
import { alphaSort, dateSort } from "../../utils/sorters";
|
import { alphaSort, dateSort } from "../../utils/sorters";
|
||||||
import { TemplateList } from "../../utils/TemplateConstants";
|
import { TemplateList } from "../../utils/TemplateConstants";
|
||||||
import BillDeleteButton from "../bill-delete-button/bill-delete-button.component";
|
import BillDeleteButton from "../bill-delete-button/bill-delete-button.component";
|
||||||
|
import BillDetailEditReturnComponent from "../bill-detail-edit/bill-detail-edit-return.component";
|
||||||
import PrintWrapperComponent from "../print-wrapper/print-wrapper.component";
|
import PrintWrapperComponent from "../print-wrapper/print-wrapper.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
@@ -58,6 +59,14 @@ export function BillsListTableComponent({
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<BillDeleteButton bill={record} />
|
<BillDeleteButton bill={record} />
|
||||||
|
<BillDetailEditReturnComponent
|
||||||
|
data={{ bills_by_pk: { ...record, jobid: job.id } }}
|
||||||
|
disabled={
|
||||||
|
record.is_credit_memo ||
|
||||||
|
record.vendorid === bodyshop.inhousevendorid ||
|
||||||
|
jobRO
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
disabled={
|
disabled={
|
||||||
record.is_credit_memo ||
|
record.is_credit_memo ||
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import AlertComponent from "../alert/alert.component";
|
|||||||
import { Prompt, useLocation } from "react-router-dom";
|
import { Prompt, useLocation } from "react-router-dom";
|
||||||
import "./form-fields-changed.styles.scss";
|
import "./form-fields-changed.styles.scss";
|
||||||
|
|
||||||
export default function FormsFieldChanged({ form }) {
|
export default function FormsFieldChanged({ form, skipPrompt }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
@@ -25,7 +25,7 @@ export default function FormsFieldChanged({ form }) {
|
|||||||
return (
|
return (
|
||||||
<Space direction="vertical" style={{ width: "100%" }}>
|
<Space direction="vertical" style={{ width: "100%" }}>
|
||||||
<Prompt
|
<Prompt
|
||||||
when={true}
|
when={skipPrompt ? false : true}
|
||||||
message={(location) => {
|
message={(location) => {
|
||||||
if (loc.pathname === location.pathname) return false;
|
if (loc.pathname === location.pathname) return false;
|
||||||
return t("general.messages.unsavedchangespopup");
|
return t("general.messages.unsavedchangespopup");
|
||||||
|
|||||||
Reference in New Issue
Block a user