aboutsummaryrefslogtreecommitdiff
path: root/src/components/Form/Items/AddNewItemForm.js
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-06-10 08:03:19 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-06-10 08:03:19 +0530
commit33c10cfa027d769c1d02a54bad766f431b1196ee (patch)
treebb487bcecf9944250c5a94267295ec917e087529 /src/components/Form/Items/AddNewItemForm.js
parent86e800430360ac3af422faf1f6f7317aea9b1a19 (diff)
added sgst, cgst, igst support instead of GST as a whole
Diffstat (limited to 'src/components/Form/Items/AddNewItemForm.js')
-rw-r--r--src/components/Form/Items/AddNewItemForm.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/components/Form/Items/AddNewItemForm.js b/src/components/Form/Items/AddNewItemForm.js
index de524c7..a4710f9 100644
--- a/src/components/Form/Items/AddNewItemForm.js
+++ b/src/components/Form/Items/AddNewItemForm.js
@@ -18,6 +18,11 @@ const AddNewItemForm = (props) => {
const [itemQtyValue, setItemQtyValue] = useState(1);
const [itemHSNValue, setItemHSNValue] = useState(0);
+ // to be handled by DocumentInfo
+ // check if client is in same state
+ // and apply cgst+sgst or igst accordingly
+ const inState = true;
+
const enterItemNamePrompt = "start typing here";
const registerItemPrompt = "add new";
const emptyItemNames = [enterItemNamePrompt, registerItemPrompt, ""];
@@ -31,16 +36,10 @@ const AddNewItemForm = (props) => {
}
// check the item name value and do stuff accordingly
- const setItemInfo = (itemName) => {
- props.savedItems.some(
- (i) => {
- itemName === i.Model.toLowerCase()
- ? applyItemInfo(i)
- : itemName === registerItemPrompt && props.registerItemFormVisibility(true)
- return null;
- }
- )
- }
+ const setItemInfo = (itemName) =>
+ (props.savedItems === null || itemName === registerItemPrompt)
+ ? props.registerItemFormVisibility(true)
+ : props.savedItems.some((i) => itemName === i.Model.toLowerCase() && applyItemInfo(i))
const resetAllValues = () => {
setItemNameValue("");
@@ -56,7 +55,6 @@ const AddNewItemForm = (props) => {
<div className={"formContainer"}>
<form className={"threePaneForm"} onSubmit={
(event) => {
- alert("submit")
event.preventDefault();
const newInvoiceItem = {
"Model": itemNameValue,
@@ -66,8 +64,13 @@ const AddNewItemForm = (props) => {
"TotalPrice": parseFloat(itemPriceValue * itemQtyValue),
"Discount": parseInt(itemDiscountValue),
"HSN": parseInt(itemHSNValue),
- "GST": parseInt(itemGSTValue)
+
+ // this also checks if igst applies or not
+ "sgst": inState ? parseInt(itemGSTValue) / 2 : "",
+ "cgst": inState ? parseInt(itemGSTValue) / 2 : "",
+ "igst": inState ? "" : parseInt(itemGSTValue)
};
+ console.log(newInvoiceItem);
props.addItem(newInvoiceItem);
resetAllValues();
}
@@ -83,12 +86,10 @@ const AddNewItemForm = (props) => {
setItemNameValue(event.target.value);
setItemInfo(event.target.value.toLowerCase());
}
- }>
+ }>
<option key={enterItemNamePrompt}>{enterItemNamePrompt}</option>
- {props.savedItems === null || props.savedItems.map(
- (i) => {
- return <option key={i.Model}>{i.Model}</option>
- }
+ {props.savedItems !== null && props.savedItems.map(
+ (i) => <option key={i.Model}>{i.Model}</option>
)}
<option key={registerItemPrompt}>{registerItemPrompt}</option>
</select>