BOD-84 Added base calculations for schedule load
This commit is contained in:
@@ -12,4 +12,9 @@ export const endLoading = (options) => ({
|
||||
export const setBreadcrumbs = (breadcrumbs) => ({
|
||||
type: ApplicationActionTypes.SET_BREAD_CRUMBS,
|
||||
payload: breadcrumbs,
|
||||
});
|
||||
});
|
||||
|
||||
export const calculateScheduleLoad = (rangeEnd) => ({
|
||||
type: ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD,
|
||||
payload: rangeEnd,
|
||||
});
|
||||
|
||||
@@ -3,10 +3,43 @@ import ApplicationActionTypes from "./application.types";
|
||||
const INITIAL_STATE = {
|
||||
loading: false,
|
||||
breadcrumbs: [],
|
||||
scheduleLoad: {
|
||||
load: [],
|
||||
calculating: false,
|
||||
error: null,
|
||||
},
|
||||
};
|
||||
|
||||
const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ApplicationActionTypes.SET_BREAD_CRUMBS:
|
||||
return {
|
||||
...state,
|
||||
breadcrumbs: action.payload,
|
||||
};
|
||||
case ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD:
|
||||
return {
|
||||
...state,
|
||||
scheduleLoad: { ...state.scheduleLoad, calculating: true, error: null },
|
||||
};
|
||||
case ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
scheduleLoad: {
|
||||
...state.scheduleLoad,
|
||||
load: action.payload,
|
||||
calculating: false,
|
||||
},
|
||||
};
|
||||
case ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
scheduleLoad: {
|
||||
...state.scheduleLoad,
|
||||
calculating: false,
|
||||
error: action.payload,
|
||||
},
|
||||
};
|
||||
case ApplicationActionTypes.START_LOADING:
|
||||
return {
|
||||
...state,
|
||||
@@ -17,11 +50,7 @@ const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
...state,
|
||||
loading: false,
|
||||
};
|
||||
case ApplicationActionTypes.SET_BREAD_CRUMBS:
|
||||
return {
|
||||
...state,
|
||||
breadcrumbs: action.payload,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -11,3 +11,13 @@ export const selectBreadcrumbs = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.breadcrumbs
|
||||
);
|
||||
|
||||
export const selectScheduleLoad = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.scheduleLoad.load
|
||||
);
|
||||
|
||||
export const selectScheduleLoadCalculating = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.scheduleLoad.calculating
|
||||
);
|
||||
|
||||
@@ -2,5 +2,8 @@ const ApplicationActionTypes = {
|
||||
START_LOADING: "START_LOADING",
|
||||
END_LOADING: "END_LOADING",
|
||||
SET_BREAD_CRUMBS: "SET_BREAD_CRUMBS",
|
||||
CALCULATE_SCHEDULE_LOAD: "CALCULATE_SCHEDULE_LOAD",
|
||||
CALCULATE_SCHEDULE_LOAD_SUCCESS: "CALCULATE_SCHEDULE_LOAD_SUCCESS",
|
||||
CALCULATE_SCHEDULE_LOAD_FAILURE: "CALCULATE_SCHEDULE_LOAD_FAILURE",
|
||||
};
|
||||
export default ApplicationActionTypes;
|
||||
|
||||
Reference in New Issue
Block a user