Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalAddRollCall.js
2025-05-06 18:18:20 +03:30

926 lines
36 KiB
JavaScript

$(document).ready(function () {
$("#modalWorkshopFullname").text($('#caseHistoryWorkshopFullname').text());
$('.btn-register').addClass('disable');
$(".select2OptionAddModal").select2({
language: "fa",
dir: "rtl",
dropdownParent: $('#MainModal')
});
// فعال و غیر فعال شدن برای تنظیمات ساعت کاری براساس ورودی هایی که اعمال میشود
if ($('#employeeSelectAddModal').val() !== '0' && $('.form-control-date-main').val() !== '') {
$('.heightControll').removeClass('disable');
} else {
$('.heightControll').addClass('disable');
}
$(".form-control-date-main").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']
//});
});
$(".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']
//});
});
$(".dateTime").each(function () {
let element = $(this);
element.on('input', function () {
let value = convertPersianNumbersToEnglish(element.val());
element.val(value);
});
new Cleave(this, {
time: true,
timePattern: ['h', 'm']
});
});
// updateDateInput(0);
ajaxPersonals();
$(".btnAddTimeWork").on("click", function () {
var currentCount = $('.groupBox').length;
var $inputs = $('.dateTime');
var $inputsDate = $('.form-control-date');
var allFilled = true;
$inputsDate.each(function () {
if ($(this).val() === '') {
allFilled = false;
$('.btn-register').addClass('disable');
showAlert('ابتدا تاریخ و ساعت شروع و پایان را وارد نمائید.', $(this));
}
});
$inputs.each(function () {
if ($(this).val() === '') {
allFilled = false;
$('.btn-register').addClass('disable');
showAlert('ابتدا تاریخ و ساعت شروع و پایان را وارد نمائید.', $(this));
}
});
if (!allFilled) {
return false;
}
if (currentCount < 5) {
var namePlacementPersian = "";
switch (currentCount + 1) {
case 2:
namePlacementPersian = "دوم";
break;
case 3:
namePlacementPersian = "سوم";
break;
case 4:
namePlacementPersian = "چهارم";
break;
case 5:
namePlacementPersian = "پنجم";
break;
default:
}
var timeWorkHtml = `
<div class="groupBox timeWork">
<div class="d-flex align-items-end align-items-md-center justify-content-between">
<div class="timeWorkTitle d-none d-md-block">
نوبت ${namePlacementPersian}
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<span class="startDatetxt">-</span>
<input type="text" class="form-control text-center form-control-date StartDate" name="Command.RollCallRecords[${currentCount}].StartDate" placeholder="0000/00/00" style="direction: ltr;">
</div>
<input type="text" class="form-control text-center cusDateTime dateTime StartTime" name="Command.RollCallRecords[${currentCount}].StartTime" placeholder="00:00" style="direction: ltr;">
</div>
<div class="mx-2 position-relative">
<div class="timeWorkTitle position-absolute d-block d-md-none" style="width: auto;bottom: 43px;right: -10px;">
نوبت ${namePlacementPersian}
</div>
<div>الی</div>
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<input type="text" class="form-control text-center cusDateTime dateTime EndTime" name="Command.RollCallRecords[${currentCount}].EndTime" placeholder="00:00" style="direction: ltr;">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<input type="text" class="order-2 order-md-0 form-control text-center form-control-date EndDate" name="Command.RollCallRecords[${currentCount}].EndDate" placeholder="0000/00/00" style="direction: ltr;">
<span class="order-1 order-md-0 endDatetxt">-</span>
</div>
</div>
<div class="removeBtn ms-2">
<button type="button" class="btnRemoveTimeWork">
<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" stroke="white"/>
<path d="M6.875 11H15.125" stroke="white"/>
</svg>
</button>
</div>
</div>
</div>
`;
$('#appendChildTimeWorkHtml').append(timeWorkHtml);
const newStartDateInput = $(`input[name="Command.RollCallRecords[${currentCount}].StartDate"]`);
const newEndDateInput = $(`input[name="Command.RollCallRecords[${currentCount}].EndDate"]`);
const newStartTimeInput = $(`input[name="Command.RollCallRecords[${currentCount}].StartTime"]`);
const newEndTimeInput = $(`input[name="Command.RollCallRecords[${currentCount}].EndTime"]`);
newStartDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newStartTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
new Cleave(newStartDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newStartDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newEndDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newEndDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newStartTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
new Cleave(newEndTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
updateAddButtonText(currentCount + 1);
if (currentCount + 1 === 5) {
$(".btnAddTimeWork").hide();
}
// Update Remove button enable/disable state
updateRemoveButtons();
}
});
$(document).on("click", ".btnRemoveTimeWork", function () {
$(this).closest(".groupBox").remove();
var currentCount = $('.groupBox').length;
updateAddButtonText(currentCount);
if (currentCount < 5) {
$(".btnAddTimeWork").show();
}
// Update Remove button enable/disable state
updateRemoveButtons();
fetchTotalsRollCall();
});
});
function updateRemoveButtons() {
$(".btnRemoveTimeWork").addClass("disable");
$(".btnRemoveTimeWork").last().removeClass("disable");
}
//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);
// $('.form-control-date').val(formattedDate);
//}
//updateAddButtonText(1);
function updateAddButtonText(currentCount) {
if (currentCount === 1) {
$('.btnAppendChildTimeWork').text('افزودن نوبت دوم');
} else if (currentCount === 2) {
$('.btnAppendChildTimeWork').text('افزودن نوبت سوم');
} else if (currentCount === 3) {
$('.btnAppendChildTimeWork').text('افزودن نوبت چهارم');
} else if (currentCount === 4) {
$('.btnAppendChildTimeWork').text('افزودن نوبت پنجم');
}
let allFilled = true;
$('.form-control-date').each(function () {
const value = $(this).val().trim();
if (value === "" || !dateValidCheck(value)) {
allFilled = false;
return false; // Break the loop
}
});
$('.dateTime').each(function () {
const value = $(this).val().trim();
if (value === "" || !timeValidCheck(value)) {
allFilled = false;
return false; // Break the loop
}
});
if (allFilled) {
$('.btn-register').removeClass('disable');
} else {
$('.btn-register').addClass('disable');
}
}
function ajaxPersonals() {
$.ajax({
url: employeeListAjax,
type: 'GET',
success: function (response) {
if (response.success) {
var employees = response.data;
var employeeOptionsHtml = '<option value="0" selected>انتخاب پرسنل ...</option>';
employees.forEach(function (employee) {
employeeOptionsHtml += `<option value="${employee.employeeId}">${employee.employeeFullName}</option>`;
});
$('#employeeSelectAddModal').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);
}
});
}
$(document).on('keyup', ".dateTime, .form-control-date", function () {
let $input = $(this);
let value = $input.val();
let lengthValue = value.length;
let currentCount = $('.groupBox').length;
const $groupBox = $input.closest('.groupBox');
const startDate = $groupBox.find('.StartDate').val();
const startTime = $groupBox.find('[name*="StartTime"]').val();
const endDate = $groupBox.find('.EndDate').val();
const endTime = $groupBox.find('[name*="EndTime"]').val();
// Validate input based on the field type
if ($input.hasClass('form-control-date')) {
// Date validation logic
if (lengthValue >= 10) {
if (!dateValidCheck(value)) {
showAlert('تاریخ را به درستی وارد نمائید', $input);
} else {
clearAlert($input);
dayOfWeekLoad(this, value);
}
} else {
if ($input.hasClass('StartDate')) {
$groupBox.find('.startDatetxt').text('-');
} else if ($input.hasClass('EndDate')) {
$groupBox.find('.endDatetxt').text('-');
}
}
} else if ($input.hasClass('dateTime')) {
if (lengthValue >= 5) {
if (!timeValidCheck(value)) {
showAlert('ساعت را به درستی وارد نمائید', $input);
} else {
clearAlert($input);
}
}
}
//if (startDate.length >= 10 && endDate.length >= 10) {
// if (!validateDates(startDate, endDate)) {
// showAlert('حضور غیاب در حال ویرایش را نمیتوانید بیشتر از یک روز از ثبت حضور غیاب عقب تر یا جلو تر ببرید', $input);
// }
//}
if (startDate.length >= 10 && startTime.length >= 5 && endDate.length >= 10 && endTime.length >= 5) {
//totalWorkingDataLoad(startDate, startTime, endDate, endTime, $groupBox);
fetchTotalsRollCall();
}
updateAddButtonText(currentCount);
});
//function validateDates(startDate, endDate) {
// return itemsEditableDatesData.some(entry => entry.startFa === startDate && entry.endFa === endDate);
//}
function dayOfWeekLoad(input, value) {
$.ajax({
url: dayOfWeekDataUrl,
type: 'GET',
data: { dateFa: value },
success: function (response) {
if (response.success) {
const $groupBox = $(input).closest('.groupBox');
if ($(input).hasClass('StartDate')) {
$groupBox.find('.startDatetxt').text(response.message);
} else if ($(input).hasClass('EndDate')) {
$groupBox.find('.endDatetxt').text(response.message);
}
} 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 totalWorkingDataLoad(startDateVal, startTimeVal, endDateVal, endTimeVal, $groupBox) {
$.ajax({
url: totalWorkingDataUrl,
type: 'GET',
data: { startDate: startDateVal, startTime: startTimeVal, endDate: endDateVal, endTime: endTimeVal },
success: function (response) {
if (response) {
//$groupBox.find('.ti').text(response.message);
} 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 showAlert(message, inputElement) {
inputElement.addClass("errored");
$('.alert-msg').show().find('p').text(message);
setTimeout(function () {
clearAlert(inputElement);
}, 3500);
}
function clearAlert(inputElement) {
inputElement.removeClass("errored");
$('.alert-msg').hide().find('p').text('');
}
function timeValidCheck(value) {
const timePattern = /^([01]\d|2[0-3]):([0-5]\d)$/;
return timePattern.test(value);
}
function dateValidCheck(value) {
const datePattern = /^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$/;
return datePattern.test(value);
}
$('.btn-register').click(function() {
var loading = $('.btn-register .spinner-loading');
var data = $('#create-form').serialize();
$.ajax({
async: false,
dataType: 'json',
type: 'POST',
url: saveRollCallWorkTimeAjax,
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('');
loading.hide();
//window.location.reload();
}, 2000);
hasData = true;
dateIndex = 0;
dateEmployeeIndex = null;
$('#caseHistoryLoadData').html('');
caseHistoryLoadAjax();
loadUntilHeightExceeds();
$('#MainModal').modal('hide');
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
loading.hide();
}, 3500);
}
},
error: function (err) {
loading.hide();
console.log(err);
}
});
});
$(document).on('change', '#employeeSelectAddModal', function () {
const employeeId = $('#employeeSelectAddModal').val();
const dateFa = $('.form-control-date-main').val();
// Toggle .heightControll based on conditions
toggleHeightControl();
// Fetch and display roll call data if conditions are met
if (employeeId !== '0' && dateFa !== '') {
fetchAndDisplayRollCallData(employeeId, dateFa);
}
});
$(document).on('keyup', '.form-control-date-main', function () {
toggleHeightControl();
const employeeId = $('#employeeSelectAddModal').val();
const dateFa = $('.form-control-date-main').val();
if (dateFa.length >= 10 && employeeId !== '0') {
fetchAndDisplayRollCallData(employeeId, dateFa);
}
});
function toggleHeightControl() {
if ($('#employeeSelectAddModal').val() !== '0' && $('.form-control-date-main').val().length >= 10) {
$('.heightControll').removeClass('disable');
$('.btn-register').removeClass('disable');
} else {
$('.heightControll').addClass('disable');
$('.btn-register').addClass('disable');
}
}
//var itemsEditableDatesData = [];
// Function to handle the AJAX request and generate HTML for roll call data
function fetchAndDisplayRollCallData(employeeId, dateFa) {
let htmlElement = '';
$('#appendChildTimeWorkHtml').html('');
$.ajax({
async: false,
dataType: 'json',
type: 'GET',
url: checkEmployeeData,
headers: { "RequestVerificationToken": antiForgeryToken },
data: { 'employeeId': employeeId, 'date': dateFa },
success: function (response) {
const rollCallData = response.data;
//itemsEditableDatesData = response.editableDates;
// console.log(response);
if (response.hasLeave) {
htmlElement = `
<div class="text-center">برای این پرسنل مرخصی ثبت شده است.</div>
`;
$('#appendChildTimeWorkHtml').html(htmlElement);
$('.btn-register').addClass('disable');
$('.btnAddTimeWork').hide();
} else if (response.hasNullEndDate) {
htmlElement = `
<div class="text-center">بدلیل عدم ثبت خروج پرسنل در این تاریخ شما قادر به افزودن نمی باشید.</div>
`;
$('#appendChildTimeWorkHtml').html(htmlElement);
$('.btn-register').addClass('disable');
$('.btnAddTimeWork').hide();
} else {
$('.btnAddTimeWork').show();
if (rollCallData.length > 0) {
rollCallData.forEach(function (employee, indexRollCallTime) {
//const currentCount = indexRollCallTime + 1;
let namePlacementPersian = '';
switch (indexRollCallTime) {
case 0:
namePlacementPersian = "اول";
break;
case 1:
namePlacementPersian = "دوم";
break;
case 2:
namePlacementPersian = "سوم";
break;
case 3:
namePlacementPersian = "چهارم";
break;
case 4:
namePlacementPersian = "پنجم";
break;
default:
namePlacementPersian = "";
}
htmlElement += `
<div class="groupBox timeWork">
<div class="d-flex align-items-end align-items-md-center justify-content-between">
<div class="timeWorkTitle d-none d-md-block">
نوبت ${namePlacementPersian}
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<span class="startDatetxt">${employee.startDayOfWeekFa}</span>
<input type="text" class="form-control text-center form-control-date StartDate" name="Command.RollCallRecords[${indexRollCallTime}].StartDate" value="${employee.startDateFa}" placeholder="0000/00/00" style="direction: ltr;">
</div>
<input type="text" class="form-control text-center cusDateTime dateTime StartTime" name="Command.RollCallRecords[${indexRollCallTime}].StartTime" value="${employee.startTimeString}" placeholder="00:00" style="direction: ltr;">
</div>
<div class="mx-2 position-relative">
<div class="timeWorkTitle position-absolute d-block d-md-none" style="width: auto;bottom: 43px;right: -10px;">
نوبت ${namePlacementPersian}
</div>
<div>الی</div>
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<input type="text" class="form-control text-center cusDateTime dateTime EndTime" name="Command.RollCallRecords[${indexRollCallTime}].EndTime" value="${employee.endTimeString}" placeholder="00:00" style="direction: ltr;">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<input type="text" class="order-2 order-md-0 form-control text-center form-control-date EndDate" name="Command.RollCallRecords[${indexRollCallTime}].EndDate" value="${employee.endDateFa}" placeholder="0000/00/00" style="direction: ltr;">
<span class="order-1 order-md-0 endDatetxt">${employee.endDayOfWeekFa}</span>
</div>
</div>`;
if (indexRollCallTime === 0) {
htmlElement += `<div class="removeBtn ms-2"></div>`;
} else {
htmlElement += `<div class="removeBtn ms-2">
<button type="button" class="btnRemoveTimeWork">
<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" stroke="white"/>
<path d="M6.875 11H15.125" stroke="white"/>
</svg>
</button>
</div>`;
}
htmlElement += `
</div>
</div>`;
htmlElement += `</div>
</div>`;
$('#appendChildTimeWorkHtml').html(htmlElement);
const newStartDateInput = $(`input[name="Command.RollCallRecords[${indexRollCallTime}].StartDate"]`);
const newEndDateInput = $(`input[name="Command.RollCallRecords[${indexRollCallTime}].EndDate"]`);
const newStartTimeInput = $(`input[name="Command.RollCallRecords[${indexRollCallTime}].StartTime"]`);
const newEndTimeInput = $(`input[name="Command.RollCallRecords[${indexRollCallTime}].EndTime"]`);
newStartDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newStartTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
new Cleave(newStartDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newStartDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newEndDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newEndDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newStartTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
new Cleave(newEndTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
// Update add button text
updateAddButtonText(indexRollCallTime + 1);
// Hide the add button if 5 records are added
if (indexRollCallTime === 4) {
$(".btnAddTimeWork").hide();
}
});
$(".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']
//});
});
$(".dateTime").each(function () {
let element = $(this);
element.on('input', function () {
let value = convertPersianNumbersToEnglish(element.val());
element.val(value);
});
new Cleave(this, {
time: true,
timePattern: ['h', 'm']
});
});
} else {
var namePlacementPersian = "اول";
var nameBtnPersian = "دوم";
htmlElement += `
<div class="groupBox timeWork">
<div class="d-flex align-items-end align-items-md-center justify-content-between">
<div class="timeWorkTitle d-none d-md-block">
نوبت ${namePlacementPersian}
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<span class="startDatetxt">-</span>
<input type="text" class="form-control text-center form-control-date StartDate" name="Command.RollCallRecords[0].StartDate" placeholder="0000/00/00" style="direction: ltr;">
</div>
<input type="text" class="form-control text-center cusDateTime dateTime StartTime" name="Command.RollCallRecords[0].StartTime" placeholder="00:00" style="direction: ltr;">
</div>
<div class="mx-2 position-relative">
<div class="timeWorkTitle position-absolute d-block d-md-none" style="width: auto;bottom: 43px;right: -10px;">
نوبت ${namePlacementPersian}
</div>
<div>الی</div>
</div>
<div class="d-flex align-items-end align-items-md-center justify-content-between gap-2">
<input type="text" class="form-control text-center cusDateTime dateTime EndTime" name="Command.RollCallRecords[0].EndTime" placeholder="00:00" style="direction: ltr;">
<div class="d-flex flex-md-row flex-column align-items-center justify-content-between gap-1 mainDate">
<input type="text" class="order-2 order-md-0 form-control text-center form-control-date EndDate" name="Command.RollCallRecords[0].EndDate" placeholder="0000/00/00" style="direction: ltr;">
<span class="order-1 order-md-0 endDatetxt">-</span>
</div>
</div>
<div class="removeBtn ms-2">
</div>
</div>
</div>
`;
// Update add button text
updateAddButtonText(1);
$('#appendChildTimeWorkHtml').html(htmlElement);
const newStartDateInput = $(`input[name="Command.RollCallRecords[0].StartDate"]`);
const newEndDateInput = $(`input[name="Command.RollCallRecords[0].EndDate"]`);
const newStartTimeInput = $(`input[name="Command.RollCallRecords[0].StartTime"]`);
const newEndTimeInput = $(`input[name="Command.RollCallRecords[0].EndTime"]`);
newStartDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndDateInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newStartTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
newEndTimeInput.on('input', function () {
const value = convertPersianNumbersToEnglish($(this).val());
$(this).val(value);
});
new Cleave(newStartDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newStartDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newEndDateInput[0], {
delimiters: ['/', '/'],
blocks: [4, 2, 2],
numericOnly: true
});
//new Cleave(newEndDateInput[0], {
// date: true,
// delimiter: '/',
// datePattern: ['Y', 'm', 'd']
//});
new Cleave(newStartTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
new Cleave(newEndTimeInput[0], {
time: true,
timePattern: ['h', 'm']
});
}
// Update Remove button enable/disable state
updateRemoveButtons();
fetchTotalsRollCall();
}
},
error: function (err) {
console.log('Error fetching roll call data:', err);
}
});
}
function getTimeWorkData() {
var rollCalls = [];
$('.groupBox.timeWork').each(function () {
var startDate = $(this).find('.StartDate').val();
var startTime = $(this).find('.StartTime').val();
var endDate = $(this).find('.EndDate').val();
var endTime = $(this).find('.EndTime').val();
const calculateRollCallsTotalDuration = {};
calculateRollCallsTotalDuration.StartDateFa = startDate;
calculateRollCallsTotalDuration.StartTime = startTime;
calculateRollCallsTotalDuration.EndDateFa = endDate ;
calculateRollCallsTotalDuration.EndTime = endTime ;
rollCalls.push(calculateRollCallsTotalDuration);
});
return rollCalls;
}
function fetchTotalsRollCall() {
const employeeId = $('#employeeSelectAddModal').val();
const dateFa = $('.form-control-date-main').val();
if (employeeId !== '0' && dateFa !== '') {
var rollCalls = getTimeWorkData();
$.ajax({
dataType: 'json',
type: 'POST',
url: calculateRollCallsTotalDurationDataUrl,
data: { rollCalls },
headers: { "RequestVerificationToken": antiForgeryToken },
success: function (response) {
if (response) {
$('#resultCalculateRollCallsTotal').show();
$('#resultCalculateRollCallsTotal').text(response.result);
} else {
$('#resultCalculateRollCallsTotal').hide();
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
}
});
}
}