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 %}
+
+
+
+ +
+
+ {% trans "Employee" %} +
+
+
{% trans "Employee" %}
{% trans "Period" %}
{% trans "Status" %}
@@ -16,6 +31,14 @@ {% for payslip in payslips %}
+
+
+ +
{{payslip.employee_id}}
+
@@ -103,5 +127,14 @@
- - + + \ No newline at end of file diff --git a/payroll/templates/payroll/payslip/view_payslips.html b/payroll/templates/payroll/payslip/view_payslips.html index 50938b44a..f0f31d4be 100644 --- a/payroll/templates/payroll/payslip/view_payslips.html +++ b/payroll/templates/payroll/payslip/view_payslips.html @@ -114,7 +114,8 @@
{% endif %} - {% if perms.payroll.add_payslip %} + + {% comment %} {% if perms.payroll.add_payslip %}
@@ -154,6 +155,70 @@
{% endif %} + {% if perms.payroll.add_payslip %} + + {% endif %} {% endcomment %} + + {% if perms.payroll.add_payslip %} +
+
+ + +
+
+ {% endif %} + +
diff --git a/payroll/templates/payroll/tax/filing_status_list.html b/payroll/templates/payroll/tax/filing_status_list.html index c11cc370f..94d9f1dd0 100644 --- a/payroll/templates/payroll/tax/filing_status_list.html +++ b/payroll/templates/payroll/tax/filing_status_list.html @@ -65,13 +65,16 @@ >
  • - {% trans "Delete" %} +
    + {% csrf_token %} + +
  • diff --git a/payroll/templates/payroll/tax/tax_bracket_view.html b/payroll/templates/payroll/tax/tax_bracket_view.html index c67289de5..562a32c6a 100644 --- a/payroll/templates/payroll/tax/tax_bracket_view.html +++ b/payroll/templates/payroll/tax/tax_bracket_view.html @@ -42,20 +42,16 @@
    - - - +
    + {% csrf_token %} + +
    diff --git a/payroll/urls/urls.py b/payroll/urls/urls.py index 5d2f0a78e..6142f3959 100644 --- a/payroll/urls/urls.py +++ b/payroll/urls/urls.py @@ -89,4 +89,9 @@ urlpatterns = [ views.payslip_export, name="dashboard-export", ), + path( + "payslip-bulk-delete", + views.payslip_bulk_delete, + name="payslip-bulk-delete", + ), ] diff --git a/payroll/views/component_views.py b/payroll/views/component_views.py index a530559fa..d347a85ee 100644 --- a/payroll/views/component_views.py +++ b/payroll/views/component_views.py @@ -267,7 +267,7 @@ def delete_allowance(request, allowance_id): """ try: payroll.models.models.Allowance.objects.get(id=allowance_id).delete() - messages.success(request, "Allowance deleted") + messages.success(request, "Allowance deleted successfully") except ObjectDoesNotExist(Exception): messages.error(request, "Allowance not found") except ValidationError as validation_error: @@ -361,13 +361,14 @@ def update_deduction(request, deduction_id): @login_required @permission_required("payroll.delete_deduction") -def delete_deduction(_request, deduction_id): +def delete_deduction(request, deduction_id): """ This method is used to delete the deduction instance Args: id : deduction instance id """ payroll.models.models.Deduction.objects.get(id=deduction_id).delete() + messages.success(request, "Deduction deleted successfully") return redirect(view_deduction) diff --git a/payroll/views/tax_views.py b/payroll/views/tax_views.py index 68568c743..b61b679f0 100644 --- a/payroll/views/tax_views.py +++ b/payroll/views/tax_views.py @@ -10,7 +10,7 @@ django.shortcuts module. """ import math -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, redirect from django.contrib import messages from horilla.decorators import permission_required, login_required @@ -108,13 +108,10 @@ def filing_status_delete(request, filing_status_id): filing_status = FilingStatus.objects.get(id=filing_status_id) filing_status.delete() messages.info(request, "Filing status successfully deleted.") - return HttpResponse("") except: messages.error(request, "This filing status assigned to employees") - status = FilingStatus.objects.all() - context = {"status": status} - return render(request, "payroll/tax/filing_status_list.html", context) + return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) @login_required @@ -206,7 +203,7 @@ def update_tax_bracket(request, tax_bracket_id): @login_required @permission_required("payroll.delete_taxbracket") -def delete_tax_bracket(_request, tax_bracket_id): +def delete_tax_bracket(request, tax_bracket_id): """ Delete an existing tax bracket record. @@ -217,9 +214,8 @@ def delete_tax_bracket(_request, tax_bracket_id): """ tax_bracket = TaxBracket.objects.get(id=tax_bracket_id) tax_bracket.delete() - return redirect( - "tax-bracket-list", filing_status_id=tax_bracket.filing_status_id.id - ) + messages.info(request, "Tax bracket successfully deleted.") + return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) @login_required diff --git a/payroll/views/views.py b/payroll/views/views.py index 03299d019..9280c6cbc 100644 --- a/payroll/views/views.py +++ b/payroll/views/views.py @@ -38,7 +38,6 @@ def get_language_code(request): scale_x_text = _("Name of Employees") scale_y_text = _("Amount") response = {"scale_x_text": scale_x_text, "scale_y_text": scale_y_text} - print(response) return JsonResponse(response) @@ -853,3 +852,31 @@ def payslip_export(request): writer.close() return response + + +@login_required +@permission_required("payroll.delete_payslip") +def payslip_bulk_delete(request): + """ + This method is used to bulk delete for Payslip + """ + ids = request.POST["ids"] + ids = json.loads(ids) + for id in ids: + payslip = Payslip.objects.get(id=id) + period = f"{payslip.start_date} to {payslip.end_date}" + try: + payslip.delete() + messages.success( + request, + _("{employee} {period} payslip deleted.").format( + employee=payslip.employee_id, period=period + ), + ) + except Exception as e: + messages.error( + request, + _("You cannot delete {payslip}").format(payslip=payslip), + ) + messages.error(request, e) + return JsonResponse({"message": "Success"}) diff --git a/recruitment/templates/recruitment/recruitment_component.html b/recruitment/templates/recruitment/recruitment_component.html index 5cb2cc68f..8a70ea299 100644 --- a/recruitment/templates/recruitment/recruitment_component.html +++ b/recruitment/templates/recruitment/recruitment_component.html @@ -38,9 +38,38 @@ $temp.val(link).select(); document.execCommand("copy"); $temp.remove(); - alert("Linke copied") + Swal.fire({ + text: "Link copied", + icon: "success", + showConfirmButton: false, + timer: 3000, // Set the timer to 3000 milliseconds (3 seconds) + timerProgressBar: true, // Show a progress bar as the timer counts down + }); } + +
    + {%for field,value in filter_dict.items %} + {%if value %} + + {{field}} + + + {%endif%} + {% endfor %} +
    +
    @@ -143,9 +172,15 @@ {% endif %} {% if perms.recruitment.delete_recruitment %} -
    + {% csrf_token %} - +
    {% endif %}
    diff --git a/templates/index.html b/templates/index.html index 7f51d2354..970824ee2 100755 --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,7 @@ + @@ -89,12 +90,12 @@
    - {% endcomment %}
    @@ -235,6 +236,8 @@ + +