diff options
author | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-06-25 15:27:58 +0530 |
---|---|---|
committer | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-06-25 15:27:58 +0530 |
commit | 35a44621c25b06471ae5b29bbdfb35fdcf652cf1 (patch) | |
tree | 377186f820685e9be05d60f0d7a2d8743a8b6a9c /src/components | |
parent | 5d2222d9fa782b94ba6787e5c6b23aab1e468308 (diff) |
Changed the way all the values are calculated for stability
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Display/ItemsDisplay.js | 5 | ||||
-rw-r--r-- | src/components/Display/SummaryDisplay.txt (renamed from src/components/Display/SummaryDisplay.js) | 5 | ||||
-rw-r--r-- | src/components/Form/Items/AddNewItemForm.tsx | 49 | ||||
-rw-r--r-- | src/components/Pages/BillingPage.tsx | 5 |
4 files changed, 34 insertions, 30 deletions
diff --git a/src/components/Display/ItemsDisplay.js b/src/components/Display/ItemsDisplay.js index 0b2fbf0..f0882af 100644 --- a/src/components/Display/ItemsDisplay.js +++ b/src/components/Display/ItemsDisplay.js @@ -9,7 +9,7 @@ import React from "react"; import "./Display.scss"; import DisplayItem from "./DisplayItem"; -import {SummaryDisplayTR} from "./SummaryDisplay"; +// import {SummaryDisplayTR} from "./SummaryDisplay"; const ItemsDisplay = (props) => { const items = props.items; @@ -43,10 +43,11 @@ const ItemsDisplay = (props) => { } )} - <SummaryDisplayTR items={props.items}/> </tbody> </table> ); + // this goes right before </tbody> + //<SummaryDisplayTR items={props.items}/> } export default ItemsDisplay; diff --git a/src/components/Display/SummaryDisplay.js b/src/components/Display/SummaryDisplay.txt index 1bcc713..e06eac5 100644 --- a/src/components/Display/SummaryDisplay.js +++ b/src/components/Display/SummaryDisplay.txt @@ -9,6 +9,9 @@ import React from "react"; import "./Display.scss"; +interface props { +} + const getBasicSummary = (items) => { let totalRawPrice = 0; let totalQuantity = 0; @@ -63,7 +66,7 @@ const getFullSummary = (items) => { ); } -export const SummaryDisplayTR = (props) => { +export const SummaryDisplayTR: React.FC<props> = (props) => { const summary = getBasicSummary(props.items); return ( diff --git a/src/components/Form/Items/AddNewItemForm.tsx b/src/components/Form/Items/AddNewItemForm.tsx index ae64b06..e51ecfc 100644 --- a/src/components/Form/Items/AddNewItemForm.tsx +++ b/src/components/Form/Items/AddNewItemForm.tsx @@ -22,15 +22,15 @@ const AddNewItemForm: React.FC<props> = (props) => { const [itemNameValue, setItemNameValue] = useState<string>(""); const [itemDescValue, setItemDescValue] = useState<string>(""); const [itemPriceValue, setItemPriceValue] = useState<number>(0.00); - const [itemDiscountValue, setItemDiscountValue] = useState<number>(0.00); - const [itemGSTValue, setItemGSTValue] = useState<number>(props.defGSTValue); + const [itemDiscountPercentage, setItemDiscountPercentage] = useState<number>(0.00); + const [itemGSTPercentage, setItemGSTValue] = useState<number>(props.defGSTValue); const [itemQTYValue, setItemQTYValue] = useState<number>(1); const [itemHSNValue, setItemHSNValue] = useState<number>(0); // to be handled by DocumentInfo // check if client is in same state // and apply cgst+sgst or igst accordingly - // const inState: boolean = true; + const inState: boolean = true; const enterItemNamePrompt: string = "start typing here"; const registerItemPrompt: string = "add new"; @@ -57,7 +57,7 @@ const AddNewItemForm: React.FC<props> = (props) => { setItemDescValue(""); setItemQTYValue(1); setItemPriceValue(1); - setItemDiscountValue(0); + setItemDiscountPercentage(0); setItemHSNValue(0); setItemGSTValue(props.defGSTValue); } @@ -68,28 +68,27 @@ const AddNewItemForm: React.FC<props> = (props) => { (event) => { event.preventDefault(); - // TODO: maybe move calculation of GST and Discount here + const discountValue: number = (itemDiscountPercentage / 100) * itemPriceValue; + const totalGSTValue: number = (itemGSTPercentage / 100) * (itemQTYValue); const newInvoiceItem: Item = { - Model: itemNameValue, - Description: itemDescValue, - Quantity: itemQTYValue, - UnitPrice: itemPriceValue, - TotalValue: (itemPriceValue * itemQTYValue), - Discount: itemDiscountValue, - HSN: itemHSNValue, - TotalGST: itemGSTValue, + Model: itemNameValue, + Description: itemDescValue, + Quantity: itemQTYValue, + UnitPrice: itemPriceValue, + TotalValue: itemPriceValue * itemQTYValue, + Discount: itemDiscountPercentage, + DiscountValue: discountValue, + HSN: itemHSNValue, + TotalGST: itemGSTPercentage, + TotalGSTValue: totalGSTValue, // this also checks if igst applies or not - // TODO: fix this - SGST: 0, - CGST: 0, - IGST: 0 - // sgst: inState ? parseInt(itemGSTValue) / 2 : "", - // cgst: inState ? parseInt(itemGSTValue) / 2 : "", - // igst: inState ? "" : parseInt(itemGSTValue) + SGST: inState && totalGSTValue / 2, + CGST: inState && totalGSTValue / 2, + IGST: inState || totalGSTValue } - props.addItem(newInvoiceItem); + props.addItem(newInvoiceItem); resetAllValues(); } }> @@ -144,10 +143,10 @@ const AddNewItemForm: React.FC<props> = (props) => { <label> Discount: - <input className={"smallInputBox"} type="number" min="0" step="0.001" value={itemDiscountValue} + <input className={"smallInputBox"} type="number" min="0" step="0.001" value={itemDiscountPercentage} onInput={ (event: React.FormEvent<HTMLInputElement>) => - setItemDiscountValue(parseInt(event.currentTarget.value)) + setItemDiscountPercentage(parseInt(event.currentTarget.value)) } /> </label> @@ -164,7 +163,7 @@ const AddNewItemForm: React.FC<props> = (props) => { <label> GST: - <input className={"smallInputBox"} type="number" min="0" value={itemGSTValue} + <input className={"smallInputBox"} type="number" min="0" value={itemGSTPercentage} onInput={ (event: React.FormEvent<HTMLInputElement>) => setItemGSTValue(parseInt(event.currentTarget.value)) @@ -189,7 +188,7 @@ const AddNewItemForm: React.FC<props> = (props) => { (emptyItemNames.includes(itemNameValue) || itemQTYValue <= 0 || itemPriceValue <= 0 - || itemGSTValue <= 0 + || itemGSTPercentage <= 0 ) ? true : false } /> diff --git a/src/components/Pages/BillingPage.tsx b/src/components/Pages/BillingPage.tsx index 9697a24..ebc0f5a 100644 --- a/src/components/Pages/BillingPage.tsx +++ b/src/components/Pages/BillingPage.tsx @@ -20,7 +20,7 @@ import DocumentInfoForm from "./../Form/Document/DocumentInfoForm"; import MetaInfoForm from "./../Form/Document/MetaInfoForm"; import ItemsDisplay from "./../Display/ItemsDisplay"; -import SummaryDisplay from "./../Display/SummaryDisplay"; +// import SummaryDisplay from "./../Display/SummaryDisplay"; const BillingPage: React.FC = () => { const [savedItems, getSavedItems] = useState<Item[]>([]); @@ -87,10 +87,11 @@ const BillingPage: React.FC = () => { <div className={"BillingPageFlex"}> <MetaInfoForm/> - <SummaryDisplay items={items}/> </div> </> ); + // this goes after metainfoform + // <SummaryDisplay items={items}/> } export default BillingPage; |