function LoadAttendanceList() { ShowPageLoader(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#attendance_list_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready(function() { new DataTable('#attendance_list_table', { paging: false, scrollCollapse: true, scrollY: '500px', layout: { topStart: { buttons: [ { text: 'Nuovo cartellino', action: function(e, dt, node, config) { NewAttendance(); } } ] } }, language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione" } }, columnDefs: [{ targets: [0], orderData: [0, 1] }, { targets: [1], orderData: [1, 0] } ] }); }); } }; xmlhttp.open("GET", "public/attendance/attendance_list_content.php"); xmlhttp.send(); } function AttendanceDetails(id) { ShowPageLoader(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#attendance_details_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready( function () { new DataTable('#attendance_details_list_table', { paging: false, scrollCollapse: true, scrollY: '500px', language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione" } }, order: { idx: 0, dir: 'asc' } }); } ); } }; xmlhttp.open("GET", "public/attendance/attendance_details_content.php?id="+id); xmlhttp.send(); } function DeleteAttendance(id) { Swal.fire({ title: "Confermi eliminazione?", text: "Il cartellino verrà eliminato definitivamente", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "grey", confirmButtonText: "Sì, elimina!", cancelButtonText: "Annulla" }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/attendance/delete_attendance.php", data: { id: id}, success: function (res) { if (res === 'ok') { HidePageLoader(); SuccessAlert("Cartellino eliminato con successo"); LoadAttendanceList(); document.querySelector("#attendance_details_content").innerHTML = ""; } else { ErrorAlert("Errore: "+res); } } }); } }); } function RecalculateAttendance(id) { Swal.fire({ title: "Confermi di voler ricalcolare il cartellino?", text: "I dati attualmente presenti saranno sovrascritti", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "grey", confirmButtonText: "Sì, ricalcola!", cancelButtonText: "Annulla" }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); CalculateAttendanceUsers(id); } }); } function AttendanceUserInfo(attendance_id, user_id) { document.getElementById("open_attendance_user_info").click(); ShowPageLoader(); setTimeout(function(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#attendance_user_info_content").innerHTML = this.responseText; HidePageLoader(); $(document).ready( function () { new DataTable('#attendance_user_details_table', { fixedColumns: { start: 1, end: 1 }, paging: false, scrollCollapse: true, scrollX: true, scrollY: '400px', layout: { topStart: { buttons: [ { extend: 'colvis', postfixButtons: ['colvisRestore'], popoverTitle: 'Visibilità colonne' }, { extend: 'print', split: ['print','excel','pdf', 'csv'] } ] } }, language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione" } }, order: { idx: 0, dir: 'asc' } }); } ); } }; xmlhttp.open("GET", "public/attendance/attendance_user_info.php?attendance_id="+attendance_id+"&&user_id="+user_id); xmlhttp.send(); }, 1000); } async function NewAttendance() { const ipAPI = "//api.ipify.org?format=json"; const { value: month } = await Swal.fire({ title: "Seleziona il mese del cartellino", input: "select", inputOptions: { 1: "Gennaio", 2: "Febbraio", 3: "Marzo", 4: "Aprile", 5: "Maggio", 6: "Giugno", 7: "Luglio", 8: "Agosto", 9: "Settembre", 10: "Ottobre", 11: "Novembre", 12: "Dicembre" }, inputPlaceholder: "Seleziona il mese", showCancelButton: true, inputValidator: (value) => { return new Promise((resolve) => { $.ajax({ type: "POST", url: "php/attendance/check_attendance_presence.php", data: { month: value }, success: function (res) { if (res === 'ok') { LoadAttendanceList(); RunProblemsControl(value, 'open'); } else { ErrorAlert("Cartellino esiste già!"); } } }); resolve(); }); } }); } function RunProblemsControl(month, type) { const current_date = new Date(); let year = current_date.getFullYear(); var start_day = new Date(year, month-1); const lastDateOfMonth = (date = new Date()) => new Date(date.getFullYear(), date.getMonth() + 1, 0); var end_day = lastDateOfMonth(new Date(start_day)); var start_date_check = start_day.toISOString(); var end_date_check = end_day.toISOString() $.ajax({ type: "POST", url: "php/check_problems.php", data: { start_date_check: start_date_check, end_date_check : end_date_check, manual : 'true'}, success: function (res) { if (res === 'ok') { CheckProblemsPresence(month, year, type, start_date_check, end_date_check); } else { ErrorAlert("Errore: "+res); } } }); } function CheckProblemsPresence(month, year, type,start_date_check, end_date_check) { $.ajax({ type: "POST", url: "php/attendance/check_problems_presence.php", data: { month: month }, success: function (res) { if (res === 'si') { OpenAttendanceProblems(month, year, type, start_date_check, end_date_check); } else { CreateAttendance(start_date_check, end_date_check); } } }); } function OpenAttendanceProblems(month, year, type, start_date_check, end_date_check) { if(type == "open") { document.getElementById("open_attendance_problems").click(); } ShowPageLoader(); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { document.querySelector("#attendance_problems_content").innerHTML = this.responseText; HidePageLoader(); setTimeout(function(){ LoadProblemsTable(month); }, 1000); } }; xmlhttp.open("GET", "public/attendance/attendance_problems_content.php?month="+month+"&&year="+year+"&&start_date_check="+start_date_check+"&&end_date_check="+end_date_check); xmlhttp.send(); } function LoadProblemsTable(month) { $(document).ready( function () { new DataTable('#problems_list_table', { paging: false, scrollCollapse: true, scrollY: '600px', layout: { topStart: { buttons: [ { extend: 'colvis', postfixButtons: ['colvisRestore'], popoverTitle: 'Visibilità colonne' }, { extend: 'print', split: ['print','excel','pdf', 'csv'] }/* , { text: 'Aggiorna', action: function (e, dt, node, config) { RunProblemsControl(month, 'update'); } } */ ] } }, language: { emptyTable: "Nessun dato presente nella tabella", search: "Cerca:", infoEmpty: "Visualizzati da 0 a 0 di 0 risultati", info: "Visualizzati da _START_ a _END_ di _TOTAL_ risultati", buttons: { print: "Stampa", colvis: "Visualizza", colvisRestore: "Ripristina visualizzazione" } }, order: { idx: 4, dir: 'desc' } }); } ); } function CreateAttendance(start_date_check, end_date_check) { $.ajax({ type: "POST", url: "php/attendance/create_attendance.php", data: { start_date: start_date_check, end_date:end_date_check }, success: function (res) { if (res === 'error') { ErrorAlert("Errore: "+res); } else { CalculateAttendanceUsers(res); } } }); } function CalculateAttendanceUsers(id) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/attendance/calculate_attendance.php", data: { id : id}, success: function (res) { HidePageLoader(); if (res === 'ok') { SuccessAlert("Cartellino generato"); LoadAttendanceList(); AttendanceDetails(id); setTimeout(function(){ GenerateAttendanceFile(id); }, 2000); } else { ErrorAlert("Errore: "+res); } } }); } function GenerateAttendanceFile(id) { $.ajax({ type: "POST", url: "php/attendance/generate_file.php", data: { id : id}, success: function (res) { if (res === 'ok') { SuccessAlert("File generato"); } else { ErrorAlert("Errore: "+res); } } }); } function SendAttendance(id) { Swal.fire({ title: "Inviare mail con cartellino allo studio paghe?", text: "L'elenco dei contatti è visivile in Impostazioni - Studio Paghe", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "grey", confirmButtonText: "Sì, invia!", cancelButtonText: "Annulla" }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/attendance/send_file.php", data: { id : id}, success: function (res) { HidePageLoader(); if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert("Email inviate: "+res); LoadAttendanceList(); AttendanceDetails(id); } } }); } }); } function CloseAttendance(id) { Swal.fire({ title: "Chiudere il cartellino?", text: "Le timbrature e permessi per il mese del cartellino non saranno più modificabili", icon: "warning", showCancelButton: true, confirmButtonColor: "#black", cancelButtonColor: "grey", confirmButtonText: "Sì, chiudi!", cancelButtonText: "Annulla" }).then((result) => { if (result.isConfirmed) { ShowPageLoader(); $.ajax({ type: "POST", url: "php/attendance/close_attendance.php", data: { id : id}, success: function (res) { HidePageLoader(); if (res === 'error') { ErrorAlert("Errore: "+res); } else { SuccessAlert("Email inviate: "+res); LoadAttendanceList(); AttendanceDetails(id); } } }); } }); }