Added vehicle groups and age calculations.

This commit is contained in:
Patrick Fic
2020-10-16 11:51:53 -07:00
parent 827243e11f
commit 4582bd0f4d
70 changed files with 1793 additions and 213 deletions

View File

@@ -6,22 +6,43 @@ import {
QUERY_JOB_BY_CLM_NO,
UPDATE_JOB,
} from "../graphql/jobs.queries";
import { QUERY_GROUPS_BY_MAKE_TYPE } from "../graphql/veh_group.queries";
import { store } from "../redux/store";
import moment from "moment";
const { logger } = window;
export async function UpsertEstimate(job) {
const shopId = store.getState().user.bodyshop.id;
logger.info("Beginning Upserting job from Renderer.");
const parsedYr = parseInt(job.v_model_yr);
console.log("UpsertEstimate -> parsedYr", parsedYr);
logger.info(
moment(job.loss_date).year() -
(parsedYr >= 0 ? 2000 + parsedYr : 1900 + parsedYr)
);
job = {
...job,
group: await DetermineVehicleGroup(job),
v_age:
moment(job.loss_date).year() -
(parsedYr >= 0 ? 2000 + parsedYr : 1900 + parsedYr),
};
//Using the claim number, find out if the job exists. If it doesnt, then we need to create it.
const existingJobs = await client.query({
query: QUERY_JOB_BY_CLM_NO,
variables: { clm_no: job.clm_no },
});
if (existingJobs.data.jobs.length === 1) {
let suppDelta = await GetSupplementDelta(
existingJobs.data.jobs[0].id,
existingJobs.data.jobs[0].joblines,
job.joblines.data
);
logger.info("Attemping to update job record.");
await client.mutate({
mutation: gql`
${suppDelta}
@@ -33,10 +54,12 @@ export async function UpsertEstimate(job) {
mutation: UPDATE_JOB,
variables: { jobId: existingJobs.data.jobs[0].id, job: job },
});
logger.info("Job updated succesfully.");
console.log("UpsertEstimate -> updatedJob", updatedJob);
} else {
console.log("Insert a new job recort.", job);
logger.info("Attemping to insert job record.");
const result = await client.mutate({
mutation: INSERT_NEW_JOB,
variables: {
@@ -44,6 +67,8 @@ export async function UpsertEstimate(job) {
},
refetchQueries: ["QUERY_ALL_JOBS_PAGINATED"],
});
logger.info("Job inserted succesfully.");
console.log("UpsertEstimate -> result", result);
}
}
@@ -129,3 +154,38 @@ const generateRemoveQuery = (lineToRemove, index) => {
id
}`;
};
const DetermineVehicleGroup = async (job) => {
logger.info(
"Searching for vehicle groups.!",
job.v_makedesc.toUpperCase(),
job.v_type ? job.v_type.toUpperCase() : null
);
const vehicleGroups = await client.query({
query: QUERY_GROUPS_BY_MAKE_TYPE,
variables: {
make: job.v_makedesc.toUpperCase(),
type: job.v_type ? job.v_type.toUpperCase() : null,
},
});
if (vehicleGroups.data.veh_groups.length === 1) {
logger.info("Found 1 vehicle group.!", vehicleGroups.data.veh_groups[0]);
return vehicleGroups.data.veh_groups[0].group;
} else if (vehicleGroups.data.veh_groups.length === 0) {
//Uh-oh, should only be 1.
logger.info("No vehicle groups found.");
return null;
} else {
//Should never be here.
alert("Fatal error. Multiple vehicle groups found for this claim.");
logger.error(
"Found multiple vehicle groups!",
job.v_makedesc.toUpperCase(),
job.v_type ? job.v_type.toUpperCase() : null
);
}
return "";
};