blob: aabd11137590d91adfe094f07ae416723bd4e2ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import React from "react";
import "./Display.css";
const getBasicSummary = (items) => {
let totalRawPrice = 0;
let totalQuantity = 0;
for (let i = 0; i < items.length; i++) {
totalRawPrice += items[i].TotalPrice;
totalQuantity += items[i].Quantity
}
return (
{
"TotalRawPrice": totalRawPrice,
"TotalQuantity": totalQuantity
}
);
}
const getFullSummary = (items) => {
let totalRawPrice = 0;
let totalDiscountPrice = 0; // to be subtracted from totalRawPrice
for (let i = 0; i < items.length; i++) {
const itemTotalPrice = items[i].TotalPrice;
const itemDiscount = items[i].Discount;
totalRawPrice += itemTotalPrice;
totalDiscountPrice += (itemDiscount / 100) * itemTotalPrice;
}
// TODO: add support for calculating gst from TotalPriceAfterDiscount
return (
{
"TotalRawPrice": totalRawPrice,
"TotalPriceAfterDiscount": totalRawPrice - totalDiscountPrice
}
);
}
export const SummaryDisplayTR = (props) => {
const summary = getBasicSummary(props.items);
return (
<tr className={"SummaryDisplayTR"}>
<td>Total</td>
<td className={"disabledBorder"}></td>
<td className={"disabledBorder"}></td>
<td>{summary.TotalQuantity}</td>
<td className={"disabledBorder"}></td>
<td className={"disabledBorder"}></td>
<td className={"disabledBorder"}></td>
<td>{summary.TotalRawPrice}</td>
</tr>
);
}
const SummaryDisplay = (props) => {
const summary = getFullSummary(props.items);
return (
<>
<p>Total: {summary.TotalRawPrice}</p>
<p>Total after discount: {summary.TotalPriceAfterDiscount}</p>
</>
);
}
export default SummaryDisplay;
|