Last active
January 29, 2021 10:45
-
-
Save antcolag/76a6d1daec1c53064bca8d411831814e to your computer and use it in GitHub Desktop.
tool per console, per inserire le ore lavorate, per in una nota agenzia interinale
This file contains hidden or 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
/* | |
skip: giorni del mese da skippare | |
firstDay: primo giorno del mese nella settimana: | |
*/ | |
lunedy = 1; | |
martedy = 2; | |
mercoledy = 3; | |
giovedy = 4; | |
venerdy = 5; | |
sabatdy = 6; | |
domedy = 0; | |
/* | |
start: da che giorno del mese | |
to: fino a che giorno del mese | |
*/ | |
orari = { | |
"1": "09.00", | |
"2": "13.00", | |
"3": "14.00", | |
"4": "18.00" | |
}; | |
skip = []; | |
start = 0; | |
to = 99; | |
inputs = undefined; | |
forceDisabled = false; | |
firstDay = undefined; | |
clear = false; | |
(function (orari, skip, start, to, inputs, forceDisabled, firstDay, clear){ | |
var processed = 0; | |
start = start || 1; | |
to = to || 31; | |
inputs = inputs || document.querySelectorAll('input'); | |
if(void 0 === firstDay){ | |
firstDay = getDate(); | |
} | |
if(firstDay instanceof Date){ | |
firstDay = getDate(firstDay); | |
} | |
inputs.forEach(function(inputElement, i){ | |
var day = parseInt( inputElement.getAttribute('day') ); | |
switch (true) { | |
case isWeekend(day): | |
case skip.includes(parseInt(day)): | |
case isInRange(day): | |
case (!forceDisabled) && (inputElement.disabled): | |
day && clear && setInputValue(inputElement, '') | |
return; | |
} | |
var orario = inputElement.id.match(/text_[0-9]+_([0-9])/) | |
if(orario && orario[1] && orari[orario[1]]) { | |
setInputValue(inputElement, orari[orario[1]]) | |
} | |
}) | |
return processed; | |
function isWeekend(day){ | |
return !((day + firstDay-1) % 7) || !((day + firstDay) % 7); | |
} | |
function isInRange(day){ | |
return (day < start) || (day > to) | |
} | |
function setInputValue(inputElement, v){ | |
/** console.log /**/(v, inputElement.value = v) | |
processed++; | |
inputElement.dispatchEvent(new Event('blur')) | |
} | |
function getDate(date){ | |
date = date || new Date(); | |
return new Date(date.getFullYear(), date.getMonth(), 1).getDay()%7 | |
} | |
})( | |
orari, | |
skip, | |
start, | |
to, | |
inputs, | |
forceDisabled, | |
firstDay, | |
clear | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copincoli in console settando i parametri
skip = ferie e festività
start/to = da / a (magari uno lavora mezzo dal 5 al 20 mese allora mette start=5 to=20)
forceDisabled = imposta anche le date future
firstDay = vedy lunedy martedy ecc, e metti quello, es per marzo 1998 firstDay = domedy
clear = prima di riempire pulisce i campi (tipo magari avevi messo le ferie male...) sabati e domeniche vengono cmq saltati