Total Upah Lembur: Rp
Rincian
{ listEntry.map((entry) => {
return (
{entry.date.format('DD MMMM YYYY')}: Rp
)
}) }
)
}
function segmentTime(duration, segments) {
const segmentSum = segments.reduce((partialSum, a) => partialSum + a, 0);
const segmentsFilled = [...segments, 24 - segmentSum];
const segmentedHours = [];
for (const[index, segmentDuration] of segmentsFilled.entries()) {
if (index < segmentsFilled.length - 1) {
const hours = Math.min(duration, segmentDuration);
segmentedHours.push(hours);
duration -= hours;
} else {
segmentedHours.push(duration);
}
}
return segmentedHours;
}
function calculatePerDay(entry, baseSalary) {
const hourlyPay = baseSalary / 173;
const overtimeDuration = entry.finish.diff(entry.start, 'hour', true);
let multiplier = 0;
// TODO: find better way
const multiplierMap = {
workDays: [
1.5, // jam pertama
2
],
holidays: [
2, // 8 jam pertama
3, // jam ke 9
4
]
}
const isWeekend = entry.date.day() === 0 || entry.date.day() === 6; // 0: Minggu, 6: Sabtu
const segmentedDuration = segmentTime(overtimeDuration, [1]);
const usedMap = isWeekend ? multiplierMap.holidays : multiplierMap.workDays;
for (let i = 0; i < segmentedDuration.length; i++) {
multiplier += segmentedDuration[i] * usedMap[i];
}
return multiplier * hourlyPay;
}
function getOvertimePayTotal(listEntry, baseSalary) {
let total = 0;
listEntry.forEach((entry) => {
total += calculatePerDay(entry, baseSalary)
});
return total;
}
export default Result;