diff --git a/attendance/static/attendance/actions.js b/attendance/static/attendance/actions.js index b8ef49406..2b5e5cbaa 100644 --- a/attendance/static/attendance/actions.js +++ b/attendance/static/attendance/actions.js @@ -20,10 +20,31 @@ $(document).ready(function () { en: "Do you really want to delete all the selected attendances?", fr: "Voulez-vous vraiment supprimer toutes les présences sélectionnées?", }; + var norowvalidateMessages = { + ar: "لم يتم تحديد أي صفوف من فحص الحضور.", + de: "Im Feld „Anwesenheit validieren“ sind keine Zeilen ausgewählt.", + es: "No se selecciona ninguna fila de Validar asistencia.", + en: "No rows are selected from Validate Attendances.", + fr: "Aucune ligne n'est sélectionnée dans Valider la présence.", + }; + var norowotMessages = { + ar: "لم يتم تحديد أي صفوف من حضور العمل الإضافي.", + de: "In der OT-Anwesenheit sind keine Zeilen ausgewählt.", + es: "No se seleccionan filas de Asistencias de OT.", + en: "No rows are selected from OT Attendances.", + fr: "Aucune ligne n'est sélectionnée dans les présences OT.", + }; + var norowdeleteMessages = { + ar: "لم يتم تحديد أي صفوف لحذف الحضور.", + de: "Es sind keine Zeilen zum Löschen von Anwesenheiten ausgewählt.", + es: "No se seleccionan filas para eliminar asistencias.", + en: "No rows are selected for deleting attendances.", + fr: "Aucune ligne n'est sélectionnée pour la suppression des présences.", + }; function getCurrentLanguageCode(callback) { $.ajax({ type: "GET", - url: "/attendance/get-language-code/", + url: "/employee/get-language-code/", success: function (response) { var languageCode = response.language_code; callback(languageCode); // Pass the language code to the callback function @@ -72,33 +93,50 @@ $(document).ready(function () { } return cookieValue; } + $("#validateAttendances").click(function (e) { e.preventDefault(); var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; - console.log(languageCode); var confirmMessage = validateMessages[languageCode]; - choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".validate-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowvalidateMessages[languageCode]; + var checkedRows = $(".validate-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/attendance/validate-bulk-attendance", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); - } else { - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/attendance/validate-bulk-attendance", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); + } else { + } + }, + }); + } }); } }); @@ -110,26 +148,43 @@ $(document).ready(function () { getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = overtimeMessages[languageCode]; - choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".ot-attendance-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowotMessages[languageCode]; + var checkedRows = $(".ot-attendance-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/attendance/approve-bulk-overtime", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); - } else { - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "success", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/attendance/approve-bulk-overtime", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); + } else { + } + }, + }); + } }); } }); @@ -141,26 +196,43 @@ $(document).ready(function () { getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = deleteMessages[languageCode]; - choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".attendance-checkbox").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowdeleteMessages[languageCode]; + var checkedRows = $(".attendance-checkbox").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/attendance/attendance-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); - } else { - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/attendance/attendance-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); + } else { + } + }, + }); + } }); } }); diff --git a/attendance/views/views.py b/attendance/views/views.py index 47b11c3b2..889823b1b 100644 --- a/attendance/views/views.py +++ b/attendance/views/views.py @@ -125,10 +125,6 @@ def attendance_validate(attendance): at_work = strtime_seconds(attendance.attendance_worked_hour) return condition_for_at_work >= at_work -def get_language_code(request): - language_code = request.LANGUAGE_CODE - return JsonResponse({"language_code": language_code}) - @login_required @manager_can_enter("attendance.add_attendance") def attendance_create(request): @@ -780,6 +776,14 @@ def approve_bulk_overtime(request): """ ids = request.POST["ids"] ids = json.loads(ids) + print('-----------------------------------------------------------------') + print('-----------------------------------------------------------------') + print('-----------------------------------------------------------------') + print('-----------------------------------------------------------------') + print(ids) + print('-----------------------------------------------------------------') + print('-----------------------------------------------------------------') + print('-----------------------------------------------------------------') for attendance_id in ids: attendance = Attendance.objects.get(id=attendance_id) attendance.attendance_overtime_approve = True diff --git a/base/static/base/actions.js b/base/static/base/actions.js index e8b6609a5..64afd1ab3 100644 --- a/base/static/base/actions.js +++ b/base/static/base/actions.js @@ -43,6 +43,13 @@ var requestDeleteMessages = { en: "Do you really want to delete all the selected requests?", fr: "Voulez-vous vraiment supprimer toutes les demandes sélectionnées?", }; +var norowMessages = { + ar: "لم يتم تحديد أي صفوف.", + de: "Es wurden keine Zeilen ausgewählt.", + es: "No se han seleccionado filas.", + en: "No rows have been selected.", + fr: "Aucune ligne n'a été sélectionnée.", +}; function getCookie(name) { let cookieValue = null; @@ -63,7 +70,7 @@ function getCookie(name) { function getCurrentLanguageCode(callback) { $.ajax({ type: "GET", - url: "get-language-code/", + url: "/employee/get-language-code/", success: function (response) { var languageCode = response.language_code; callback(languageCode); // Pass the language code to the callback @@ -80,33 +87,52 @@ $(".all-rshift").change(function (e) { } }); + $("#archiveRotatingShiftAssign").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = archiveMessages[languageCode]; - choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rshift-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rshift-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/rotating-shift-assign-bulk-archive?is_active=False", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/rotating-shift-assign-bulk-archive?is_active=False", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -114,31 +140,49 @@ $("#archiveRotatingShiftAssign").click(function (e) { $("#unArchiveRotatingShiftAssign").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = unarchiveMessages[languageCode]; - choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rshift-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rshift-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/rotating-shift-assign-bulk-archive?is_active=True", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/rotating-shift-assign-bulk-archive?is_active=True", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -146,31 +190,49 @@ $("#unArchiveRotatingShiftAssign").click(function (e) { $("#deleteRotatingShiftAssign").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = deleteMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rshift-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rshift-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/rotating-shift-assign-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/rotating-shift-assign-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -185,33 +247,52 @@ $(".all-rwork-type").change(function (e) { } }); + $("#archiveRotatingWorkTypeAssign").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = archiveMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rwork-type-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rwork-type-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); - $.ajax({ - type: "POST", - url: "/rotating-work-type-assign-bulk-archive?is_active=False", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + $.ajax({ + type: "POST", + url: "/rotating-work-type-assign-bulk-archive?is_active=False", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -219,32 +300,48 @@ $("#archiveRotatingWorkTypeAssign").click(function (e) { $("#unArchiveRotatingWorkTypeAssign").click(function (e) { e.preventDefault(); - var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = unarchiveMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rwork-type-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rwork-type-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/rotating-work-type-assign-bulk-archive?is_active=True", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/rotating-work-type-assign-bulk-archive?is_active=True", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -252,32 +349,50 @@ $("#unArchiveRotatingWorkTypeAssign").click(function (e) { $("#deleteRotatingWorkTypeAssign").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = deleteMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-rwork-type-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-rwork-type-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/rotating-work-type-assign-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/rotating-work-type-assign-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -292,34 +407,54 @@ $(".all-shift-requests").change(function (e) { } }); + $("#approveShiftRequest").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = approveMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-shift-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-shift-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + // Use SweetAlert for the confirmation dialog + Swal.fire({ + text: confirmMessage, + icon: "success", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/shift-request-bulk-approve", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/shift-request-bulk-approve", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -327,32 +462,50 @@ $("#approveShiftRequest").click(function (e) { $("#cancelShiftRequest").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = cancelMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-shift-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-shift-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "info", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/shift-request-bulk-cancel", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/shift-request-bulk-cancel", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -360,32 +513,50 @@ $("#cancelShiftRequest").click(function (e) { $("#deleteShiftRequest").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = requestDeleteMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-shift-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-shift-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + var ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/shift-request-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/shift-request-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -400,67 +571,54 @@ $(".all-work-type-requests").change(function (e) { } }); + $("#approveWorkTypeRequest").click(function (e) { + e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = approveMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - e.preventDefault(); - var checkedRows = $(".all-work-type-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-work-type-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "success", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + e.preventDefault(); + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/work-type-request-bulk-approve", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, - }); - } - }); -}); - -$("#deleteWorkTypeRequest").click(function (e) { - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = requestDeleteMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - e.preventDefault(); - var checkedRows = $(".all-work-type-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - - $.ajax({ - type: "POST", - url: "/work-type-request-bulk-delete", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/work-type-request-bulk-approve", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); @@ -468,32 +626,102 @@ $("#deleteWorkTypeRequest").click(function (e) { $("#cancelWorkTypeRequest").click(function (e) { e.preventDefault(); + var languageCode = null; getCurrentLanguageCode(function (code) { languageCode = code; var confirmMessage = cancelMessages[languageCode]; - var choice = originalConfirm(confirmMessage); - if (choice) { - var checkedRows = $(".all-work-type-requests-row").filter(":checked"); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-work-type-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); - $.ajax({ - type: "POST", - url: "/work-type-request-bulk-cancel", - data: { - csrfmiddlewaretoken: getCookie("csrftoken"), - ids: JSON.stringify(ids), - }, - success: function (response, textStatus, jqXHR) { - if (jqXHR.status === 200) { - location.reload(); // Reload the current page - } else { - // console.log("Unexpected HTTP status:", jqXHR.status); - } - }, + $.ajax({ + type: "POST", + url: "/work-type-request-bulk-cancel", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } + }); + } + }); +}); + +$("#deleteWorkTypeRequest").click(function (e) { + e.preventDefault(); + + var languageCode = null; + getCurrentLanguageCode(function (code) { + languageCode = code; + var confirmMessage = requestDeleteMessages[languageCode]; + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-work-type-requests-row").filter(":checked"); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", + }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + e.preventDefault(); + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + + $.ajax({ + type: "POST", + url: "/work-type-request-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } }); } }); diff --git a/base/views.py b/base/views.py index 6cc4ca666..5c749b975 100644 --- a/base/views.py +++ b/base/views.py @@ -978,7 +978,11 @@ def rotating_work_type_assign_bulk_archive(request): is_active=True, employee_id=rwork_type_assign.employee_id ) flag = True - if len(employees_rwork_type_assign) < 1: + if is_active: + if len(employees_rwork_type_assign) < 1: + flag = False + rwork_type_assign.is_active = is_active + else: flag = False rwork_type_assign.is_active = is_active rwork_type_assign.save() @@ -1488,7 +1492,11 @@ def rotating_shift_assign_bulk_archive(request): is_active=True, employee_id=rshift_assign.employee_id ) flag = True - if len(employees_rshift_assign) < 1: + if is_active: + if len(employees_rshift_assign) < 1: + flag = False + rshift_assign.is_active = is_active + else: flag = False rshift_assign.is_active = is_active rshift_assign.save() @@ -1782,6 +1790,7 @@ def work_type_request_bulk_cancel(request): """ ids = request.POST["ids"] ids = json.loads(ids) + result = False for id in ids: work_type_request = WorkTypeRequest.objects.get(id=id) if ( @@ -1809,7 +1818,8 @@ def work_type_request_bulk_cancel(request): redirect="/", icon="close", ) - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + result = True + return JsonResponse({"result": result}) @login_required @@ -1855,6 +1865,7 @@ def work_type_request_bulk_approve(request): """ ids = request.POST["ids"] ids = json.loads(ids) + result = False for id in ids: work_type_request = WorkTypeRequest.objects.get(id=id) if ( @@ -1884,7 +1895,8 @@ def work_type_request_bulk_approve(request): redirect="/", icon="checkmark", ) - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + result = True + return JsonResponse({"result": result}) @login_required @@ -1992,13 +2004,8 @@ def work_type_request_bulk_delete(request): date=work_type_request.requested_date, ), ) - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) - - -@login_required -def get_language_code(request): - language_code = request.LANGUAGE_CODE - return JsonResponse({"language_code": language_code}) + result = True + return JsonResponse({"result": result}) @login_required @@ -2179,6 +2186,7 @@ def shift_request_bulk_cancel(request): """ ids = request.POST["ids"] ids = json.loads(ids) + result = False for id in ids: shift_request = ShiftRequest.objects.get(id=id) if ( @@ -2206,7 +2214,8 @@ def shift_request_bulk_cancel(request): redirect="/", icon="close", ) - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + result = True + return JsonResponse({"result": result}) @login_required @@ -2257,7 +2266,7 @@ def shift_request_bulk_approve(request): """ ids = request.POST["ids"] ids = json.loads(ids) - + result = False for id in ids: shift_request = ShiftRequest.objects.get(id=id) if ( @@ -2275,7 +2284,7 @@ def shift_request_bulk_approve(request): employee_work_info.shift_id = shift_request.shift_id employee_work_info.save() shift_request.save() - messages.success(request, _("Shift has been approved.")) + messages.success(request, _("Shifts have been approved.")) notify.send( request.user.employee_get, recipient=shift_request.employee_id.employee_user_id, @@ -2287,7 +2296,8 @@ def shift_request_bulk_approve(request): redirect="/", icon="checkmark", ) - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + result = True + return JsonResponse({"result": result}) @login_required @@ -2304,7 +2314,6 @@ def shift_request_delete(request, id): shift_request = ShiftRequest.objects.get(id=id) user = shift_request.employee_id.employee_user_id shift_request.delete() - messages.success(request, _("Shift request deleted.")) notify.send( request.user.employee_get, recipient=user, @@ -2335,7 +2344,7 @@ def shift_request_bulk_delete(request): """ ids = request.POST["ids"] ids = json.loads(ids) - + result = False for id in ids: try: shift_request = ShiftRequest.objects.get(id=id) @@ -2364,8 +2373,8 @@ def shift_request_bulk_delete(request): date=shift_request.requested_date, ), ) - - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + result = True + return JsonResponse({"result": result}) @login_required diff --git a/payroll/static/payroll/action.js b/payroll/static/payroll/action.js new file mode 100644 index 000000000..c197b65f6 --- /dev/null +++ b/payroll/static/payroll/action.js @@ -0,0 +1,100 @@ +var deleteMessages = { + ar: "هل تريد حقًا حذف جميع كشوف الدفع المحددة؟", + de: "Sind Sie sicher, dass Sie alle ausgewählten Gehaltsabrechnungen löschen möchten?", + es: "¿Realmente quieres eliminar todas las nóminas seleccionadas?", + en: "Do you really want to delete all the selected payslips?", + fr: "Voulez-vous vraiment supprimer tous les bulletins de paie sélectionnés?", +}; +var norowMessages = { + ar: "لم يتم تحديد أي صفوف.", + de: "Es wurden keine Zeilen ausgewählt.", + es: "No se han seleccionado filas.", + en: "No rows have been selected.", + fr: "Aucune ligne n'a été sélectionnée.", +}; + +function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === name + "=") { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} + +function getCurrentLanguageCode(callback) { + $.ajax({ + type: "GET", + url: "/employee/get-language-code/", + success: function (response) { + var languageCode = response.language_code; + callback(languageCode); // Pass the language code to the callback + }, + }); +} + +$(".all-payslip").change(function (e) { + var is_checked = $(this).is(":checked"); + if (is_checked) { + $(".all-payslip-row").prop("checked", true); + } else { + $(".all-payslip-row").prop("checked", false); + } +}); + +$("#DeletePayslipBulk").click(function (e) { + e.preventDefault(); + + var languageCode = null; + getCurrentLanguageCode(function (code) { + languageCode = code; + var confirmMessage = deleteMessages[languageCode]; + var textMessage = norowMessages[languageCode]; + var checkedRows = $(".all-payslip-row").filter(":checked"); + ids = []; + checkedRows.each(function () { + ids.push($(this).attr("id")); + }); + if (checkedRows.length === 0) { + Swal.fire({ + text: textMessage, + icon: "warning", + confirmButtonText: "Close", + }); + } else { + Swal.fire({ + text: confirmMessage, + icon: "error", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + $.ajax({ + type: "POST", + url: "/payroll/payslip-bulk-delete", + data: { + csrfmiddlewaretoken: getCookie("csrftoken"), + ids: JSON.stringify(ids), + }, + success: function (response, textStatus, jqXHR) { + if (jqXHR.status === 200) { + location.reload(); // Reload the current page + } else { + // console.log("Unexpected HTTP status:", jqXHR.status); + } + }, + }); + } + }); + } + }); +}); diff --git a/payroll/templates/payroll/payslip/list_payslips.html b/payroll/templates/payroll/payslip/list_payslips.html index 4c6fd31ae..42fc0e018 100644 --- a/payroll/templates/payroll/payslip/list_payslips.html +++ b/payroll/templates/payroll/payslip/list_payslips.html @@ -1,8 +1,23 @@ {% load i18n %} +{% load static i18n %}