BOD-84 Added base calculations for schedule load

This commit is contained in:
Patrick Fic
2020-05-08 15:33:08 -07:00
parent 3d74a4106e
commit 6096fce7a6
17 changed files with 456 additions and 122 deletions

View File

@@ -1,47 +1,87 @@
import { all } from "redux-saga/effects";
import { all, takeLatest, call } 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 moment from "moment";
// export function* onSendEmail() {
// yield takeLatest(EmailActionTypes.SEND_EMAIL, sendEmail);
// }
// export function* sendEmail(payload) {
// try {
// console.log("Sending thta email", payload);
// axios.post("/sendemail", payload).then(response => {
// console.log(JSON.stringify(response));
// put(sendEmailSuccess());
// });
// } catch (error) {
// console.log("Error in sendEmail saga.");
// yield put(sendEmailFailure(error.message));
// }
// }
export function* onCalculateScheduleLoad() {
yield takeLatest(
ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD,
calculateScheduleLoad
);
}
export function* calculateScheduleLoad({ payload: end }) {
const today = moment(new Date()).startOf("day");
try {
const result = yield client.query({
query: QUERY_SCHEDULE_LOAD_DATA,
variables: {
start: today,
end: end,
},
});
// export function* onSendEmailSuccess() {
// yield takeLatest(EmailActionTypes.SEND_EMAIL_SUCCESS, sendEmailSuccessSaga);
// }
// export function* sendEmailSuccessSaga() {
// try {
// console.log("Send email success.");
// } catch (error) {
// console.log("Error in sendEmailSuccess saga.");
// yield put(sendEmailFailure(error.message));
// }
// }
const productionHoursTotal =
result.data.productionview_aggregate.aggregate.sum.larhrs +
result.data.productionview_aggregate.aggregate.sum.labhrs;
// export function* onRenderTemplate() {
// yield takeLatest(ApplicationActionTypes.RENDER_TEMPLATE, renderTemplate);
// }
// export function* renderTemplate({ payload: template }) {
// try {
// yield console.log("Render Template Saga => template", template);
// } catch (error) {
// console.log("Error in sendEmailFailure saga.", error.message);
// }
// }
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) => {
const itemDate = moment(item.scheduled_in).toISOString().substr(0, 10);
if (!!load[itemDate]) {
load[itemDate].hoursIn =
(load[itemDate].hoursIn || 0) +
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs;
} else {
load[itemDate] = {
hoursIn:
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs,
};
}
});
compJobs.forEach((item) => {
const itemDate = moment(item.scheduled_completion)
.toISOString()
.substr(0, 10);
if (!!load[itemDate]) {
load[itemDate].hoursOut =
(load[itemDate].hoursOut || 0) +
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs;
} else {
load[itemDate] = {
hoursOut:
item.labhrs.aggregate.sum.mod_lb_hrs +
item.larhrs.aggregate.sum.mod_lb_hrs,
};
}
});
console.log("load", load);
} catch (error) {
//console.log("Error in sendEmailFailure saga.", error.message);
console.log("error", error);
}
}
export function* applicationSagas() {
yield all([
// call(onSendEmail),
call(onCalculateScheduleLoad),
// call(onSendEmailFailure),
// call(onSendEmailSuccess)
//call(onRenderTemplate),