From ca044349cac7434560f2646bc4ea4c27f5783d47 Mon Sep 17 00:00:00 2001
From: Rosyid Haryadi <rosyid_haryadi@protonmail.com>
Date: Sat, 30 Sep 2023 18:29:36 +0700
Subject: cursed state management

---
 src/Result.jsx | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/Result.jsx

(limited to 'src/Result.jsx')

diff --git a/src/Result.jsx b/src/Result.jsx
new file mode 100644
index 0000000..0ea4810
--- /dev/null
+++ b/src/Result.jsx
@@ -0,0 +1,44 @@
+import {useEffect, useState} from "react";
+import entry from "./Entry.jsx";
+
+function Result({listEntry, baseSalary}) {
+    const [totalOvertimePay, setTotalOvertimePay] = useState(0);
+
+    useEffect(() => {
+        setTotalOvertimePay(getOvertimePayTotal(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>
+    )
+}
+
+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
+    }
+
+    return multiplier * hourlyPay;
+}
+
+function getOvertimePayTotal(listEntry, baseSalary) {
+    let total = 0;
+    listEntry.forEach((entry) => {
+        total += calculatePerDay(entry, baseSalary)
+    });
+    return total;
+}
+
+export default Result;
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

