Feriefridage logic improved, mobile styling
This commit is contained in:
parent
c48c26290e
commit
71aeb691df
2 changed files with 89 additions and 12 deletions
35
app.js
35
app.js
|
|
@ -637,13 +637,46 @@ function calculateCurrentSnapshot(settings, entries, corrections = {}, feriefrid
|
|||
if (feriefridageBalance < -0.001) warnings.push({ level: 'bad', text: `Feriefridage balance is negative today: ${days(feriefridageBalance)} days.` });
|
||||
if (flexBalance < -0.001) warnings.push({ level: 'bad', text: `FLEX balance is negative today: ${hours(flexBalance)}.` });
|
||||
if (today.getMonth() + 1 <= Number(settings.feriefridage_expiry_month || 8) && feriefridageBalance > 0.001) {
|
||||
warnings.push({ level: 'warn', text: `${days(feriefridageBalance)} feriefridage must be used before 31 August.` });
|
||||
const remainingAfterApprovedPlans = feriefridageRemainingAfterApprovedPlans(settings, entries, today, {
|
||||
vacationBalance,
|
||||
feriefridageBalance,
|
||||
flexBalance,
|
||||
});
|
||||
if (remainingAfterApprovedPlans > 0.001) {
|
||||
warnings.push({ level: 'warn', text: `${days(remainingAfterApprovedPlans)} feriefridage need approved plan before 31 August.` });
|
||||
}
|
||||
}
|
||||
|
||||
const totalDays = vacationBalance + feriefridageBalance + (flexBalance / avgDayHours);
|
||||
return { vacation: vacationBalance, feriefridage: feriefridageBalance, flex: flexBalance, totalDays, warnings: dedupeWarnings(warnings) };
|
||||
}
|
||||
|
||||
function feriefridageRemainingAfterApprovedPlans(settings, entries, today, balances) {
|
||||
const expiryMonth = Number(settings.feriefridage_expiry_month || 8);
|
||||
const deadline = dateFromParts(today.getFullYear(), expiryMonth + 1, 0);
|
||||
let { vacationBalance, feriefridageBalance, flexBalance } = balances;
|
||||
|
||||
const futureApprovedWorkdays = [];
|
||||
for (const entry of entries) {
|
||||
if (entry.status !== 'approved') continue;
|
||||
for (const date of workdaysBetween(entry.start_date, entry.end_date)) {
|
||||
if (date > today && date <= deadline) {
|
||||
futureApprovedWorkdays.push({ date, entry });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
futureApprovedWorkdays.sort((a, b) => a.date - b.date || a.entry.id - b.entry.id);
|
||||
for (const item of futureApprovedWorkdays) {
|
||||
const allocation = allocateDay(item.entry, item.date, { vacationBalance, feriefridageBalance, flexBalance }, settings);
|
||||
vacationBalance = allocation.balances.vacationBalance;
|
||||
feriefridageBalance = allocation.balances.feriefridageBalance;
|
||||
flexBalance = allocation.balances.flexBalance;
|
||||
}
|
||||
|
||||
return feriefridageBalance;
|
||||
}
|
||||
|
||||
function allocateDay(entry, date, balances, settings) {
|
||||
const source = entry.source;
|
||||
const allowUnpaid = Boolean(Number(entry.allow_unpaid));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue