499 lines
16 KiB
JavaScript
499 lines
16 KiB
JavaScript
|
||
$(document).ready(function () {
|
||
$(".debtor").prop("disabled", true);
|
||
$(".creditor").prop("disabled", true);
|
||
});
|
||
|
||
//رنگ بندی ستون های جمع مبلغ
|
||
let cols = $(".totalBalance").val();
|
||
if (cols > 0) {
|
||
$(".totalBalanceTd").css("color", "#9f210c");
|
||
} else {
|
||
$(".totalBalanceTd").css("color", "#2b8f1b");
|
||
}
|
||
$('.main-table').find(".balance").each(function () {
|
||
const balance = $(this).closest(".remainder-td");
|
||
const value = $(this).val();
|
||
if (value > 0) {
|
||
balance.css("color", "#9f210c");
|
||
} else {
|
||
balance.css("color", "#2b8f1b");
|
||
}
|
||
});
|
||
|
||
//فعال سازی دکمه ی اینتر برای ثبت نهایی
|
||
$('.panelRequiredFields .form-control').keypress(function (event) {
|
||
if (event.which === 13) {
|
||
checkNecessaryInputs();
|
||
}
|
||
});
|
||
|
||
|
||
//بدست آوردن تاریخ امروز
|
||
$('.currentDay').on("click",
|
||
function () {
|
||
console.log("clicked");
|
||
$.ajax({
|
||
async: false,
|
||
url: ajaxCurrentDay,
|
||
type: "Get",
|
||
dataType: 'json',
|
||
success: function (response) {
|
||
|
||
$('#today').val(response.datOfToday);
|
||
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
}); //endOf Ajax
|
||
});
|
||
//صفحه بندی
|
||
|
||
//صفحه اول
|
||
$('.first-page-number').on("click",
|
||
function () {
|
||
pagination(1);
|
||
$("input[name=currentPageNumber]").val(1);
|
||
});
|
||
//صفحه اول
|
||
$('.first-page-text').on("click",
|
||
function () {
|
||
pagination(1);
|
||
$("input[name=currentPageNumber]").val(1);
|
||
});
|
||
//صفحه قبل
|
||
$('.prev-page').on("click",
|
||
function () {
|
||
const firstPageNumber = $("input[name=firtPageNumber]").val();
|
||
|
||
let currentPageNumber = $("input[name=currentPageNumber]").val();
|
||
currentPageNumber = Number(currentPageNumber);
|
||
currentPageNumber -= 1;
|
||
if (currentPageNumber >= firstPageNumber) {
|
||
$('.table-container').remove();
|
||
|
||
$("input[name=currentPageNumber]").val(currentPageNumber);
|
||
pagination(currentPageNumber);
|
||
|
||
}
|
||
|
||
|
||
});
|
||
// اینتر بر روی عدد
|
||
$("input[name=currentPageNumber]").on('keyup keypress',
|
||
function (e) {
|
||
const keyCode = e.keyCode || e.which;
|
||
if (keyCode === 13) {
|
||
e.preventDefault();
|
||
const firstPageNumber = Number($("input[name=firtPageNumber]").val());
|
||
const goToCurrentNumber = $(this).val();
|
||
const lastPageNumber = Number($("input[name=lastPageNumber]").val());
|
||
if (goToCurrentNumber >= firstPageNumber && goToCurrentNumber <= lastPageNumber) {
|
||
pagination(goToCurrentNumber);
|
||
}
|
||
|
||
|
||
return false;
|
||
}
|
||
});
|
||
//صفحه بعد
|
||
$('.next-page').on("click",
|
||
function () {
|
||
const lastPageNumber = $("input[name=lastPageNumber]").val();
|
||
let currentPageNumber = $("input[name=currentPageNumber]").val();
|
||
currentPageNumber = Number(currentPageNumber);
|
||
currentPageNumber += 1;
|
||
console.log(`cuntentPlusOne ${currentPageNumber}`);
|
||
if (currentPageNumber <= lastPageNumber) {
|
||
$('.table-container').remove();
|
||
$("input[name=currentPageNumber]").val(currentPageNumber);
|
||
pagination(currentPageNumber);
|
||
}
|
||
});
|
||
|
||
//صفحه آخر
|
||
$(".last-page-text").on("click",
|
||
function () {
|
||
const lastPageNumber = $("input[name=lastPageNumber]").val();
|
||
const goToLastPage = Number(lastPageNumber);
|
||
$("input[name=currentPageNumber]").val(goToLastPage);
|
||
pagination(goToLastPage);
|
||
|
||
});
|
||
//صفحه آخر
|
||
$(".last-page-number").on("click",
|
||
function () {
|
||
const lastPageNumber = $("input[name=lastPageNumber]").val();
|
||
const goToLastPage = Number(lastPageNumber);
|
||
$("input[name=currentPageNumber]").val(goToLastPage);
|
||
pagination(goToLastPage);
|
||
});
|
||
|
||
//Ajax Pagination
|
||
function pagination(currentPageNumber) {
|
||
const contractingPartyId = $('#contractingPartyId').val();
|
||
$.ajax({
|
||
async: false,
|
||
url: ajaxPagination,
|
||
data: {
|
||
"id": contractingPartyId,
|
||
"pageNumber": currentPageNumber
|
||
},
|
||
type: "Get",
|
||
dataType: 'html',
|
||
|
||
|
||
success: function (response) {
|
||
|
||
$('.table-panel').html(response);
|
||
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
}); //endOf Ajax
|
||
}
|
||
|
||
//غیرفعال یا فعالسازی اینپوت های بدهکار و بستانکار , آپشن های پرداخت / ایجاد بدهی
|
||
let jobRelation = "بابت قرارداد مابین (روابط کار)";
|
||
let taxAndFinancial = "بابت قرارداد مابین (حسابداری و مالیات)";
|
||
let debtorOptions = $(
|
||
`<option class="debtOption" value="0">انتخاب کنید...</option>
|
||
<option class="debtOption" value = "${jobRelation}"> ${jobRelation} </option>
|
||
<option class="debtOption" value = "${taxAndFinancial}"> ${taxAndFinancial} </option>
|
||
<option class="debtOption" value = " بابت قراردادهای گذشته پرسنل" > بابت قراردادهای گذشته پرسنل </option>
|
||
<option class="debtOption" value = "بابت پرونده" > بابت پرونده</option>
|
||
<option class="debtOption" value = "بابت مبلغ بیمه کارگاه" > بابت مبلغ بیمه کارگاه </option>
|
||
<option class="debtOption" value = "بابت مبلغ بیمه خویش فرما " > بابت مبلغ بیمه خویش فرما </option>
|
||
<option class="debtOption" value = "بابت فیش کارگزاری " > بابت فیش کارگزاری </option>
|
||
<option class="debtOption" value = "بابت بدهی از قرارداد قبل " > بابت بدهی از قرارداد قبل </option>
|
||
<option class="debtOption" value = "بابت خرید" > بابت خرید </option>
|
||
<option class="debtOption" value = "بابت بدهی سایر " > بابت بدهی سایر </option>
|
||
`
|
||
);
|
||
let creditorOptions = $(
|
||
`<option class="creditOption" value="0">انتخاب کنید...</option>
|
||
<option class="creditOption" value = "${jobRelation}"> ${jobRelation} </option>
|
||
<option class="creditOption" value = "${taxAndFinancial}"> ${taxAndFinancial} </option>
|
||
<option class="creditOption" value = " بابت قراردادهای گذشته پرسنل" > بابت قراردادهای گذشته پرسنل </option>
|
||
<option class="creditOption" value = "بابت پرونده" > بابت پرونده</option>
|
||
<option class="creditOption" value = "بابت مبلغ بیمه کارگاه" > بابت مبلغ بیمه کارگاه </option>
|
||
<option class="creditOption" value = "بابت مبلغ بیمه خویش فرما " > بابت مبلغ بیمه خویش فرما </option>
|
||
<option class="creditOption" value = "بابت فیش کارگزاری " > بابت فیش کارگزاری </option>
|
||
<option class="creditOption" value = "بابت بدهی از قرارداد قبل " > بابت بدهی از قرارداد قبل </option>
|
||
<option class="creditOption" value = "بابت بدهی سایر " > بابت بدهی سایر </option>
|
||
<option class="creditOption" value = "بابت حق بیمه کارگاه" > بابت حق بیمه کارگاه </option>
|
||
<option class="creditOption" value = "بابت حق بیمه خویش فرما" > بابت حق بیمه خویش فرما </option>
|
||
<option class="creditOption" value = "بابت خرید" > بابت خرید </option>
|
||
<option class="creditOption" value = "بابت خدمات" > بابت خدمات </option>
|
||
<option class="creditOption" value = "بابت تخفیف" > بابت تخفیف </option>`
|
||
);
|
||
|
||
$(".options-select").change(function () {
|
||
const selectedOption = $(this).val();
|
||
$(".options-select2").html("");
|
||
if (selectedOption == "debt") {
|
||
$(".options-select2").append(debtorOptions);
|
||
$(".debtor").prop("disabled", false);
|
||
$(".creditor").prop("disabled", true);
|
||
$(".creditor").val("").removeClass("errored");
|
||
} else if (selectedOption == "credit") {
|
||
$(".options-select2").append(creditorOptions);
|
||
$(".creditor").prop("disabled", false);
|
||
$(".debtor").prop("disabled", true);
|
||
$(".debtor").val("").removeClass("errored");
|
||
} else {
|
||
$(".creditor").val("").prop("disabled", true);
|
||
$(".debtor").val("").prop("disabled", true);
|
||
}
|
||
});
|
||
|
||
//تنظیمات بخش های پول
|
||
$('#debtInput').on('input',
|
||
function () {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var contractAmount = $("#debtInput");
|
||
numeral.defaultFormat("0,0 تومان");
|
||
contractAmount.on("keyup",
|
||
function (e) {
|
||
contractAmount.val(numeral(contractAmount.val()).format());
|
||
});
|
||
});
|
||
$('#creditInput').on('input',
|
||
function () {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var contractAmount = $("#creditInput");
|
||
numeral.defaultFormat("0,0 تومان");
|
||
contractAmount.on("keyup",
|
||
function (e) {
|
||
contractAmount.val(numeral(contractAmount.val()).format());
|
||
});
|
||
});
|
||
|
||
//لرزیدن دکمه ها
|
||
$(".op-container a").on("mouseenter",
|
||
function () {
|
||
vibratingAnimation(this);
|
||
});
|
||
|
||
function vibratingAnimation(element) {
|
||
$(element).animate({ left: "-2px" }, 50)
|
||
.animate({ left: "2px" }, 50)
|
||
.animate({ left: "0px" }, 50);
|
||
}
|
||
|
||
|
||
//حذف
|
||
function removeTransaction(Id) {
|
||
swal({
|
||
title: "توجه داشته باشید با تایید این پیام سند مورد نظر بطور کامل از بانک اطلاعات حذف می شود ",
|
||
text: "",
|
||
type: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#DD6B55",
|
||
confirmButtonText: "تایید",
|
||
cancelButtonText: "خیر",
|
||
closeOnConfirm: false
|
||
},
|
||
function (isConfirm) {
|
||
if (isConfirm) {
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: ajaxRemoveTransaction,
|
||
data: { "id": Id },
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.success) {
|
||
window.location.reload();
|
||
}
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
}
|
||
}); //endOf Ajax
|
||
} else {
|
||
}
|
||
});
|
||
}
|
||
|
||
// چک کردن اینپوت های ضروری هنگام ثبت
|
||
function checkNecessaryInputs() {
|
||
if ($(".persianDateInput").val().length < 10) {
|
||
$(".persianDateInput").addClass("errored");
|
||
} else {
|
||
$(".persianDateInput").removeClass("errored");
|
||
}
|
||
var selectedOption = $(".options-select").val();
|
||
var selectedOption2 = $(".options-select2").val();
|
||
if (selectedOption == 0) {
|
||
$(".options-select").addClass("errored");
|
||
} else {
|
||
$(".options-select").removeClass("errored");
|
||
}
|
||
if (selectedOption2 == 0 || selectedOption2 == null) {
|
||
$(".options-select2").addClass("errored");
|
||
} else {
|
||
$(".options-select2").removeClass("errored");
|
||
}
|
||
|
||
if (selectedOption == "debt" && $(".debtor").val() == "") {
|
||
$(".debtor").addClass("errored");
|
||
} else {
|
||
$(".debtor").removeClass("errored");
|
||
}
|
||
if (selectedOption == "credit" && $(".creditor").val() == "" && $(".creditor").prop("disabled") == false) {
|
||
$(".creditor").addClass("errored");
|
||
} else {
|
||
$(".creditor").removeClass("errored");
|
||
}
|
||
|
||
if ($('.errored').length > 0) {
|
||
$.Notification.autoHideNotify('error', 'top right', 'پیام سیستم ', "لطفا موارد اجباری را تکمیل کنید.");
|
||
} else {
|
||
$.Notification.autoHideNotify('success', 'top right', 'پیام سیستم ', "ثبت با موفقیت انجام شد.");
|
||
var command = {};
|
||
command.ContractingPartyId = $('#contractingPartyId').val();
|
||
command.ContractingPartyName = $('#contractingPartyName').val();
|
||
command.TdateFa = $(".persianDateInput").val();
|
||
command.Description = $('#description').val();
|
||
command.TypeOfTransaction = selectedOption;
|
||
command.DeptorString = $(".debtor").val();
|
||
command.Deptor = 0;
|
||
command.Creditor = 0;
|
||
command.CreditorString = $(".creditor").val();
|
||
command.DescriptionOption = selectedOption2;
|
||
console.log(command);
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: ajaxCreate,
|
||
data: command,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.success) {
|
||
console.log("success");
|
||
window.location.reload();
|
||
} else {
|
||
$.Notification.autoHideNotify('error', 'top right', 'پیام سیستم ', "رکورد تکراری است");
|
||
}
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
}); //endOf Ajax
|
||
}
|
||
}
|
||
|
||
// چک کردن درستی تاریخ وارد شده
|
||
$(".persianDateInput").on('keyup',
|
||
function () {
|
||
if (event.which !== 8 && event.which !== 46) {
|
||
let value = $(this).val();
|
||
const lengthValue = value.length;
|
||
if (lengthValue === 4) {
|
||
value += '/';
|
||
}
|
||
if (lengthValue === 7) {
|
||
value += '/';
|
||
}
|
||
$(this).val(value);
|
||
}
|
||
});
|
||
if ($(window).width() < 768) {
|
||
$(".persianDateInput").on("keydown",
|
||
function (event) {
|
||
const keyCode = event.which || event.keyCode;
|
||
const isDigit = (keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105);
|
||
const isControlKey = (keyCode === 8) || (keyCode === 9) || (keyCode === 13) || (keyCode === 229); // Adjusted for mobile
|
||
const isSlash = (keyCode === 191); // Adjusted for mobile
|
||
const isBackspace = (keyCode === 8); // Adjusted for mobile
|
||
|
||
if (!(isDigit || isControlKey || isSlash || isBackspace)) {
|
||
event.preventDefault();
|
||
}
|
||
});
|
||
}
|
||
if ($(window).width() > 768) {
|
||
$(".persianDateInput").on("keydown",
|
||
function (event) {
|
||
const keyCode = event.which || event.keyCode;
|
||
const isDigit = (keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105);
|
||
const isControlKey = (keyCode === 8) || (keyCode === 9) || (keyCode === 13) || (keyCode === 35) || (keyCode === 36) || (keyCode === 37) || (keyCode === 39) || (keyCode === 46);
|
||
if (!isDigit && !isControlKey) {
|
||
event.preventDefault();
|
||
}
|
||
});
|
||
}
|
||
|
||
$(".persianDateInput").on('blur',
|
||
function () {
|
||
const value = $(this).val();
|
||
const lengthValue = value.length;
|
||
if (lengthValue == 10) {
|
||
if (!dateValidCheck(this)) {
|
||
$(this).addClass("errored");
|
||
} else {
|
||
$(this).removeClass("errored");
|
||
}
|
||
}
|
||
});
|
||
|
||
$(window).on('resize',
|
||
function () {
|
||
if ($(window).width() < 768) {
|
||
locateButtonContainerMobile();
|
||
}
|
||
});
|
||
$(document).on("click",
|
||
function (event) {
|
||
const target = $(event.target);
|
||
if (!target.closest(".buttons-container").length && !target.is(".employee-operations") && !target.is("#EditTransactionBody") && !target.is("#EditTransactionBody *")
|
||
) {
|
||
$(".buttons-container").removeClass("active").addClass("reverse");
|
||
$(".more-buttons").removeClass("active");
|
||
setTimeout(function () {
|
||
$(".buttons-container").removeClass("reverse").css("display", "none");
|
||
},
|
||
200);
|
||
}
|
||
});
|
||
$(".employee-operations").on("click",
|
||
function () {
|
||
console.log(1);
|
||
if ($(window).width() < 768) {
|
||
locateButtonContainerMobile();
|
||
}
|
||
var buttonsContainer = $(this).next(".buttons-container");
|
||
if (buttonsContainer.hasClass("active")) {
|
||
buttonsContainer.removeClass("active").addClass("reverse");
|
||
$(this).closest(".more-buttons").removeClass("active");
|
||
setTimeout(function () {
|
||
buttonsContainer.removeClass("reverse").css("display", "none");
|
||
},
|
||
200);
|
||
} else {
|
||
buttonsContainer.removeClass("reverse").addClass("active").css("display", "flex");
|
||
$(this).closest(".more-buttons").addClass("active");
|
||
}
|
||
|
||
$(".buttons-container").not(buttonsContainer).removeClass("active reverse").css("display", "none");
|
||
$(".more-buttons").not($(this).closest(".more-buttons")).removeClass("active");
|
||
});
|
||
|
||
function locateButtonContainerMobile() {
|
||
const beforePosition = $(".mobile-view .employee-operations").position();
|
||
const containerWidth = $('.mobile-view .buttons-container').outerWidth();
|
||
const containerHeight = $('.mobile-view .buttons-container').outerHeight();
|
||
const containerLeft = beforePosition.left + $(".mobile-view .employee-operations").outerWidth() + 25;
|
||
const containerTop = beforePosition.top + ($(".mobile-view .employee-operations").outerHeight() / 2) - (containerHeight / 2);
|
||
$('.mobile-view .buttons-container').css({
|
||
left: containerLeft,
|
||
top: containerTop
|
||
});
|
||
}
|
||
|
||
|
||
function removeBlocked(trId) {
|
||
|
||
swal({
|
||
title: "توجه داشته باشید با تایید این پیام رنگ طوسی آیتم نظر حذف می شود ",
|
||
text: "",
|
||
type: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#DD6B55",
|
||
confirmButtonText: "تایید",
|
||
cancelButtonText: "خیر",
|
||
closeOnConfirm: true
|
||
},
|
||
function (isConfirm) {
|
||
if (isConfirm) {
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: ajaxRemoveBlocked,
|
||
data: { "id": Number(trId) },
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.isSuccedded) {
|
||
$(`#${trId}`).removeClass("blocked");
|
||
$(`#closeBtn-${trId}`).remove();
|
||
}
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
}
|
||
}); //endOf Ajax
|
||
} else {
|
||
}
|
||
});
|
||
} |