Added predictive completion time based on cycle times for job scheduling. BOD-401

This commit is contained in:
Patrick Fic
2020-09-17 14:28:48 -07:00
parent 88559e95a3
commit cb337b557c
19 changed files with 572 additions and 101 deletions

View File

@@ -3873,6 +3873,27 @@
</concept_node>
</children>
</folder_node>
<concept_node>
<name>target_touchtime</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>zip_post</name>
<definition_loaded>false</definition_loaded>

View File

@@ -26,6 +26,7 @@ const FormDatePicker = ({ value, onChange, onBlur, ...restProps }, ref) => {
value={value ? moment(value) : null}
onChange={handleChange}
format={dateFormat}
onBlur={onBlur}
{...restProps}
/>
</div>

View File

@@ -15,13 +15,14 @@ const DateTimePicker = ({ value, onChange, onBlur }, ref) => {
return (
<div>
<FormDatePicker value={value} onChange={onChange} />
<FormDatePicker value={value} onBlur={onBlur} onChange={onChange} />
<TimePicker
value={value ? moment(value) : null}
onChange={onChange}
showSecond={false}
minuteStep={15}
onBlur={onBlur}
format="hh:mm a"
/>
</div>

View File

@@ -1,29 +1,43 @@
import { Button, Checkbox, Col, Row } from "antd";
import { Button, Col, Form, Row, Switch } from "antd";
import axios from "axios";
import moment from "moment";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { DateFormatter } from "../../utils/DateFormatter";
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component";
import EmailInput from "../form-items-formatted/email-form-item.component";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
import ScheduleDayViewContainer from "../schedule-day-view/schedule-day-view.container";
import ScheduleExistingAppointmentsList from "../schedule-existing-appointments-list/schedule-existing-appointments-list.component";
export default function ScheduleJobModalComponent({
jobId,
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function ScheduleJobModalComponent({
bodyshop,
form,
existingAppointments,
appData,
setAppData,
lbrHrsData,
jobId,
}) {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const [smartOptions, setSmartOptions] = useState([]);
const handleAuto = async () => {
setLoading(true);
try {
const response = await axios.post("/scheduling/job", {
jobId: "661dd1d5-bf06-426f-8bd2-bd9e41de8eb1",
jobId: jobId,
});
setAppData({ ...appData, smartDates: response.data });
if (response.data) setSmartOptions(response.data);
} catch (error) {
console.log("error", error, error.message);
} finally {
@@ -34,60 +48,100 @@ export default function ScheduleJobModalComponent({
//TODO Existing appointments list only refreshes sometimes after modal close. May have to do with the container class.
return (
<Row gutter={[32, 32]}>
<Col span={14}>
<div className="imex-flex-row imex-flex-row__flex-space-around">
<strong>{t("appointments.fields.time")}</strong>
<DateTimePicker
value={appData.start}
onChange={(e) => {
setAppData({ ...appData, start: e });
}}
/>
<Col span={12}>
<LayoutFormRow grow>
<Form.Item
name={"start"}
label={t("appointments.fields.time")}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<DateTimePicker
onBlur={() => {
const values = form.getFieldsValue();
if (lbrHrsData) {
const totalHours =
lbrHrsData.jobs_by_pk.labhrs.aggregate.sum.mod_lb_hrs +
lbrHrsData.jobs_by_pk.larhrs.aggregate.sum.mod_lb_hrs;
if (values.start && !values.scheduled_completion)
form.setFieldsValue({
scheduled_completion: moment(values.start).businessAdd(
totalHours / bodyshop.target_touchtime,
"days"
),
});
}
}}
/>
</Form.Item>
<Button onClick={handleAuto} loading={loading}>
{t("appointments.actions.smartscheduling")}
</Button>
</div>
<div className="imex-flex-row imex-flex-row__flex-space-around">
{appData.smartDates.map((d, idx) => (
<Button
className="imex-flex-row__margin"
key={idx}
onClick={() => {
setAppData({
...appData,
start: new moment(d).add(8, "hours"),
});
}}
>
<DateFormatter>{d}</DateFormatter>
</Button>
))}
</div>
<div className="imex-flex-row imex-flex-row__flex-space-around">
{smartOptions.map((d, idx) => (
<Button
className="imex-flex-row__margin"
key={idx}
onClick={() => {
form.setFieldsValue({ start: new moment(d).add(8, "hours") });
}}
>
<DateFormatter>{d}</DateFormatter>
</Button>
))}
</div>
</LayoutFormRow>
<LayoutFormRow grow>
<Form.Item
name={"scheduled_completion"}
label={t("jobs.fields.scheduled_completion")}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<DateTimePicker />
</Form.Item>
<Form.Item
name={"notifyCustomer"}
valuePropName="checked"
label={t("jobs.labels.appointmentconfirmation")}
>
<Switch />
</Form.Item>
<Form.Item name={"email"} label={t("jobs.fields.ownr_ea")}>
<EmailInput />
</Form.Item>
</LayoutFormRow>
{t("appointments.labels.history")}
<ScheduleExistingAppointmentsList
existingAppointments={existingAppointments}
/>
<Checkbox
defaultChecked={appData.notifyCustomer}
onChange={(e) =>
setAppData({ ...appData, notifyCustomer: e.target.checked })
}
>
{t("jobs.labels.appointmentconfirmation")}
</Checkbox>
<EmailInput
defaultValue={appData.email}
title={t("owner.fields.ownr_ea")}
onChange={(e) => setAppData({ ...appData, email: e.target.value })}
/>
</Col>
<Col span={10}>
<div style={{ height: "70vh" }}>
<ScheduleDayViewContainer day={appData.start} />
</div>
<Col span={12}>
<Form.Item shouldUpdate>
{() => {
const values = form.getFieldsValue();
return (
<div style={{ height: "70vh" }}>
<ScheduleDayViewContainer day={values.start} />
</div>
);
}}
</Form.Item>
</Col>
</Row>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(ScheduleJobModalComponent);

View File

@@ -1,23 +1,24 @@
import React, { useState, useEffect } from "react";
import ScheduleJobModalComponent from "./schedule-job-modal.component";
import { useMutation, useQuery } from "@apollo/react-hooks";
import {
INSERT_APPOINTMENT,
CANCEL_APPOINTMENT_BY_ID,
QUERY_APPOINTMENTS_BY_JOBID,
} from "../../graphql/appointments.queries";
import moment from "moment";
import { notification, Modal } from "antd";
//import moment from "moment";
import { Form, Modal, notification } from "antd";
import moment from "moment-business-days";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { UPDATE_JOBS } from "../../graphql/jobs.queries";
import { setEmailOptions } from "../../redux/email/email.actions";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { selectSchedule } from "../../redux/modals/modals.selectors";
import { toggleModalVisible } from "../../redux/modals/modals.actions";
import { TemplateList } from "../../utils/TemplateConstants";
import { logImEXEvent } from "../../firebase/firebase.utils";
import {
CANCEL_APPOINTMENT_BY_ID,
INSERT_APPOINTMENT,
QUERY_APPOINTMENTS_BY_JOBID,
} from "../../graphql/appointments.queries";
import { QUERY_LBR_HRS_BY_PK, UPDATE_JOBS } from "../../graphql/jobs.queries";
import { setEmailOptions } from "../../redux/email/email.actions";
import { toggleModalVisible } from "../../redux/modals/modals.actions";
import { selectSchedule } from "../../redux/modals/modals.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { TemplateList } from "../../utils/TemplateConstants";
import ScheduleJobModalComponent from "./schedule-job-modal.component";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -36,26 +37,23 @@ export function ScheduleJobModalContainer({
}) {
const { visible, context, actions } = scheduleModal;
const { jobId, job, previousEvent } = context;
const { refetch } = actions;
const [loading, setLoading] = useState(false);
const [appData, setAppData] = useState({
notifyCustomer: !!(job && job.ownr_ea),
email: (job && job.ownr_ea) || "",
start: null,
smartDates: [],
const [form] = Form.useForm();
const { data: lbrHrsData } = useQuery(QUERY_LBR_HRS_BY_PK, {
variables: { id: job && job.id },
skip: !job || !job.id,
});
const [loading, setLoading] = useState(false);
const [cancelAppointment] = useMutation(CANCEL_APPOINTMENT_BY_ID);
const [insertAppointment] = useMutation(INSERT_APPOINTMENT);
const [updateJobStatus] = useMutation(UPDATE_JOBS);
useEffect(() => {
setAppData({
notifyCustomer: !!(job && job.ownr_ea),
email: (job && job.ownr_ea) || "",
start: null,
smartDates: [],
});
}, [job, setAppData]);
form.resetFields();
}, [job, form]);
const { t } = useTranslation();
@@ -65,7 +63,7 @@ export function ScheduleJobModalContainer({
skip: !visible || !!!jobId,
});
const handleOk = async () => {
const handleFinish = async (values) => {
logImEXEvent("schedule_new_appointment");
setLoading(true);
@@ -90,11 +88,10 @@ export function ScheduleJobModalContainer({
const appt = await insertAppointment({
variables: {
app: {
//...appData,
jobid: jobId,
bodyshopid: bodyshop.id,
start: moment(appData.start),
end: moment(appData.start).add(bodyshop.appt_length || 60, "minutes"),
start: moment(values.start),
end: moment(values.start).add(bodyshop.appt_length || 60, "minutes"),
},
},
});
@@ -117,7 +114,8 @@ export function ScheduleJobModalContainer({
fields: {
status: bodyshop.md_ro_statuses.default_scheduled,
date_scheduled: new Date(),
scheduled_in: appData.start,
scheduled_in: values.start,
scheduled_completion: values.scheduled_completion,
},
},
});
@@ -133,10 +131,10 @@ export function ScheduleJobModalContainer({
}
setLoading(false);
toggleModalVisible();
if (appData.notifyCustomer) {
if (values.notifyCustomer) {
setEmailOptions({
messageOptions: {
to: [appData.email],
to: [values.email],
replyTo: bodyshop.email,
},
template: {
@@ -154,21 +152,34 @@ export function ScheduleJobModalContainer({
<Modal
visible={visible}
onCancel={() => toggleModalVisible()}
onOk={handleOk}
onOk={() => form.submit()}
width={"90%"}
maskClosable={false}
destroyOnClose
forceRender
okButtonProps={{
disabled: appData.start ? false : true,
loading: loading,
}}
>
<ScheduleJobModalComponent
jobId={jobId}
existingAppointments={existingAppointments}
appData={appData}
setAppData={setAppData}
/>
<Form
form={form}
layout="vertical"
onFinish={handleFinish}
initialValues={{
notifyCustomer: !!(job && job.ownr_ea),
email: (job && job.ownr_ea) || "",
start: null,
// smartDates: [],
scheduled_completion: null,
}}
>
<ScheduleJobModalComponent
existingAppointments={existingAppointments}
lbrHrsData={lbrHrsData}
form={form}
jobId={jobId}
/>
</Form>
</Modal>
);
}

View File

@@ -27,25 +27,65 @@ export default function ShopInfoComponent({ form, saveLoading }) {
const { t } = useTranslation();
return (
<div>
<Button type="primary" loading={saveLoading} htmlType="submit">
<Button
type="primary"
loading={saveLoading}
onClick={() => form.submit()}
>
{t("general.actions.save")}
</Button>
<Collapse>
<Collapse.Panel key="shopinfo" header={t("bodyshop.labels.shopinfo")}>
<LayoutFormRow>
<Form.Item label={t("bodyshop.fields.shopname")} name="shopname">
<Form.Item
label={t("bodyshop.fields.shopname")}
name="shopname"
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<Input />
</Form.Item>
<Form.Item label={t("bodyshop.fields.address1")} name="address1">
<Form.Item
label={t("bodyshop.fields.address1")}
name="address1"
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<Input />
</Form.Item>
<Form.Item label={t("bodyshop.fields.address2")} name="address2">
<Input />
</Form.Item>
<Form.Item label={t("bodyshop.fields.city")} name="city">
<Form.Item
label={t("bodyshop.fields.city")}
name="city"
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<Input />
</Form.Item>
<Form.Item label={t("bodyshop.fields.state")} name="state">
<Form.Item
label={t("bodyshop.fields.state")}
name="state"
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<Input />
</Form.Item>
<Form.Item label={t("bodyshop.fields.zip_post")} name="zip_post">
@@ -65,6 +105,12 @@ export default function ShopInfoComponent({ form, saveLoading }) {
<Form.Item
label={t("bodyshop.fields.federal_tax_id")}
name="federal_tax_id"
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<Input />
</Form.Item>
@@ -91,18 +137,36 @@ export default function ShopInfoComponent({ form, saveLoading }) {
<Form.Item
label={t("bodyshop.fields.invoice_federal_tax_rate")}
name={["invoice_tax_rates", "federal_tax_rate"]}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<InputNumber />
</Form.Item>
<Form.Item
label={t("bodyshop.fields.invoice_state_tax_rate")}
name={["invoice_tax_rates", "state_tax_rate"]}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<InputNumber />
</Form.Item>
<Form.Item
label={t("bodyshop.fields.invoice_local_tax_rate")}
name={["invoice_tax_rates", "local_tax_rate"]}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<InputNumber />
</Form.Item>
@@ -467,6 +531,18 @@ export default function ShopInfoComponent({ form, saveLoading }) {
>
<Switch />
</Form.Item>
<Form.Item
name={["target_touchtime"]}
label={t("bodyshop.fields.target_touchtime")}
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}
>
<InputNumber min={0.1} precision={1} />
</Form.Item>
</Collapse.Panel>
<Collapse.Panel
key="speedprint"

View File

@@ -69,6 +69,7 @@ export const QUERY_BODYSHOP = gql`
enforce_class
md_labor_rates
deliverchecklist
target_touchtime
employees {
id
first_name
@@ -136,6 +137,7 @@ export const UPDATE_SHOP = gql`
enforce_class
md_labor_rates
deliverchecklist
target_touchtime
employees {
id
first_name

View File

@@ -121,6 +121,28 @@ export const SUBSCRIPTION_JOBS_IN_PRODUCTION = gql`
}
`;
export const QUERY_LBR_HRS_BY_PK = gql`
query QUERY_LBR_HRS_BY_PK($id: uuid!) {
jobs_by_pk(id: $id) {
id
labhrs: joblines_aggregate(where: { mod_lbr_ty: { _eq: "LAB" } }) {
aggregate {
sum {
mod_lb_hrs
}
}
}
larhrs: joblines_aggregate(where: { mod_lbr_ty: { _eq: "LAR" } }) {
aggregate {
sum {
mod_lb_hrs
}
}
}
}
}
`;
export const QUERY_JOB_COSTING_DETAILS = gql`
query QUERY_JOB_COSTING_DETAILS($id: uuid!) {
jobs_by_pk(id: $id) {

View File

@@ -254,6 +254,7 @@
"pre_production_statuses": "Pre-Production Statuses",
"production_statuses": "Production Statuses"
},
"target_touchtime": "Target Touch Time",
"zip_post": "Zip/Postal Code"
},
"labels": {

View File

@@ -254,6 +254,7 @@
"pre_production_statuses": "",
"production_statuses": ""
},
"target_touchtime": "",
"zip_post": ""
},
"labels": {

View File

@@ -254,6 +254,7 @@
"pre_production_statuses": "",
"production_statuses": ""
},
"target_touchtime": "",
"zip_post": ""
},
"labels": {

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "target_touchtime";
type: run_sql

View File

@@ -0,0 +1,6 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "target_touchtime" numeric NULL
DEFAULT 3.5;
type: run_sql

View File

@@ -0,0 +1,69 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- accountingconfig
- address1
- address2
- appt_length
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- invoice_tax_rates
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- messagingservicesid
- phone
- prodtargethrs
- production_config
- region_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- stripe_acct_id
- template_header
- textid
- updated_at
- zip_post
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,70 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- accountingconfig
- address1
- address2
- appt_length
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- invoice_tax_rates
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- messagingservicesid
- phone
- prodtargethrs
- production_config
- region_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- stripe_acct_id
- target_touchtime
- template_header
- textid
- updated_at
- zip_post
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,63 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- accountingconfig
- address1
- address2
- appt_length
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- invoice_tax_rates
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- phone
- prodtargethrs
- production_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- updated_at
- zip_post
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission

View File

@@ -0,0 +1,64 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- accountingconfig
- address1
- address2
- appt_length
- city
- country
- created_at
- deliverchecklist
- email
- enforce_class
- federal_tax_id
- id
- inhousevendorid
- insurance_vendor_id
- intakechecklist
- invoice_tax_rates
- logo_img_path
- md_categories
- md_classes
- md_ins_cos
- md_labor_rates
- md_messaging_presets
- md_notes_presets
- md_order_statuses
- md_parts_locations
- md_rbac
- md_referral_sources
- md_responsibility_centers
- md_ro_statuses
- phone
- prodtargethrs
- production_config
- scoreboard_target
- shopname
- shoprates
- speedprint
- ssbuckets
- state
- state_tax_id
- target_touchtime
- updated_at
- zip_post
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission

View File

@@ -510,6 +510,7 @@ tables:
- state
- state_tax_id
- stripe_acct_id
- target_touchtime
- template_header
- textid
- updated_at
@@ -564,6 +565,7 @@ tables:
- ssbuckets
- state
- state_tax_id
- target_touchtime
- updated_at
- zip_post
filter:

View File

@@ -15,6 +15,7 @@ exports.job = async (req, res) => {
try {
const BearerToken = req.headers.authorization;
const { jobId } = req.body;
console.log("exports.job -> jobId", jobId)
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
headers: {