Skip to content

Commit

Permalink
beforArzesh calculation fixed. dest and origin code functionality cha…
Browse files Browse the repository at this point in the history
…nged to correct way. results are ok according to all changes. karbarEzafe calculation changed in all components.
  • Loading branch information
devomid committed Jun 19, 2024
1 parent 48ad697 commit 8fa6742
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Omid Azad",
"main": "src/start.js",
"name": "frontend",
"version": "2.1.3",
"version": "2.2.0",
"private": false,
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down
18 changes: 15 additions & 3 deletions src/context/generalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ const GeneralProvider = ({ children }) => {

const [saleTakhfifAmount, setSaleTakhfifAmount] = useState(0);
const [upgradeTakhfifAmount, setUpgradeTakhfifAmount] = useState(0);
const [destChandSherkatiTakhfifAmount, setDestChandSherkatiTakhfifAmount] = useState(0);
const [tamdidTakhfifAmount, setTamdidTakhfifAmount] = useState(0);
const [karbarEzafeTakhfifAmount, setKarbarEzafeTakhfifAmount] = useState(0);
const [modulesTakhfifAmount, setModulesTakhfifAmount] = useState(0);
const [khadamatTakhfifAmount, setKhadamatTakhfifAmount] = useState(0);
const [jameKolaTakhfifAmount, setJameKolTakhfifAmount] = useState(0);

const [originPrice, setOriginPrice] = useState(0);
const [destPrice, setDestPrice] = useState(0);
const [originPrice, setOriginPrice] = useState(null);
const [destPrice, setDestPrice] = useState(null);
const [originChandSherkatiPrice, setOriginChandSherkatiPrice] = useState(null);
const [destChandSherkatiPrice, setDestChandSherkatiPrice] = useState(null);
const [upgradeDifference, setUpgradeDifference] = useState(0);
Expand Down Expand Up @@ -166,7 +172,13 @@ const GeneralProvider = ({ children }) => {
destChandSherkatiPriceBefore, setDestChandSherkatiPriceBefore,
printRes, setPrintRes,
saleTakhfifAmount, setSaleTakhfifAmount,
upgradeTakhfifAmount, setUpgradeTakhfifAmount
upgradeTakhfifAmount, setUpgradeTakhfifAmount,
destChandSherkatiTakhfifAmount, setDestChandSherkatiTakhfifAmount,
tamdidTakhfifAmount, setTamdidTakhfifAmount,
karbarEzafeTakhfifAmount, setKarbarEzafeTakhfifAmount,
modulesTakhfifAmount, setModulesTakhfifAmount,
khadamatTakhfifAmount, setKhadamatTakhfifAmount,
jameKolaTakhfifAmount, setJameKolTakhfifAmount
}}>
{children}
</GeneralContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const About = ({ open, setOpen }) => {
SSP Price Calculation Utility{'\n'}
created and developed by: Omid Azad{'\n'}
Date created: May 5th 2024{'\n'}
Ver 2.1.3
Ver 2.2.0
</Typography>
</Box>
</Box>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ const ButtonsSection = () => {

return (

<Box sx={{ width: '100%', backgroundColor: 'rgba(255, 255, 255, 0.5)', backdropFilter: 'blur(5px) saturate(180%)', border: '1px solid rgba(38, 66, 50, 0.5)', borderRadius: 5, boxShadow: 3, p: 1.5, display: 'flex', flexDirection: 'row', mt:4 }}>
<Box sx={{ width: '100%', backgroundColor: 'rgba(255, 255, 255, 0.5)', backdropFilter: 'blur(5px) saturate(180%)', border: '1px solid rgba(38, 66, 50, 0.5)', borderRadius: 5, boxShadow: 3, p: 1.5, display: 'flex', flexDirection: 'row', mt:1 }}>

<Button onClick={() => {
{ ipcRenderer.send('reset', []) }
}} color="warning" sx={{ ml: 2, width: '50%' }} variant="outlined" endIcon={<RestartAltOutlinedIcon sx={{ width: 35, height: 55 }} />}>
<Typography variant="h6" sx={{ ml: 4 }}>
}} color="warning" sx={{ ml: 2, width: '50%' }} variant="outlined" endIcon={<RestartAltOutlinedIcon sx={{ width: 35, height: 78 }} />}>
<Typography variant="h5" sx={{ ml: 4 }}>
پاک کردن فرم
</Typography>
</Button>

<Button color="info" sx={{ width: '50%' }} variant="outlined" endIcon={<CalculateOutlinedIcon sx={{ width: 35, height: 55 }} />} onClick={handleChange} >
<Typography variant="h6" sx={{ ml: 4 }}>
<Button color="info" sx={{ width: '50%' }} variant="outlined" endIcon={<CalculateOutlinedIcon sx={{ width: 35, height: 78 }} />} onClick={handleChange} >
<Typography variant="h5" sx={{ ml: 4 }}>
محاسبه
</Typography>
</Button>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Discount.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DiscountSection = () => {


return (
<Box sx={{ width: '20%', backgroundColor: 'rgba(255, 255, 255, 0.5)', backdropFilter: 'blur(5px) saturate(180%)', border: '1px solid rgba(38, 66, 50, 0.5)', borderRadius: 5, boxShadow: 3, padding: '1rem', justifyContent: 'center', alignItems: 'center', mt: '1rem', mr:1, ml:1 }}>
<Box sx={{ width: '20%', backgroundColor: 'rgba(255, 255, 255, 0.5)', backdropFilter: 'blur(5px) saturate(180%)', border: '1px solid rgba(38, 66, 50, 0.5)', borderRadius: 5, boxShadow: 3, padding: '1rem 1rem 0.5rem 1rem', justifyContent: 'center', alignItems: 'center', mt: '1rem', mr:1, ml:1 }}>

<Stack sx={{mb:5.5}} spacing={3}>

Expand Down Expand Up @@ -41,23 +41,23 @@ const DiscountSection = () => {
}} onChange={(e) => setTamdidTakhfif(e.target.value)} InputLabelProps={{ style: { fontSize: '12px' } }} sx={{ backgroundColor: 'rgba(252, 243, 224, 0.1)', backdropFilter: 'blur(5px) saturate(180%)' }} type="text" label="تخفیف تمدید" variant="outlined" size="small" />
</FormControl>

<FormControl sx={{mt:13}}>
<FormControl sx={{mt:16}}>
<TextField onKeyDown={(event) => {
if (event.key === 'Enter') {
handleKeyDown()
}
}} onChange={(e) => setKarbarEzafeTakhfif(e.target.value)} InputLabelProps={{ style: { fontSize: '12px' } }} sx={{ backgroundColor: 'rgba(252, 243, 224, 0.1)', backdropFilter: 'blur(5px) saturate(180%)' }} type="text" label="تخفیف کاربر " variant="outlined" size="small" />
</FormControl>

<FormControl sx={{mt:14}}>
<FormControl sx={{mt:16}}>
<TextField onKeyDown={(event) => {
if (event.key === 'Enter') {
handleKeyDown()
}
}} onChange={(e) => setModulesTakhfif(e.target.value)} InputLabelProps={{ style: { fontSize: '12px' } }} sx={{ backgroundColor: 'rgba(252, 243, 224, 0.1)', backdropFilter: 'blur(5px) saturate(180%)' }} type="text" label="تخفیف ماژول" variant="outlined" size="small" />
</FormControl>

<FormControl sx={{mt:4}}>
<FormControl sx={{mt:5}}>
<TextField onKeyDown={(event) => {
if (event.key === 'Enter') {
handleKeyDown()
Expand Down
95 changes: 59 additions & 36 deletions src/pages/EntrySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ const EntrySection = () => {
originChandSherkatiPriceBefore, setOriginChandSherkatiPriceBefore,
destChandSherkatiPriceBefore, setDestChandSherkatiPriceBefore,
saleTakhfifAmount, setSaleTakhfifAmount,
upgradeTakhfifAmount, setUpgradeTakhfifAmount
upgradeTakhfifAmount, setUpgradeTakhfifAmount,
destChandSherkatiTakhfifAmount, setDestChandSherkatiTakhfifAmount,
tamdidTakhfifAmount, setTamdidTakhfifAmount,
karbarEzafeTakhfifAmount, setKarbarEzafeTakhfifAmount,
modulesTakhfifAmount, setModulesTakhfifAmount,
khadamatTakhfifAmount, setKhadamatTakhfifAmount,
jameKolaTakhfifAmount, setJameKolTakhfifAmount
} = GeneralState();

const [originErr, setOriginErr] = useState(false);
Expand Down Expand Up @@ -126,13 +132,18 @@ const EntrySection = () => {
const calculateUpgrade = async () => {
let upgradeDiffValue;

if (appCodes.hasOwnProperty(originCode) && appCodes.hasOwnProperty(destCode)) {
setOriginPrice(Number(appPrices[originCode]));
setDestPrice(Number(appPrices[destCode]));
if (appCodes.hasOwnProperty(originCode) || appCodes.hasOwnProperty(destCode)) {
if(originCode && ! destCode) {
setDestPrice(0);
setOriginPrice(Number(appPrices[originCode]));
} else if (destCode && !originCode) {
setOriginPrice(0)
setDestPrice(Number(appPrices[destCode]));
}
const halfOriginPrice = originPrice / 2;
const halfDestPrice = destPrice / 2;

if (originPrice !== 0 && destPrice !== 0) {
if (originPrice && destPrice) {

if (originChandSherkati && !destChandSherkati) {
setOriginChandSherkatiPrice(halfOriginPrice);
Expand All @@ -157,12 +168,14 @@ const EntrySection = () => {
await setUpgradeDifference(upgradeDiffValue);
}

} else if (originPrice == 0 && destPrice !== 0 && destChandSherkati) {
setDestChandSherkatiPrice(halfDestPrice);
} else if (originPrice && !destPrice && originChandSherkati) {
setDestPrice(0);
setOriginChandSherkatiPrice(halfOriginPrice);
await setUpgradeDifference(0)

} else if (originPrice !== 0 && destPrice == 0 && originChandSherkati) {
setOriginChandSherkatiPrice(halfDestPrice);

} else if (!originPrice && destPrice && destChandSherkati) {
setOriginPrice(0)
setDestChandSherkatiPrice(halfDestPrice);
await setUpgradeDifference(0)

} else {
Expand All @@ -175,7 +188,7 @@ const EntrySection = () => {

const originCodeValidation = () => {
setOriginErr(false);

if (originCode && appCodes.hasOwnProperty(originCode)) {
setOriginPrice(appPrices[originCode]);
setOriginCodeName(appCodes[originCode]);
Expand Down Expand Up @@ -205,6 +218,8 @@ const EntrySection = () => {
const currentDate = moment();
const differdDate = moment(tamdidDate, 'jYYYY/jMM/jDD');
const daysDifference = currentDate.diff(differdDate, 'days');
const tamdidPrice = tamdidPrices[originCode]
const formattedTamdidPrice = Number(tamdidPrice).toLocaleString()

if (tamdidDate) {

Expand All @@ -223,7 +238,7 @@ const EntrySection = () => {
} else if (daysDifference > 1086) {
setSanavat('بالای ۲ سال');
}
} else setSanavat('\u00A0')
} else setSanavat(`مبلغ تمدید عادی ${formattedTamdidPrice} ریال`)
};

const calculateTamdid = () => {
Expand Down Expand Up @@ -319,11 +334,8 @@ const EntrySection = () => {

const claculateKarbarEzafe = () => {
if (originCode && !destCode) {
console.log('1')
if (tamdidPrice) {
console.log('2')
if (networkCodes.includes(originCode) || karbarEzafe == 0) {
console.log('3')
const karbarEzafeValue = (Number(tamdidPrice) / 10) * (Number(karbarEzafe))
setKarbarEzafePrice(karbarEzafeValue)
} else {
Expand All @@ -332,9 +344,7 @@ const EntrySection = () => {
}

} else {
console.log('4')
if (networkCodes.includes(originCode) || karbarEzafe == 0) {
console.log('5')
const karbarEzafeValue = Number(((appPrices[originCode]) / 10) * karbarEzafe)
setKarbarEzafePrice(karbarEzafeValue)
} else {
Expand Down Expand Up @@ -363,7 +373,7 @@ const EntrySection = () => {

const calculateTabdilBeGhofl = () => {
if (originCode && tabdilBeGhofl) {
setTabdilBeGhoflPrice(6500000)
setTabdilBeGhoflPrice(7150000)
} else setTabdilBeGhoflPrice(0)
};

Expand Down Expand Up @@ -399,7 +409,9 @@ const EntrySection = () => {

const calculateTamdidTakhfif = () => {
if (tamdidTakhfif && originCode && tamdidDate) {
const tamdidAfter = Number(tamdidPrice) - ((Number(tamdidPrice) * Number(tamdidTakhfif)) / 100)
const takhfifAmount = ((Number(tamdidPrice) * Number(tamdidTakhfif)) / 100)
const tamdidAfter = Number(tamdidPrice) - takhfifAmount
setTamdidTakhfifAmount(takhfifAmount)
setTamdidAfterTakhfif(tamdidAfter)
} else if (tamdidTakhfif && !originCode && !tamdidDate) {
setTamdidAfterTakhfifErr(true)
Expand All @@ -409,7 +421,9 @@ const EntrySection = () => {

const claculateKarbarEzafeTakhfif = () => {
if (karbarEzafeTakhfif && karbaeEzafePrice) {
const karbarEzafeAfter = Number(karbaeEzafePrice) - ((Number(karbaeEzafePrice) * Number(karbarEzafeTakhfif)) / 100)
const takhfifAmount = ((Number(karbaeEzafePrice) * Number(karbarEzafeTakhfif)) / 100)
const karbarEzafeAfter = Number(karbaeEzafePrice) - takhfifAmount
setKarbarEzafeTakhfifAmount(takhfifAmount)
setKarbarEzafeAfterTakhfif(karbarEzafeAfter)
} else if (karbarEzafeTakhfif && !karbaeEzafePrice) {
setKarbarEzafeAfterTakhfifErr(true)
Expand All @@ -418,13 +432,15 @@ const EntrySection = () => {
};

const calculateChandSherkatiTakhfif = () => {
if (chandSherkatiTakhfif && chandSherkatiPrice) {
const ChandSherkatiAfter = Number(chandSherkatiPrice) - ((Number(chandSherkatiPrice) * Number(chandSherkatiTakhfif)) / 100)
setChandSherkatiAfterTakhfif(ChandSherkatiAfter)
} else if (chandSherkatiTakhfif && !chandSherkatiPrice) {
setChandSherkatiAfterTakhfifErr(true)
setChandSherkatiAfterTakhfif(0)
} else setChandSherkatiAfterTakhfif(0)
if (chandSherkatiTakhfif && destChandSherkatiPrice) {
const chandSherkatiTakhfifAmount = ((Number(destChandSherkatiPrice) * Number(chandSherkatiTakhfif)) / 100);
const ChandSherkatiAfter = Number(destChandSherkatiPrice) - chandSherkatiTakhfifAmount;
setChandSherkatiAfterTakhfif(ChandSherkatiAfter);
setDestChandSherkatiTakhfifAmount(chandSherkatiTakhfifAmount);
} else if (chandSherkatiTakhfif && !destChandSherkatiPrice) {
setChandSherkatiAfterTakhfifErr(true);
setChandSherkatiAfterTakhfif(0);
} else setChandSherkatiAfterTakhfif(0);
};

const calculateTabdilBeGhoflTakhfif = () => {
Expand All @@ -439,7 +455,9 @@ const EntrySection = () => {

const calculateModulesTakhfif = () => {
if (modulesTakhfif && modulesPrice) {
const modulesAfter = Number(modulesPrice) - ((Number(modulesPrice) * Number(modulesTakhfif)) / 100)
const takhfifAmount = ((Number(modulesPrice) * Number(modulesTakhfif)) / 100)
const modulesAfter = Number(modulesPrice) - takhfifAmount
setModulesTakhfifAmount(takhfifAmount);
setModulesAfterTakhfif(modulesAfter)
} else if (modulesTakhfif && !modulesPrice) {
setModulesAfterTakhfifErr(true)
Expand All @@ -459,7 +477,9 @@ const EntrySection = () => {

const calculateKhadamatTakhfif = () => {
if (khadamatTakhfif && khadamatPrice) {
const khadamatAfter = Number(khadamatPrice) - ((Number(khadamatPrice) * Number(khadamatTakhfif)) / 100)
const takhfifAmount = ((Number(khadamatPrice) * Number(khadamatTakhfif)) / 100)
const khadamatAfter = Number(khadamatPrice) - takhfifAmount
setKhadamatTakhfifAmount(takhfifAmount);
setKhadamatAfterTakhfif(khadamatAfter)
} else if (khadamatTakhfif && !khadamatPrice) {
setKhadamatAfterTakhfifErr(true)
Expand All @@ -468,7 +488,7 @@ const EntrySection = () => {
};

const calculateJameKol = () => {
let total = Number((Number(destPrice) + Number(upgradeDifference) + (Number(tamdidPrice) - Number(motevaliPrice)) + Number(karbaeEzafePrice) + Number(chandSherkatiPrice) + Number(tabdilBeGhoflPrice) + Number(modulesPrice) + Number(bargashtiPrice) + Number(khadamatPrice)));
let total = Number((Number(destPrice) + Number(upgradeDifference) + (Number(tamdidPrice) - Number(motevaliPrice)) + Number(karbaeEzafePrice) + Number(destChandSherkatiPrice) + Number(tabdilBeGhoflPrice) + Number(modulesPrice) + Number(khadamatPrice)) - Number(bargashtiPrice));
if (forooshJadid) {
setJameKol(total);
} else if (!forooshJadid) {
Expand Down Expand Up @@ -506,7 +526,9 @@ const EntrySection = () => {
}

const calculateJameKolTakhfif = () => {
let totalAfter = (Number(destAfterTakhfif) + Number(tamdidAfterTakhfif) + Number(upgradeAfterTakhfif) + Number(karbarEzafeAfterTakhfif) + Number(chandSherkatiAfterTakhfif) + Number(tabdilBeGhoflAfterTakhfif) + Number(modulesAfterTakhfif) + Number(khadamatAfterTakhfif)) - (Number(motevaliPrice) + Number(bargashtiAfterTakhfif));
let totalAfter = (Number(destAfterTakhfif) + Number(tamdidAfterTakhfif) + Number(upgradeAfterTakhfif) + Number(karbarEzafeAfterTakhfif) + Number(chandSherkatiAfterTakhfif) + Number(tabdilBeGhoflAfterTakhfif) + Number(modulesAfterTakhfif) + Number(khadamatAfterTakhfif)) - (Number(motevaliPrice));
const takhfifAmount = Number(saleTakhfifAmount) + Number(upgradeTakhfifAmount) + Number(destChandSherkatiTakhfifAmount) + Number(tamdidTakhfifAmount) + Number(karbarEzafeTakhfifAmount) + Number(modulesTakhfifAmount) + Number(khadamatTakhfifAmount)
setJameKolTakhfifAmount(takhfifAmount)
if (forooshJadid) {
setJameKolAfterTakhfif(totalAfter);
} else if (!forooshJadid) {
Expand Down Expand Up @@ -598,7 +620,7 @@ const EntrySection = () => {

useEffect(() => {
calculateJameKol();
}, [destPrice, saleTakhfifAmount, upgradeDifference, tamdidPrice, karbaeEzafePrice, chandSherkatiPrice, tabdilBeGhoflPrice, modulesPrice, bargashtiPrice, khadamatPrice, motevaliPrice, forooshJadid])
}, [destPrice, saleTakhfifAmount, upgradeDifference, tamdidPrice, karbaeEzafePrice, destChandSherkatiPrice, tabdilBeGhoflPrice, modulesPrice, bargashtiPrice, khadamatPrice, motevaliPrice, forooshJadid])

useEffect(() => {
calculateJameKolTakhfif();
Expand Down Expand Up @@ -850,11 +872,12 @@ const EntrySection = () => {
<Stack direction='column' spacing={2}>

<Stack direction='row'>
<Box sx={{width:'100%', mr:-2}}>
{/* <Box sx={{width:'100%', mr:-2}}>
<FormControlLabel sx={{ width: '8rem' }} control={<Switch onChange={(e) => setOriginChandSherkati(e.target.checked)} />} labelPlacement="right" label="کاربر جدید" />
</Box>
</Box> */}

<Box sx={{width:'80%', mr:2}}>
{/* <Box sx={{width:'100%', mr:2}}> */}
<Box sx={{width:'100%'}}>
<FormControl error={karbarEzafeErr} fullWidth>
<TextField onKeyDown={(event) => {
if (event.key === 'Enter') {
Expand All @@ -864,7 +887,7 @@ const EntrySection = () => {
<Box sx={{height:'2rem', mb:1, display:'flex', justifyContent:'end'}}>
<FormHelperText>
<Typography color="royalblue" variant="caption">
{karbarEzafeErr ? (karbarEzafeErrTxt) : (karbaeEzafePrice == 0 ? ('\u00A0') : `${(Number(karbaeEzafePrice).toLocaleString())} ریال برای ${karbarEzafe} کاربر`)}
{karbarEzafeErr ? (karbarEzafeErrTxt) : (karbaeEzafePrice == 0 ? ('\u00A0') : `مبلغ ${(Number(karbaeEzafePrice).toLocaleString())} ریال برای ${karbarEzafe} کاربر`)}
</Typography>
</FormHelperText>
</Box>
Expand Down
Loading

0 comments on commit 8fa6742

Please sign in to comment.