feat: add total at header table

main
Firman Ramdhani 2024-10-03 11:00:06 +07:00
parent 6964ca5764
commit 3df442b6a1
1 changed files with 137 additions and 74 deletions

View File

@ -9,13 +9,17 @@ import { v4 } from 'uuid';
export default function Admin() { export default function Admin() {
const [dataItem, setDataItem] = useState<any[]>([]); const [dataItem, setDataItem] = useState<any[]>([]);
const [dataItemMaster, setDataItemMaster] = useState<any[]>([]);
const [dataItemKeys, setDataItemKeys] = useState<any[]>([]); const [dataItemKeys, setDataItemKeys] = useState<any[]>([]);
const [dataItemMasterKeys, setDataItemMasterKeys] = useState<any[]>([]);
const [loadingDataItem, setLoadingDataItem] = useState<boolean>(false); const [loadingDataItem, setLoadingDataItem] = useState<boolean>(false);
const [dataItemTotalPax, setDataItemTotalPax] = useState<number>(0);
const [dataItemTotalRevenue, setDataItemTotalRevenue] = useState<number>(0);
const [dataItemMaster, setDataItemMaster] = useState<any[]>([]);
const [dataItemMasterKeys, setDataItemMasterKeys] = useState<any[]>([]);
const [loadingDataItemMaster, setLoadingDataItemMaster] = useState<boolean>(false); const [loadingDataItemMaster, setLoadingDataItemMaster] = useState<boolean>(false);
const [dataItemMasterTotalPax, setDataItemMasterTotalPax] = useState<number>(0);
const [dataItemMasterTotalRevenue, setDataItemMasterTotalRevenue] = useState<number>(0);
const [filterDate, setFilerDate] = useState(dayjs()); const [filterDate, setFilerDate] = useState(dayjs());
async function getDataItem(params: any) { async function getDataItem(params: any) {
@ -44,6 +48,11 @@ export default function Admin() {
}; };
}); });
const totalPax = lodash.sumBy(data, (item: any) => Number(item.tr_item__qty));
const totalRevenue = lodash.sumBy(data, (item: any) => Number(item.tr_item__total_net_price));
setDataItemTotalPax(totalPax);
setDataItemTotalRevenue(totalRevenue);
setDataItemKeys(groupedData.map((item) => item.key)); setDataItemKeys(groupedData.map((item) => item.key));
setDataItem(groupedData); setDataItem(groupedData);
}) })
@ -88,6 +97,11 @@ export default function Admin() {
}; };
}); });
const totalPax = lodash.sumBy(data, (item: any) => Number(item.tr_item__qty));
const totalRevenue = lodash.sumBy(data, (item: any) => Number(item.tr_item_bundling__total_net_price));
setDataItemMasterTotalPax(totalPax);
setDataItemMasterTotalRevenue(totalRevenue);
setDataItemMasterKeys(groupedData.map((item) => item.key)); setDataItemMasterKeys(groupedData.map((item) => item.key));
setDataItemMaster(groupedData); setDataItemMaster(groupedData);
}) })
@ -116,7 +130,7 @@ export default function Admin() {
<Col xl={8} lg={8} md={12} span={24}> <Col xl={8} lg={8} md={12} span={24}>
<DatePicker <DatePicker
size="large" size="large"
popupStyle={{ fontSize: 18 }} popupStyle={{ fontSize: 16 }}
allowClear={false} allowClear={false}
value={filterDate} value={filterDate}
style={{ width: '100%' }} style={{ width: '100%' }}
@ -127,6 +141,8 @@ export default function Admin() {
</Row> </Row>
<div style={{ marginBottom: 20 }}></div> <div style={{ marginBottom: 20 }}></div>
<Row gutter={[16, 16]}>
<Col xl={12} lg={12} span={24}>
<Card <Card
title={ title={
<div style={{ paddingTop: 10, paddingBottom: 10 }}> <div style={{ paddingTop: 10, paddingBottom: 10 }}>
@ -137,6 +153,27 @@ export default function Admin() {
</div> </div>
} }
> >
<Row gutter={[8, 8]}>
<Col span={12}>
<Card styles={{ body: { padding: '6px 12px 6px 12px' } }}>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'rgba(0,0,0,0.4)' }}>TOTAL PAX</div>
<div style={{ fontSize: 16, fontWeight: 600, color: 'rgba(0,0,0,0.6)' }}>{dataItemTotalPax}</div>
</div>
</Card>
</Col>
<Col span={12}>
<Card styles={{ body: { padding: '6px 12px 6px 12px' } }}>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'rgba(0,0,0,0.4)' }}>TOTAL REVENUE</div>
<div style={{ fontSize: 16, fontWeight: 600, color: 'rgba(0,0,0,0.6)' }}>
{currencyFormatter({ value: dataItemTotalRevenue })}
</div>
</div>
</Card>
</Col>
</Row>
<div style={{ marginBottom: 10 }}></div>
<Table <Table
bordered bordered
size="small" size="small"
@ -161,7 +198,8 @@ export default function Admin() {
]} ]}
/> />
</Card> </Card>
<div style={{ marginBottom: 20 }}></div> </Col>
<Col xl={12} lg={12} span={24}>
<Card <Card
title={ title={
<div style={{ paddingTop: 10, paddingBottom: 10 }}> <div style={{ paddingTop: 10, paddingBottom: 10 }}>
@ -172,6 +210,29 @@ export default function Admin() {
</div> </div>
} }
> >
<Row gutter={[8, 8]}>
<Col span={12}>
<Card styles={{ body: { padding: '6px 12px 6px 12px' } }}>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'rgba(0,0,0,0.4)' }}>TOTAL PAX</div>
<div style={{ fontSize: 16, fontWeight: 600, color: 'rgba(0,0,0,0.6)' }}>
{dataItemMasterTotalPax}
</div>
</div>
</Card>
</Col>
<Col span={12}>
<Card styles={{ body: { padding: '6px 12px 6px 12px' } }}>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'rgba(0,0,0,0.4)' }}>TOTAL REVENUE</div>
<div style={{ fontSize: 16, fontWeight: 600, color: 'rgba(0,0,0,0.6)' }}>
{currencyFormatter({ value: dataItemMasterTotalRevenue })}
</div>
</div>
</Card>
</Col>
</Row>
<div style={{ marginBottom: 10 }}></div>
<Table <Table
bordered bordered
size="small" size="small"
@ -197,6 +258,8 @@ export default function Admin() {
]} ]}
/> />
</Card> </Card>
</Col>
</Row>
</AdminLayout> </AdminLayout>
); );
} }