aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/go.mod5
-rw-r--r--server/go.sum2
-rw-r--r--server/main.go10
-rw-r--r--src/components/App.js16
-rw-r--r--src/components/Display/SummaryDisplay.js33
5 files changed, 49 insertions, 17 deletions
diff --git a/server/go.mod b/server/go.mod
index 70699fa..c920659 100644
--- a/server/go.mod
+++ b/server/go.mod
@@ -2,4 +2,7 @@ module github.com/MikunoNaka/openbills
go 1.16
-require github.com/gin-gonic/gin v1.7.1 // indirect
+require (
+ github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 // indirect
+ github.com/gin-gonic/gin v1.7.1 // indirect
+)
diff --git a/server/go.sum b/server/go.sum
index 00998d3..4952cd2 100644
--- a/server/go.sum
+++ b/server/go.sum
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
+github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 h1:J2LPEOcQmWaooBnBtUDV9KHFEnP5LYTZY03GiQ0oQBw=
+github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
github.com/gin-gonic/gin v1.7.1 h1:qC89GU3p8TvKWMAVhEpmpB2CIb1hnqt2UdKZaP93mS8=
github.com/gin-gonic/gin v1.7.1/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
diff --git a/server/main.go b/server/main.go
index b0d3f9d..9a84f7b 100644
--- a/server/main.go
+++ b/server/main.go
@@ -2,14 +2,16 @@ package main
import (
"github.com/gin-gonic/gin"
- // "net/http"
+ "github.com/gin-gonic/contrib/static"
)
func main() {
- myRouter := gin.New()
- // myRouter.Use(gin.Logger())
+ myRouter := gin.Default()
+ myRouter.Use(gin.Logger())
- myRouter.Static("/app", "./app")
+ // serve static front end on /
+ myRouter.Use(static.Serve("/",
+ static.LocalFile("./app", true)))
myRouter.Run(":8080")
}
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>
+ </>
);
}