706 lines
19 KiB
JavaScript
706 lines
19 KiB
JavaScript
|
||
var submitcheck1 = true;
|
||
var submitcheck2 = true;
|
||
var submitcheck3 = true;
|
||
|
||
|
||
//$(document).ready(function() {
|
||
// $('#amount').on('input', function() {
|
||
// var amount = $(this).val();
|
||
// var totalAmount = amount * 10;
|
||
// $('#totalAmount').val(totalAmount);
|
||
// });
|
||
//});
|
||
$(".date").mask("0000/00/00");
|
||
$('.add_project_file').click(function(e) {
|
||
e.preventDefault();
|
||
const a = ($(".items").length) / 4;
|
||
const html = `<div class="row">
|
||
<div class="col-md-3" style="padding: 0 0;">
|
||
<div class="form-group">
|
||
<label class="control-label"> نوع شماره </label>
|
||
<select class="form-control items" data-phonetype="${a}" name="ContactInformationList[${a}].PhoneType">'
|
||
<option value=""> </option>'
|
||
<option value="شماره همراه"> شماره همراه </option>
|
||
<option value="شماره ثابت"> شماره ثابت </option>
|
||
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-3" style="padding: 0 0;">
|
||
<div class="form-group">
|
||
<label class="control-label"> سمت </label>
|
||
<select class="form-control items" name="ContactInformationList[${a}].Position">
|
||
<option value=""> </option>
|
||
<option value="طرف قرارداد"> طرف قرارداد </option>
|
||
<option value="کارفرما"> کارفرما </option>
|
||
<option value="مدیرعامل"> مدیرعامل </option>
|
||
<option value="نماینده کارفرما"> نماینده کارفرما </option>
|
||
<option value="مالی"> مالی </option>
|
||
|
||
</select>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="col-md-3" style="padding: 0 0;">
|
||
<div class="form-group">
|
||
<label class="control-label"> نام و نام خانوادگی </label>
|
||
<input type="text" class="form-control items" name="ContactInformationList[${a}].FnameLname">
|
||
</div>
|
||
</div>
|
||
<div class="col-md-3" style="padding: 0 0;">
|
||
<div style="display: flex;align-items: center; ">
|
||
<div class="form-group">
|
||
<label class="control-label"> شماره تماس </label>
|
||
<input type="text" class="form-control items" data-mobile="${a}" onkeyup="mobileValidation(this);" name="ContactInformationList[${a}].PhoneNumber">
|
||
<span data-mobile-err="${a}" style="font-size: 8px; color: red"></span>
|
||
<input type="checkbox" onclick="checking(this);" data-checkbox="${a}" name="check" style="position: relative; top: -28px; right:99px;"/>
|
||
<input type="hidden" data-checkboxStr="${a}" name="ContactInformationList[${a}].SendSmsString"/>
|
||
</div>
|
||
<a href="#" class="remove_project_file" data-remove="${a}" style="padding: 0 3px;"><i style="color: red;font-size: 15px;" class="ion-close-circled pull-left"></i></a>
|
||
</div>
|
||
</div>
|
||
|
||
</div>`;
|
||
$(".project_images").append(html);
|
||
|
||
});
|
||
|
||
//mobile validation
|
||
function mobileValidation(el) {
|
||
$(el).on("input",
|
||
function() {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
});
|
||
|
||
|
||
const contactRow = $(el).closest('div.row');
|
||
const elData = $(el).attr("data-mobile");
|
||
|
||
let selectedPhoneType;
|
||
contactRow.find("select").each(function() {
|
||
if ($(this).attr("data-phonetype") == elData) {
|
||
selectedPhoneType = $(this).prop("selectedIndex");
|
||
}
|
||
});
|
||
|
||
if (selectedPhoneType == 1) {
|
||
if ($(el).val().length < 11 || $(el).val().length > 11) {
|
||
|
||
$(el).addClass("invalidMobile");
|
||
contactRow.find("span[data-mobile-err]").text("شماره همراه 11 رقمی وارد کنید");
|
||
} else {
|
||
|
||
$(el).removeClass("invalidMobile");
|
||
contactRow.find("span[data-mobile-err]").text("");
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
// Remove parent of 'remove' link when link is clicked.
|
||
$('.project_images').on('click',
|
||
'.remove_project_file',
|
||
function(e) {
|
||
e.preventDefault();
|
||
const contactRow = $(this).closest('div.row');
|
||
if ($(this).attr("data-remove") == 0) {
|
||
contactRow.find('input:text').val('');
|
||
contactRow.find('input:checkbox').prop('checked', false);
|
||
contactRow.find("select").each(function() {
|
||
$(this).prop("selectedIndex", 0);
|
||
});
|
||
} else {
|
||
$(this).closest('div.row').remove();
|
||
}
|
||
|
||
});
|
||
|
||
//checkbox value copy to string input
|
||
function checking(el) {
|
||
const datacheckbox = $(el).attr("data-checkbox");
|
||
const contactRow = $(el).closest('div.row');
|
||
if ($(el).is(":checked")) {
|
||
let selectedPhoneType;
|
||
contactRow.find("select").each(function() {
|
||
if ($(this).attr("data-phonetype") == datacheckbox) {
|
||
selectedPhoneType = $(this).prop("selectedIndex");
|
||
}
|
||
});
|
||
if (selectedPhoneType == 1) {
|
||
$(`input[data-checkboxStr='${datacheckbox}']`).val("true");
|
||
} else {
|
||
$(`input[data-checkboxStr='${datacheckbox}']`).val("false");
|
||
$(el).prop("checked", false);
|
||
$.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "ابتدا نوع شماره را همراه انتخاب کنید");
|
||
}
|
||
|
||
|
||
} else {
|
||
$(`input[data-checkboxStr='${datacheckbox}']`).val("false");
|
||
}
|
||
|
||
}
|
||
|
||
function setValueAdded() {
|
||
$('input[name="checkTaxAdded"]').val("true");
|
||
calculateTotalAmount();
|
||
|
||
}
|
||
|
||
function removeValueAdded() {
|
||
$('input[name="checkTaxAdded"]').val("false");
|
||
calculateTotalAmount();
|
||
|
||
}
|
||
|
||
function findEndOfYear(date) {
|
||
$.ajax({
|
||
/* contentType: 'charset=utf-8',*/
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: ajaxFindeEndOfYear,
|
||
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
||
data: { "start": date },
|
||
|
||
success: function(response) {
|
||
|
||
$('#end').val(response.end);
|
||
|
||
},
|
||
failure: function(response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
//ارزش افزوده
|
||
$('#officialStatus').on('change',
|
||
function() {
|
||
if ($(this).val() == "Official") {
|
||
|
||
const tax = `<div class="col-xs-12">
|
||
<fieldset style="border: 1px solid #999797; border-radius: 10px; padding: revert">
|
||
|
||
<div class="radio-box" style=" display: flex">
|
||
<label class="radio-label" style="background-color: #fad7d7;
|
||
padding: 5px;
|
||
border-radius: 5px;"> مالیات بر ارزش افزوده </label>
|
||
<span> </span> <span> </span> <span> </span> <span> </span>
|
||
<div class="radio-input">
|
||
<label>
|
||
<input type="radio" style="margin: 10px 0px;" value="true" onclick="setValueAdded()" asp-for="HasValueAddedTax" name="HasValueAddedTax"><span> </span> <span>دارد</span>
|
||
|
||
</label>
|
||
<span> </span> <span> </span> <span> </span> <span> </span>
|
||
<label>
|
||
<input type="radio" style="margin: 10px 0px;" value="false" onclick="removeValueAdded()" asp-for="HasValueAddedTax" name="HasValueAddedTax"><span> </span> <span>ندارد</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</fieldset>
|
||
</div>`;
|
||
$('#valueAdded').append(tax);
|
||
$('#valueAdded').show();
|
||
} else {
|
||
$('#valueAdded').html('');
|
||
$('#valueAdded').hide();
|
||
$('input[name="checkTaxAdded"]').val("false");
|
||
calculateTotalAmount();
|
||
}
|
||
});
|
||
|
||
// تابع برای محاسبه و نمایش مقدار در فیلد totalAmount
|
||
function calculateTotalAmount() {
|
||
const start = $('#start').val();
|
||
|
||
const end = $('#end').val();
|
||
|
||
const amount = $('#amount').val();
|
||
|
||
|
||
const checkTax = $('input[name="checkTaxAdded"]').val();
|
||
console.log(checkTax);
|
||
let isTaxAdded = "false";
|
||
if ($('#officialStatus').val() == "Official") {
|
||
|
||
if (checkTax == "true") {
|
||
isTaxAdded = "true";
|
||
} else {
|
||
isTaxAdded = "false";
|
||
}
|
||
|
||
|
||
}
|
||
if (start.length == 10 && end.length == 10 && amount.length > 1) {
|
||
$.ajax({
|
||
/* contentType: 'charset=utf-8',*/
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: ajaxCalculateTotalAmount,
|
||
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
||
data: { "start": start, "end": end, "amount": amount, "valueAddedtax": isTaxAdded },
|
||
|
||
success: function(response) {
|
||
|
||
|
||
numeral.defaultFormat("0,0 تومان");
|
||
const compute = numeral(response.totalAmount).format();
|
||
const finalAmount = numeral(response.finalAmount).format();
|
||
const valueAddedTax = numeral(response.valueAddedTax).format();
|
||
$('#obligation').val(compute);
|
||
$('#totalAmount').val(compute);
|
||
$('#finalAmount').val(finalAmount);
|
||
$('#finalAmountFake').val(finalAmount);
|
||
$('#valueAddedTax').val(valueAddedTax);
|
||
$('#valueAddedTaxFake').val(valueAddedTax);
|
||
|
||
},
|
||
failure: function(response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
}
|
||
|
||
$(document).ready(function() {
|
||
$('#sendData').on('click',
|
||
function(e) {
|
||
|
||
if (submitcheck1 === false || submitcheck2 === false || submitcheck3 === false) {
|
||
e.preventDefault();
|
||
}
|
||
|
||
|
||
});
|
||
|
||
$('#city2').on('change',
|
||
function() {
|
||
const selectedcity = jQuery("#city2 option:selected").text();
|
||
$('#hidencity').val(selectedcity);
|
||
|
||
});
|
||
$('#contractDate').on('change',
|
||
function() {
|
||
submitcheck1 = dateValidcheck(this);
|
||
|
||
});
|
||
// هنگام ورود مقدار به فیلد start
|
||
$('#start').on('input',
|
||
function() {
|
||
const startDate = this.value;
|
||
if (startDate.length == 10) {
|
||
submitcheck2 = dateValidcheck(this);
|
||
if (submitcheck2) {
|
||
findEndOfYear(startDate);
|
||
calculateTotalAmount();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
});
|
||
|
||
// هنگام ورود مقدار به فیلد end
|
||
$('#end').on('input',
|
||
function() {
|
||
const endDate = this.value;
|
||
if (endDate.length == 10) {
|
||
submitcheck3 = dateValidcheck(this);
|
||
calculateTotalAmount();
|
||
}
|
||
|
||
|
||
});
|
||
|
||
// هنگام ورود مقدار به فیلد amount
|
||
$('#amount').on('input',
|
||
function() {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var contractAmount = $("#amount");
|
||
//setting format
|
||
numeral.defaultFormat("0,0 تومان");
|
||
contractAmount.on("keyup",
|
||
function(e) {
|
||
contractAmount.val(numeral(contractAmount.val()).format());
|
||
});
|
||
calculateTotalAmount();
|
||
});
|
||
$('#obligation').on('input',
|
||
function() {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var obligation = $("#obligation");
|
||
//setting format
|
||
numeral.defaultFormat("0,0 تومان");
|
||
obligation.on("keyup",
|
||
function(e) {
|
||
obligation.val(numeral(obligation.val()).format());
|
||
});
|
||
|
||
});
|
||
$('#totalAmount').on('input',
|
||
function() {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var totalAmount = $("#totalAmount");
|
||
//setting format
|
||
numeral.defaultFormat("0,0 تومان");
|
||
totalAmount.on("keyup",
|
||
function(e) {
|
||
totalAmount.val(numeral(totalAmount.val()).format());
|
||
});
|
||
|
||
});
|
||
$('#dailyCompenseation').on('input',
|
||
function() {
|
||
this.value = this.value.replace(/[^\d]/, '');
|
||
var dailyCompenseation = $("#dailyCompenseation");
|
||
//setting format
|
||
numeral.defaultFormat("0,0 تومان");
|
||
dailyCompenseation.on("keyup",
|
||
function(e) {
|
||
dailyCompenseation.val(numeral(dailyCompenseation.val()).format());
|
||
});
|
||
|
||
});
|
||
|
||
});
|
||
|
||
var start1valid = false;
|
||
|
||
function dateValidcheck(inputField1) {
|
||
|
||
let persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g],
|
||
arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g],
|
||
fixNumbers = function(str) {
|
||
if (typeof str === 'string') {
|
||
for (let i = 0; i < 10; i++) {
|
||
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
let getdate = inputField1.value;
|
||
|
||
let m1, m2;
|
||
let y1, y2, y3, y4;
|
||
let d1, d2;
|
||
let s1, s2;
|
||
for (var i = 0; i < getdate.length; i++) {
|
||
if (i === 0) {
|
||
y1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 1) {
|
||
y2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 2) {
|
||
y3 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 3) {
|
||
y4 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 4) {
|
||
s1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 5) {
|
||
m1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 6) {
|
||
m2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 7) {
|
||
s2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 8) {
|
||
d1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 9) {
|
||
d2 = fixNumbers(getdate[i]);
|
||
}
|
||
|
||
}
|
||
let yRes = y1 + y2 + y3 + y4;
|
||
let year = parseInt(yRes);
|
||
let mRes = m1 + m2;
|
||
let month = parseInt(mRes);
|
||
let dRes = d1 + d2;
|
||
let day = parseInt(dRes);
|
||
let fixResult = yRes + s1 + mRes + s2 + dRes;
|
||
let test1 = checkEnValid(inputField1.value);
|
||
|
||
let isValid = /^([1][3-4][0-9][0-9][/])([0][1-9]|[1][0-2])([/])([0][1-9]|[1-2][0-9]|[3][0-1])$/.test(fixResult);
|
||
|
||
|
||
if (isValid && test1) {
|
||
inputField1.style.backgroundColor = '#a6e9a6';
|
||
start1valid = true;
|
||
|
||
|
||
} else {
|
||
|
||
if (inputField1.value != "") {
|
||
inputField1.style.backgroundColor = '#f94c4c';
|
||
$.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "لطفا تاریخ را بصورت صحیح وارد کنید");
|
||
start1valid = false;
|
||
}
|
||
|
||
|
||
}
|
||
return start1valid;
|
||
|
||
}
|
||
|
||
function checkEnValid(fixDate1) {
|
||
|
||
let persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g],
|
||
arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g],
|
||
fixNumbers = function(str) {
|
||
if (typeof str === 'string') {
|
||
for (let i = 0; i < 10; i++) {
|
||
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
let getdate = fixDate1;
|
||
|
||
let m1, m2;
|
||
let y1, y2, y3, y4;
|
||
let d1, d2;
|
||
for (let i = 0; i < getdate.length; i++) {
|
||
if (i === 0) {
|
||
y1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 1) {
|
||
y2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 2) {
|
||
y3 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 3) {
|
||
y4 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 5) {
|
||
m1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 6) {
|
||
m2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 8) {
|
||
d1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 9) {
|
||
d2 = fixNumbers(getdate[i]);
|
||
}
|
||
|
||
}
|
||
let yRes = y1 + y2 + y3 + y4;
|
||
let year = parseInt(yRes);
|
||
let mRes = m1 + m2;
|
||
let month = parseInt(mRes);
|
||
let dRes = d1 + d2;
|
||
let day = parseInt(dRes);
|
||
let kabiseh = false;
|
||
if (month <= 6 && day > 31) {
|
||
return false;
|
||
} else if (month > 6 && month < 12 && day > 30) {
|
||
return false;
|
||
} else if (month === 12) {
|
||
|
||
switch (year) {
|
||
case 1346:
|
||
kabiseh = true;
|
||
break;
|
||
case 1350:
|
||
kabiseh = true;
|
||
break;
|
||
case 1354:
|
||
kabiseh = true;
|
||
break;
|
||
case 1358:
|
||
kabiseh = true;
|
||
break;
|
||
case 1362:
|
||
kabiseh = true;
|
||
break;
|
||
case 1366:
|
||
kabiseh = true;
|
||
break;
|
||
case 1370:
|
||
kabiseh = true;
|
||
break;
|
||
case 1375:
|
||
kabiseh = true;
|
||
break;
|
||
case 1379:
|
||
kabiseh = true;
|
||
break;
|
||
case 1383:
|
||
kabiseh = true;
|
||
break;
|
||
case 1387:
|
||
kabiseh = true;
|
||
break;
|
||
case 1391:
|
||
kabiseh = true;
|
||
break;
|
||
case 1395:
|
||
kabiseh = true;
|
||
break;
|
||
case 1399:
|
||
kabiseh = true;
|
||
break;
|
||
case 1403:
|
||
kabiseh = true;
|
||
break;
|
||
case 1408:
|
||
kabiseh = true;
|
||
break;
|
||
case 1412:
|
||
kabiseh = true;
|
||
break;
|
||
case 1416:
|
||
kabiseh = true;
|
||
break;
|
||
case 1420:
|
||
kabiseh = true;
|
||
break;
|
||
case 1424:
|
||
kabiseh = true;
|
||
break;
|
||
case 1428:
|
||
kabiseh = true;
|
||
break;
|
||
case 1432:
|
||
kabiseh = true;
|
||
break;
|
||
case 1436:
|
||
kabiseh = true;
|
||
break;
|
||
case 1441:
|
||
kabiseh = true;
|
||
break;
|
||
case 1445:
|
||
kabiseh = true;
|
||
break;
|
||
default:
|
||
kabiseh = false;
|
||
|
||
}
|
||
if (kabiseh == true && day > 30) {
|
||
return false;
|
||
} else if (kabiseh == false && day > 29) {
|
||
return false;
|
||
} else {
|
||
return true;
|
||
}
|
||
} else {
|
||
return true;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
async function loadContractingPrties() {
|
||
/* loadPersonnel();*/
|
||
const nameId = document.getElementById("getContractingPrties").value;
|
||
|
||
|
||
$('#getContracingPartiesInfo').empty().append('<option selected="selected" value="0" >انتخاب طرف حساب</option>');
|
||
|
||
|
||
if (nameId != "noId") {
|
||
$.ajax({
|
||
/* contentType: 'charset=utf-8',*/
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: ajaxLoadContractingPrties,
|
||
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
||
data: { "id": nameId },
|
||
|
||
success: function (response) {
|
||
//var items2 = [];
|
||
|
||
//$.each(response,
|
||
// function (key, val) {
|
||
// items2.push({ id: key, vall: val });
|
||
|
||
// });
|
||
|
||
|
||
$.each(response.mylist,
|
||
function (i, item) {
|
||
$('#getContracingPartiesInfo').append($('<option>',
|
||
{
|
||
value: item.id,
|
||
text: item.fullName,
|
||
}));
|
||
|
||
});
|
||
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
async function loadContracingPartiesInfo() {
|
||
const id = document.getElementById("getContracingPartiesInfo").value;
|
||
const workshopId = document.getElementById("getContractingPrties").value;
|
||
|
||
if (workshopId == "noId") {
|
||
$.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "ابتدا معرف را انتخاب نمایید");
|
||
}
|
||
|
||
if (id > 0 && workshopId != "noId") {
|
||
$.ajax({
|
||
//contentType: 'application/json; charset=utf-8',
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: ajaxLoadContractingPrtiesInfo,
|
||
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
||
data: { "id": id },
|
||
|
||
success: function (response) {
|
||
var items2 = [];
|
||
$.each(response,
|
||
function (key, val) {
|
||
items2.push({ id: key, vall: val });
|
||
|
||
});
|
||
//if (items2[8].vall == "")
|
||
// $.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ',"ابتدا تاریخ شروع به کار را در بخش پرسنل <br/>برای این شخص و کارگاه مورد نظر ایجاد نموده و سپس اقدام به ایجاد قرارداد نمایید");
|
||
document.getElementById("WCounter").value = items2[1].vall;
|
||
document.getElementById("ECounter").value = items2[2].vall;
|
||
|
||
|
||
},
|
||
failure: function (response) {
|
||
console.log(5, response);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
}
|