Refactored to use invoice form for modal + detail edit page. BOD-634
This commit is contained in:
@@ -1,136 +0,0 @@
|
||||
import { DatePicker, Form, Input, Switch, Tag } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
import DocumentsUploadContainer from "../documents-upload/documents-upload.container";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import InvoiceEnterModalLinesComponent from "../invoice-enter-modal/invoice-enter-modal.lines.component";
|
||||
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
||||
|
||||
export default function InvoiceDetailEditComponent({
|
||||
form,
|
||||
roAutoCompleteOptions,
|
||||
loadLines,
|
||||
lineData,
|
||||
responsibilityCenters,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [amounts, setAmounts] = useState({ invoiceTotal: 0, enteredAmount: 0 });
|
||||
const { getFieldsValue } = form;
|
||||
|
||||
const calculateTotals = () => {
|
||||
setAmounts({
|
||||
invoiceTotal: getFieldsValue().total || 0,
|
||||
enteredTotal: getFieldsValue("invoicelines").invoicelines
|
||||
? getFieldsValue("invoicelines").invoicelines.reduce(
|
||||
(acc, value) =>
|
||||
acc + (value && value.actual_cost ? value.actual_cost : 0),
|
||||
0
|
||||
)
|
||||
: 0,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ display: "flex" }}>
|
||||
<Form.Item
|
||||
name="jobid"
|
||||
label={t("invoices.fields.ro_number")}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<JobSearchSelect
|
||||
options={roAutoCompleteOptions}
|
||||
onBlur={() => {
|
||||
if (form.getFieldValue("jobid") !== null) {
|
||||
//loadLines({ variables: { id: form.getFieldValue("jobid") } });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div style={{ display: "flex" }}>
|
||||
<Form.Item
|
||||
label={t("invoices.fields.invoice_number")}
|
||||
name="invoice_number"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("invoices.fields.date")}
|
||||
name="date"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<DatePicker />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("invoices.fields.is_credit_memo")}
|
||||
name="is_credit_memo"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("invoices.fields.total")}
|
||||
name="total"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<CurrencyInput />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<InvoiceEnterModalLinesComponent
|
||||
lineData={lineData}
|
||||
discount={0.1} //TODO Derive the actual discount from the vendor.
|
||||
form={form}
|
||||
responsibilityCenters={responsibilityCenters}
|
||||
calculateTotals={calculateTotals}
|
||||
/>
|
||||
|
||||
<Form.Item name="upload" label="Upload">
|
||||
<DocumentsUploadContainer jobId={form.getFieldValue("jobid")} />
|
||||
</Form.Item>
|
||||
{t("invoicelines.labels.entered")}
|
||||
<CurrencyFormatter>{amounts.enteredTotal || 0}</CurrencyFormatter>
|
||||
|
||||
{amounts.invoiceTotal - amounts.enteredTotal === 0 ? (
|
||||
<Tag color="green">{t("invoicelines.labels.reconciled")}</Tag>
|
||||
) : (
|
||||
<Tag color="red">
|
||||
{t("invoicelines.labels.unreconciled")}:
|
||||
<CurrencyFormatter>
|
||||
{amounts.invoiceTotal - amounts.enteredTotal}
|
||||
</CurrencyFormatter>
|
||||
</Tag>
|
||||
)}
|
||||
<button
|
||||
onClick={() => {
|
||||
//console.log(form.getFieldsValue());
|
||||
form.resetFields();
|
||||
}}
|
||||
>
|
||||
a
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -8,12 +8,10 @@ import { connect } from "react-redux";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_INVOICE_BY_PK } from "../../graphql/invoices.queries";
|
||||
import { GET_JOB_LINES_TO_ENTER_INVOICE } from "../../graphql/jobs-lines.queries";
|
||||
import { ACTIVE_JOBS_FOR_AUTOCOMPLETE } from "../../graphql/jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import InvoiceFormContainer from "../invoice-form/invoice-form.container";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import InvoiceDetailEditComponent from "./invoice-detail-edit.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -29,35 +27,19 @@ export function InvoiceDetailEditContainer({ bodyshop }) {
|
||||
skip: !!!search.invoiceid,
|
||||
});
|
||||
|
||||
const { data: RoAutoCompleteData } = useQuery(ACTIVE_JOBS_FOR_AUTOCOMPLETE, {
|
||||
fetchPolicy: "network-only",
|
||||
variables: { statuses: bodyshop.md_ro_statuses.open_statuses || ["Open"] },
|
||||
});
|
||||
|
||||
const {
|
||||
loading: linesLoading,
|
||||
data: lineData,
|
||||
refetch: loadLines,
|
||||
} = useQuery(GET_JOB_LINES_TO_ENTER_INVOICE, {
|
||||
variables: { id: data && data.invoices_by_pk.jobid },
|
||||
fetchPolicy: "network-only",
|
||||
skip: !!!(data && data.invoices_by_pk.id),
|
||||
});
|
||||
|
||||
const handleFinish = (values) => {
|
||||
console.log("values", values);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// if (data) {
|
||||
// loadLines();
|
||||
// if (lineData) //form.resetFields();
|
||||
// }
|
||||
}, [data, lineData]);
|
||||
if (search.invoiceid) {
|
||||
form.resetFields();
|
||||
}
|
||||
}, [form, search.invoiceid]);
|
||||
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
return (
|
||||
<LoadingSkeleton loading={loading || linesLoading}>
|
||||
<LoadingSkeleton loading={loading}>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={handleFinish}
|
||||
@@ -78,13 +60,7 @@ export function InvoiceDetailEditContainer({ bodyshop }) {
|
||||
: {}
|
||||
}
|
||||
>
|
||||
<InvoiceDetailEditComponent
|
||||
form={form}
|
||||
roAutoCompleteOptions={RoAutoCompleteData && RoAutoCompleteData.jobs}
|
||||
loadLines={loadLines}
|
||||
lineData={lineData ? lineData.joblines : null}
|
||||
responsibilityCenters={bodyshop.md_responsibility_centers || null}
|
||||
/>
|
||||
<InvoiceFormContainer form={form} hideVendor />
|
||||
</Form>
|
||||
</LoadingSkeleton>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user