364 lines
12 KiB
JavaScript
364 lines
12 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();
|
|
});
|
|
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
$('#createData').on('click', CheckExistAjax);
|
|
|
|
function CheckExistAjax() {
|
|
var loading = $('#createData .spinner-loading');
|
|
|
|
var employeeSelect = $('#employeeSelect').val();
|
|
var Amount = $('#Amount ');
|
|
var GrantDate = $('#GrantDate');
|
|
|
|
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 (!GrantDate.val()) {
|
|
GrantDate.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا تاریخ را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
GrantDate.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
$('#createData').addClass('disable');
|
|
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'GET',
|
|
url: checkoutExistsAjaxUrl,
|
|
headers: { "RequestVerificationToken": antiForgeryToken },
|
|
traditional: true,
|
|
data: {
|
|
grantDate: GrantDate.val(),
|
|
employeeIds: employeeSelect
|
|
},
|
|
success: function (response) {
|
|
//if (response.checkout)
|
|
var checkoutType = "";
|
|
|
|
if (response.customizeCheckout) {
|
|
checkoutType = "نهایی";
|
|
} else if (response.customizeCheckoutTemp) {
|
|
checkoutType = "موقت";
|
|
}
|
|
|
|
if (response.customizeCheckout || response.customizeCheckoutTemp) {
|
|
swal({
|
|
title: `برای این پرسنل فیش حقوقی غیررسمی ${checkoutType} صادر شده است. در صورت تایید، این فیش حقوقی به صورت خودکار تغییر پیدا میکند.`,
|
|
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 Description = $('#Description');
|
|
var GrantDate = $('#GrantDate');
|
|
|
|
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.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 (!GrantDate.val()) {
|
|
GrantDate.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا تاریخ را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
GrantDate.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
//if (!Description.val()) {
|
|
// Description.addClass('errored');
|
|
// $('.alert-msg').show();
|
|
// $('.alert-msg p').text('لطفا علت توضیحات را وارد نمائید');
|
|
// setTimeout(function () {
|
|
// $('.alert-msg').hide();
|
|
// $('.alert-msg p').text('');
|
|
// Description.removeClass('errored');
|
|
// }, 3500);
|
|
// return;
|
|
//}
|
|
|
|
$('#createData').addClass('disable');
|
|
|
|
var data = $('#create-form').serialize();
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: saveNewRewardAjax,
|
|
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/Reward') > -1) {
|
|
$('#rewardListAjax').html('');
|
|
$('#rewardEmployeesList').html('');
|
|
$('#PageIndex').val(0);
|
|
pageIndexJs = 0;
|
|
loadRewardList();
|
|
}
|
|
|
|
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);
|
|
}
|
|
});
|
|
} |