Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/Employees/js/IdentityInformationModal.js
2025-03-09 21:52:06 +03:30

205 lines
7.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var currentUrl = window.location.href;
var goToStep2 = false;
$(document).ready(function () {
$("#nationalCode").mask("0000000000");
$("#birthDate").each(function () {
let element = $(this);
element.on('input', function () {
let value = convertPersianNumbersToEnglish(element.val());
element.val(value);
});
new Cleave(this, {
date: true,
delimiter: '/',
datePattern: ['Y', 'm', 'd']
});
});
$(".checkNationalCodeAndBirthDate").click(function () {
let lastNationalCode = "";
const nationalCode = $('#nationalCode').val();
const birthDate = $('#birthDate').val();
checkNationalCodeAndBirthday();
if (nationalCode.length === 10 && birthDate.length === 10) {
if (nationalCode !== lastNationalCode) {
checkNationalCode(nationalCode, birthDate);
lastNationalCode = nationalCode;
}
} else {
lastNationalCode = "";
}
});
});
function checkNationalCodeAndBirthday() {
let nationalCode = $("#nationalCode").val().trim();
let birthDate = $("#birthDate").val().trim();
if (nationalCode === "") {
validateField("#nationalCode", "لطفا شماره ملی پرسنل را وارد کنید.");
return false;
} else if (!/^\d{10}$/.test(nationalCode)) {
validateField("#nationalCode", "شماره ملی باید ۱۰ رقم باشد.");
return false;
}
if (birthDate === "") {
validateField("#birthDate", "لطفا تاریخ تولد پرسنل را وارد کنید.");
return false;
} else if (!/^\d{4}[-\/]\d{2}[-\/]\d{2}$/.test(birthDate) || birthDate.length !== 10) {
validateField("#birthDate", "تاریخ تولد را به درستی وارد کنید.");
return false;
}
return true;
}
function checkNationalCode(nationalCode, birthDate) {
let checkNationalUrl = '';
if (currentUrl.includes("/Client/Company/RollCall/EmployeeUploadPicture")) {
checkNationalUrl = getRollCallDataByNationalCodeUrl;
} else {
checkNationalUrl = getEmployeeDataByNationalCodeUrl;
}
$("#IdentityLoading").show();
$.ajax({
async: false,
url: checkNationalUrl,
method: "GET",
data: { nationalCode: nationalCode, birthDate: birthDate },
success: (response) => {
if (response.isSuccedded) {
if (response.data) {
$(".saveData").prop("disabled", false);
$("#IdentityLoading").hide();
//$(".checkByNationalCode").each(function () {
// $(this).addClass("disable");
//});
$("#nationalCodeStep2").val(nationalCode);
$("#birthDateStep2").val(birthDate);
var defaultPersonnelCode = $("#personnelCode").text();
if (response.data.personnelCode) {
$("#personnelCodeStep2").text(response.data.personnelCode);
} else {
$("#personnelCodeStep2").text(defaultPersonnelCode);
}
if (response.data.nationality === "غیرایرانی") {
$("#NationalitySelect").val(recommendedValue2).trigger('change');
} else {
$("#NationalitySelect").val(response.data.nationality).trigger('change');
}
if (response.data.gender === "مرد") {
$("#gender1").prop("checked", true);
} else if (response.data.gender === "زن") {
$("#gender2").prop("checked", true);
} else {
$("#gender2").prop("checked", false);
$("#gender1").prop("checked", false);
$(".mightBeNullDB2").removeClass("disable");
}
// Disable Military Service Card form Step 6
if (currentUrl.includes("/Client/Company/Employees/EmployeeList")) {
if (response.data.gender === "زن") {
$('#MilitaryServiceCardSection').addClass('disable');
$('#requiredStar').hide();
} else {
$('#MilitaryServiceCardSection').removeClass('disable');
$('#requiredStar').show();
}
}
if (response.data.maritalStatus === "مجرد") {
$("#marriage2").prop("checked", true);
} else if (response.data.maritalStatus === "متاهل") {
$("#marriage1").prop("checked", true);
} else {
$("#marriage1").prop("checked", false);
$("#marriage2").prop("checked", false);
$(".mightBeNullDB3").removeClass("disable");
}
$("#firstName").val(response.data.employeeFName);
$("#lastName").val(response.data.employeeLName);
$(".checkByHistoryCode2").removeClass("disable");
if (response.data.picture1 && response.data.picture2) {
// Ensure the images are not empty
if (response.data.picture1 !== "" && response.data.picture2 !== "") {
take_snapshot1("data:image/jpeg;base64," + response.data.picture1);
take_snapshot2("data:image/jpeg;base64," + response.data.picture2);
} else {
// Handle the case where the images are empty
//console.log("One or both images are empty");
}
}
$(".validateLoading .loading").hide();
goToStep2 = true;
//$('.alert-msg').show();
//$('.alert-msg p').text("اطلاعات پرسنل وجود دارد.");
//setTimeout(function () {
// $('.alert-msg').hide();
// $('.alert-msg p').text('');
//
//}, 1000);
} else {
$(".checkByNationalCode").each(function () {
$(this).removeClass("disable");
});
$("#IdentityLoading").hide();
}
} else {
//$(".saveData").prop("disabled", true);
$(".checkByNationalCode").each(function () {
$(this).addClass("disable");
});
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text(response.message);
}, 3500);
$("#IdentityLoading").hide();
goToStep2 = false;
}
},
error: (err) => {
$('.alert-msg').show();
$('.alert-msg p').text(err.message);
$(".checkByNationalCode").each(function () {
$(this).addClass("disable");
});
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text(err.message);
}, 3500);
$("#IdentityLoading").hide();
goToStep2 = false;
}
});
}