From f4fa43d4686651b62f67e24d3698ea2324082f8e Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sat, 30 Sep 2023 21:03:28 +0700 Subject: a more proper calculation including weekend, libur nasional not considered yet --- src/App.jsx | 1 - src/Result.jsx | 66 ++++++++++++++++++++++++++++++++++++++++------------- src/SalaryInput.jsx | 2 ++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 8a487e0..705587c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -15,7 +15,6 @@ function App() { ] ); const [removeDisabled, setRemoveDisabled] = useState(false); - // const [lastId, setLastId] = useState(0); useEffect(() => { setRemoveDisabled(listEntry.length === 1); 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 ( -
- Totalnye: Rp{totalOvertimePay} - {listEntry.map((entry) => { - return ( -
-

{entry.date.format('DD MMMM YYYY')} dapetnya Rp{calculatePerDay(entry, baseSalary)}

-
- ) - })} -
+ + + Total Overtime Pay: Rp + + {/*{listEntry.map((entry) => {*/} + {/* return (*/} + {/*
*/} + {/*

*/} + {/* {entry.date.format('DD MMMM YYYY')} dapetnya Rp*/} + {/*

*/} + {/*
*/} + {/* )*/} + {/*})}*/} +
) } 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) { diff --git a/src/SalaryInput.jsx b/src/SalaryInput.jsx index 753d457..2091a36 100644 --- a/src/SalaryInput.jsx +++ b/src/SalaryInput.jsx @@ -11,6 +11,8 @@ function SalaryInput({handleBaseSalaryChange}) { variant="outlined" valueIsNumericString={true} thousandSeparator={true} + allowNegative={false} + decimalScale={0} value={baseSalary} onValueChange={(value, sourceInfo) => { setBaseSalary(value.value); -- cgit v1.2.3-70-g09d2