aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/App.js16
-rw-r--r--src/components/Display/SummaryDisplay.js33
2 files changed, 37 insertions, 12 deletions
diff --git a/src/components/App.js b/src/components/App.js
index d2b7d21..62cc15c 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -3,14 +3,14 @@ import Header from "./Header/Header";
import BillingPage from "./BillingPage";
const App = () => {
- return (
- <>
- <Header/>
- <div className={"root-content"}>
- <BillingPage />
- </div>
- </>
- );
+ return (
+ <>
+ <Header/>
+ <div className={"root-content"}>
+ <BillingPage />
+ </div>
+ </>
+ );
}
export default App;
diff --git a/src/components/Display/SummaryDisplay.js b/src/components/Display/SummaryDisplay.js
index 27ebe0b..aabd111 100644
--- a/src/components/Display/SummaryDisplay.js
+++ b/src/components/Display/SummaryDisplay.js
@@ -1,7 +1,7 @@
import React from "react";
import "./Display.css";
-const getSummary = (items) => {
+const getBasicSummary = (items) => {
let totalRawPrice = 0;
let totalQuantity = 0;
@@ -18,8 +18,30 @@ const getSummary = (items) => {
);
}
+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 = getSummary(props.items);
+ const summary = getBasicSummary(props.items);
return (
<tr className={"SummaryDisplayTR"}>
@@ -36,10 +58,13 @@ export const SummaryDisplayTR = (props) => {
}
const SummaryDisplay = (props) => {
- const summary = getSummary(props.items);
+ const summary = getFullSummary(props.items);
return (
- <p>Total: {summary.TotalRawPrice}</p>
+ <>
+ <p>Total: {summary.TotalRawPrice}</p>
+ <p>Total after discount: {summary.TotalPriceAfterDiscount}</p>
+ </>
);
}