Added parts returning as a part of BOD-19
This commit is contained in:
@@ -7,6 +7,7 @@ import CurrencyInput from "../form-items-formatted/currency-form-item.component"
|
||||
export default function PartsOrderModalComponent({
|
||||
vendorList,
|
||||
sendTypeState,
|
||||
isReturn
|
||||
}) {
|
||||
const [sendType, setSendType] = sendTypeState;
|
||||
|
||||
@@ -24,7 +25,7 @@ export default function PartsOrderModalComponent({
|
||||
},
|
||||
]}
|
||||
>
|
||||
<VendorSearchSelect options={vendorList} />
|
||||
<VendorSearchSelect options={vendorList} disabled={isReturn} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="deliver_by"
|
||||
|
||||
@@ -18,7 +18,11 @@ import {
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||
import PartsOrderModalComponent from "./parts-order-modal.component";
|
||||
import RenderTemplate from "../../utils/RenderTemplate";
|
||||
import RenderTemplate, {
|
||||
displayTemplateInWindow,
|
||||
} from "../../utils/RenderTemplate";
|
||||
import moment from "moment";
|
||||
import { TemplateList } from "../../utils/TemplateConstants";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
@@ -41,7 +45,15 @@ export function PartsOrderModalContainer({
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { visible, context, actions } = partsOrderModal;
|
||||
const { jobId, linesToOrder } = context;
|
||||
const {
|
||||
jobId,
|
||||
linesToOrder,
|
||||
isReturn,
|
||||
vendorId,
|
||||
returnFromInvoice,
|
||||
invoiceNumber,
|
||||
} = context;
|
||||
|
||||
const { refetch } = actions;
|
||||
const [form] = Form.useForm();
|
||||
|
||||
@@ -56,7 +68,7 @@ export function PartsOrderModalContainer({
|
||||
const [insertInvoice] = useMutation(INSERT_NEW_INVOICE);
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
insertPartOrder({
|
||||
const insertResult = await insertPartOrder({
|
||||
variables: {
|
||||
po: [
|
||||
{
|
||||
@@ -67,117 +79,123 @@ export function PartsOrderModalContainer({
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.then((r) => {
|
||||
updateJobLines({
|
||||
variables: {
|
||||
ids: values.parts_order_lines.data.map((item) => item.job_line_id),
|
||||
status: bodyshop.md_order_statuses.default_ordered || "Ordered*",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
notification["success"]({
|
||||
message: t("parts_orders.successes.created"),
|
||||
});
|
||||
|
||||
if (values.vendorid === bodyshop.inhousevendorid) {
|
||||
console.log("Inhouse Invoice needs to be psoted.");
|
||||
let invoiceToPost = {
|
||||
vendorid: bodyshop.inhousevendorid,
|
||||
jobid: jobId,
|
||||
total: 0,
|
||||
invoice_number: `${jobId}`, //TODO Add INhouse invoice generation?
|
||||
federal_tax_rate:
|
||||
bodyshop.invoice_tax_rates.federal_tax_rate || 0,
|
||||
state_tax_rate: bodyshop.invoice_tax_rates.state_tax_rate || 0,
|
||||
local_tax_rate: bodyshop.invoice_tax_rates.local_tax_rate || 0,
|
||||
invoicelines: {
|
||||
data: values.parts_order_lines.data.map((p) => {
|
||||
return {
|
||||
joblineid: p.job_line_id,
|
||||
actual_price: 0,
|
||||
actual_cost: 0,
|
||||
line_desc: p.line_desc,
|
||||
quantity: p.quantity || 1,
|
||||
cost_center:
|
||||
bodyshop.md_responsibility_centers.defaults.PAO ||
|
||||
"Other*",
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
insertInvoice({
|
||||
variables: { invoice: invoiceToPost },
|
||||
});
|
||||
}
|
||||
|
||||
if (refetch) refetch();
|
||||
toggleModalVisible();
|
||||
|
||||
if (sendType === "e") {
|
||||
//TODO Remove hardcoding
|
||||
setEmailOptions({
|
||||
messageOptions: {
|
||||
to:
|
||||
data.vendors.filter((item) => item.id === values.id)[0] ||
|
||||
null,
|
||||
replyTo: bodyshop.email,
|
||||
},
|
||||
template: {
|
||||
name: "parts_order_confirmation",
|
||||
variables: {
|
||||
id: r.data.insert_parts_orders.returning[0].id,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
RenderTemplate(
|
||||
{
|
||||
name: "parts_order_confirmation",
|
||||
variables: {
|
||||
id: r.data.insert_parts_orders.returning[0].id,
|
||||
},
|
||||
},
|
||||
|
||||
bodyshop
|
||||
).then((html) => {
|
||||
var newWin = window.open();
|
||||
newWin.document.write(html);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
notification["error"]({
|
||||
message: t("parts_orders.errors.creating"),
|
||||
description: error.message,
|
||||
});
|
||||
});
|
||||
|
||||
//end no good
|
||||
})
|
||||
.catch((error) => {
|
||||
notification["error"]({
|
||||
message: t("parts_orders.errors.creating"),
|
||||
description: error.message,
|
||||
});
|
||||
});
|
||||
if (!!insertResult.error) {
|
||||
notification["error"]({
|
||||
message: t("parts_orders.errors.creating"),
|
||||
description: JSON.stringify(insertResult.error),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const jobLinesResult = await updateJobLines({
|
||||
variables: {
|
||||
ids: values.parts_order_lines.data.map((item) => item.job_line_id),
|
||||
status: isReturn
|
||||
? bodyshop.md_order_statuses.default_returned || "Returned*"
|
||||
: bodyshop.md_order_statuses.default_ordered || "Ordered*",
|
||||
},
|
||||
});
|
||||
if (!!jobLinesResult.errors) {
|
||||
notification["error"]({
|
||||
message: t("parts_orders.errors.creating"),
|
||||
description: JSON.stringify(jobLinesResult.errors),
|
||||
});
|
||||
}
|
||||
|
||||
notification["success"]({
|
||||
message: t("parts_orders.successes.created"),
|
||||
});
|
||||
|
||||
if (values.vendorid === bodyshop.inhousevendorid) {
|
||||
console.log("Inhouse Invoice needs to be psoted.");
|
||||
let invoiceToPost = {
|
||||
vendorid: bodyshop.inhousevendorid,
|
||||
jobid: jobId,
|
||||
total: 0,
|
||||
invoice_number: `${jobId}`, //TODO Add INhouse invoice generation?
|
||||
federal_tax_rate: bodyshop.invoice_tax_rates.federal_tax_rate || 0,
|
||||
state_tax_rate: bodyshop.invoice_tax_rates.state_tax_rate || 0,
|
||||
local_tax_rate: bodyshop.invoice_tax_rates.local_tax_rate || 0,
|
||||
invoicelines: {
|
||||
data: values.parts_order_lines.data.map((p) => {
|
||||
return {
|
||||
joblineid: p.job_line_id,
|
||||
actual_price: 0,
|
||||
actual_cost: 0,
|
||||
line_desc: p.line_desc,
|
||||
quantity: p.quantity || 1,
|
||||
cost_center:
|
||||
bodyshop.md_responsibility_centers.defaults.PAO || "Other*",
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
await insertInvoice({
|
||||
variables: { invoice: invoiceToPost },
|
||||
});
|
||||
}
|
||||
|
||||
if (refetch) refetch();
|
||||
toggleModalVisible();
|
||||
|
||||
if (sendType === "e") {
|
||||
//TODO Remove hardcoding
|
||||
setEmailOptions({
|
||||
messageOptions: {
|
||||
to: data.vendors.filter((item) => item.id === values.id)[0] || null,
|
||||
replyTo: bodyshop.email,
|
||||
},
|
||||
template: {
|
||||
name: isReturn
|
||||
? TemplateList.parts_return_confirmation.key
|
||||
: TemplateList.parts_order_confirmation.key,
|
||||
variables: {
|
||||
id: insertResult.data.insert_parts_orders.returning[0].id,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
displayTemplateInWindow(
|
||||
await RenderTemplate(
|
||||
{
|
||||
name: isReturn
|
||||
? TemplateList.parts_return_confirmation.key
|
||||
: TemplateList.parts_order_confirmation.key,
|
||||
variables: {
|
||||
id: insertResult.data.insert_parts_orders.returning[0].id,
|
||||
},
|
||||
},
|
||||
bodyshop
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const initialValues =
|
||||
linesToOrder &&
|
||||
linesToOrder.reduce((acc, value) => {
|
||||
acc.push({
|
||||
line_desc: value.line_desc,
|
||||
oem_partno: value.oem_partno,
|
||||
db_price: value.db_price,
|
||||
act_price: value.act_price,
|
||||
quantity: value.part_qty,
|
||||
job_line_id: value.id,
|
||||
status: bodyshop.md_order_statuses.default_ordered || "Ordered*",
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
const initialValues = {
|
||||
jobid: jobId,
|
||||
return: isReturn,
|
||||
deliver_by: isReturn ? moment(new Date()) : null,
|
||||
vendorid: vendorId,
|
||||
returnfrominvoice: returnFromInvoice,
|
||||
|
||||
parts_order_lines: {
|
||||
data: linesToOrder
|
||||
? linesToOrder.reduce((acc, value) => {
|
||||
acc.push({
|
||||
line_desc: value.line_desc,
|
||||
oem_partno: value.oem_partno,
|
||||
db_price: value.db_price,
|
||||
act_price: value.act_price,
|
||||
quantity: value.part_qty,
|
||||
job_line_id: isReturn ? value.joblineid : value.id,
|
||||
});
|
||||
return acc;
|
||||
}, [])
|
||||
: [],
|
||||
},
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && !!linesToOrder) {
|
||||
@@ -188,6 +206,11 @@ export function PartsOrderModalContainer({
|
||||
return (
|
||||
<Modal
|
||||
visible={visible}
|
||||
title={
|
||||
isReturn
|
||||
? `${t("parts_orders.labels.returnpartsorder")} ${invoiceNumber}`
|
||||
: t("parts_orders.labels.newpartsorder")
|
||||
}
|
||||
onCancel={() => toggleModalVisible()}
|
||||
width='90%'
|
||||
onOk={() => form.submit()}
|
||||
@@ -199,10 +222,11 @@ export function PartsOrderModalContainer({
|
||||
form={form}
|
||||
autoComplete='no'
|
||||
onFinish={handleFinish}
|
||||
initialValues={{ parts_order_lines: { data: initialValues } }}>
|
||||
initialValues={initialValues}>
|
||||
<PartsOrderModalComponent
|
||||
vendorList={(data && data.vendors) || []}
|
||||
sendTypeState={sendTypeState}
|
||||
isReturn={isReturn}
|
||||
/>
|
||||
</Form>
|
||||
</LoadingSpinner>
|
||||
|
||||
Reference in New Issue
Block a user