Begin refactoring smart schedule calculations.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { all, takeLatest, call, put } from "redux-saga/effects";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
import client from "../../utils/GraphQLClient";
|
||||
import moment from "moment";
|
||||
import { all, call, put, select, takeLatest } from "redux-saga/effects";
|
||||
import { QUERY_SCHEDULE_LOAD_DATA } from "../../graphql/appointments.queries";
|
||||
import client from "../../utils/GraphQLClient";
|
||||
import { CalculateLoad, CheckJobBucket } from "../../utils/SSSUtils";
|
||||
import {
|
||||
scheduleLoadFailure,
|
||||
scheduleLoadSuccess,
|
||||
} from "./application.actions";
|
||||
import moment from "moment";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
|
||||
export function* onCalculateScheduleLoad() {
|
||||
yield takeLatest(
|
||||
@@ -17,6 +18,9 @@ export function* onCalculateScheduleLoad() {
|
||||
export function* calculateScheduleLoad({ payload: end }) {
|
||||
//REMINDER: Moment.js is not immutable. Today WILL change when adjusted.
|
||||
const today = moment(new Date()).startOf("day");
|
||||
const state = yield select();
|
||||
const buckets = state.user.bodyshop.ssbuckets;
|
||||
|
||||
try {
|
||||
const result = yield client.query({
|
||||
query: QUERY_SCHEDULE_LOAD_DATA,
|
||||
@@ -26,14 +30,26 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
},
|
||||
fetchPolicy: "network-only",
|
||||
});
|
||||
const { prodJobs, arrJobs, compJobs } = result.data;
|
||||
|
||||
let load = {
|
||||
productionHoursTotal:
|
||||
result.data.larhrs.aggregate.sum.mod_lb_hrs +
|
||||
result.data.labhrs.aggregate.sum.mod_lb_hrs,
|
||||
const load = {
|
||||
productionTotal: {},
|
||||
};
|
||||
|
||||
const { arrJobs, compJobs } = result.data;
|
||||
//Set the current load.
|
||||
buckets.forEach((bucket) => {
|
||||
load.productionTotal[bucket.id] = { count: 0, label: bucket.label };
|
||||
});
|
||||
|
||||
prodJobs.forEach((item) => {
|
||||
const bucketId = CheckJobBucket(buckets, item);
|
||||
if (bucketId) {
|
||||
load.productionTotal[bucketId].count =
|
||||
load.productionTotal[bucketId].count + 1;
|
||||
} else {
|
||||
console.log("Uh oh, this job doesn't fit in a bucket!", item);
|
||||
}
|
||||
});
|
||||
|
||||
arrJobs.forEach((item) => {
|
||||
const itemDate = moment(item.scheduled_in).format("yyyy-MM-DD");
|
||||
@@ -84,17 +100,23 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
}
|
||||
if (day === 0) {
|
||||
//Starting on day 1. The load is current.
|
||||
load[current].expectedLoad =
|
||||
load.productionHoursTotal +
|
||||
(load[current].hoursIn || 0) -
|
||||
(load[current].hoursOut || 0);
|
||||
load[current].expectedLoad = CalculateLoad(
|
||||
load.productionTotal,
|
||||
buckets,
|
||||
load[current].jobsIn || [],
|
||||
load[current].jobsOut || []
|
||||
);
|
||||
} else {
|
||||
load[current].expectedLoad =
|
||||
load[prev].expectedLoad +
|
||||
(load[current].hoursIn || 0) -
|
||||
(load[current].hoursOut || 0);
|
||||
load[current].expectedLoad = CalculateLoad(
|
||||
load[prev].expectedLoad,
|
||||
buckets,
|
||||
load[current].jobsIn || [],
|
||||
load[current].jobsOut || []
|
||||
);
|
||||
}
|
||||
console.log(load);
|
||||
}
|
||||
|
||||
yield put(scheduleLoadSuccess(load));
|
||||
} catch (error) {
|
||||
//console.log("Error in sendEmailFailure saga.", error.message);
|
||||
|
||||
Reference in New Issue
Block a user