495 lines
16 KiB
JavaScript
495 lines
16 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);
|
|
});
|
|
|
|
$('.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();
|
|
ajaxYears();
|
|
create_custom_dropdowns();
|
|
});
|
|
|
|
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) {
|
|
employeeOptionsHtml += `<option 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);
|
|
}
|
|
});
|
|
}
|
|
|
|
function ajaxYears() {
|
|
$.ajax({
|
|
url: yearlyListUrl,
|
|
type: 'GET',
|
|
success: function (response) {
|
|
if (response.success) {
|
|
var data = response.data;
|
|
var optionsHtml = ' <option value="0">سال</option>';
|
|
data.forEach(function (item) {
|
|
optionsHtml += `<option value="${item}">${item}</option>`;
|
|
});
|
|
$('#calculationYear').html(optionsHtml);
|
|
|
|
$('#calculationYear').next('.dropdown-select').remove();
|
|
create_custom_dropdowns();
|
|
} 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);
|
|
}
|
|
});
|
|
}
|
|
|
|
function create_custom_dropdowns() {
|
|
$('select').each(function (i, select) {
|
|
if (!$(this).next().hasClass('dropdown-select')) {
|
|
$(this).after('<div class="dropdown-select wide ' + ($(this).attr('class') || '') + '" tabindex="0"><span class="current"></span><div class="list"><ul></ul></div></div>');
|
|
var dropdown = $(this).next();
|
|
var options = $(select).find('option');
|
|
var selected = $(this).find('option:selected');
|
|
dropdown.find('.current').html(selected.data('display-text') || selected.text());
|
|
options.each(function (j, o) {
|
|
var display = $(o).data('display-text') || '';
|
|
dropdown.find('ul').append('<li class="option ' + ($(o).is(':selected') ? 'selected' : '') + '" data-value="' + $(o).val() + '" data-display-text="' + display + '">' + $(o).text() + '</li>');
|
|
});
|
|
}
|
|
});
|
|
}
|
|
$(document).off('click', '.dropdown-select').on('click', '.dropdown-select', function (event) {
|
|
if ($(event.target).hasClass('dd-searchbox')) {
|
|
return;
|
|
}
|
|
$('.dropdown-select').not($(this)).removeClass('open');
|
|
$(this).toggleClass('open');
|
|
if ($(this).hasClass('open')) {
|
|
$(this).find('.option').attr('tabindex', 0);
|
|
$(this).find('.selected').focus();
|
|
} else {
|
|
$(this).find('.option').removeAttr('tabindex');
|
|
$(this).focus();
|
|
}
|
|
});
|
|
|
|
$(document).on('click', function (event) {
|
|
if ($(event.target).closest('.dropdown-select').length === 0) {
|
|
$('.dropdown-select').removeClass('open');
|
|
$('.dropdown-select .option').removeAttr('tabindex');
|
|
}
|
|
event.stopPropagation();
|
|
});
|
|
|
|
function filter() {
|
|
var valThis = $('#txtSearchValue').val();
|
|
$('.dropdown-select ul > li').each(function () {
|
|
var text = $(this).text();
|
|
(text.toLowerCase().indexOf(valThis.toLowerCase()) > -1) ? $(this).show() : $(this).hide();
|
|
});
|
|
};
|
|
|
|
$(document).on('click', '.dropdown-select .option', function (event) {
|
|
$(this).closest('.list').find('.selected').removeClass('selected');
|
|
$(this).addClass('selected');
|
|
var text = $(this).data('display-text') || $(this).text();
|
|
$(this).closest('.dropdown-select').find('.current').text(text);
|
|
$(this).closest('.dropdown-select').prev('select').val($(this).data('value')).trigger('change');
|
|
});
|
|
|
|
$(document).on('keydown', '.dropdown-select', function (event) {
|
|
var focused_option = $($(this).find('.list .option:focus')[0] || $(this).find('.list .option.selected')[0]);
|
|
if (event.keyCode === 13) {
|
|
if ($(this).hasClass('open')) {
|
|
focused_option.trigger('click');
|
|
} else {
|
|
$(this).trigger('click');
|
|
}
|
|
return false;
|
|
// Down
|
|
} else if (event.keyCode === 40) {
|
|
if (!$(this).hasClass('open')) {
|
|
$(this).trigger('click');
|
|
} else {
|
|
focused_option.next().focus();
|
|
}
|
|
return false;
|
|
// Up
|
|
} else if (event.keyCode === 38) {
|
|
if (!$(this).hasClass('open')) {
|
|
$(this).trigger('click');
|
|
} else {
|
|
var focused_option = $($(this).find('.list .option:focus')[0] || $(this).find('.list .option.selected')[0]);
|
|
focused_option.prev().focus();
|
|
}
|
|
return false;
|
|
// Esc
|
|
} else if (event.keyCode === 27) {
|
|
if ($(this).hasClass('open')) {
|
|
$(this).trigger('click');
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
|
|
|
|
$('#createData').on('click', CheckExistAjax);
|
|
|
|
function CheckExistAjax() {
|
|
var loading = $('#createData .spinner-loading');
|
|
|
|
var employeeSelect = $('#employeeSelect').val();
|
|
var Amount = $('#Amount ');
|
|
var SalaryDateTime = $('#SalaryDateTime');
|
|
var calculationYear = $('#calculationYear');
|
|
var calculationMonth = $('#calculationMonth');
|
|
|
|
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 (!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 (!SalaryDateTime.val()) {
|
|
SalaryDateTime.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا تاریخ را مشخص نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
SalaryDateTime.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
|
|
if (calculationYear.val() === "0" || calculationMonth.val() === "0") {
|
|
$('.calculationYear').addClass('errored');
|
|
$('.calculationMonth').addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا سال و ماه را مشخص نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
$('.calculationYear').removeClass('errored');
|
|
$('.calculationMonth').removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
$('#createData').addClass('disable');
|
|
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: checkoutExistsAjaxUrl,
|
|
headers: { "RequestVerificationToken": antiForgeryToken },
|
|
traditional: true,
|
|
data: {
|
|
calculationDate: `${calculationYear.val()}/${calculationMonth.val()}/01`,
|
|
employeeIds: employeeSelect
|
|
},
|
|
success: function (response) {
|
|
var checkoutType = "";
|
|
|
|
if (response.checkout){
|
|
if (response.checkout)
|
|
checkoutType = "-فیش حقوقی رسمی\n";
|
|
|
|
var message = " با افزودن مبلغ مساعده فیش های حقوقی ذیل تغییر میکنند:\n " +
|
|
checkoutType +
|
|
"در صورت نیاز به فیش با محاسبه دقیق پس از ثبت مساعده، فیش های موجود را حذف و مجددا اقدام به صدور نمایید.";
|
|
|
|
|
|
swal({
|
|
title: message,
|
|
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 Amount = $('#Amount ');
|
|
var SalaryDateTime = $('#SalaryDateTime');
|
|
var calculationYear = $('#calculationYear');
|
|
var calculationMonth = $('#calculationMonth');
|
|
|
|
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 (!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 (!SalaryDateTime.val()) {
|
|
SalaryDateTime.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا تاریخ را مشخص نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
SalaryDateTime.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
|
|
if (calculationYear.val() === "0" || calculationMonth.val() === "0") {
|
|
$('.calculationYear').addClass('errored');
|
|
$('.calculationMonth').addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا سال و ماه را مشخص نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
$('.calculationYear').removeClass('errored');
|
|
$('.calculationMonth').removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
$('#createData').addClass('disable');
|
|
|
|
var data = $('#create-form').serialize();
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: saveNewSalaryAidAjax,
|
|
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('');
|
|
}, 1500);
|
|
|
|
if (urlPathname.indexOf('/Client/Company/SalaryAid') > -1) {
|
|
$('#salaryaidListAjax').html('');
|
|
$('#PageIndex').val(0);
|
|
pageIndexJs = 0;
|
|
loadSalaryAidList();
|
|
//window.location.reload();
|
|
}
|
|
|
|
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);
|
|
}
|
|
});
|
|
} |