diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2023-09-30 21:03:28 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2023-09-30 21:03:28 +0700 |
commit | f4fa43d4686651b62f67e24d3698ea2324082f8e (patch) | |
tree | dd46717c66a4172d6a111f389140e97947397e8e /src/Result.jsx | |
parent | ca044349cac7434560f2646bc4ea4c27f5783d47 (diff) |
a more proper calculation including weekend, libur nasional not considered yet
Diffstat (limited to 'src/Result.jsx')
-rw-r--r-- | src/Result.jsx | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/src/Result.jsx b/src/Result.jsx index 0ea4810..685f88d 100644 --- a/src/Result.jsx +++ b/src/Result.jsx @@ -1,5 +1,6 @@ import {useEffect, useState} from "react"; -import entry from "./Entry.jsx"; +import {NumericFormat} from "react-number-format"; +import {Container, Typography} from "@mui/material"; function Result({listEntry, baseSalary}) { const [totalOvertimePay, setTotalOvertimePay] = useState(0); @@ -9,28 +10,61 @@ function Result({listEntry, baseSalary}) { }, [listEntry, baseSalary]); return ( - <div> - Totalnye: Rp{totalOvertimePay} - {listEntry.map((entry) => { - return ( - <div key={entry.id}> - <p>{entry.date.format('DD MMMM YYYY')} dapetnya Rp{calculatePerDay(entry, baseSalary)}</p> - </div> - ) - })} - </div> + <Container> + <Typography variant='h6'> + Total Overtime Pay: Rp<NumericFormat displayType="text" decimalScale={0} thousandSeparator={true} value={totalOvertimePay} /> + </Typography> + {/*{listEntry.map((entry) => {*/} + {/* return (*/} + {/* <div key={entry.id}>*/} + {/* <p>*/} + {/* {entry.date.format('DD MMMM YYYY')} dapetnya Rp<NumericFormat displayType="text" decimalScale={0} thousandSeparator={true} value={calculatePerDay(entry, baseSalary)} />*/} + {/* </p>*/} + {/* </div>*/} + {/* )*/} + {/*})}*/} + </Container> ) } function calculatePerDay(entry, baseSalary) { const hourlyPay = baseSalary / 173; - const timeDiff = entry.finish.diff(entry.start, 'hour', true); - let multiplier = 1.5; // Jam pertama - if (timeDiff > 1) { - multiplier += (timeDiff - 1) * 2; // Jam jam berikutnya + const overtimeDuration = entry.finish.diff(entry.start, 'hour', true); + let multiplier; + + // TODO: hmm... Adakah cara yg lebih cerdas dari ini? + const multiplierMap = { + workDays: { + oneHour: 1.5, + moreHours: 3.5 // 1.5 + 2 + }, + holidays: { + eightHours: 2, + nineHours: 5, // 2 + 3 + moreHours: 9 // 2 + 3 + 4 + } + } + + // Jelek bgt buset + if (entry.date.day() === 0 || entry.date.day() === 6) { // 0: Minggu, 6: Sabtu + // Kerja di hari libur. Temennya Yohana wkwk + if (0 < overtimeDuration <= 8) { + multiplier = multiplierMap.holidays.eightHours; + } else if (8 < overtimeDuration <= 9){ + multiplier = multiplierMap.holidays.nineHours; + } else { + multiplier = multiplierMap.holidays.moreHours; + } + } else { + // Lembur hari kerja + if (0 < overtimeDuration <= 8) { + multiplier = multiplierMap.workDays.oneHour; + } else { + multiplier = multiplierMap.workDays.moreHours; + } } - return multiplier * hourlyPay; + return multiplier * overtimeDuration * hourlyPay; } function getOvertimePayTotal(listEntry, baseSalary) { |