IO-1605 Refactor smart scheduling.
This commit is contained in:
@@ -10,13 +10,17 @@ import Event from "../job-at-change/schedule-event.container";
|
||||
import HeaderComponent from "./schedule-calendar-header.component";
|
||||
import "./schedule-calendar.styles.scss";
|
||||
import JobDetailCards from "../job-detail-cards/job-detail-cards.component";
|
||||
import { selectProblemJobs } from "../../redux/application/application.selectors";
|
||||
import { Alert } from "antd";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
problemJobs: selectProblemJobs,
|
||||
});
|
||||
const localizer = momentLocalizer(moment);
|
||||
export function ScheduleCalendarWrapperComponent({
|
||||
bodyshop,
|
||||
problemJobs,
|
||||
data,
|
||||
refetch,
|
||||
defaultView,
|
||||
@@ -48,6 +52,15 @@ export function ScheduleCalendarWrapperComponent({
|
||||
return (
|
||||
<>
|
||||
<JobDetailCards />
|
||||
{problemJobs &&
|
||||
problemJobs.map((problem) => (
|
||||
<Alert
|
||||
key={problem.id}
|
||||
type="error"
|
||||
message={`${problem.ro_number} has a data consistency issue. It has been exlcuded for scheduling purposes. CODE: ${problem.code}`}
|
||||
/>
|
||||
))}
|
||||
|
||||
<Calendar
|
||||
events={data}
|
||||
defaultView={search.view || defaultView || "week"}
|
||||
|
||||
@@ -5,6 +5,7 @@ import ScheduleCalendarWrapperComponent from "../schedule-calendar-wrapper/sched
|
||||
import ScheduleModal from "../schedule-job-modal/schedule-job-modal.container";
|
||||
//import ScheduleManualEvent from "../schedule-manual-event/schedule-manual-event.component";
|
||||
import ScheduleProductionList from "../schedule-production-list/schedule-production-list.component";
|
||||
import ScheduleVerifyIntegrity from "../schedule-verify-integrity/schedule-verify-integrity.component";
|
||||
|
||||
export default function ScheduleCalendarComponent({ data, refetch }) {
|
||||
return (
|
||||
@@ -15,6 +16,7 @@ export default function ScheduleCalendarComponent({ data, refetch }) {
|
||||
<PageHeader
|
||||
extra={
|
||||
<Space wrap>
|
||||
<ScheduleVerifyIntegrity />
|
||||
<Button
|
||||
onClick={() => {
|
||||
refetch();
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useApolloClient } from "@apollo/client";
|
||||
import { Button } from "antd";
|
||||
import moment from "moment";
|
||||
import React, { useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_SCHEDULE_LOAD_DATA } from "../../graphql/appointments.queries";
|
||||
import { selectCurrentUser } from "../../redux/user/user.selectors";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(ScheduleVerifyIntegrity);
|
||||
|
||||
export function ScheduleVerifyIntegrity({ currentUser }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const client = useApolloClient();
|
||||
const handleVerify = async () => {
|
||||
setLoading(true);
|
||||
const {
|
||||
data: { arrJobs, compJobs, prodJobs },
|
||||
} = await client.query({
|
||||
query: QUERY_SCHEDULE_LOAD_DATA,
|
||||
variables: { start: moment(), end: moment().add(180, "days") },
|
||||
});
|
||||
|
||||
//check that the leaving jobs are either in the arriving list, or in production.
|
||||
const issues = [];
|
||||
|
||||
compJobs.forEach((j) => {
|
||||
const inProdJobs = prodJobs.find((p) => p.id === j.id);
|
||||
const inArrJobs = arrJobs.find((p) => p.id === j.id);
|
||||
|
||||
if (!(inProdJobs || inArrJobs)) {
|
||||
// NOT FOUND!
|
||||
issues.push(j);
|
||||
}
|
||||
});
|
||||
console.log(
|
||||
"The following completing jobs are not in production, or are arriving within the next 180 days. ",
|
||||
issues
|
||||
);
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
if (currentUser.email === "patrick@imex.prod")
|
||||
return (
|
||||
<Button loading={loading} onClick={handleVerify}>
|
||||
Developer Use Only - Verify Schedule Integrity
|
||||
</Button>
|
||||
);
|
||||
else return null;
|
||||
}
|
||||
@@ -234,11 +234,17 @@ export const QUERY_SCHEDULE_LOAD_DATA = gql`
|
||||
}
|
||||
}
|
||||
compJobs: jobs(
|
||||
where: { scheduled_completion: { _gte: $start, _lte: $end } }
|
||||
where: {
|
||||
_or: [
|
||||
{ scheduled_completion: { _gte: $start, _lte: $end } }
|
||||
{ actual_completion: { _gte: $start, _lte: $end } }
|
||||
]
|
||||
}
|
||||
) {
|
||||
id
|
||||
ro_number
|
||||
scheduled_completion
|
||||
actual_completion
|
||||
labhrs: joblines_aggregate(
|
||||
where: { mod_lbr_ty: { _neq: "LAR" }, removed: { _eq: false } }
|
||||
) {
|
||||
|
||||
@@ -58,3 +58,7 @@ export const insertAuditTrail = ({ jobid, billid, operation }) => ({
|
||||
type: ApplicationActionTypes.INSERT_AUDIT_TRAIL,
|
||||
payload: { jobid, billid, operation },
|
||||
});
|
||||
export const setProblemJobs = (problemJobs) => ({
|
||||
type: ApplicationActionTypes.SET_PROBLEM_JOBS,
|
||||
payload: problemJobs,
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ const INITIAL_STATE = {
|
||||
breadcrumbs: [],
|
||||
recentItems: [],
|
||||
selectedHeader: "home",
|
||||
problemJobs: [],
|
||||
scheduleLoad: {
|
||||
load: {},
|
||||
calculating: false,
|
||||
@@ -40,6 +41,7 @@ const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
case ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD:
|
||||
return {
|
||||
...state,
|
||||
problemJobs: [],
|
||||
scheduleLoad: { ...state.scheduleLoad, calculating: true, error: null },
|
||||
};
|
||||
case ApplicationActionTypes.CALCULATE_SCHEDULE_LOAD_SUCCESS:
|
||||
@@ -76,7 +78,9 @@ const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
|
||||
case ApplicationActionTypes.SET_PARTNER_VERSION:
|
||||
return { ...state, partnerVersion: action.payload };
|
||||
|
||||
case ApplicationActionTypes.SET_PROBLEM_JOBS: {
|
||||
return { ...state, problemJobs: action.payload };
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CalculateLoad, CheckJobBucket } from "../../utils/SSSUtils";
|
||||
import {
|
||||
scheduleLoadFailure,
|
||||
scheduleLoadSuccess,
|
||||
setProblemJobs,
|
||||
} from "./application.actions";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
|
||||
@@ -53,6 +54,8 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
});
|
||||
|
||||
arrJobs.forEach((item) => {
|
||||
if (!item.scheduled_in)
|
||||
console.log("JOB HAS NO SCHEDULED IN DATE.", item);
|
||||
const itemDate = moment(item.scheduled_in).format("yyyy-MM-DD");
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursIn =
|
||||
@@ -71,7 +74,26 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
}
|
||||
});
|
||||
|
||||
let problemJobs = [];
|
||||
compJobs.forEach((item) => {
|
||||
if (!item.scheduled_completion)
|
||||
console.log("JOB HAS NO SCHEDULED COMPLETION DATE.", item);
|
||||
|
||||
const inProdJobs = prodJobs.find((p) => p.id === item.id);
|
||||
const inArrJobs = arrJobs.find((p) => p.id === item.id);
|
||||
|
||||
if (
|
||||
!(inProdJobs || inArrJobs) &&
|
||||
!moment(item.scheduled_completion).isSame(moment(), "day")
|
||||
) {
|
||||
// NOT FOUND!
|
||||
problemJobs.push({
|
||||
...item,
|
||||
code: "Job is scheduled for completion, but it is not marked in production nor is it an arriving job in this period. Check the scheduled in and completion dates",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const itemDate = moment(item.scheduled_completion).format("yyyy-MM-DD");
|
||||
if (!!load[itemDate]) {
|
||||
load[itemDate].hoursOut =
|
||||
@@ -116,7 +138,7 @@ export function* calculateScheduleLoad({ payload: end }) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
yield put(setProblemJobs(problemJobs));
|
||||
yield put(scheduleLoadSuccess(load));
|
||||
} catch (error) {
|
||||
yield put(scheduleLoadFailure(error));
|
||||
|
||||
@@ -44,3 +44,7 @@ export const selectOnline = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.online
|
||||
);
|
||||
export const selectProblemJobs = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.problemJobs
|
||||
);
|
||||
|
||||
@@ -11,5 +11,6 @@ const ApplicationActionTypes = {
|
||||
SET_PARTNER_VERSION: "SET_PARTNER_VERSION",
|
||||
SET_ONLINE_STATUS: "SET_ONLINE_STATUS",
|
||||
INSERT_AUDIT_TRAIL: "INSERT_AUDIT_TRAIL",
|
||||
SET_PROBLEM_JOBS: "SET_PROBLEM_JOBS",
|
||||
};
|
||||
export default ApplicationActionTypes;
|
||||
|
||||
@@ -30,6 +30,9 @@ export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
|
||||
const bucketId = CheckJobBucket(buckets, job);
|
||||
if (bucketId) {
|
||||
newLoad[bucketId].count = newLoad[bucketId].count - 1;
|
||||
if (newLoad[bucketId].count < 0) {
|
||||
console.log("***ERROR: NEGATIVE LOAD", bucketId, job);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
"[Util Out Job]Uh oh, this job doesn't fit in a bucket!",
|
||||
|
||||
Reference in New Issue
Block a user