873 lines
44 KiB
JavaScript
873 lines
44 KiB
JavaScript
var urlPathname = location.pathname;
|
|
var rawDataArray = [];
|
|
var validDataArray = [];
|
|
|
|
$(document).on('click', ".openActionModal", function () {
|
|
if (window.matchMedia('(max-width: 767px)').matches) {
|
|
$(this).next().find(".operations-btns").slideToggle(500);
|
|
$(".operations-btns").not($(this).next().find(".operations-btns")).slideUp(500);
|
|
}
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
document.getElementById('uploadExcelFile').onclick = function () {
|
|
$('#uploadExcelFileInput').val('');
|
|
document.getElementById('uploadExcelFileInput').click();
|
|
};
|
|
|
|
|
|
$('#uploadExcelFileInput').change(function (e) {
|
|
e.preventDefault();
|
|
var fileInputFile = this.files[0];
|
|
|
|
if (!fileInputFile) return;
|
|
|
|
var fileName = fileInputFile.name;
|
|
var fileExtension = fileName.split('.').pop().toLowerCase();
|
|
|
|
if (fileExtension !== 'xlsx') {
|
|
showAlertMessage('.alert-msg', 'لطفا فقط فایل با پسوند .xlsx را انتخاب کنید', 3500);
|
|
$('#uploadExcelFileInput').val('');
|
|
return;
|
|
}
|
|
|
|
if (fileInputFile.size > 20000000) {
|
|
showAlertMessage('.alert-msg', 'لطفا فایل حجم کمتر از 20 مگابایت را انتخاب کنید', 3500);
|
|
$(`#uploadExcelFileInput`).val('');
|
|
return;
|
|
}
|
|
|
|
uploadFile(fileInputFile);
|
|
});
|
|
|
|
|
|
});
|
|
|
|
function uploadFile(file) {
|
|
const formData = new FormData();
|
|
formData.append('excel', file);
|
|
|
|
|
|
$('#createData').prop('disabled', true).addClass('disable');
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', uploadAndValidate, true);
|
|
xhr.setRequestHeader('RequestVerificationToken', antiForgeryToken);
|
|
const loading = $("#uploadExcelFile").find('.spinner-loading-progress').css('color', `#ffffff`).show();
|
|
let uploadStartTime = Date.now();
|
|
|
|
xhr.upload.addEventListener('progress', function (e) {
|
|
if (e.lengthComputable) {
|
|
var percentComplete = Math.round((e.loaded / e.total) * 100);
|
|
loading.text(percentComplete + '%').css('width', percentComplete + '%');
|
|
}
|
|
});
|
|
|
|
|
|
xhr.onload = function () {
|
|
|
|
let elapsedTime = Date.now() - uploadStartTime;
|
|
let remainingTime = Math.max(1000 - elapsedTime, 0);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
if (xhr.status === 200) {
|
|
const response = JSON.parse(xhr.responseText);
|
|
const loadingResult = $(".exportOutputContainer").find('.spinner-loading').show();
|
|
setTimeout(() => {
|
|
loadingResult.hide();
|
|
if (response.isSuccess) {
|
|
loading.css('width', '0').hide();
|
|
let responseDataContainer = $('#responseDataTheStructureOfExcel');
|
|
responseDataContainer.empty();
|
|
|
|
let errorsContainer = $('#errorsTheStructureOfExcel');
|
|
errorsContainer.empty();
|
|
|
|
responseDataContainer.html(loadFinalExcelDataAjax(response.data));
|
|
checkInputsEnabled();
|
|
} else {
|
|
validDataArray = [];
|
|
|
|
$('#createData').prop('disabled', true).addClass('disable');
|
|
loading.css('width', '0').hide();
|
|
|
|
let responseDataContainer = $('#responseDataTheStructureOfExcel');
|
|
responseDataContainer.empty();
|
|
|
|
let errorsContainer = $('#errorsTheStructureOfExcel');
|
|
errorsContainer.empty();
|
|
|
|
responseDataContainer.html(loadErrorExcelDataAjax(response.data));
|
|
|
|
showAlertMessage('.alert-msg', 'خطا در آپلود فایل', 3500);
|
|
$("#uploadExcelFileInput").val('');
|
|
}
|
|
}, 1500);
|
|
}
|
|
}, remainingTime);
|
|
};
|
|
|
|
xhr.onerror = function () {
|
|
storedExcelData = null;
|
|
showAlertMessage('.alert-msg', 'مشکلی در آپلود فایل به وجود آمد.', 3500);
|
|
$("#uploadExcelFileInput").val('');
|
|
$('#createData').prop('disabled', true).addClass('disable');
|
|
};
|
|
|
|
xhr.send(formData);
|
|
}
|
|
|
|
function showAlertMessage(selector, message, timeout) {
|
|
$(selector).show();
|
|
$(selector + ' p').text(message);
|
|
setTimeout(function () {
|
|
$(selector).hide();
|
|
$(selector + ' p').text('');
|
|
}, timeout);
|
|
}
|
|
|
|
function loadErrorExcelDataAjax(data) {
|
|
|
|
var htmlTable = '';
|
|
if (data.errors.length > 0) {
|
|
var month = data.rawData[0]?.calculationMonth < 10 ? data.rawData[0]?.calculationMonth.toString().padStart(2, '0') : data.rawData[0]?.calculationMonth.toString();
|
|
var dateCalculate = `${data.rawData[0]?.calculationYear}/${month}/01`;
|
|
|
|
//let allRows = new Array(Math.max(data.rawData.length, data.errors.length)).fill(null);
|
|
//let rowErrorsDataArray = data.rawData.filter(x => data.errors.some(e => e.row === x.row));
|
|
|
|
htmlTable += `
|
|
<div class="wrapper">
|
|
<div class="excelTable Rtable Rtable--5cols Rtable--collapse rowCustom px-1">
|
|
<div class="Rtable-row Rtable-row--head align-items-center d-flex flex-column w-100 error-header sticky p-0">
|
|
|
|
<div class="Rtable-cell column-heading rowHeaderCustom text-center d-flex justify-content-between w-100 px-3">
|
|
<div>تاریخ پرداخت ${data.rawData[0]?.salaryAidDateTime ?? ""}</div>
|
|
<div>تاریخ محاسبه ${data.rawData[0]?.calculationMonth ? dateCalculate : ""}</div>
|
|
</div>
|
|
<div class="lineHead w-100"></div>
|
|
<div class="d-flex w-100 px-1 gap-2">
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width1">
|
|
<span class="d-flex text-white align-items-center">
|
|
<label for="checkAllCreate2" class="text-white prevent-select">ردیف</label>
|
|
</span>
|
|
</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width2">جایگاه</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width3">نام و نام خانوادگی</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width4 text-center d-none d-md-block">کد ملی</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width5 text-center d-none d-md-block">شماره حساب</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width6 text-center d-none d-md-block">مبلغ قابل پرداخت</div>
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
|
let errorsMap = {};
|
|
data.errors.forEach(error => {
|
|
if (!errorsMap[error.row]) {
|
|
errorsMap[error.row] = [];
|
|
}
|
|
errorsMap[error.row].push(error);
|
|
});
|
|
|
|
const formattedErrors = Object.keys(errorsMap).map(row => ({
|
|
row,
|
|
data: errorsMap[row]
|
|
}));
|
|
|
|
//let rowErrorsDataMap = data.errors.reduce((acc, error) => {
|
|
// if (!acc[error.row]) {
|
|
// acc[error.row] = {
|
|
// ...data.rawData.find(x => x.row === error.row) || {},
|
|
// formattedErrors: [],
|
|
// row: error.row
|
|
// };
|
|
// }
|
|
// acc[error.row].formattedErrors.push(error);
|
|
// return acc;
|
|
//}, {});
|
|
|
|
//let rowErrorsDataArray = Object.values(rowErrorsDataMap);
|
|
|
|
let rowErrorsDataMap = data.errors.reduce((acc, error, index) => {
|
|
if (error.row === 0) {
|
|
let newKey = Object.keys(acc).length;
|
|
acc[newKey] = Object.assign(
|
|
{},
|
|
data.rawData.find(x => x.row === error.row) || {},
|
|
{ formattedErrors: [error], row: error.row }
|
|
);
|
|
} else {
|
|
if (!acc[error.row]) {
|
|
acc[error.row] = Object.assign(
|
|
{},
|
|
data.rawData.find(x => x.row === error.row) || {},
|
|
{ formattedErrors: [], row: error.row }
|
|
);
|
|
}
|
|
acc[error.row].formattedErrors.push(error);
|
|
}
|
|
|
|
return acc;
|
|
}, {});
|
|
|
|
let rowErrorsDataArray = Object.values(rowErrorsDataMap);
|
|
|
|
rowErrorsDataArray.forEach((item, index) => {
|
|
|
|
const rowErrors = errorsMap[item.row];
|
|
const rowData = data.rawData.find(x => x.row === item.row);
|
|
|
|
htmlTable += `<div class="Rtable-row rowPad align-items-center position-relative employee-row openActionModal error-row gap-2">`;
|
|
|
|
htmlTable += `<div class="Rtable-cell width1">
|
|
<label class="Rtable-cell--content prevent-select">
|
|
<span class="d-flex align-items-center justify-content-center gap-1 numberIndex">${index + 1}</span>
|
|
</label>
|
|
</div>`;
|
|
|
|
if (rowErrors.some(e => e.columns === "None")) {
|
|
//let fullErrorMessage = rowErrors.map(e => e.message).join('<br>');
|
|
let fullErrorMessage = item.row === 0 ? rowErrors[index].message : rowErrors.map(e => e.message).join('<br>');
|
|
|
|
htmlTable += `
|
|
<div class="Rtable-cell widthNone1">${item.row === 0 ? `-` : `ردیف ${item.row}`}</div>
|
|
<div class="text-start widthNone2 text-danger">${fullErrorMessage}</div>
|
|
</div>`;
|
|
} else {
|
|
let getColumnError = column => rowErrors.find(e => e.columns === column);
|
|
|
|
htmlTable += `<div class="Rtable-cell width2">ردیف ${item.row}</div>
|
|
<div class="Rtable-cell width3 d-flex justify-content-center ${getColumnError('FullName') ? 'error-column tooltipfull-container' : ''}">
|
|
<div class="Rtable-cell--content text-start ellipsed">${rowData?.fullName ?
|
|
getColumnError('FullName') ?
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>${rowData.fullName}</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
: rowData.fullName
|
|
:
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>-</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
}
|
|
</div>
|
|
${getColumnError('FullName') ? `<span class="tooltipfull">${getColumnError('FullName').message}</span>` : ''}
|
|
</div>
|
|
|
|
<div class="Rtable-cell width4 d-md-flex d-none justify-content-center ${getColumnError('NationalCode') ? 'error-column tooltipfull-container' : ''}">
|
|
<div class="Rtable-cell--content text-center w-100">${rowData?.nationalCode ?
|
|
getColumnError('NationalCode') ?
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>${rowData.nationalCode}</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
: rowData.nationalCode
|
|
:
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>-</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
}
|
|
</div>
|
|
${getColumnError('NationalCode') ? `<span class="tooltipfull">${getColumnError('NationalCode').message}</span>` : ''}
|
|
</div>
|
|
|
|
<div class="Rtable-cell width5 d-md-flex d-none justify-content-center ${getColumnError('AccountNumber') ? 'error-column tooltipfull-container' : ''}">
|
|
<div class="Rtable-cell--content text-center w-100">${rowData?.accountNumber ?
|
|
getColumnError('AccountNumber') ?
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>${rowData.accountNumber}</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
: rowData.accountNumber
|
|
:
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>-</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
}
|
|
</div>
|
|
${getColumnError('AccountNumber') ? `<span class="tooltipfull">${getColumnError('AccountNumber').message}</span>` : ''}
|
|
</div>
|
|
|
|
<div class="Rtable-cell width6 d-md-flex d-none justify-content-center ${getColumnError('Amount') ? 'error-column tooltipfull-container' : ''}">
|
|
<div class="Rtable-cell--content text-center w-100">${rowData?.amount ?
|
|
getColumnError('Amount') ?
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>${parseFloat(rowData.amount).toLocaleString()}</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
: parseFloat(rowData.amount).toLocaleString()
|
|
:
|
|
`<div class="d-flex justify-content-between align-items-center px-2">
|
|
<span>-</span>
|
|
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="11" cy="11" r="8.25" fill="#ED5252"/>
|
|
<path d="M11.9166 6.41667C11.9166 6.92293 11.5062 7.33333 10.9999 7.33333C10.4937 7.33333 10.0833 6.92293 10.0833 6.41667C10.0833 5.91041 10.4937 5.5 10.9999 5.5C11.5062 5.5 11.9166 5.91041 11.9166 6.41667Z" fill="white"/>
|
|
<path d="M11.0001 15.1276V10.5443C11.0001 10.2346 11.0001 10.0797 10.9773 9.95047C10.8678 9.32945 10.3816 8.84323 9.76055 8.73373C9.63131 8.71094 9.47646 8.71094 9.16675 8.71094V8.71094M11.0001 15.1276H12.3751M11.0001 15.1276H9.62508" stroke="white"/>
|
|
</svg>
|
|
</div>`
|
|
}
|
|
</div>
|
|
${getColumnError('Amount') ? `<span class="tooltipfull">${getColumnError('Amount').message}</span>` : ''}
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
htmlTable += `<div class="operation-div w-100">
|
|
<div class="operations-btns">
|
|
<div class="row p-0">
|
|
<div class="py-1 ${getColumnError('NationalCode') ? 'error-column rounded-lg' : ''}">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">کد ملی:</span>
|
|
<span class="span1">${rowData?.nationalCode ? rowData.nationalCode : ""}</span>
|
|
</div>
|
|
<div>${getColumnError('NationalCode') ? getColumnError('NationalCode').message : ''}</div>
|
|
</div>
|
|
<div class="py-1 ${getColumnError('AccountNumber') ? 'error-column rounded-lg' : ''}">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">شماره حساب:</span>
|
|
<span class="span1">${rowData?.accountNumber ? rowData.accountNumber : ""}</span>
|
|
</div>
|
|
<div>${getColumnError('AccountNumber') ? getColumnError('AccountNumber').message : ''}</div>
|
|
</div>
|
|
<div class="py-1 ${getColumnError('Amount') ? 'error-column rounded-lg' : ''}">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">مبلغ قابل پرداخت:</span>
|
|
<span class="span1">${rowData?.amount ? parseFloat(rowData.amount).toLocaleString() : ""}</span>
|
|
</div>
|
|
<div>${getColumnError('Amount') ? getColumnError('Amount').message : ''}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div >`;
|
|
}
|
|
|
|
});
|
|
|
|
htmlTable += `</div></div>`;
|
|
}
|
|
|
|
return htmlTable;
|
|
}
|
|
|
|
function loadFinalExcelDataAjax(data) {
|
|
rawDataArray = [...data.rawData];
|
|
validDataArray = [...data.validData];
|
|
|
|
let htmlTable = '';
|
|
|
|
if (data.rawData.length > 0) {
|
|
const rowValidDataDuplicateExist = data.rawData.filter(x => x.duplicated);
|
|
|
|
var month = data.rawData[0]?.calculationMonth < 10 ? data.rawData[0]?.calculationMonth.toString().padStart(2, '0') : data.rawData[0]?.calculationMonth.toString();
|
|
var dateCalculate = `${data.rawData[0]?.calculationYear}/${month}/01`;
|
|
|
|
htmlTable += `<div class="wrapper">
|
|
<div class="excelValidTable Rtable Rtable--5cols Rtable--collapse rowCustom px-1">
|
|
<div class="Rtable-row Rtable-row--head align-items-center d-flex flex-column w-100 sticky p-0">
|
|
<div class="Rtable-cell column-heading rowHeaderCustom d-flex align-items-center justify-content-between w-100 px-2">
|
|
<div>تاریخ پرداخت ${data.rawData[0].salaryAidDateTime}</div>
|
|
<div>تاریخ محاسبه ${dateCalculate ?? ""}</div>`;
|
|
|
|
|
|
if (rowValidDataDuplicateExist.length > 0) {
|
|
htmlTable += `<div class="d-flex align-items-center gap-1">
|
|
<div class="radio-group">
|
|
<input type="radio" id="acceptAll" name="approvalAll" class="radio-input">
|
|
<label for="acceptAll" class="btnRadioAll btnAcceptAll">
|
|
<span>تایید همه</span>
|
|
<svg width="17" height="16" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="5.5" cy="5.5" r="4.125" stroke="white"/>
|
|
<path d="M3.66683 5.5L5.04183 6.875L7.3335 4.125" stroke="white" stroke-linecap="round"/>
|
|
</svg>
|
|
</label>
|
|
|
|
<input type="radio" id="rejectAll" name="approvalAll" class="radio-input">
|
|
<label for="rejectAll" class="btnRadioAll btnRejectAll">
|
|
<span>رد همه</span>
|
|
<svg width="15" height="16" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M5.5 9.625C4.9583 9.625 4.4219 9.5183 3.92143 9.311C3.42096 9.1037 2.96623 8.79986 2.58318 8.41682C2.20014 8.03377 1.8963 7.57904 1.689 7.07857C1.4817 6.5781 1.375 6.0417 1.375 5.5C1.375 4.9583 1.4817 4.4219 1.689 3.92143C1.8963 3.42096 2.20014 2.96623 2.58318 2.58318C2.96623 2.20014 3.42096 1.8963 3.92143 1.689C4.4219 1.4817 4.9583 1.375 5.5 1.375C6.0417 1.375 6.5781 1.4817 7.07857 1.689C7.57904 1.8963 8.03377 2.20014 8.41682 2.58319C8.79986 2.96623 9.1037 3.42096 9.311 3.92143C9.5183 4.4219 9.625 4.9583 9.625 5.5C9.625 6.0417 9.5183 6.5781 9.311 7.07857C9.1037 7.57904 8.79986 8.03377 8.41681 8.41682C8.03377 8.79986 7.57904 9.1037 7.07857 9.311C6.5781 9.5183 6.0417 9.625 5.5 9.625L5.5 9.625Z" stroke="white"/>
|
|
<path d="M4.125 4.125L6.875 6.875" stroke="white" stroke-linecap="round"/>
|
|
<path d="M6.875 4.125L4.125 6.875" stroke="white" stroke-linecap="round"/>
|
|
</svg>
|
|
</label>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
htmlTable += `</div>
|
|
<div class="lineHeadValid w-100"></div>
|
|
<div class="d-flex w-100 px-2">
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width1">
|
|
<span class="d-flex text-white align-items-center">
|
|
<label for="checkAllCreate2" class="text-white prevent-select">ردیف</label>
|
|
</span>
|
|
</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width2">نام و نام خانوادگی</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width3 text-center d-none d-md-block">کد ملی</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width4 text-center d-none d-md-block">شماره حساب</div>
|
|
<div class="Rtable-cell column-heading rowHeaderCustom width5 text-center d-none d-md-block">مبلغ قابل پرداخت</div>`;
|
|
|
|
if (rowValidDataDuplicateExist.length > 0) {
|
|
htmlTable += `<div class="Rtable-cell column-heading rowHeaderCustom width6 text-end">عملیات</div>`;
|
|
}
|
|
|
|
htmlTable += `</div></div>`;
|
|
|
|
const sortedData = data.rawData.sort((a, b) => {
|
|
if (a.duplicated === b.duplicated) {
|
|
return a.rejected === b.rejected ? 0 : a.rejected ? 1 : -1;
|
|
}
|
|
return a.duplicated ? -1 : 1;
|
|
});
|
|
|
|
|
|
htmlTable += `<div class="w-100 appendDepand">`;
|
|
|
|
sortedData.forEach((item, index) => {
|
|
htmlTable += `<div></div>
|
|
<div data-row-id="${item.row}" class="Rtable-row align-items-center position-relative employee-row openActionModal ${item.duplicated ? 'rowDuplicated' : ''}">`;
|
|
|
|
htmlTable += `<div class="Rtable-cell width1">
|
|
<div class="Rtable-cell--heading d-none">ردیف</div>
|
|
<label for="employee_id_${index}" class="Rtable-cell--content prevent-select">
|
|
<span class="d-flex align-items-center justify-content-center gap-1 numberIndex">
|
|
${index + 1}
|
|
</span>
|
|
</label>
|
|
</div>`;
|
|
|
|
if (item) {
|
|
htmlTable += `
|
|
<div class="Rtable-cell width2">${item.fullName}</div>
|
|
<div class="Rtable-cell width3 d-md-flex d-none justify-content-center">${item.nationalCode}</div>
|
|
<div class="Rtable-cell width4 d-md-flex d-none justify-content-center">${item.accountNumber}</div>
|
|
<div class="Rtable-cell width5 d-md-flex d-none justify-content-center">${parseFloat(item.amount).toLocaleString()}</div>`;
|
|
|
|
if (rowValidDataDuplicateExist.length > 0) {
|
|
htmlTable += `<div class="Rtable-cell width6 justify-content-end">`;
|
|
|
|
if (item.duplicated) {
|
|
htmlTable += `
|
|
<div class="radio-group" data-handle-change="false">
|
|
<input type="radio" id="accept_${index}" name="approval_${index}" class="radio-input radioAccept">
|
|
<label for="accept_${index}" class="btnRadio btnAccept">
|
|
<span>تایید</span>
|
|
<svg width="17" height="16" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="5.5" cy="5.5" r="4.125" stroke="white"/>
|
|
<path d="M3.66683 5.5L5.04183 6.875L7.3335 4.125" stroke="white" stroke-linecap="round"/>
|
|
</svg>
|
|
</label>
|
|
<input type="radio" id="reject_${index}" name="approval_${index}" class="radio-input radioReject">
|
|
<label for="reject_${index}" class="btnRadio btnReject">
|
|
<span>رد</span>
|
|
<svg width="15" height="16" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M5.5 9.625C4.9583 9.625 4.4219 9.5183 3.92143 9.311C3.42096 9.1037 2.96623 8.79986 2.58318 8.41682C2.20014 8.03377 1.8963 7.57904 1.689 7.07857C1.4817 6.5781 1.375 6.0417 1.375 5.5C1.375 4.9583 1.4817 4.4219 1.689 3.92143C1.8963 3.42096 2.20014 2.96623 2.58318 2.58318C2.96623 2.20014 3.42096 1.8963 3.92143 1.689C4.4219 1.4817 4.9583 1.375 5.5 1.375C6.0417 1.375 6.5781 1.4817 7.07857 1.689C7.57904 1.8963 8.03377 2.20014 8.41682 2.58319C8.79986 2.96623 9.1037 3.42096 9.311 3.92143C9.5183 4.4219 9.625 4.9583 9.625 5.5C9.625 6.0417 9.5183 6.5781 9.311 7.07857C9.1037 7.57904 8.79986 8.03377 8.41681 8.41682C8.03377 8.79986 7.57904 9.1037 7.07857 9.311C6.5781 9.5183 6.0417 9.625 5.5 9.625L5.5 9.625Z" stroke="white"/>
|
|
<path d="M4.125 4.125L6.875 6.875" stroke="white" stroke-linecap="round"/>
|
|
<path d="M6.875 4.125L4.125 6.875" stroke="white" stroke-linecap="round"/>
|
|
</svg>
|
|
</label>
|
|
</div>`;
|
|
}
|
|
htmlTable += `</div>`;
|
|
}
|
|
}
|
|
|
|
htmlTable += `</div>`;
|
|
|
|
htmlTable += `<div class="operation-div w-100">
|
|
<div class="operations-btns">
|
|
<div class="row p-0">
|
|
<div class="py-1">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">کد ملی:</span>
|
|
<span class="span1">${item.nationalCode}</span>
|
|
</div>
|
|
</div>
|
|
<div class="py-1">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">شماره حساب:</span>
|
|
<span class="span1">${item.accountNumber}</span>
|
|
</div>
|
|
</div>
|
|
<div class="py-1">
|
|
<div class="d-flex align-items-center justify-content-between">
|
|
<span class="span1">مبلغ قابل پرداخت:</span>
|
|
<span class="span1">${parseFloat(item.amount).toLocaleString()}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div >`;
|
|
});
|
|
|
|
htmlTable += `</div></div>`;
|
|
}
|
|
|
|
return htmlTable;
|
|
}
|
|
|
|
|
|
function reorderRows() {
|
|
var i = 1;
|
|
const table = $('.appendDepand');
|
|
|
|
const rowsWithOperations = [];
|
|
table.find('.Rtable-row').each(function () {
|
|
const row = $(this);
|
|
const operationDiv = row.next('.operation-div');
|
|
rowsWithOperations.push({ row, operationDiv });
|
|
});
|
|
|
|
const duplicatedRows = rowsWithOperations.filter(x => x.row.hasClass('rowDuplicated'));
|
|
const acceptedRows = rowsWithOperations.filter(x => x.row.hasClass('rowAccept'));
|
|
const rejectedRows = rowsWithOperations.filter(x => x.row.hasClass('rowRejected'));
|
|
const otherRows = rowsWithOperations.filter(x =>
|
|
!x.row.hasClass('rowDuplicated') &&
|
|
!x.row.hasClass('rowAccept') &&
|
|
!x.row.hasClass('rowRejected')
|
|
);
|
|
|
|
table.empty();
|
|
table.append('<div></div>');
|
|
|
|
[...duplicatedRows, ...acceptedRows, ...rejectedRows, ...otherRows].forEach(pair => {
|
|
table.append(pair.row);
|
|
table.append(pair.operationDiv);
|
|
});
|
|
|
|
$(".numberIndex").each(function () {
|
|
$(this).text(i++);
|
|
});
|
|
}
|
|
|
|
|
|
|
|
//function reorderRows() {
|
|
// var i = 1;
|
|
// const table = $('.appendDepand');
|
|
|
|
// const duplicatedRows = table.find('.Rtable-row.rowDuplicated').detach();
|
|
// const acceptedRows = table.find('.Rtable-row.rowAccept').detach();
|
|
// const rejectedRows = table.find('.Rtable-row.rowRejected').detach();
|
|
// const otherRows = table.find('.Rtable-row:not(.rowDuplicated, .rowAccept, .rowRejected)').detach();
|
|
|
|
// table.append(duplicatedRows);
|
|
// table.append(acceptedRows);
|
|
// table.append(rejectedRows);
|
|
// table.append(otherRows);
|
|
|
|
// $(".numberIndex").each(function () {
|
|
// $(this).text(i++);
|
|
// });
|
|
//}
|
|
|
|
$(document).on("change", ".radioReject", function () {
|
|
const row = $(this).closest('.Rtable-row');
|
|
row.removeClass('rowDuplicated rowAccept').addClass('rowRejected');
|
|
|
|
const radioInput = $(this).closest('.radio-group').find('.radio-input');
|
|
$(this).closest('.radio-group').attr("data-handle-change", "true");
|
|
//radioInput.prop('disabled', true);
|
|
//$(this).closest('.radio-group').addClass('disable');
|
|
|
|
const rowID = row.data("row-id");
|
|
validDataArray = validDataArray.filter(item => item.row !== rowID);
|
|
|
|
//console.log("بعد از رد کردن:", validDataArray);
|
|
|
|
reorderRows();
|
|
checkInputsEnabled();
|
|
});
|
|
|
|
|
|
|
|
$(document).on("change", ".radioAccept", function () {
|
|
const row = $(this).closest('.Rtable-row');
|
|
row.removeClass('rowRejected rowDuplicated').addClass('rowAccept');
|
|
|
|
const radioInput = $(this).closest('.radio-group').find('.radio-input');
|
|
$(this).closest('.radio-group').attr("data-handle-change", "true");
|
|
//radioInput.prop('disabled', true);
|
|
//$(this).closest('.radio-group').addClass('disable');
|
|
|
|
const rowID = row.data("row-id");
|
|
const selectedItem = rawDataArray.find(item => item.row === rowID);
|
|
if (selectedItem && !validDataArray.some(item => item.row === rowID)) {
|
|
validDataArray.push(selectedItem);
|
|
}
|
|
|
|
//console.log("بعد از تایید کردن:", validDataArray);
|
|
|
|
reorderRows();
|
|
checkInputsEnabled();
|
|
});
|
|
|
|
$(document).on("click", ".btnAcceptAll", function () {
|
|
checkInputsEnabled();
|
|
|
|
swal({
|
|
title: "آیا میخواهید همه را انتخاب کنید؟",
|
|
text: "",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "بله",
|
|
cancelButtonText: "خیر",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
}, function (isConfirm) {
|
|
if (isConfirm) {
|
|
$(".radioAccept").each(function () {
|
|
const radioGroup = $(this).closest('.radio-group');
|
|
if (radioGroup.attr("data-handle-change") === "false") {
|
|
$(this).prop("checked", true).trigger("change");
|
|
radioGroup.addClass('disable');
|
|
$(this).prop("disabled", true);
|
|
}
|
|
});
|
|
|
|
$('.btnAcceptAll').closest('.radio-group').find('.radio-input').prop('disabled', true);
|
|
$('.btnAcceptAll').closest('.radio-group').addClass('disable');
|
|
}
|
|
});
|
|
});
|
|
|
|
$(document).on("click", ".btnRejectAll", function () {
|
|
checkInputsEnabled();
|
|
|
|
swal({
|
|
title: "آیا میخواهید همه را انتخاب کنید؟",
|
|
text: "",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "بله",
|
|
cancelButtonText: "خیر",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
}, function (isConfirm) {
|
|
if (isConfirm) {
|
|
$(".radioReject").each(function () {
|
|
const radioGroup = $(this).closest('.radio-group');
|
|
if (radioGroup.attr("data-handle-change") === "false") {
|
|
$(this).prop("checked", true).trigger("change");
|
|
radioGroup.addClass('disable');
|
|
$(this).prop("disabled", true);
|
|
}
|
|
});
|
|
$('.btnRejectAll').closest('.radio-group').find('.radio-input').prop('disabled', true);
|
|
$('.btnRejectAll').closest('.radio-group').addClass('disable');
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
function checkInputsEnabled() {
|
|
const totalRequiredRows = $('.Rtable-row').has('.radioAccept, .radioReject').length;
|
|
const selectedRows = $('.Rtable-row').has('.radioAccept:checked, .radioReject:checked').length;
|
|
|
|
//let checkCount = $(".radio-group[data-handle-change='true']").length;
|
|
|
|
//console.log(totalRequiredRows);
|
|
//console.log(selectedRows);
|
|
//console.log(checkCount);
|
|
|
|
//totalRequiredRows > 0 &&
|
|
if (totalRequiredRows === selectedRows ) {
|
|
$('#createData').prop('disabled', false).removeClass('disable');
|
|
|
|
$('.btnAcceptAll').closest('.radio-group').find('.radio-input').prop('disabled', true);
|
|
$('.btnAcceptAll').closest('.radio-group').addClass('disable');
|
|
|
|
$('.btnRejectAll').closest('.radio-group').find('.radio-input').prop('disabled', true);
|
|
$('.btnRejectAll').closest('.radio-group').addClass('disable');
|
|
} else {
|
|
$('#createData').prop('disabled', true).addClass('disable');
|
|
|
|
$('.btnAcceptAll').closest('.radio-group').find('.radio-input').prop('disabled', false);
|
|
$('.btnAcceptAll').closest('.radio-group').removeClass('disable');
|
|
|
|
$('.btnRejectAll').closest('.radio-group').find('.radio-input').prop('disabled', false);
|
|
$('.btnRejectAll').closest('.radio-group').removeClass('disable');
|
|
}
|
|
}
|
|
|
|
|
|
$('#createData').on('click', CheckExistAjax);
|
|
|
|
function CheckExistAjax() {
|
|
var employeeSelectArray = [];
|
|
|
|
validDataArray.forEach(function(item) {
|
|
employeeSelectArray.push(item.employeeId);
|
|
});
|
|
|
|
if (!validDataArray) {
|
|
showAlertMessage('.alert-msg', 'داده ای برای ارسال وجود ندارد.', 3500);
|
|
return;
|
|
}
|
|
|
|
var month = validDataArray[0].calculationMonth < 10 ? validDataArray[0].calculationMonth.toString().padStart(2, '0') : validDataArray[0].calculationMonth.toString();
|
|
var dateCalculate = `${validDataArray[0].calculationYear}/${month}/01`;
|
|
|
|
var loading = $("#createData").find('.spinner-loading').show();
|
|
$('#createData').addClass('disable');
|
|
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'GET',
|
|
url: checkoutExistsAjaxUrl,
|
|
headers: { "RequestVerificationToken": antiForgeryToken },
|
|
traditional: true,
|
|
data: {
|
|
calculationDate: dateCalculate,
|
|
employeeIds: employeeSelectArray
|
|
},
|
|
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 {
|
|
loading.hide();
|
|
$('#createData').removeClass('disable');
|
|
}
|
|
});
|
|
} else {
|
|
SaveDataAjax();
|
|
}
|
|
},
|
|
error: function (err) {
|
|
loading.hide();
|
|
$('#createData').removeClass('disable');
|
|
console.log(err);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function SaveDataAjax() {
|
|
if (!validDataArray) {
|
|
showAlertMessage('.alert-msg', 'داده ای برای ارسال وجود ندارد.', 3500);
|
|
return;
|
|
}
|
|
|
|
var loading = $("#createData").find('.spinner-loading').show();
|
|
$('#createData').addClass('disable');
|
|
|
|
$.ajax({
|
|
async: false,
|
|
type: 'POST',
|
|
url: sendExcelDataAjax,
|
|
headers: { "RequestVerificationToken": antiForgeryToken },
|
|
data: { data: validDataArray },
|
|
success: function (response) {
|
|
if (response.isSuccedded) {
|
|
$('.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/SalaryAid') > -1) {
|
|
$('#salaryAidListAjax').html('');
|
|
$('#PageIndex').val(0);
|
|
pageIndexJs = 0;
|
|
loadSalaryAidList();
|
|
}
|
|
|
|
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) {
|
|
console.log(err);
|
|
loading.hide();
|
|
$('#createData').removeClass('disable');
|
|
}
|
|
});
|
|
}
|
|
|
|
function downloadExcelTemplate(url) {
|
|
$.ajax({
|
|
url: url,
|
|
method: 'GET',
|
|
xhrFields: {
|
|
responseType: 'blob'
|
|
},
|
|
success: function (data, status, xhr) {
|
|
let filename = "قالب مساعده.xlsx";
|
|
|
|
let blob = new Blob([data], { type: xhr.getResponseHeader('Content-Type') });
|
|
let link = document.createElement('a');
|
|
link.href = window.URL.createObjectURL(blob);
|
|
link.download = filename;
|
|
link.filename = "قالب مساعده.xlsx";
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error('Error downloading file:', error);
|
|
}
|
|
});
|
|
} |