IO-2240 Moved the calculation within the function

This commit is contained in:
swtmply
2023-04-15 01:11:44 +08:00
parent 79e2fecb24
commit 8e8208dd9a
2 changed files with 17 additions and 19 deletions

View File

@@ -81,6 +81,7 @@ export default function ScoreboardTimeTickets() {
totalLastMonth: 0, totalLastMonth: 0,
totalOverPeriod: 0, totalOverPeriod: 0,
actualTotalOverPeriod: 0, actualTotalOverPeriod: 0,
totalEffieciencyOverPeriod: 0,
employees: {}, employees: {},
}; };
data.fixedperiod.forEach((ticket) => { data.fixedperiod.forEach((ticket) => {
@@ -94,6 +95,7 @@ export default function ScoreboardTimeTickets() {
totalLastMonth: 0, totalLastMonth: 0,
totalOverPeriod: 0, totalOverPeriod: 0,
actualTotalOverPeriod: 0, actualTotalOverPeriod: 0,
totalEffieciencyOverPeriod: 0,
}; };
} }
@@ -217,6 +219,19 @@ export default function ScoreboardTimeTickets() {
r.employees[ticket.employee.employee_number].actual + r.employees[ticket.employee.employee_number].actual +
ticket.actualhrs; ticket.actualhrs;
}); });
// Add total efficiency of employees
ret.totalEffieciencyOverPeriod = Object.keys(ret.employees)
.map((key) => {
return { employee_number: key, ...ret.employees[key] };
})
.map((e) =>
(
(e.totalOverPeriod / (e.actualTotalOverPeriod || 0.1)) *
100
).toFixed(1)
)
.reduce((acc, prev) => acc + Number(prev), 0);
} }
ret2.push(r); ret2.push(r);

View File

@@ -1,5 +1,5 @@
import { Card, Col, Row, Statistic, Table, Typography } from "antd"; import { Card, Col, Row, Statistic, Table, Typography } from "antd";
import React, { useMemo } from "react"; import React 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";
@@ -74,23 +74,6 @@ export function ScoreboardTicketsStats({ data, bodyshop }) {
}) })
: []; : [];
const totalEffieciencyOverPeriod = useMemo(
() =>
Object.keys(data?.employees ?? [])
.map((key) => {
return { employee_number: key, ...data.employees[key] };
})
.map((e) =>
(
(e.totalOverPeriod / (e.actualTotalOverPeriod || 0.1)) *
100
).toFixed(1)
)
.reduce((acc, prev) => acc + Number(prev), 0)
.toFixed(1),
[data]
);
return ( return (
<Card title={t("scoreboard.labels.productivestatistics")}> <Card title={t("scoreboard.labels.productivestatistics")}>
<Row gutter={[16, 16]}> <Row gutter={[16, 16]}>
@@ -133,7 +116,7 @@ export function ScoreboardTicketsStats({ data, bodyshop }) {
<Col span={12}> <Col span={12}>
<Statistic <Statistic
title={t("scoreboard.labels.efficiencyoverperiod")} title={t("scoreboard.labels.efficiencyoverperiod")}
value={`${totalEffieciencyOverPeriod}%`} value={`${data.totalEffieciencyOverPeriod}%`}
/> />
</Col> </Col>
</Row> </Row>