diff --git a/README.md b/README.md index 2617847..754771e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ The SQLite database is created automatically in `data/go.sqlite`. - Feriefridage must be used before `31 August` and expire before September planning. - FLEX days use `7.5h` Monday-Thursday and `7h` Friday. - Start balances are configured separately from current FLEX hours. -- Monthly vacation-day corrections can be entered, e.g. `+1.2` or `-2.6` days. +- The planner shows configurable numbers of previous and future months around the current month. +- Monthly vacation-day corrections can be entered directly in the planner table, e.g. `+1.2` or `-2.6` days. - Each date-range entry can individually allow unpaid fallback so only that range is converted to unpaid days if balances are insufficient. ## Data diff --git a/api.php b/api.php index 493b000..62be7de 100644 --- a/api.php +++ b/api.php @@ -122,6 +122,8 @@ function migrate(PDO $db): void 'planning_start_month' => '1', 'planning_years' => '3', 'planning_months' => '36', + 'previous_months' => '5', + 'future_months' => '30', 'vacation_days_per_month' => '2.08', 'feriefridage_per_year' => '5', 'feriefridage_expiry_month' => '8', @@ -156,6 +158,8 @@ function save_settings(PDO $db, array $settings): void 'planning_start_month', 'planning_years', 'planning_months', + 'previous_months', + 'future_months', 'vacation_days_per_month', 'feriefridage_per_year', 'feriefridage_expiry_month', diff --git a/app.js b/app.js index 3cdc86c..db40751 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,7 @@ const state = { }; const settingKeys = [ - 'planning_start_year', 'planning_start_month', 'planning_months', + 'previous_months', 'future_months', 'vacation_days_per_month', 'feriefridage_per_year', 'feriefridage_expiry_month', 'normal_day_hours', 'friday_hours', 'opening_vacation_days', 'opening_feriefridage_days', 'opening_flex_hours' @@ -55,8 +55,8 @@ async function loadState() { function normalizeSettings(settings) { const normalized = { ...settings }; - normalized.planning_start_month = Number(normalized.planning_start_month || 1); - normalized.planning_months = Number(normalized.planning_months || (Number(normalized.planning_years || 3) * 12)); + normalized.previous_months = Number(normalized.previous_months ?? 5); + normalized.future_months = Number(normalized.future_months ?? 30); return normalized; } @@ -338,9 +338,13 @@ function renderMonthRow(month) { } function calculatePlan(settings, entries, corrections = {}) { - const startYear = Number(settings.planning_start_year || new Date().getFullYear()); - const startMonth = Number(settings.planning_start_month || 1); - const monthCount = Number(settings.planning_months || (Number(settings.planning_years || 3) * 12)); + const today = dateFromParts(new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()); + const previousMonths = Number(settings.previous_months ?? 5); + const futureMonths = Number(settings.future_months ?? 30); + const startCursor = dateFromParts(today.getFullYear(), today.getMonth() + 1 - previousMonths, 1); + const startYear = startCursor.getFullYear(); + const startMonth = startCursor.getMonth() + 1; + const monthCount = previousMonths + futureMonths + 1; const startDate = dateFromParts(startYear, startMonth, 1); const endDate = dateFromParts(startYear, startMonth + monthCount, 0); const months = []; @@ -371,7 +375,6 @@ function calculatePlan(settings, entries, corrections = {}) { } const avgDayHours = averageDayHours(settings); - const today = dateFromParts(new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()); const currentFlexHours = Number(settings.current_flex_hours ?? flexBalance); for (let i = 0; i < monthCount; i++) { @@ -504,8 +507,10 @@ function calculatePlan(settings, entries, corrections = {}) { function calculateCurrentSnapshot(settings, entries, corrections = {}) { const today = dateFromParts(new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()); - const startYear = Number(settings.planning_start_year || today.getFullYear()); - const startMonth = Number(settings.planning_start_month || 1); + const previousMonths = Number(settings.previous_months ?? 5); + const startCursor = dateFromParts(today.getFullYear(), today.getMonth() + 1 - previousMonths, 1); + const startYear = startCursor.getFullYear(); + const startMonth = startCursor.getMonth() + 1; const startDate = dateFromParts(startYear, startMonth, 1); const avgDayHours = averageDayHours(settings); const warnings = []; diff --git a/index.html b/index.html index 61e451e..c509b5f 100644 --- a/index.html +++ b/index.html @@ -114,9 +114,8 @@