IO-2030 Add totals to labor allocations table.

This commit is contained in:
Patrick Fic
2022-08-25 14:56:59 -07:00
parent 5264dfa49f
commit 79563a5cba
2 changed files with 36 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { EditFilled } from "@ant-design/icons";
import { Card, Col, Row, Space, Table } from "antd";
import { Card, Col, Row, Space, Table, Typography } from "antd";
import _ from "lodash";
import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
@@ -188,6 +188,19 @@ export function LaborAllocationsTable({
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
};
const summary =
totals &&
totals.reduce(
(acc, val) => {
acc.hrs_total += val.total;
acc.hrs_claimed += val.claimed;
acc.adjustments += val.adjustments;
acc.difference += val.difference;
return acc;
},
{ hrs_total: 0, hrs_claimed: 0, adjustments: 0, difference: 0 }
);
return (
<Row gutter={[16, 16]}>
<Col span={24}>
@@ -201,6 +214,27 @@ export function LaborAllocationsTable({
scroll={{
x: true,
}}
summary={() => (
<Table.Summary.Row>
<Table.Summary.Cell>
<Typography.Title level={4}>
{t("general.labels.totals")}
</Typography.Title>
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.hrs_total.toFixed(1)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.hrs_claimed.toFixed(1)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.adjustments.toFixed(1)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.difference.toFixed(1)}
</Table.Summary.Cell>
</Table.Summary.Row>
)}
/>
</Card>
</Col>

View File

@@ -39,7 +39,7 @@ export const CalculateAllocationsTotals = (
}, 0),
};
r.difference = (r.total + r.adjustments - r.claimed).toFixed(2);
r.difference = r.total + r.adjustments - r.claimed;
acc.push(r);
return acc;
}, []);