summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2023-09-30 21:03:28 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2023-09-30 21:03:28 +0700
commitf4fa43d4686651b62f67e24d3698ea2324082f8e (patch)
treedd46717c66a4172d6a111f389140e97947397e8e /src
parentca044349cac7434560f2646bc4ea4c27f5783d47 (diff)
a more proper calculation including weekend, libur nasional not considered yet
Diffstat (limited to 'src')
-rw-r--r--src/App.jsx1
-rw-r--r--src/Result.jsx66
-rw-r--r--src/SalaryInput.jsx2
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 (
- <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) {
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);