Skip to content

Instantly share code, notes, and snippets.

@Glutexo
Last active July 1, 2020 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glutexo/c07cc56085a00d11906094597c97ff9d to your computer and use it in GitHub Desktop.
Save Glutexo/c07cc56085a00d11906094597c97ff9d to your computer and use it in GitHub Desktop.
OrangeHRM timesheet fill-out
// ==UserScript==
// @name OrangeHRM filler
// @version 1.0.0
// @description Simplifies OrangeHRM monthly timesheet submission
// @author Glutexo
// @homepage https://gist.github.com/Glutexo/c07cc56085a00d11906094597c97ff9d
// @match https://*.orangehrm.com/index.php/time/viewTimesheet/mode/my
// ==/UserScript==
/**
* Simplifies OrangeHRM monthly timesheet submission
*
* Fills in each regular day with the same time (08:00 – 16:30, 00:30 lunch break).
* A regular day is a day without special flags: no public holiday, no vacation,
* no weekend.
*/
(function() {
function fillTimeSheet() {
var rows = document.querySelectorAll('#timesheetTable .activeRow');
function eachRow(row, _index, _list) {
// @TODO Make less cryptic. :)
var regularDay = row.classList.length == 1 && row.classList[0] == 'activeRow';
function fillRow() {
var inTimeInput = row.querySelector('[name$=\\[inTime\\]]'),
outTimeInput = row.querySelector('[name$=\\[outTime\\]]'),
breakDurationInput = row.querySelector('[name$=\\[breakDuration\\]]'),
event = new MouseEvent('blur'),
empty = inTimeInput.value === '' && outTimeInput.value === '' && breakDurationInput.value === '';
// Only empty rows, do not overwrite something special.
if (empty) {
// 8 hrs of work, ½ hr lunch break
inTimeInput.value = '08:00';
outTimeInput.value = '16:30';
breakDurationInput.value = '00:30';
// Must trigger a blur event, so the app counts the working hours for the day.
breakDurationInput.dispatchEvent(event);
}
}
// Only regular days, everything else is a special case.
if (regularDay) {
fillRow();
}
}
rows.forEach(eachRow);
}
function init() {
var saveButton = document.getElementById('topBtnSave'),
formGroup = saveButton.parentNode,
fillButton = document.createElement('input');
function buttonClick(event) {
event.preventDefault();
fillTimeSheet();
}
fillButton.type = 'button';
fillButton.value = 'Fill';
fillButton.classList.add('btn', 'btn-sm', 'rh-grn');
fillButton.addEventListener('click', buttonClick);
formGroup.appendChild(fillButton);
}
init();
})();
@slemrmartin
Copy link

@Glutexo most useful code in RH :D

@Glutexo
Copy link
Author

Glutexo commented Jan 8, 2020

Added a userscript header so it can be used with Tampermonkey.

@313malek
Copy link

How can I integrate this code to my projet Orangehrm and make it work?

@Glutexo
Copy link
Author

Glutexo commented Jun 30, 2020

@313malek Install Tampermonkey into your browser. Then click its toolbar icon and add a new script. Copy-paste this code into the editor. Feel free to contact me if you have any more questions.

@Glutexo
Copy link
Author

Glutexo commented Jun 30, 2020

@slemrmartin Workday script is being born. https://gist.github.com/Glutexo/9776ca630ac33e889fdb63133156dfc3 Prety shitty as for now. It still requires a lot of manual work like blurring all the fields. I‘ll give it some more love next month again. 😆

@slemrmartin
Copy link

Great, thanks!

@Glutexo
Copy link
Author

Glutexo commented Jul 1, 2020

@slemrmartin Continued in https://github.com/Glutexo/workday-timesheet-filler. Blurring is fixed. Still not very automatic, but saves some manual input. Also please note that Workday has an auto-fill function that allows you to copy time entries from previous weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment