Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/Fine/js/ModalCreateNewFine.js
MahanCh d1e5adf96f add salaryAid calculation Date and
edit checkout on cahnge salary & ...
2025-05-08 14:08:28 +03:30

491 lines
15 KiB
JavaScript

var urlPathname = location.pathname;
document.querySelectorAll('.scroll-container-amount').forEach(container => {
let isDown = false;
let startX;
let scrollLeft;
container.addEventListener('mousedown', (e) => {
isDown = true;
startX = e.pageX - container.offsetLeft;
scrollLeft = container.scrollLeft;
container.style.cursor = "grabbing";
});
container.addEventListener('mouseleave', () => {
isDown = false;
container.style.cursor = "grab";
});
container.addEventListener('mouseup', () => {
isDown = false;
container.style.cursor = "grab";
});
container.addEventListener('mousemove', (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - container.offsetLeft;
const walk = (x - startX) * 2;
container.scrollLeft = scrollLeft - walk;
});
});
$(document).ready(function () {
$('.loading').hide();
$(".modal-xxl").css('max-width', '460px');
$(".select2Option").select2({
language: "fa",
dir: "rtl",
dropdownParent: $('#MainModal'),
templateResult: function (data, container) {
if (data.element) {
$(container).addClass($(data.element).attr("class"));
}
return data.text;
}
});
$('#Amount').keyup(function () {
var amount = $(this).val();
var amountRials = wordifyRials(amount);
var amountTomans = wordifyRialsInTomans(amount);
$('#amountRials').text(amountRials);
$('#amountTomans').text(amountTomans);
});
$('#CRUDFineSubjectBTN').on('click', function() {
$('#CRUDFineSubjectModal').show();
});
$('.form-control-number').on('keydown', function (e) {
const allowedKeys = [
'Backspace', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight',
'ArrowUp', 'ArrowDown', 'Delete', 'Home', 'End'
];
if (allowedKeys.includes(e.key) || (e.key === 'a' && (e.ctrlKey || e.metaKey))) {
return;
}
if (!/^\d$/.test(e.key)) {
e.preventDefault();
}
});
$(".form-control-currency").each(function () {
let element = $(this);
element.on('input', function () {
let value = convertPersianNumbersToEnglish(element.val());
element.val(value);
});
new Cleave(this, {
numeral: true,
numeralThousandsGroupStyle: 'thousand'
});
});
$(".form-control-date").each(function () {
let element = $(this);
element.on('input', function () {
let value = convertPersianNumbersToEnglish(element.val());
element.val(value);
});
new Cleave(this, {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
// new Cleave(this, {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
// });
});
updateDateInput(0);
ajaxPersonals();
});
function updateDateInput(daysToAdd) {
var today = new Date();
today.setDate(today.getDate() + daysToAdd);
var jalaaliDate = jalaali.toJalaali(today);
var formattedDate = jalaaliDate.jy + '/' + (jalaaliDate.jm < 10 ? '0' + jalaaliDate.jm : jalaaliDate.jm) + '/' + (jalaaliDate.jd < 10 ? '0' + jalaaliDate.jd : jalaaliDate.jd);
$('.dateTime').val(formattedDate);
}
function ajaxPersonals() {
$.ajax({
url: employeeListAjax,
type: 'GET',
success: function (response) {
if (response.success) {
var employees = response.data;
var employeeOptionsHtml = '<option value="" disabled>انتخاب پرسنل ...</option>';
employees.forEach(function (employee) {
var black = employee.black ? "blackSelect" : "";
employeeOptionsHtml += `<option class="${black}" value="${employee.id}">${employee.employeeFullName}</option>`;
});
$('#employeeSelect').html(employeeOptionsHtml);
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
}
});
}
$(document).on('click', '.FineTitleSearch', function () {
searchResulTitle.html('');
let searchTextTitle = $(this).val();
var li = '';
$.ajax({
contentType: 'charset=utf-8',
dataType: 'json',
type: 'GET',
url: searchFineSubjectModal,
data: { "searchSubject": searchTextTitle },
headers: { "RequestVerificationToken": antiForgeryToken },
success: function (response) {
if (response.data.length > 0) {
containerTitle.show();
$.each(response.data, function (i, item) {
li += `<li class="li-subject" onclick="selectItemTitle('${item.subject}', '${item.amount}');">${item.subject}</li>`;
});
searchResulTitle.html(li);
} else {
containerTitle.hide();
}
}
});
});
// نمایش عنوان دلبخواه
var containerTitle = $('#FineTitle');
var searchBoxTitle = $('.FineTitleSearch');
var searchResulTitle = $('.searchTitleResult');
var mixContainerAndSerchResultTitle = $('#FineTitle , .searchTitleResult');
containerTitle.hide();
var liListTitle;
var liPointerTitle;
var countTitle = 0;
//close search Employee when click on body
//$(document).on('click', function (event) {
// if (!$(event.target).closest(container).length) {
// containerTitle.hide();
// }
//});
$(document).on('keydown', function (event) {
if (event.keyCode === 9) {
$('#FineTitle').hide();
}
});
function searchSubjectFine() {
var input, filter, tbody, tr, i, td, containerResult;
input = document.getElementsByClassName("ModelTitleFine");
console.log(input);
filter = input.value.toUpperCase();
tbody = document.getElementById("searchTitleResult");
tr = tbody.getElementsByClassName("li-subject");
var hasVisibleResults = false;
for (i = 0; i < tr.length; i++) {
td = tr[i];
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
hasVisibleResults = true;
} else {
tr[i].style.display = "none";
}
}
containerResult = document.getElementById("FineTitle");
if (hasVisibleResults) {
containerResult.style.display = "block";
} else {
containerResult.style.display = "none";
}
}
//$(document).on('click', '.selectTitleDiv ul li', function () {
// var containerResult = document.getElementById("FineTitle");
// containerResult.style.display = "none";
//});
function selectItemTitle(subject, amount) {
var amountRials = wordifyRials(amount);
var amountTomans = wordifyRialsInTomans(amount);
$('#amountRials').text(amountRials);
$('#amountTomans').text(amountTomans);
searchBoxTitle.val(subject);
$('#Amount').val(amount);
containerTitle.hide();
};
function searchSubjectFine() {
// Get the input element
var input = document.getElementsByClassName("ModelTitleFine")[0];
var filter = input.value.toUpperCase();
var tbody = document.getElementById("searchTitleResult");
var tr = tbody.getElementsByClassName("li-subject");
var hasVisibleResults = false;
for (var i = 0; i < tr.length; i++) {
var td = tr[i];
if (td && td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
hasVisibleResults = true;
} else {
tr[i].style.display = "none";
}
}
var containerResult = document.getElementById("FineTitle");
if (hasVisibleResults) {
containerResult.style.display = "block";
} else {
containerResult.style.display = "none";
}
}
// نمایش عنوان دلبخواه
function fineSubjectModal() {
var goTo = `#showmodal=${fineSubjectModal}`;
window.location.href = goTo;
}
$('#createData').on('click', CheckExistAjax);
function CheckExistAjax() {
var loading = $('#createData .spinner-loading');
var employeeSelect = $('#employeeSelect').val();
var Title = $('#Title ');
var Amount = $('#Amount ');
var FineDate = $('#FineDate');
if (employeeSelect.length === 0) {
$('.alert-msg').show();
$('.alert-msg p').text('لطفا اسامی پرسنل را کلیک و مشخص نمائید');
$('.select-alert').addClass('errored');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
$('.select-alert').removeClass('errored');
}, 3500);
return;
}
if (!Title.val()) {
Title.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا عنوان را وارد نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
Title.removeClass('errored');
}, 3500);
return;
}
if (!Amount.val() || Amount.val() === "0") {
Amount.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا مبلغ را وارد نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
Amount.removeClass('errored');
}, 3500);
return;
}
if (!FineDate.val()) {
FineDate.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا تاریخ را مشخص نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
FineDate.removeClass('errored');
}, 3500);
return;
}
$('#createData').addClass('disable');
$.ajax({
async: false,
dataType: 'json',
type: 'GET',
url: checkoutExistsAjaxUrl,
headers: { "RequestVerificationToken": antiForgeryToken },
traditional: true,
data: {
fineDate: FineDate.val(),
employeeIds: employeeSelect
},
success: function (response) {
//if (response.checkout)
if (response.customizeCheckout || response.customizeCheckoutTemp) {
swal({
title: "آیا میخواهید ادامه دهید؟",
text: "",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "بله",
cancelButtonText: "خیر",
closeOnConfirm: true,
closeOnCancel: true
}, function (isConfirm) {
if (isConfirm) {
SaveDataAjax();
} else {
$('#createData').removeClass('disable');
}
});
} else {
SaveDataAjax();
}
},
error: function (err) {
loading.hide();
$('#createData').removeClass('disable');
console.log(err);
}
});
}
function SaveDataAjax() {
var loading = $('#createData .spinner-loading');
var employeeSelect = $('#employeeSelect').val();
var Title = $('#Title ');
var Amount = $('#Amount ');
var FineDate = $('#FineDate');
if (employeeSelect.length === 0) {
$('.alert-msg').show();
$('.alert-msg p').text('لطفا اسامی پرسنل را کلیک و مشخص نمائید');
$('.select-alert').addClass('errored');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
$('.select-alert').removeClass('errored');
}, 3500);
return;
}
if (!Title.val()) {
Title.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا عنوان را وارد نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
Title.removeClass('errored');
}, 3500);
return;
}
if (!Amount.val() || Amount.val() === "0") {
Amount.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا مبلغ را وارد نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
Amount.removeClass('errored');
}, 3500);
return;
}
if (!FineDate.val()) {
FineDate.addClass('errored');
$('.alert-msg').show();
$('.alert-msg p').text('لطفا تاریخ را مشخص نمائید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
FineDate.removeClass('errored');
}, 3500);
return;
}
$('#createData').addClass('disable');
var data = $('#create-form').serialize();
$.ajax({
async: false,
dataType: 'json',
type: 'POST',
url: saveNewFineAjax,
headers: { "RequestVerificationToken": antiForgeryToken },
data: data,
success: function (response) {
if (response.success) {
loading.show();
$('.alert-success-msg').show();
$('.alert-success-msg p').text(response.message);
setTimeout(function () {
$('.alert-success-msg').hide();
$('.alert-success-msg p').text('');
}, 2000);
if (urlPathname.indexOf('/Client/Company/Fine') > -1) {
$('#fineListAjax').html('');
$('#PageIndex').val(0);
pageIndexJs = 0;
loadFineList();
}
loading.hide();
$('#MainModal').modal('hide');
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
loading.hide();
$('#createData').removeClass('disable');
}
},
error: function (err) {
loading.hide();
$('#createData').removeClass('disable');
console.log(err);
}
});
}