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

@@ -22,9 +22,11 @@ export default function JobsDetailDescriptionMolecule({ loading, job }) {
</Descriptions.Item>
<Descriptions.Item label="Owner">{`${job.ownr_fn} ${job.ownr_ln}`}</Descriptions.Item>
<Descriptions.Item label="Vehicle">{`${job.v_model_yr} ${job.v_makedesc} ${job.v_model}`}</Descriptions.Item>
<Descriptions.Item label="Claim Total.">
<Descriptions.Item label="Claim Total">
<CurrencyFormatterAtom>{job.clm_total}</CurrencyFormatterAtom>
</Descriptions.Item>
<Descriptions.Item label="Group">{job.group}</Descriptions.Item>
<Descriptions.Item label="Age">{job.v_age}</Descriptions.Item>
</Descriptions>
</div>
);

View File

@@ -68,6 +68,8 @@ export const QUERY_JOB_BY_PK = gql`
clm_total
ro_number
updated_at
group
v_age
joblines(order_by: { unq_seq: asc }) {
id
act_price

View File

@@ -0,0 +1,14 @@
import gql from "graphql-tag";
export const QUERY_GROUPS_BY_MAKE_TYPE = gql`
query QUERY_GROUPS_BY_MAKE_TYPE($make: String!, $type: String) {
veh_groups(
where: { _and: { make: { _eq: $make } }, type: { _eq: $type } }
) {
id
group
make
type
}
}
`;

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 "";
};

View File

@@ -1,149 +0,0 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://bit.ly/CRA-PWA"
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
// Start addition---
// https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#manual_updates
// Added code, as our application will be open for a long time and we are a SPA, we need
// to trigger checks for updates frequently
setInterval(() => {
console.log("Checking if service worker was updated in server");
registration.update();
}, 15 * 60 * 1000); // Every 15 mins check
// End addition---
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
"New content is available and will be used when all " +
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log("Content is cached for offline use.");
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch((error) => {
console.error("Error during service worker registration:", error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
console.log("Seeing if service worker cna be found.");
fetch(swUrl)
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get("content-type");
if (
response.status === 404 ||
(contentType != null && contentType.indexOf("javascript") === -1)
) {
// No service worker found. Probably a different app. Reload the page.
console.log("No service worker found. Unregistering.");
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
console.log("Service worker found. Registering.");
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
"No internet connection found. App is running in offline mode."
);
});
}
export function unregister() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister();
});
}
}