NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/PR/PRV6.js
2026-02-10 14:19:30 +08:00

125 lines
3.8 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();
}
});
}
});
}
$(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();
}
});
}
}