- progress update.

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-01-25 15:23:42 -05:00
parent 80483b617b
commit 461bc726aa
2 changed files with 382 additions and 370 deletions

View File

@@ -51,12 +51,23 @@ const Eula = ({currentEula, currentUser, acceptEula}) => {
try { try {
const {accepted_terms, ...otherFormValues} = formValues; const {accepted_terms, ...otherFormValues} = formValues;
// Trim the values of the fields before submitting
const trimmedFormValues = {
first_name: otherFormValues.first_name.trim(),
last_name: otherFormValues.last_name.trim(),
business_name: otherFormValues.business_name.trim(),
address: otherFormValues.address.trim(),
phone_number: otherFormValues.phone_number.trim(),
};
await insertEulaAcceptance({ await insertEulaAcceptance({
variables: { variables: {
eulaAcceptance: { eulaAcceptance: {
eulaid: eulaId, eulaid: eulaId,
useremail, useremail,
...otherFormValues, ...otherFormValues,
...trimmedFormValues,
date_accepted: new Date(), date_accepted: new Date(),
} }
} }
@@ -101,7 +112,7 @@ const Eula = ({currentEula, currentUser, acceptEula}) => {
> >
<Card type='inner' className='eula-markdown-card' onScroll={handleScroll} ref={markdownCardRef}> <Card type='inner' className='eula-markdown-card' onScroll={handleScroll} ref={markdownCardRef}>
<div id='markdowndiv' className='eula-markdown-div'> <div id='markdowndiv' className='eula-markdown-div'>
<Markdown children={currentEula?.content?.replace(/\\n/g, '\n')}/> <Markdown children={currentEula?.content?.replace(/\\n|\\r|\\n\\r|\\r\\n/g, '\n')}/>
</div> </div>
</Card> </Card>

View File

@@ -1,13 +1,13 @@
import { useQuery } from "@apollo/client"; import {useQuery} from "@apollo/client";
import { Col, Row } from "antd"; import {Col, Row} from "antd";
import _ from "lodash"; import _ from "lodash";
import dayjs from "../../utils/day"; import dayjs from "../../utils/day";
import React, { useMemo } from "react"; import React, {useMemo} from "react";
import { useTranslation } from "react-i18next"; import {useTranslation} from "react-i18next";
import { connect } from "react-redux"; import {connect} from "react-redux";
import { createStructuredSelector } from "reselect"; import {createStructuredSelector} from "reselect";
import { QUERY_TIME_TICKETS_IN_RANGE_SB } from "../../graphql/timetickets.queries"; import {QUERY_TIME_TICKETS_IN_RANGE_SB} from "../../graphql/timetickets.queries";
import { selectBodyshop } from "../../redux/user/user.selectors"; import {selectBodyshop} from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component"; import AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import * as Utils from "../scoreboard-targets-table/scoreboard-targets-table.util"; import * as Utils from "../scoreboard-targets-table/scoreboard-targets-table.util";
@@ -16,396 +16,397 @@ import ScoreboardTicketsStats from "./scoreboard-timetickets.stats.component";
import ScoreboardTimeticketsTargetsTable from "./scoreboard-timetickets.targets-table.component"; import ScoreboardTimeticketsTargetsTable from "./scoreboard-timetickets.targets-table.component";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
}); });
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language)) //setUserLanguage: language => dispatch(setUserLanguage(language))
}); });
export default connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(ScoreboardTimeTicketsStats); )(ScoreboardTimeTicketsStats);
export function ScoreboardTimeTicketsStats({ bodyshop }) { export function ScoreboardTimeTicketsStats({bodyshop}) {
const { t } = useTranslation(); const {t} = useTranslation();
const startDate = dayjs().startOf("month") const startDate = dayjs().startOf("month")
const endDate = dayjs().endOf("month"); const endDate = dayjs().endOf("month");
const fixedPeriods = useMemo(() => { const fixedPeriods = useMemo(() => {
const endOfThisMonth = dayjs().endOf("month"); const endOfThisMonth = dayjs().endOf("month");
const startofthisMonth = dayjs().startOf("month"); const startofthisMonth = dayjs().startOf("month");
const endOfLastmonth = dayjs().subtract(1, "month").endOf("month"); const endOfLastmonth = dayjs().subtract(1, "month").endOf("month");
const startOfLastmonth = dayjs().subtract(1, "month").startOf("month"); const startOfLastmonth = dayjs().subtract(1, "month").startOf("month");
const endOfThisWeek = dayjs().endOf("week"); const endOfThisWeek = dayjs().endOf("week");
const startOfThisWeek = dayjs().startOf("week"); const startOfThisWeek = dayjs().startOf("week");
const endOfLastWeek = dayjs().subtract(1, "week").endOf("week"); const endOfLastWeek = dayjs().subtract(1, "week").endOf("week");
const startOfLastWeek = dayjs().subtract(1, "week").startOf("week"); const startOfLastWeek = dayjs().subtract(1, "week").startOf("week");
const endOfPriorWeek = dayjs().subtract(2, "week").endOf("week"); const endOfPriorWeek = dayjs().subtract(2, "week").endOf("week");
const startOfPriorWeek = dayjs().subtract(2, "week").startOf("week"); const startOfPriorWeek = dayjs().subtract(2, "week").startOf("week");
const allDates = [ const allDates = [
endOfThisMonth, endOfThisMonth,
startofthisMonth, startofthisMonth,
endOfLastmonth, endOfLastmonth,
startOfLastmonth, startOfLastmonth,
endOfThisWeek, endOfThisWeek,
startOfThisWeek, startOfThisWeek,
endOfLastWeek, endOfLastWeek,
startOfLastWeek, startOfLastWeek,
endOfPriorWeek, endOfPriorWeek,
startOfPriorWeek, startOfPriorWeek,
]; ];
const start = dayjs.min(allDates); const start = dayjs.min(allDates);
const end = dayjs.max(allDates); const end = dayjs.max(allDates);
return { return {
start, start,
end, end,
endOfThisMonth, endOfThisMonth,
startofthisMonth, startofthisMonth,
endOfLastmonth, endOfLastmonth,
startOfLastmonth, startOfLastmonth,
endOfThisWeek, endOfThisWeek,
startOfThisWeek, startOfThisWeek,
endOfLastWeek, endOfLastWeek,
startOfLastWeek, startOfLastWeek,
endOfPriorWeek, endOfPriorWeek,
startOfPriorWeek, startOfPriorWeek,
}; };
}, []); }, []);
const { loading, error, data } = useQuery(QUERY_TIME_TICKETS_IN_RANGE_SB, { const {loading, error, data} = useQuery(QUERY_TIME_TICKETS_IN_RANGE_SB, {
variables: { variables: {
start: startDate.format("YYYY-MM-DD"), start: startDate.format("YYYY-MM-DD"),
end: endDate.format("YYYY-MM-DD"), end: endDate.format("YYYY-MM-DD"),
fixedStart: fixedPeriods.start.format("YYYY-MM-DD"), fixedStart: fixedPeriods.start.format("YYYY-MM-DD"),
fixedEnd: fixedPeriods.end.format("YYYY-MM-DD"), fixedEnd: fixedPeriods.end.format("YYYY-MM-DD"),
jobStart: startDate, jobStart: startDate,
jobEnd: endDate, jobEnd: endDate,
},
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
pollInterval: 60000,
skip: !fixedPeriods,
});
const calculatedData = useMemo(() => {
if (!data) return [];
const ret = {
totalThisWeek: 0,
totalThisWeekLAB: 0,
totalThisWeekLAR: 0,
totalLastWeek: 0,
totalLastWeekLAB: 0,
totalLastWeekLAR: 0,
totalPriorWeek: 0,
totalPriorWeekLAB: 0,
totalPriorWeekLAR: 0,
totalThisMonth: 0,
totalThisMonthLAB: 0,
totalThisMonthLAR: 0,
totalLastMonth: 0,
totalLastMonthLAB: 0,
totalLastMonthLAR: 0,
actualTotalOverPeriod: 0,
actualTotalOverPeriodLAB: 0,
actualTotalOverPeriodLAR: 0,
totalEffieciencyOverPeriod: 0,
totalEffieciencyOverPeriodLAB: 0,
totalEffieciencyOverPeriodLAR: 0,
seperatedThisWeek: {
sunday: {
total: 0,
lab: 0,
lar: 0,
}, },
monday: { fetchPolicy: "network-only",
total: 0, nextFetchPolicy: "network-only",
lab: 0, pollInterval: 60000,
lar: 0, skip: !fixedPeriods,
},
tuesday: {
total: 0,
lab: 0,
lar: 0,
},
wednesday: {
total: 0,
lab: 0,
lar: 0,
},
thursday: {
total: 0,
lab: 0,
lar: 0,
},
friday: {
total: 0,
lab: 0,
lar: 0,
},
saturday: {
total: 0,
lab: 0,
lar: 0,
},
},
};
data.fixedperiod.forEach((ticket) => {
const ticketDate = dayjs(ticket.date);
if (
ticketDate.isBetween(
fixedPeriods.startOfThisWeek,
fixedPeriods.endOfThisWeek,
undefined,
"[]"
)
) {
ret.totalThisWeek = ret.totalThisWeek + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalThisWeekLAB = ret.totalThisWeekLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalThisWeekLAR = ret.totalThisWeekLAR + ticket.productivehrs;
//Seperate out to Day of Week
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].total =
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].total + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].lab =
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].lab + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].lar =
ret.seperatedThisWeek[
dayjs(ticket.date).format("dddd").toLowerCase()
].lar + ticket.productivehrs;
} else if (
ticketDate.isBetween(
fixedPeriods.startOfLastWeek,
fixedPeriods.endOfLastWeek,
undefined,
"[]"
)
) {
ret.totalLastWeek = ret.totalLastWeek + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalLastWeekLAB = ret.totalLastWeekLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalLastWeekLAR = ret.totalLastWeekLAR + ticket.productivehrs;
} else if (
ticketDate.isBetween(
fixedPeriods.startOfPriorWeek,
fixedPeriods.endOfPriorWeek,
undefined,
"[]"
)
) {
ret.totalPriorWeek = ret.totalPriorWeek + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalPriorWeekLAB = ret.totalPriorWeekLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalPriorWeekLAR = ret.totalPriorWeekLAR + ticket.productivehrs;
}
if (
ticketDate.isBetween(
fixedPeriods.startofthisMonth,
fixedPeriods.endOfThisMonth,
undefined,
"[]"
)
) {
ret.totalThisMonth = ret.totalThisMonth + ticket.productivehrs;
ret.actualTotalOverPeriod =
ret.actualTotalOverPeriod + (ticket.actualhrs || 0);
if (ticket.ciecacode !== "LAR") {
ret.totalThisMonthLAB = ret.totalThisMonthLAB + ticket.productivehrs;
ret.actualTotalOverPeriodLAB =
ret.actualTotalOverPeriodLAB + (ticket.actualhrs || 0);
}
if (ticket.ciecacode === "LAR") {
ret.totalThisMonthLAR = ret.totalThisMonthLAR + ticket.productivehrs;
ret.actualTotalOverPeriodLAR =
ret.actualTotalOverPeriodLAR + (ticket.actualhrs || 0);
}
} else if (
ticketDate.isBetween(
fixedPeriods.startOfLastmonth,
fixedPeriods.endOfLastmonth,
undefined,
"[]"
)
) {
ret.totalLastMonth = ret.totalLastMonth + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalLastMonthLAB = ret.totalLastMonthLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalLastMonthLAR = ret.totalLastMonthLAR + ticket.productivehrs;
}
}); });
ret.totalEffieciencyOverPeriod = ret.actualTotalOverPeriod const calculatedData = useMemo(() => {
? (ret.totalThisMonth / ret.actualTotalOverPeriod) * 100 if (!data) return [];
: 0; const ret = {
ret.totalEffieciencyOverPeriodLAB = ret.actualTotalOverPeriodLAB totalThisWeek: 0,
? (ret.totalThisMonthLAB / ret.actualTotalOverPeriodLAB) * 100 totalThisWeekLAB: 0,
: 0; totalThisWeekLAR: 0,
ret.totalEffieciencyOverPeriodLAR = ret.actualTotalOverPeriodLAR totalLastWeek: 0,
? (ret.totalThisMonthLAR / ret.actualTotalOverPeriodLAR) * 100 totalLastWeekLAB: 0,
: 0; totalLastWeekLAR: 0,
totalPriorWeek: 0,
totalPriorWeekLAB: 0,
totalPriorWeekLAR: 0,
totalThisMonth: 0,
totalThisMonthLAB: 0,
totalThisMonthLAR: 0,
totalLastMonth: 0,
totalLastMonthLAB: 0,
totalLastMonthLAR: 0,
actualTotalOverPeriod: 0,
actualTotalOverPeriodLAB: 0,
actualTotalOverPeriodLAR: 0,
totalEffieciencyOverPeriod: 0,
totalEffieciencyOverPeriodLAB: 0,
totalEffieciencyOverPeriodLAR: 0,
seperatedThisWeek: {
sunday: {
total: 0,
lab: 0,
lar: 0,
},
monday: {
total: 0,
lab: 0,
lar: 0,
},
tuesday: {
total: 0,
lab: 0,
lar: 0,
},
wednesday: {
total: 0,
lab: 0,
lar: 0,
},
thursday: {
total: 0,
lab: 0,
lar: 0,
},
friday: {
total: 0,
lab: 0,
lar: 0,
},
saturday: {
total: 0,
lab: 0,
lar: 0,
},
},
};
roundObject(ret); data.fixedperiod.forEach((ticket) => {
const ticketDate = dayjs(ticket.date);
if (
ticketDate.isBetween(
fixedPeriods.startOfThisWeek,
fixedPeriods.endOfThisWeek,
undefined,
"[]"
)
) {
ret.totalThisWeek = ret.totalThisWeek + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalThisWeekLAB = ret.totalThisWeekLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalThisWeekLAR = ret.totalThisWeekLAR + ticket.productivehrs;
const ticketsGroupedByDate = _.groupBy(data.timetickets, "date"); //Seperate out to Day of Week
ret.seperatedThisWeek[
const listOfDays = Utils.ListOfDaysInCurrentMonth(); dayjs(ticket.date).format("dddd").toLowerCase()
].total =
const combinedData = [], ret.seperatedThisWeek[
labData = [], dayjs(ticket.date).format("dddd").toLowerCase()
larData = []; ].total + ticket.productivehrs;
var acc_comb = 0; if (ticket.ciecacode !== "LAR")
var acc_lab = 0; ret.seperatedThisWeek[
var acc_lar = 0; dayjs(ticket.date).format("dddd").toLowerCase()
].lab =
listOfDays.forEach((day) => { ret.seperatedThisWeek[
const r = { dayjs(ticket.date).format("dddd").toLowerCase()
date: dayjs(day).format("MM/DD"), ].lab + ticket.productivehrs;
actualhrs: 0, if (ticket.ciecacode === "LAR")
productivehrs: 0, ret.seperatedThisWeek[
}; dayjs(ticket.date).format("dddd").toLowerCase()
].lar =
const combined = { ret.seperatedThisWeek[
accTargetHrs: _.round( dayjs(ticket.date).format("dddd").toLowerCase()
Utils.AsOfDateTargetHours( ].lar + ticket.productivehrs;
bodyshop.scoreboard_target.dailyBodyTarget + } else if (
bodyshop.scoreboard_target.dailyPaintTarget, ticketDate.isBetween(
day fixedPeriods.startOfLastWeek,
) + fixedPeriods.endOfLastWeek,
(bodyshop.scoreboard_target.dailyBodyTarget + undefined,
bodyshop.scoreboard_target.dailyPaintTarget), "[]"
1 )
), ) {
accHrs: 0, ret.totalLastWeek = ret.totalLastWeek + ticket.productivehrs;
}; if (ticket.ciecacode !== "LAR")
const lab = { ret.totalLastWeekLAB = ret.totalLastWeekLAB + ticket.productivehrs;
accTargetHrs: _.round( if (ticket.ciecacode === "LAR")
Utils.AsOfDateTargetHours( ret.totalLastWeekLAR = ret.totalLastWeekLAR + ticket.productivehrs;
bodyshop.scoreboard_target.dailyBodyTarget, } else if (
day ticketDate.isBetween(
) + bodyshop.scoreboard_target.dailyBodyTarget, fixedPeriods.startOfPriorWeek,
1 fixedPeriods.endOfPriorWeek,
), undefined,
accHrs: 0, "[]"
}; )
const lar = { ) {
accTargetHrs: _.round( ret.totalPriorWeek = ret.totalPriorWeek + ticket.productivehrs;
Utils.AsOfDateTargetHours( if (ticket.ciecacode !== "LAR")
bodyshop.scoreboard_target.dailyPaintTarget, ret.totalPriorWeekLAB = ret.totalPriorWeekLAB + ticket.productivehrs;
day if (ticket.ciecacode === "LAR")
) + bodyshop.scoreboard_target.dailyPaintTarget, ret.totalPriorWeekLAR = ret.totalPriorWeekLAR + ticket.productivehrs;
1 }
), if (
accHrs: 0, ticketDate.isBetween(
}; fixedPeriods.startofthisMonth,
fixedPeriods.endOfThisMonth,
if (ticketsGroupedByDate[day]) { undefined,
ticketsGroupedByDate[day].forEach((ticket) => { "[]"
r.actualhrs = r.actualhrs + ticket.actualhrs; )
r.productivehrs = r.productivehrs + ticket.productivehrs; ) {
acc_comb = acc_comb + ticket.productivehrs; ret.totalThisMonth = ret.totalThisMonth + ticket.productivehrs;
ret.actualTotalOverPeriod =
if (ticket.ciecacode !== "LAR") ret.actualTotalOverPeriod + (ticket.actualhrs || 0);
acc_lab = acc_lab + ticket.productivehrs; if (ticket.ciecacode !== "LAR") {
if (ticket.ciecacode === "LAR") ret.totalThisMonthLAB = ret.totalThisMonthLAB + ticket.productivehrs;
acc_lar = acc_lar + ticket.productivehrs; ret.actualTotalOverPeriodLAB =
ret.actualTotalOverPeriodLAB + (ticket.actualhrs || 0);
}
if (ticket.ciecacode === "LAR") {
ret.totalThisMonthLAR = ret.totalThisMonthLAR + ticket.productivehrs;
ret.actualTotalOverPeriodLAR =
ret.actualTotalOverPeriodLAR + (ticket.actualhrs || 0);
}
} else if (
ticketDate.isBetween(
fixedPeriods.startOfLastmonth,
fixedPeriods.endOfLastmonth,
undefined,
"[]"
)
) {
ret.totalLastMonth = ret.totalLastMonth + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
ret.totalLastMonthLAB = ret.totalLastMonthLAB + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
ret.totalLastMonthLAR = ret.totalLastMonthLAR + ticket.productivehrs;
}
}); });
}
combined.accHrs = acc_comb;
lab.accHrs = acc_lab;
lar.accHrs = acc_lar;
combinedData.push({ ...r, ...combined }); ret.totalEffieciencyOverPeriod = ret.actualTotalOverPeriod
labData.push({ ...r, ...lab }); ? (ret.totalThisMonth / ret.actualTotalOverPeriod) * 100
larData.push({ ...r, ...lar }); : 0;
}); ret.totalEffieciencyOverPeriodLAB = ret.actualTotalOverPeriodLAB
? (ret.totalThisMonthLAB / ret.actualTotalOverPeriodLAB) * 100
: 0;
ret.totalEffieciencyOverPeriodLAR = ret.actualTotalOverPeriodLAR
? (ret.totalThisMonthLAR / ret.actualTotalOverPeriodLAR) * 100
: 0;
const jobData = {}; roundObject(ret);
data.jobs.forEach((job) => { const ticketsGroupedByDate = _.groupBy(data.timetickets, "date");
job.tthrs = job.joblines.reduce((acc, val) => acc + val.mod_lb_hrs, 0);
});
jobData.tthrs = data.jobs const listOfDays = Utils.ListOfDaysInCurrentMonth();
.reduce((acc, val) => acc + val.tthrs, 0)
.toFixed(1);
jobData.count = data.jobs.length.toFixed(0); const combinedData = [],
labData = [],
larData = [];
var acc_comb = 0;
var acc_lab = 0;
var acc_lar = 0;
return { listOfDays.forEach((day) => {
fixed: ret, const r = {
combinedData: combinedData, date: dayjs(day).format("MM/DD"),
labData: labData, actualhrs: 0,
larData: larData, productivehrs: 0,
jobData: jobData, };
};
}, [fixedPeriods, data, bodyshop]);
if (error) return <AlertComponent message={error.message} type="error" />; const combined = {
if (loading) return <LoadingSpinner />; accTargetHrs: _.round(
return ( Utils.AsOfDateTargetHours(
<Row gutter={[16, 16]}> bodyshop.scoreboard_target.dailyBodyTarget +
<Col span={24}> bodyshop.scoreboard_target.dailyPaintTarget,
<ScoreboardTimeticketsTargetsTable /> day
</Col> ) +
<Col span={24}> (bodyshop.scoreboard_target.dailyBodyTarget +
<ScoreboardTicketsStats bodyshop.scoreboard_target.dailyPaintTarget),
data={calculatedData.fixed} 1
jobData={calculatedData.jobData} ),
/> accHrs: 0,
</Col> };
<Col span={24}> const lab = {
<ScoreboardTimeTicketsChart accTargetHrs: _.round(
data={calculatedData.combinedData} Utils.AsOfDateTargetHours(
chartTitle={t("scoreboard.labels.combinedcharttitle")} bodyshop.scoreboard_target.dailyBodyTarget,
/> day
</Col> ) + bodyshop.scoreboard_target.dailyBodyTarget,
<Col span={12}> 1
<ScoreboardTimeTicketsChart ),
data={calculatedData.labData} accHrs: 0,
chartTitle={t("scoreboard.labels.bodycharttitle")} };
/> const lar = {
</Col> accTargetHrs: _.round(
<Col span={12}> Utils.AsOfDateTargetHours(
<ScoreboardTimeTicketsChart bodyshop.scoreboard_target.dailyPaintTarget,
data={calculatedData.larData} day
chartTitle={t("scoreboard.labels.refinishcharttitle")} ) + bodyshop.scoreboard_target.dailyPaintTarget,
/> 1
</Col> ),
</Row> accHrs: 0,
); };
if (ticketsGroupedByDate[day]) {
ticketsGroupedByDate[day].forEach((ticket) => {
r.actualhrs = r.actualhrs + ticket.actualhrs;
r.productivehrs = r.productivehrs + ticket.productivehrs;
acc_comb = acc_comb + ticket.productivehrs;
if (ticket.ciecacode !== "LAR")
acc_lab = acc_lab + ticket.productivehrs;
if (ticket.ciecacode === "LAR")
acc_lar = acc_lar + ticket.productivehrs;
});
}
combined.accHrs = acc_comb;
lab.accHrs = acc_lab;
lar.accHrs = acc_lar;
combinedData.push({...r, ...combined});
labData.push({...r, ...lab});
larData.push({...r, ...lar});
});
const jobData = {};
const dataJobs = data.jobs.map((job) => ({
...job,
tthrs: job.joblines.reduce((acc, val) => acc + val.mod_lb_hrs, 0)
}));
jobData.tthrs = dataJobs
.reduce((acc, val) => acc + val.tthrs, 0)
.toFixed(1);
jobData.count = dataJobs.length.toFixed(0);
return {
fixed: ret,
combinedData: combinedData,
labData: labData,
larData: larData,
jobData: jobData,
};
}, [fixedPeriods, data, bodyshop]);
if (error) return <AlertComponent message={error.message} type="error"/>;
if (loading) return <LoadingSpinner/>;
return (
<Row gutter={[16, 16]}>
<Col span={24}>
<ScoreboardTimeticketsTargetsTable/>
</Col>
<Col span={24}>
<ScoreboardTicketsStats
data={calculatedData.fixed}
jobData={calculatedData.jobData}
/>
</Col>
<Col span={24}>
<ScoreboardTimeTicketsChart
data={calculatedData.combinedData}
chartTitle={t("scoreboard.labels.combinedcharttitle")}
/>
</Col>
<Col span={12}>
<ScoreboardTimeTicketsChart
data={calculatedData.labData}
chartTitle={t("scoreboard.labels.bodycharttitle")}
/>
</Col>
<Col span={12}>
<ScoreboardTimeTicketsChart
data={calculatedData.larData}
chartTitle={t("scoreboard.labels.refinishcharttitle")}
/>
</Col>
</Row>
);
} }
function roundObject(inputObj) { function roundObject(inputObj) {
for (var key of Object.keys(inputObj)) { for (var key of Object.keys(inputObj)) {
if (typeof inputObj[key] === "number") { if (typeof inputObj[key] === "number") {
inputObj[key] = inputObj[key].toFixed(1); inputObj[key] = inputObj[key].toFixed(1);
} else if (Array.isArray(inputObj[key])) { } else if (Array.isArray(inputObj[key])) {
inputObj[key].forEach((item) => roundObject(item)); inputObj[key].forEach((item) => roundObject(item));
} else if (typeof inputObj[key] === "object") { } else if (typeof inputObj[key] === "object") {
roundObject(inputObj[key]); roundObject(inputObj[key]);
}
} }
}
} }