IO-244 IOU Parts
This commit is contained in:
@@ -2,6 +2,8 @@ import Axios from "axios";
|
||||
import _ from "lodash";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { INSERT_NEW_JOB, QUERY_JOB_FOR_DUPE } from "../../graphql/jobs.queries";
|
||||
import moment from "moment";
|
||||
import i18n from "i18next";
|
||||
|
||||
export default async function DuplicateJob(
|
||||
apolloClient,
|
||||
@@ -57,3 +59,71 @@ export default async function DuplicateJob(
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
export async function CreateIouForJob(
|
||||
apolloClient,
|
||||
jobId,
|
||||
config,
|
||||
jobLinesToKeep
|
||||
) {
|
||||
logImEXEvent("job_create_iou");
|
||||
|
||||
const { status } = config;
|
||||
//get a list of all fields on the job
|
||||
const res = await apolloClient.query({
|
||||
query: QUERY_JOB_FOR_DUPE,
|
||||
variables: { id: jobId },
|
||||
});
|
||||
|
||||
const { jobs_by_pk } = res.data;
|
||||
const existingJob = _.cloneDeep(jobs_by_pk);
|
||||
delete existingJob.__typename;
|
||||
delete existingJob.id;
|
||||
delete existingJob.createdat;
|
||||
delete existingJob.updatedat;
|
||||
|
||||
const newJob = {
|
||||
...existingJob,
|
||||
|
||||
converted: true,
|
||||
status: status,
|
||||
iouparent: jobId,
|
||||
date_open: moment(),
|
||||
audit_trails: {
|
||||
data: [
|
||||
{
|
||||
useremail: config.useremail,
|
||||
bodyshopid: config.bodyshopid,
|
||||
operation: i18n.t("audit_trail.messages.jobioucreated"),
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const selectedJoblinesIds = jobLinesToKeep.map((l) => l.id);
|
||||
|
||||
const _tempLines = _.cloneDeep(existingJob.joblines).filter((l) =>
|
||||
selectedJoblinesIds.includes(l.id)
|
||||
);
|
||||
_tempLines.forEach((line) => {
|
||||
delete line.id;
|
||||
delete line.__typename;
|
||||
line.manual_line = true;
|
||||
});
|
||||
|
||||
delete newJob.joblines;
|
||||
newJob.joblines = { data: _tempLines };
|
||||
|
||||
const res2 = await apolloClient.mutate({
|
||||
mutation: INSERT_NEW_JOB,
|
||||
variables: { job: [newJob] },
|
||||
});
|
||||
|
||||
Axios.post("/job/totalsssu", {
|
||||
id: res2.data.insert_jobs.returning[0].id,
|
||||
});
|
||||
|
||||
//insert the new job. call the callback with the returned ID when done.
|
||||
|
||||
return res2.data.insert_jobs.returning[0].id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user