feature/IO-3499-React-19 checkpoint
This commit is contained in:
@@ -82,29 +82,40 @@ export function PartsOrderModalContainer({
|
|||||||
setSaving(true);
|
setSaving(true);
|
||||||
let insertResult;
|
let insertResult;
|
||||||
|
|
||||||
insertResult = await insertPartOrder({
|
try {
|
||||||
variables: {
|
insertResult = await insertPartOrder({
|
||||||
po: [
|
variables: {
|
||||||
{
|
po: [
|
||||||
...values,
|
{
|
||||||
order_date: dayjs().format("YYYY-MM-DD"),
|
...values,
|
||||||
orderedby: currentUser.email,
|
order_date: dayjs().format("YYYY-MM-DD"),
|
||||||
jobid: jobId,
|
orderedby: currentUser.email,
|
||||||
user_email: currentUser.email,
|
jobid: jobId,
|
||||||
return: isReturn,
|
user_email: currentUser.email,
|
||||||
status: is_quote
|
return: isReturn,
|
||||||
? bodyshop.md_order_statuses.default_quote || "Quote"
|
status: is_quote
|
||||||
: bodyshop.md_order_statuses.default_ordered || "Ordered*"
|
? bodyshop.md_order_statuses.default_quote || "Quote"
|
||||||
}
|
: bodyshop.md_order_statuses.default_ordered || "Ordered*"
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
refetchQueries: ["QUERY_PARTS_BILLS_BY_JOBID"]
|
},
|
||||||
});
|
refetchQueries: ["QUERY_PARTS_BILLS_BY_JOBID"]
|
||||||
if (insertResult.errors) {
|
});
|
||||||
|
if (insertResult.errors) {
|
||||||
|
notification.error({
|
||||||
|
title: t("parts_orders.errors.creating"),
|
||||||
|
description: JSON.stringify(insertResult.errors)
|
||||||
|
});
|
||||||
|
setSaving(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
notification.error({
|
notification.error({
|
||||||
title: t("parts_orders.errors.creating"),
|
title: t("parts_orders.errors.creating"),
|
||||||
description: JSON.stringify(insertResult.errors)
|
description: error.message
|
||||||
});
|
});
|
||||||
|
console.error("Parts order insert error:", error);
|
||||||
|
setSaving(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notification.success({
|
notification.success({
|
||||||
@@ -118,36 +129,54 @@ export function PartsOrderModalContainer({
|
|||||||
type: isReturn ? "jobspartsreturn" : "jobspartsorder"
|
type: isReturn ? "jobspartsreturn" : "jobspartsorder"
|
||||||
});
|
});
|
||||||
|
|
||||||
const jobLinesResult = await updateJobLines({
|
// Use linesToOrder from context instead of form values to preserve job_line_id
|
||||||
variables: {
|
const jobLineIds = linesToOrder
|
||||||
ids: values.parts_order_lines.data.filter((item) => item.job_line_id).map((item) => item.job_line_id),
|
.filter((line) => (isReturn ? line.joblineid : line.id))
|
||||||
status: isReturn
|
.map((line) => (isReturn ? line.joblineid : line.id));
|
||||||
? bodyshop.md_order_statuses.default_returned || "Returned*"
|
|
||||||
: is_quote
|
|
||||||
? bodyshop.md_order_statuses.default_quote || "Quote"
|
|
||||||
: bodyshop.md_order_statuses.default_ordered || "Ordered*"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isReturn && removefrompartsqueue) {
|
try {
|
||||||
await updateJob({
|
const jobLinesResult = await updateJobLines({
|
||||||
variables: {
|
variables: {
|
||||||
jobId: jobId,
|
ids: jobLineIds,
|
||||||
job: {
|
status: isReturn
|
||||||
queued_for_parts: false
|
? bodyshop.md_order_statuses.default_returned || "Returned*"
|
||||||
}
|
: is_quote
|
||||||
|
? bodyshop.md_order_statuses.default_quote || "Quote"
|
||||||
|
: bodyshop.md_order_statuses.default_ordered || "Ordered*"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (jobLinesResult.errors) {
|
||||||
|
notification.error({
|
||||||
|
title: t("parts_orders.errors.updating_status"),
|
||||||
|
description: JSON.stringify(jobLinesResult.errors)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
notification.error({
|
||||||
|
title: t("parts_orders.errors.updating_status"),
|
||||||
|
description: error.message
|
||||||
|
});
|
||||||
|
console.error("Job lines update error:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jobLinesResult.errors) {
|
if (!isReturn && removefrompartsqueue) {
|
||||||
notification.error({
|
try {
|
||||||
title: t("parts_orders.errors.creating"),
|
await updateJob({
|
||||||
description: JSON.stringify(jobLinesResult.errors)
|
variables: {
|
||||||
});
|
jobId: jobId,
|
||||||
|
job: {
|
||||||
|
queued_for_parts: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Update job queue error:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.vendorid === bodyshop.inhousevendorid) {
|
if (values.vendorid === bodyshop.inhousevendorid) {
|
||||||
|
// Use linesToOrder for job_line_id, merge with form values for other fields
|
||||||
setBillEnterContext({
|
setBillEnterContext({
|
||||||
actions: { refetch: refetch },
|
actions: { refetch: refetch },
|
||||||
context: {
|
context: {
|
||||||
@@ -159,9 +188,10 @@ export function PartsOrderModalContainer({
|
|||||||
isinhouse: true,
|
isinhouse: true,
|
||||||
date: dayjs(),
|
date: dayjs(),
|
||||||
total: 0,
|
total: 0,
|
||||||
billlines: values.parts_order_lines.data.map((p) => {
|
billlines: values.parts_order_lines.data.map((p, index) => {
|
||||||
|
const originalLine = linesToOrder[index];
|
||||||
return {
|
return {
|
||||||
joblineid: p.job_line_id,
|
joblineid: isReturn ? originalLine?.joblineid : originalLine?.id,
|
||||||
actual_price: p.act_price,
|
actual_price: p.act_price,
|
||||||
actual_cost: 0, //p.act_price,
|
actual_cost: 0, //p.act_price,
|
||||||
line_desc: p.line_desc,
|
line_desc: p.line_desc,
|
||||||
|
|||||||
Reference in New Issue
Block a user