Updates for dynamic ruleset choices.
This commit is contained in:
@@ -140,6 +140,16 @@ export const QUERY_JOB_BY_CLM_NO = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
export const QUERY_CLOSE_DATE_BY_CLM_NO = gql`
|
||||
query QUERY_CLOSE_DATE_BY_CLM_NO($clm_no: String!) {
|
||||
jobs(where: { clm_no: { _eq: $clm_no } }) {
|
||||
id
|
||||
close_date
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_JOB = gql`
|
||||
mutation UPDATE_JOB($jobId: uuid!, $job: jobs_set_input!) {
|
||||
update_jobs(where: { id: { _eq: $jobId } }, _set: $job) {
|
||||
|
||||
@@ -13,13 +13,14 @@ exports.default = {
|
||||
downloadUpdates: "app_downloadUpdates",
|
||||
installUpdates: "app_installupdates",
|
||||
getReleaseNotes: "app_getReleaseNotes",
|
||||
importJob:"app_importJob",
|
||||
log: {
|
||||
info: "app_logInfo",
|
||||
debug: "app_logDebug",
|
||||
warn: "app_logWarn",
|
||||
error: "app_logError",
|
||||
silly: "app_logSilly"
|
||||
}
|
||||
silly: "app_logSilly",
|
||||
},
|
||||
},
|
||||
toRenderer: {
|
||||
updateAvailable: "app_updateAvailable",
|
||||
@@ -67,6 +68,7 @@ exports.default = {
|
||||
estimateDecodeStart: "estimatedecode__start",
|
||||
estimateDecodeSuccess: "estimatedecode__success",
|
||||
estimateDecodeFailure: "estimatedecode__failure",
|
||||
getCloseDate: "getclosedate",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import moment from "moment";
|
||||
import client from "../graphql/GraphQLClient";
|
||||
import {
|
||||
INSERT_NEW_JOB,
|
||||
QUERY_CLOSE_DATE_BY_CLM_NO,
|
||||
QUERY_JOB_BY_CLM_NO,
|
||||
UPDATE_JOB,
|
||||
} from "../graphql/jobs.queries";
|
||||
@@ -48,6 +49,14 @@ export function CalculateVehicleAge(job) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
export async function GetR4PDateWithClaim(clm_no) {
|
||||
const existingJobs = await client.query({
|
||||
query: QUERY_CLOSE_DATE_BY_CLM_NO,
|
||||
variables: { clm_no: clm_no },
|
||||
});
|
||||
return existingJobs.data.jobs[0] && existingJobs.data.jobs[0].close_date;
|
||||
}
|
||||
|
||||
export async function UpsertEstimate(job) {
|
||||
const shopId = store.getState().user.bodyshop.id;
|
||||
//logger.info("Beginning Upserting job from Renderer.");
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
setWatcherStatus,
|
||||
} from "../redux/application/application.actions";
|
||||
import { store } from "../redux/store";
|
||||
import { UpsertEstimate } from "./ipc-estimate-utils";
|
||||
import { GetR4PDateWithClaim, UpsertEstimate } from "./ipc-estimate-utils";
|
||||
import { setScanEstimateList } from "../redux/scan/scan.actions";
|
||||
import { signOutStart } from "../redux/user/user.actions";
|
||||
const { ipcRenderer } = window;
|
||||
@@ -44,16 +44,19 @@ ipcRenderer.on(ipcTypes.default.fileWatcher.toRenderer.error, (event, obj) => {
|
||||
|
||||
//Estimate Section
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeStart,
|
||||
(event, obj) => {
|
||||
console.log("Decoding started!");
|
||||
ipcTypes.default.estimate.toRenderer.getCloseDate,
|
||||
async (event, { filepath, clm_no }) => {
|
||||
const close_date = await GetR4PDateWithClaim(clm_no);
|
||||
ipcRenderer.send(ipcTypes.default.app.toMain.importJob, {
|
||||
filepath,
|
||||
close_date,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
|
||||
async (event, obj) => {
|
||||
|
||||
await UpsertEstimate(obj);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
import moment from "moment";
|
||||
|
||||
export const DateFormat = "MM/DD/yyyy";
|
||||
const RuleSets = [
|
||||
{
|
||||
title: "V1",
|
||||
range: [moment("2010-01-01"), moment("2023-04-01")],
|
||||
},
|
||||
{
|
||||
title: "V2",
|
||||
range: [moment("2023-04-01"), moment("2040-01-01")],
|
||||
},
|
||||
];
|
||||
|
||||
export function ChangeOfRuleSet({
|
||||
prevDateMoment = moment(),
|
||||
newDateMoment = moment(),
|
||||
}) {
|
||||
console.log("🚀 ~ file: constants.js ~ line 9 ~ newDateMoment", newDateMoment)
|
||||
console.log("🚀 ~ file: constants.js ~ line 9 ~ prevDateMoment", prevDateMoment)
|
||||
|
||||
|
||||
//Define the rule periods.
|
||||
const V1 = {
|
||||
title: "V1",
|
||||
range: [moment("2010-01-01"), moment("2023-04-01")],
|
||||
};
|
||||
const V2 = {
|
||||
title: "V2",
|
||||
range: [moment("2023-04-01"), moment("2040-01-01")],
|
||||
}; //Arbitrarily long away date.
|
||||
|
||||
const RuleSets = [V1, V2];
|
||||
|
||||
const prevRuleSet = RuleSets.find(
|
||||
(r) =>
|
||||
prevDateMoment.isSameOrAfter(r.range[0]) &&
|
||||
@@ -36,3 +30,13 @@ export function ChangeOfRuleSet({
|
||||
|
||||
return prevRuleSet?.title !== newRuleSet?.title;
|
||||
}
|
||||
|
||||
export function WhichRulesetToApply({ DateMoment = moment() }) {
|
||||
const newRuleSet = RuleSets.find(
|
||||
(r) =>
|
||||
DateMoment.isSameOrAfter(r.range[0]) &&
|
||||
DateMoment.isSameOrBefore(r.range[1])
|
||||
);
|
||||
|
||||
return newRuleSet?.title;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user