-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fa0f59
commit 501729b
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const overtimeCalc = require('./utils/calc') | ||
|
||
router.get('/results/:email', async (req, res) => { | ||
try { | ||
// Find the logged in user based on the session ID | ||
const entryData = await Entry.findByPk(req.params.email, { | ||
}); | ||
|
||
const entry = entryData.get({ plain: true }); | ||
const X, Y, Z | ||
overtimeCalc(entry.start, entry.end, entry.lunch, entry.salary); | ||
res.render('results', { | ||
X, Y, Z, | ||
}); | ||
|
||
} catch (err) { | ||
res.status(500).json(err); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const entryFormHandler = async (event) => { | ||
event.preventDefault(); | ||
|
||
const email = document.querySelector('#email-entry').value.trim(); | ||
const industry = document.querySelector('#industry-entry').value.trim(); | ||
const start = document.querySelector('#start-entry').value.trim(); | ||
const end = document.querySelector('#end-entry').value.trim(); | ||
const lunch = document.querySelector('#lunch-entry').value.trim(); | ||
const salary = document.querySelector('#salary-gross').value.trim(); | ||
|
||
if (email && industry && start && end && lunch && salary) { | ||
const response = await fetch('/api/entry', { | ||
method: 'POST', | ||
body: JSON.stringify({ mail, industry, start, end, lunch, salary }), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
if (response.ok) { | ||
document.location.replace('/results'); | ||
} else { | ||
alert(response.statusText); | ||
} | ||
} | ||
}; | ||
|
||
document | ||
.querySelector('.entry-form') | ||
.addEventListener('submit', entryFormHandler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
const moment = require('moment'); | ||
|
||
module.exports = { | ||
overtimeCalc: (start, end, lunch, salary) => { | ||
// const start = moment(document.querySelector('#start-entry').value.format("HH:MM")); | ||
// const end = moment(document.querySelector('#end-entry').value.format("HH:MM")); | ||
// const lunch = parseFloat(document.querySelector('#lunch-entry').value.trim()); | ||
// const salary = parseFloat(document.querySelector('#salary-gross').value.trim()); | ||
const duration = moment.duration(moment(end).diff(start)); | ||
|
||
if (lunch == "nolunch") { | ||
var newDuration = moment(duration).add(30, 'm').toDate(); | ||
} | ||
|
||
const X = newDuration.asHours(); | ||
const Y = hoursWorkedDaily * 230 | ||
const hourlyRate = (salary/260)/7.5 | ||
const Z = hourlyRate * hoursWorkedAnnual | ||
|
||
if (hoursWorkedDaily >= 7.5) { | ||
return { X, Y, Z } | ||
} else { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,15 @@ | |
|
||
<h1 class="text-white mb-5">You have the right to switch off.</h1> | ||
|
||
<form> | ||
<form class= "entry-form" id="entry-form"> | ||
<div class="row"> | ||
<div class="col"> | ||
<label class="text-white mb-2">Email address <span>*</span> </label> | ||
<input type="text" class="form-control mb-3" placeholder="[email protected]" name="email_address" id="email" required /> | ||
<input type="text" class="form-control mb-3 email-entry" placeholder="[email protected]" name="email_address" id="email-entry" required /> | ||
</div> | ||
</div> | ||
|
||
<div class="row mb-4"> | ||
<div class="row mb-4 industry-entry" id="industry-entry"> | ||
<div class="col"> | ||
<label class="text-white mb-2">Industry <span>*</span> </label> | ||
<select class="form-select"> | ||
|
@@ -69,7 +69,7 @@ | |
</div> | ||
</div> | ||
|
||
<div class="row mb-4"> | ||
<div class="row mb-4 start-entry" id="start-entry"> | ||
<div class="col"> | ||
<label class="text-white mb-2">Start time <span>*</span> </label> | ||
<select class="form-select"> | ||
|
@@ -125,7 +125,7 @@ | |
</select> | ||
</div> | ||
|
||
<div class="col"> | ||
<div class="col end-entry" id="end-entry"> | ||
<label class="text-white mb-2">Finish time <span>*</span> </label> | ||
<select class="form-select"> | ||
<option selected>9:00am</option> | ||
|