BOD-84 Load calculates for this week. Bug exists going past current week.
This commit is contained in:
@@ -18,3 +18,13 @@ export const calculateScheduleLoad = (rangeEnd) => ({
|
||||
type: ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD,
|
||||
payload: rangeEnd,
|
||||
});
|
||||
|
||||
export const scheduleLoadSuccess = (load) => ({
|
||||
type: ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD_SUCCESS,
|
||||
payload: load,
|
||||
});
|
||||
|
||||
export const scheduleLoadFailure = (error) => ({
|
||||
type: ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD_FAILURE,
|
||||
payload: error,
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ const INITIAL_STATE = {
|
||||
loading: false,
|
||||
breadcrumbs: [],
|
||||
scheduleLoad: {
|
||||
load: [],
|
||||
load: {},
|
||||
calculating: false,
|
||||
error: null,
|
||||
},
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { all, takeLatest, call } from "redux-saga/effects";
|
||||
import { all, takeLatest, call, put } from "redux-saga/effects";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
import { client } from "../../App/App.container";
|
||||
import { QUERY_SCHEDULE_LOAD_DATA } from "../../graphql/appointments.queries";
|
||||
import {
|
||||
scheduleLoadFailure,
|
||||
scheduleLoadSuccess,
|
||||
} from "./application.actions";
|
||||
import moment from "moment";
|
||||
|
||||
export function* onCalculateScheduleLoad() {
|
||||
@@ -11,6 +15,7 @@ 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");
|
||||
try {
|
||||
const result = yield client.query({
|
||||
@@ -21,21 +26,12 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
},
|
||||
});
|
||||
|
||||
const productionHoursTotal =
|
||||
result.data.productionview_aggregate.aggregate.sum.larhrs +
|
||||
result.data.productionview_aggregate.aggregate.sum.labhrs;
|
||||
let load = {
|
||||
productionHoursTotal:
|
||||
result.data.productionview_aggregate.aggregate.sum.larhrs +
|
||||
result.data.productionview_aggregate.aggregate.sum.labhrs,
|
||||
};
|
||||
|
||||
const range = Math.round(moment.duration(end.diff(today)).asDays());
|
||||
let load = {};
|
||||
|
||||
//Start from today and go until the range.
|
||||
// for (var day = 0; day < range; day++) {
|
||||
// let workingDate = today.add(day, "days");
|
||||
// console.log(
|
||||
// "function*calculateScheduleLoad -> workingDate",
|
||||
// workingDate.toLocaleString()
|
||||
// );
|
||||
// }
|
||||
const { arrJobs, compJobs } = result.data;
|
||||
|
||||
arrJobs.forEach((item) => {
|
||||
@@ -45,8 +41,11 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
(load[itemDate].hoursIn || 0) +
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs;
|
||||
load[itemDate].jobsIn.push(item);
|
||||
} else {
|
||||
load[itemDate] = {
|
||||
jobsIn: [],
|
||||
jobsOut: [],
|
||||
hoursIn:
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs,
|
||||
@@ -63,6 +62,7 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
(load[itemDate].hoursOut || 0) +
|
||||
item.labhrs.aggregate.sum.mod_lb_hrs +
|
||||
item.larhrs.aggregate.sum.mod_lb_hrs;
|
||||
load[itemDate].jobsOut.push(item);
|
||||
} else {
|
||||
load[itemDate] = {
|
||||
hoursOut:
|
||||
@@ -72,10 +72,43 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
}
|
||||
});
|
||||
|
||||
console.log("load", load);
|
||||
//Propagate the expected load to each day.
|
||||
const range = Math.round(moment.duration(end.diff(today)).asDays());
|
||||
for (var day = 0; day < range; day++) {
|
||||
console.log(
|
||||
"function*calculateScheduleLoad -> today",
|
||||
today.toISOString()
|
||||
);
|
||||
const current = moment(today)
|
||||
.add(day, "days")
|
||||
.toISOString()
|
||||
.substr(0, 10);
|
||||
console.log(
|
||||
"function*calculateScheduleLoad -> today",
|
||||
today.toISOString()
|
||||
);
|
||||
console.log("function*calculateScheduleLoad -> current", current);
|
||||
const prev = moment(today)
|
||||
.add(day - 1, "days")
|
||||
.toISOString()
|
||||
.substr(0, 10);
|
||||
console.log("function*calculateScheduleLoad -> prev", prev);
|
||||
if (day === 0) {
|
||||
//Starting on day 1. The load is current.
|
||||
load[current].expectedLoad = load.productionHoursTotal;
|
||||
} else {
|
||||
load[current].expectedLoad =
|
||||
load[prev].expectedLoad +
|
||||
(load[current].hoursIn || 0) -
|
||||
(load[current].hoursOut || 0);
|
||||
}
|
||||
}
|
||||
|
||||
yield put(scheduleLoadSuccess(load));
|
||||
} catch (error) {
|
||||
//console.log("Error in sendEmailFailure saga.", error.message);
|
||||
console.log("error", error);
|
||||
yield put(scheduleLoadFailure(error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user