Skip to content

Commit

Permalink
Added Starting PTO
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmennater committed Nov 15, 2023
1 parent 3992192 commit 3be5c37
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ <h2 class="header">Settings</h2>
<input id="pto-start-year">
</div>

<!-- Start Time Off -->
<div class="line">
<div class="label">START PTO</div>
<input id="setting-start">
</div>

<!-- Reset Button -->
<div class="line">
<button class="button" onclick="clearData()">Reset</button>
Expand Down
5 changes: 4 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down
20 changes: 18 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -173,6 +180,8 @@ class Month {
}

class Day {
static startingDay = null;

constructor(month, dayOfWeek, dayOfMonth) {
this.month = month;
this.dayOfWeek = dayOfWeek;
Expand Down Expand Up @@ -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;
Expand All @@ -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]
Expand All @@ -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;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3be5c37

Please sign in to comment.