148 lines
4.6 KiB
JavaScript
148 lines
4.6 KiB
JavaScript
function confirmPRApproveReject(isApprove, Remarks) {
|
|
loader = $('#overlay, #loader').css('z-index', 1060);
|
|
var ItemNo = document.getElementById("itemNo").value;
|
|
|
|
var Status = isApprove;
|
|
|
|
showConfirmation({
|
|
title: 'P.R. Item Approval',
|
|
message: 'Are you sure you want to approve this item? This action cannot be undone.',
|
|
type: 'warning',
|
|
confirmText: 'Yes, Approve',
|
|
cancelText: 'No'
|
|
}).then((confirmed) => {
|
|
if (confirmed) {
|
|
$.ajax({
|
|
url: endpoint.PostPRApproveReject,
|
|
type: 'POST',
|
|
data: { ItemNo: ItemNo, Status: Status, PRDetailsId: PRDetailsId, Remarks: Remarks },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
getApproverName(PRDetailsId);
|
|
|
|
prDataTable.ajax.reload(null, false);
|
|
isApproval = true;
|
|
|
|
if (isApprove == 1) {
|
|
hideButtonApproval(true);
|
|
$('#viewPRItemDetails').modal('hide');
|
|
$('#addRemarksUpdate').modal('hide');
|
|
showToast('success', 'Item successfully approved!', 'Success', 4000);
|
|
}
|
|
} else {
|
|
hideButtonApproval(true);
|
|
prDataTable.ajax.reload(null, false);
|
|
showToast('error', response.response, title + ' failed', 4000);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function getApproverName(prDetailsId) {
|
|
PRDetailsId = prDetailsId;
|
|
$.ajax({
|
|
url: '/PRMgmt/GetApproverName',
|
|
type: 'POST',
|
|
data: { PRDetailsId },
|
|
success: function (data) {
|
|
if (data && data.data && data.data.length > 0) {
|
|
var item = data.data[0];
|
|
|
|
const attestedBy = document.getElementById('label-pr-attestedBy');
|
|
const approveBy = document.getElementById('label-pr-approvedBy');
|
|
if (attestedBy) {
|
|
attestedBy.innerHTML = item.attestedBy;
|
|
}
|
|
if (approveBy) {
|
|
approveBy.innerHTML = item.approvedBy;
|
|
}
|
|
}
|
|
},
|
|
error: errorHandler
|
|
});
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
loader = $('#overlay, #loader');
|
|
|
|
UserRights = document.getElementById("roleRights").value;
|
|
|
|
prTable = $('#PRTable').DataTable({
|
|
ajax: {
|
|
url: '/PRMgmt/GetAllPR',
|
|
type: 'GET',
|
|
beforeSend: function () {
|
|
// Show the loader before making the AJAX request
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
},
|
|
initComplete: initCompleteCallback,
|
|
columns: colOnPRTable,
|
|
order: [10, 'asc'],
|
|
rowCallback: rowStatusColorCallback,
|
|
responsive: true,
|
|
language: {
|
|
emptyTable: "No record available"
|
|
},
|
|
error: errorHandler
|
|
});
|
|
})
|
|
function submitItem() {
|
|
loader = $('#overlay, #loader');
|
|
|
|
var selectedCheckboxes = $('.selectedItem-checkbox:checked');
|
|
var requestData = [];
|
|
|
|
selectedCheckboxes.each(function () {
|
|
var $row = $(this).closest('tr');
|
|
var rowIndex = itemTable.row($row).index();
|
|
var rowData = itemTable.row(rowIndex).data();
|
|
|
|
var itemCartId = rowData.itemCartId;
|
|
var qty = $row.find('.editable-qty').val() || rowData.qty;
|
|
|
|
var itemData = {
|
|
itemCartId: itemCartId,
|
|
qty: qty
|
|
};
|
|
|
|
requestData.push(itemData);
|
|
});
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
|
|
if (confirmation) {
|
|
$.ajax({
|
|
url: '/ItemMgmt/PostPurchRequest',
|
|
type: 'POST',
|
|
data: { ItemCartIds: requestData },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
itemTable.ajax.reload();
|
|
window.location.href = '/ItemMgmt/Index';
|
|
alert('Successfully requested!');
|
|
|
|
} else {
|
|
itemTable.ajax.reload();
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
}
|