BOD-26 Added totals calculation for job reconciliation.
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
import { Button, Table, Statistic } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
import Dinero from "dinero.js";
|
||||
|
||||
export default function JobReconcilitionPartsTable({
|
||||
jobLineState,
|
||||
jobLineData,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
});
|
||||
|
||||
const [selectedLines, setSelectedLines] = jobLineState;
|
||||
const [total, setTotal] = useState(Dinero({ amount: 0 }).toFormat());
|
||||
|
||||
const columns = [
|
||||
// {
|
||||
// title: t("joblines.fields.line_no"),
|
||||
// dataIndex: "line_no",
|
||||
// key: "line_no",
|
||||
// sorter: (a, b) => a.line_no - b.line_no,
|
||||
// sortOrder:
|
||||
// state.sortedInfo.columnKey === "line_no" && state.sortedInfo.order,
|
||||
// //ellipsis: true,
|
||||
// editable: true,
|
||||
// width: 75,
|
||||
// },
|
||||
{
|
||||
title: t("joblines.fields.line_desc"),
|
||||
dataIndex: "line_desc",
|
||||
key: "line_desc",
|
||||
sorter: (a, b) => alphaSort(a.line_desc, b.line_desc),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "line_desc" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.oem_partno"),
|
||||
dataIndex: "oem_partno",
|
||||
key: "oem_partno",
|
||||
sorter: (a, b) =>
|
||||
alphaSort(
|
||||
a.oem_partno ? a.oem_partno : a.op_code_desc,
|
||||
b.oem_partno ? b.oem_partno : b.op_code_desc
|
||||
),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "oem_partno" && state.sortedInfo.order,
|
||||
|
||||
render: (text, record) => (
|
||||
<span>
|
||||
{record.oem_partno ? record.oem_partno : record.op_code_desc}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.part_type"),
|
||||
dataIndex: "part_type",
|
||||
key: "part_type",
|
||||
sorter: (a, b) => alphaSort(a.part_type, b.part_type),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "part_type" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.act_price"),
|
||||
dataIndex: "act_price",
|
||||
key: "act_price",
|
||||
sorter: (a, b) => a.act_price - b.act_price,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "act_price" && state.sortedInfo.order,
|
||||
|
||||
render: (text, record) => (
|
||||
<CurrencyFormatter>{record.act_price}</CurrencyFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.part_qty"),
|
||||
dataIndex: "part_qty",
|
||||
key: "part_qty",
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.total"),
|
||||
dataIndex: "total",
|
||||
key: "total",
|
||||
sorter: (a, b) => a.act_price * a.part_qty - b.act_price * b.part_qty,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
|
||||
|
||||
render: (text, record) => (
|
||||
<CurrencyFormatter>
|
||||
{record.act_price * record.part_qty}
|
||||
</CurrencyFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.mod_lb_hrs"),
|
||||
dataIndex: "mod_lb_hrs",
|
||||
key: "mod_lb_hrs",
|
||||
sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "mod_lb_hrs" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.status"),
|
||||
dataIndex: "status",
|
||||
key: "status",
|
||||
sorter: (a, b) => alphaSort(a.status, b.status),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
||||
},
|
||||
];
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
||||
};
|
||||
const handleOnRowClick = (selectedRecordKeys, selectedRecords) => {
|
||||
setSelectedLines(selectedRecordKeys);
|
||||
calculateTotal(selectedRecords);
|
||||
};
|
||||
|
||||
const calculateTotal = (selectedRecords) => {
|
||||
let total = Dinero({ amount: 0 });
|
||||
selectedRecords.forEach(
|
||||
(record) =>
|
||||
(total = total.add(
|
||||
Dinero({ amount: record.act_price * 100 }).multiply(record.part_qty)
|
||||
))
|
||||
);
|
||||
|
||||
setTotal(total.toFormat());
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Table
|
||||
size='small'
|
||||
title={() => (
|
||||
<div>
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top", defaultPageSize: 25 }}
|
||||
columns={columns}
|
||||
rowKey='id'
|
||||
dataSource={jobLineData}
|
||||
onChange={handleTableChange}
|
||||
rowSelection={{
|
||||
onChange: handleOnRowClick,
|
||||
selectedRowKeys: selectedLines,
|
||||
}}
|
||||
/>
|
||||
<Statistic value={total} title='total' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user