2021-10-19 08:52:45 +00:00
|
|
|
var userData = "";
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2023-11-28 13:50:11 +00:00
|
|
|
userData = JSON.parse(localStorage.getItem("userData"));
|
2021-10-19 08:52:45 +00:00
|
|
|
FastClick.attach(document.body);
|
|
|
|
setView();
|
|
|
|
setEvents();
|
|
|
|
});
|
|
|
|
|
|
|
|
function setEvents() {
|
|
|
|
|
|
|
|
$(".btnSalir").on("click", function () {
|
|
|
|
cerrar();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".in").on("click", function () {
|
|
|
|
fichar('in');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".inMiddle").on("click", function () {
|
|
|
|
fichar('middle');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".outMiddle").on("click", function () {
|
|
|
|
fichar('middle');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".out").on("click", function () {
|
|
|
|
fichar('out');
|
|
|
|
});
|
2022-05-24 06:01:06 +00:00
|
|
|
|
2021-10-19 08:52:45 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
cerrar();
|
2022-05-24 06:01:06 +00:00
|
|
|
}, 5000);
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setView() {
|
|
|
|
$(".footer").hide();
|
|
|
|
$("#txtNombre").text(userData["name"] + " " + userData["surname"]);
|
|
|
|
getInfo();
|
|
|
|
$("." + userData["button1"]).show();
|
|
|
|
$("." + userData["button2"]).show();
|
|
|
|
}
|
|
|
|
|
2022-05-23 13:28:03 +00:00
|
|
|
function fichar(direction) {
|
2023-11-28 13:50:11 +00:00
|
|
|
const data = {
|
|
|
|
workerFk: userData['userFk'],
|
|
|
|
direction
|
|
|
|
}
|
|
|
|
|
2021-10-19 08:52:45 +00:00
|
|
|
$.post({
|
2023-11-28 13:50:11 +00:00
|
|
|
urlPath: 'WorkerTimeControls/clockIn',
|
|
|
|
jsonData: data,
|
2021-10-19 08:52:45 +00:00
|
|
|
processData: false,
|
|
|
|
success: function (msg) {
|
|
|
|
if (msg[0].error){
|
|
|
|
printErrores(msg);
|
|
|
|
setTimeout(function () {
|
|
|
|
cerrar();
|
2023-08-23 10:54:58 +00:00
|
|
|
}, 2000);
|
2021-10-19 08:52:45 +00:00
|
|
|
}else {
|
|
|
|
$(".confirm").fadeIn(200);
|
2023-08-23 08:22:33 +00:00
|
|
|
$(".txtConfirm").append('Fichada registrada correctamente');
|
2021-10-19 08:52:45 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
cerrar();
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setView() {
|
|
|
|
$(".footer").hide();
|
|
|
|
$(".in").hide();
|
|
|
|
$(".inMiddle").hide();
|
|
|
|
$(".outMiddle").hide();
|
|
|
|
$(".out").hide();
|
|
|
|
$("#txtNombre").text(userData["name"] + " " + userData["surname"]);
|
|
|
|
getInfo();
|
2022-02-28 08:44:00 +00:00
|
|
|
if(userData["button1"] === null && userData["button2"] === null ) {
|
2022-05-12 09:18:40 +00:00
|
|
|
printError ("Contacta con tu responsable")
|
2022-02-28 08:44:00 +00:00
|
|
|
} else {
|
|
|
|
$("." + userData["button1"]).show();
|
|
|
|
$("." + userData["button2"]).show();
|
|
|
|
}
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getInfo() {
|
2023-11-28 13:50:11 +00:00
|
|
|
const queryString = $.param({ workerFk: userData['userFk'] });
|
|
|
|
|
|
|
|
$.get({
|
|
|
|
urlPath: `WorkerTimeControls/getClockIn?${queryString}`,
|
2021-10-19 08:52:45 +00:00
|
|
|
processData: false,
|
|
|
|
success: function (data) {
|
|
|
|
$('.footer').show();
|
2022-05-23 13:28:03 +00:00
|
|
|
printTimetable(data);
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-23 13:28:03 +00:00
|
|
|
function printTimetable(timetable) {
|
2022-05-24 14:15:19 +00:00
|
|
|
var listWeekName = weekDays();
|
2022-05-23 13:28:03 +00:00
|
|
|
var dated = new Date();
|
|
|
|
dated.setDate(dated.getDate() - 6);
|
|
|
|
|
|
|
|
for (var i = 0; i < 6; i++) {
|
|
|
|
$(".listHorario").append('<label>' + listWeekName[dated.getDay()] +'</label>');
|
|
|
|
dated.setDate(dated.getDate() + 1);
|
|
|
|
}
|
|
|
|
$(".listHorario").append('<label class="hoy">HOY</label>');
|
2023-08-23 08:22:33 +00:00
|
|
|
$(".listHorario").append('<li class="hrTop"></li>');
|
2022-05-23 13:28:03 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < timetable.length; i++) {
|
|
|
|
|
|
|
|
$(".listHorario").append(
|
|
|
|
'<li>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["6daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["6daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["6daysAgo"]) + '</p>' +
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["5daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["5daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["5daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["4daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["4daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["4daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["3daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["3daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["3daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["2daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["2daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["2daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["1daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["1daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["1daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'<div class="time ' + ifIsEmpty(timetable[i]["0daysAgo"]) + '">' +
|
2023-08-23 08:22:33 +00:00
|
|
|
'<div>' +
|
|
|
|
'<img src="' + ifIsEmptyImage(timetable[i]["0daysAgoDirection"]) + '" />' +
|
|
|
|
'<p>' + ifIsEmptyText(timetable[i]["0daysAgo"]) + '</p>'+
|
|
|
|
'</div>' +
|
2022-05-23 13:28:03 +00:00
|
|
|
'</div>' +
|
|
|
|
'</li>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
printTotalHours(timetable);
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 13:28:03 +00:00
|
|
|
function printTotalHours(timetable) {
|
2023-08-23 08:22:33 +00:00
|
|
|
if(timetable.length > 0) {
|
2022-05-23 13:28:03 +00:00
|
|
|
|
2023-08-23 08:22:33 +00:00
|
|
|
$(".listHorario").append('<hr>');
|
2022-05-23 13:28:03 +00:00
|
|
|
$(".listHorario").append('<li><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["6daysAgoTotal"]))
|
2023-08-23 10:03:15 +00:00
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["5daysAgoTotal"]))
|
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["4daysAgoTotal"]))
|
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["3daysAgoTotal"]))
|
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["2daysAgoTotal"]))
|
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["1daysAgoTotal"]))
|
|
|
|
+ ' h</div><div class="time">' + secondsToHm(ifIsEmptyText(timetable[0]["0daysAgoTotal"]))
|
|
|
|
+ ' h</div></li>');
|
2022-05-23 13:28:03 +00:00
|
|
|
|
|
|
|
$(".total").text('Total: ' +
|
2023-08-23 08:22:33 +00:00
|
|
|
secondsToHm(
|
|
|
|
Number(timetable[0]["6daysAgoTotal"] == null) +
|
|
|
|
Number(timetable[0]["5daysAgoTotal"]) +
|
|
|
|
Number(timetable[0]["4daysAgoTotal"]) +
|
|
|
|
Number(timetable[0]["3daysAgoTotal"]) +
|
|
|
|
Number(timetable[0]["2daysAgoTotal"]) +
|
|
|
|
Number(timetable[0]["1daysAgoTotal"]) +
|
|
|
|
Number(timetable[0]["0daysAgoTotal"])
|
2023-08-23 10:03:15 +00:00
|
|
|
) + ' h');
|
2022-05-23 13:28:03 +00:00
|
|
|
} else{
|
2023-08-23 08:22:33 +00:00
|
|
|
$(".total").text('Total: 0h');
|
2022-05-23 13:28:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 14:15:19 +00:00
|
|
|
function weekDays() {
|
|
|
|
var weekDays = [
|
|
|
|
'Domingo',
|
|
|
|
'Lunes',
|
|
|
|
'Martes',
|
|
|
|
'Miércoles',
|
|
|
|
'Jueves',
|
|
|
|
'Viernes',
|
|
|
|
'Sábado'
|
|
|
|
];
|
|
|
|
|
|
|
|
return weekDays;
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 14:15:19 +00:00
|
|
|
|
2021-10-19 08:52:45 +00:00
|
|
|
|
|
|
|
function printErrores(errores) {
|
2023-08-23 10:54:58 +00:00
|
|
|
var error = '';
|
2021-10-19 08:52:45 +00:00
|
|
|
for (var i = 0; i < errores.length; i++) {
|
|
|
|
if (errores[i].error) {
|
|
|
|
error += errores[i].error + "<br>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ifIsEmpty(value) {
|
|
|
|
if (value.trim().length === 0) {
|
|
|
|
return "hide";
|
|
|
|
} else {
|
|
|
|
return "show";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 13:28:03 +00:00
|
|
|
function ifIsEmptyImage(value) {
|
|
|
|
if (value.trim().length === 0) {
|
2023-08-23 12:25:20 +00:00
|
|
|
return "img/in.svg";
|
2022-05-23 13:28:03 +00:00
|
|
|
} else {
|
2023-08-23 12:25:20 +00:00
|
|
|
return "img/" + value + ".svg";
|
2022-05-23 13:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 08:52:45 +00:00
|
|
|
function ifIsEmptyText(value) {
|
|
|
|
if (value.trim().length === 0) {
|
|
|
|
return "00:00";
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cerrar(){
|
|
|
|
localStorage.removeItem("userData");
|
|
|
|
setTimeout(function () {
|
2021-10-25 17:07:11 +00:00
|
|
|
window.location='index.html';
|
2021-10-19 08:52:45 +00:00
|
|
|
}, 200);
|
2022-05-23 13:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function secondsToHm(seconds) {
|
|
|
|
seconds = Number(seconds);
|
|
|
|
let hours = Math.floor(seconds / 3600);
|
|
|
|
let minutes = Math.floor(seconds % 3600 / 60);
|
|
|
|
return hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0');
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|