diff --git a/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx b/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx index ffd7d01b9..da3ba9b57 100644 --- a/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx +++ b/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx @@ -7,10 +7,13 @@ import { createStructuredSelector } from "reselect"; import { INSERT_NEW_INVOICE } from "../../graphql/invoices.queries"; import { toggleModalVisible } from "../../redux/modals/modals.actions"; import { selectInvoiceEnterModal } from "../../redux/modals/modals.selectors"; -import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors"; +import { + selectBodyshop, + selectCurrentUser, +} from "../../redux/user/user.selectors"; import { handleUpload } from "../documents-upload/documents-upload.utility"; import InvoiceFormContainer from "../invoice-form/invoice-form.container"; - +import { UPDATE_JOB_LINE_STATUS } from "../../graphql/jobs-lines.queries"; const mapStateToProps = createStructuredSelector({ invoiceEnterModal: selectInvoiceEnterModal, bodyshop: selectBodyshop, @@ -30,6 +33,7 @@ function InvoiceEnterModalContainer({ const { t } = useTranslation(); const [enterAgain, setEnterAgain] = useState(false); const [insertInvoice] = useMutation(INSERT_NEW_INVOICE); + const [updateJobLines] = useMutation(UPDATE_JOB_LINE_STATUS); const [loading, setLoading] = useState(false); const handleFinish = (values) => { @@ -53,38 +57,47 @@ function InvoiceEnterModalContainer({ }) .then((r) => { const invoiceId = r.data.insert_invoices.returning[0].id; - console.log("invoiceId", invoiceId); - ///////////////////////// - if (upload && upload.length > 0) { - //insert Each of the documents? - upload.forEach((u) => { - handleUpload( - { file: u.originFileObj }, - { - bodyshop: bodyshop, - uploaded_by: currentUser.email, - jobId: values.jobid, - invoiceId: invoiceId, - tagsArray: null, - callback: null, - } - ); - }); - } - /////////////////////////// - setLoading(false); - notification["success"]({ - message: t("invoices.successes.created"), - }); - if (invoiceEnterModal.actions.refetch) - invoiceEnterModal.actions.refetch(); - if (enterAgain) { - form.resetFields(); - } else { - toggleModalVisible(); - } - setEnterAgain(false); + updateJobLines({ + variables: { + ids: remainingValues.invoicelines + .filter((il) => il.joblineid !== " noline") + .map((li) => li.joblineid), + status: bodyshop.md_order_statuses.default_received || "Received*", + }, + }).then((joblineresult) => { + ///////////////////////// + if (upload && upload.length > 0) { + //insert Each of the documents? + upload.forEach((u) => { + handleUpload( + { file: u.originFileObj }, + { + bodyshop: bodyshop, + uploaded_by: currentUser.email, + jobId: values.jobid, + invoiceId: invoiceId, + tagsArray: null, + callback: null, + } + ); + }); + } + /////////////////////////// + setLoading(false); + notification["success"]({ + message: t("invoices.successes.created"), + }); + if (invoiceEnterModal.actions.refetch) + invoiceEnterModal.actions.refetch(); + + if (enterAgain) { + form.resetFields(); + } else { + toggleModalVisible(); + } + setEnterAgain(false); + }); }) .catch((error) => { setLoading(false); @@ -122,19 +135,17 @@ function InvoiceEnterModalContainer({ {invoiceEnterModal.context && invoiceEnterModal.context.id ? null : ( )} } - destroyOnClose - > + destroyOnClose>