diff --git a/index.html b/index.html index 3e3be8a..53df78e 100644 --- a/index.html +++ b/index.html @@ -168,6 +168,12 @@

Settings

+ +
+
START PTO
+ +
+
diff --git a/src/actions.js b/src/actions.js index 1c4108f..1e02547 100644 --- a/src/actions.js +++ b/src/actions.js @@ -151,6 +151,8 @@ function updateAllPTO() { } function calculateAccruals(calcPTO = false) { + Day.startingDay = null; + // Starting day of accruals const startMonth = Settings.startDay.month; const startYear = Settings.startDay.year; @@ -192,7 +194,8 @@ function saveData() { add: Settings.getSetting("add"), sub: Settings.getSetting("sub"), max: Settings.getSetting("max"), - carry: Settings.getSetting("carry") + carry: Settings.getSetting("carry"), + start: Settings.getSetting("start") }; const payroll = { payroll: Settings.getSetting("payroll"), diff --git a/src/main.js b/src/main.js index f96ca20..c3012f7 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,7 @@ function initListeners() { const subSettingElem = document.getElementById("setting-sub"); const maxSettingElem = document.getElementById("setting-max"); const carrySettingElem = document.getElementById("setting-carry"); + const startPTOElem = document.getElementById("setting-start"); const startMonthElem = document.getElementById("pto-start-month"); const startDayElem = document.getElementById("pto-start-day"); const startYearElem = document.getElementById("pto-start-year"); @@ -36,6 +37,12 @@ function initListeners() { updateAllPTO(); saveChanges(); }); + startPTOElem.addEventListener("change", ()=>{ + Settings.setSetting("start", parseFloat(startPTOElem.value)); + Settings.unknownMaxDate(); + updateAllPTO(); + saveChanges(); + }); startMonthElem.addEventListener("change", ()=>{ Settings.startDay.month = parseFloat(startMonthElem.value) - 1; Settings.unknownMaxDate(); @@ -173,6 +180,8 @@ class Month { } class Day { + static startingDay = null; + constructor(month, dayOfWeek, dayOfMonth) { this.month = month; this.dayOfWeek = dayOfWeek; @@ -206,7 +215,8 @@ class Day { } getLocalTimeOff() { - let time = this.data.time; + let time = this.isStartingDay() ? Settings.start : 0; + time += this.data.time; if (this.data.add) time += Settings.getSetting("add"); if (this.data.sub) time -= Settings.getSetting("sub"); return time; @@ -219,6 +229,9 @@ class Day { } isStartingDay() { + if (Day.startingDay !== null) + return this == Day.startingDay; + // Starting day of accruals const startMonth = Settings.startDay.month; // [0] const startDay = Settings.startDay.day; // [1] @@ -229,7 +242,10 @@ class Day { return false; // Starting day? - return (startDay - 1 == this.dayOfMonth); + if (startDay - 1 == this.dayOfMonth) { + Day.startingDay = this; + return true; + } else return false; } } diff --git a/src/settings.js b/src/settings.js index 49facaa..ecde339 100644 --- a/src/settings.js +++ b/src/settings.js @@ -5,6 +5,7 @@ class Settings { static max = 0; static carry = 0; static round = 1; + static start = 0; static payroll = "Weekly"; static payrollWeek = "Saturday"; static payrollDay = 1; @@ -15,6 +16,7 @@ class Settings { Settings.setSetting("sub", 8); Settings.setSetting("max", 120); Settings.setSetting("carry", 120); + Settings.setSetting("start", 0); // Current day const currentDay = new Date(); @@ -52,6 +54,7 @@ class Settings { } static setStartDate(month, day, year) { + Day.startingDay = null; Settings.startDay.month = month; Settings.startDay.day = day; Settings.startDay.year = year;