417 lines
16 KiB
JavaScript
417 lines
16 KiB
JavaScript
function approvedSelectedPRItem() {
|
|
const loader = $('#overlay, #loader').css('z-index', 1070);
|
|
|
|
const selectedItems = Object.values(selectedProductsMap);
|
|
if (selectedItems.length === 0) {
|
|
showToast('warning', 'Please select items first!', 'Approval failed', 4000);
|
|
return;
|
|
}
|
|
|
|
const PRList = selectedItems.map(item => {
|
|
return {
|
|
prNo: item.prNo,
|
|
prDetailsId: item.prDetailsId,
|
|
itemNo: item.itemNo
|
|
};
|
|
});
|
|
|
|
let message = PRList.length > 1
|
|
? 'Are you sure you want to approve these selected items? This action cannot be undone.'
|
|
: 'Are you sure you want to approve this selected item? This action cannot be undone.';
|
|
|
|
showConfirmation({
|
|
title: 'Multiple P.R. Item Approval',
|
|
message: message,
|
|
type: 'warning',
|
|
confirmText: 'Yes, Approve',
|
|
cancelText: 'No'
|
|
}).then((confirmed) => {
|
|
if (confirmed) {
|
|
$.ajax({
|
|
url: endpoint.ApprovedSelectedPRItem,
|
|
type: 'POST',
|
|
data: { PRList },
|
|
...beforeComplete(loader),
|
|
success: function (response) {
|
|
if (response.success) {
|
|
|
|
getApproverName(PRList[0].prDetailsId);
|
|
|
|
PRList.forEach(item => {
|
|
delete selectedProductsMap[item.prDetailsId];
|
|
});
|
|
|
|
const approvedIds = new Set(PRList.map(x => x.prDetailsId));
|
|
prDataTable.rows(function (idx, data) {
|
|
return approvedIds.has(data.prDetailsId);
|
|
}).remove().draw(false);
|
|
|
|
clearTableSelection('#PRdataTable', selectedProductsMap, () => {
|
|
totalSelectedLabel.text(0);
|
|
}, 'selected-row', '.select-all-item-checkbox');
|
|
|
|
hideButtonApproval(true);
|
|
$('#addRemarksUpdate').modal('hide');
|
|
showToast('success', 'Item successfully approved!', 'Success', 4000);
|
|
} else {
|
|
showToast('error', response.response, 'Approval failed', 4000);
|
|
}
|
|
},
|
|
error: errorHandler
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function prItemRemoval(data) {
|
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
|
const remarksInput = document.getElementById('remove-remarks');
|
|
remarksInput.addEventListener('input', removeErrorClass);
|
|
const Remarks = remarksInput.value;
|
|
|
|
if (!Remarks) {
|
|
remarksInput.classList.add('error-input');
|
|
showToast('warning', 'Please input remarks!', 'warning', 4000);
|
|
return;
|
|
}
|
|
showConfirmation({
|
|
title: 'PR Item Removal',
|
|
message: `Remove "${ItemName}" (P.R. #${PRNo}, Item No. ${ItemNo})? This cannot be undone.`,
|
|
type: 'warning',
|
|
confirmText: 'Yes, Remove',
|
|
cancelText: 'No'
|
|
}).then((confirmed) => {
|
|
if (confirmed) {
|
|
$.ajax({
|
|
url: endpoint.PRItemRemoval,
|
|
type: 'POST',
|
|
data: { PRDetailsId, Remarks },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#viewItemRemovalRemarks').modal('hide');
|
|
prTable.ajax.reload(null, false);
|
|
prDataTable.ajax.reload(null, false);
|
|
remarksInput.value = "";
|
|
showToast('success', 'PR item was removed successfully.', 'success', 4000);
|
|
} else {
|
|
prTable.ajax.reload(null, false);
|
|
prDataTable.ajax.reload(null, false);
|
|
remarksInput.value = "";
|
|
showToast('error', response.response, 'failed', 4000);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function putSupplierAlterOffer() {
|
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
|
let AlternativeOfferId = $('#AlterOfferListDataTable')
|
|
.find('.choose-alternative-checkbox:checked')
|
|
.data('id');
|
|
|
|
if (!AlternativeOfferId) {
|
|
showToast('warning', 'Please select one alternative offer.', 'warning', 4000);
|
|
return;
|
|
}
|
|
let CanvassDetailId = $('#canvassDetailId').val();
|
|
showConfirmation({
|
|
title: 'Alternative 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.PutSupplierAlterOffer,
|
|
type: 'POST',
|
|
data: { AlternativeOfferId, CanvassDetailId },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#viewSupplierAlterOfferList').modal('hide');
|
|
showToast('success', 'Approval of alternative item has been selected!', 'success', 4000);
|
|
} else {
|
|
prTable.ajax.reload(null, false);
|
|
prDataTable.ajax.reload(null, false);
|
|
showToast('error', response.response, 'failed', 4000);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function postPutDeniedItem() {
|
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
|
Remarks = $('#reject-remarks').val();
|
|
ItemList = [];
|
|
tableElement = $('#RRdataTable').DataTable();
|
|
tableElement.rows().every(function () {
|
|
rowData = this.data();
|
|
var prDetailsId = rowData.prDetailsId;
|
|
var prNo = rowData.prNo;
|
|
var itemNo = rowData.itemNo;
|
|
var itemData = {
|
|
PRDetailsId: prDetailsId,
|
|
PRNo: prNo,
|
|
ItemNo: itemNo,
|
|
};
|
|
ItemList.push(itemData);
|
|
});
|
|
|
|
if (ItemList.length <= 0) {
|
|
alert("You don't have a list to be denied!");
|
|
return;
|
|
}
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
|
|
if (confirmation) {
|
|
$.ajax($.extend({
|
|
url: '/PRMgmt/PostPutDeniedItem',
|
|
type: 'POST',
|
|
data: { ItemList,Remarks },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#rejectRemarks').modal('hide');
|
|
$('#viewRRDetailByPO').modal('hide');
|
|
receivingTableTable.ajax.reload(null, false);
|
|
alert('This item has been denied!');
|
|
} else {
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
error: errorHandler
|
|
}, beforeComplete(loader)));
|
|
}
|
|
}
|
|
function putPOClose() {
|
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
|
PONo = $('#poNo').val();
|
|
POTypeId = $('#poTypeId').val();
|
|
EmailAddress = $('#emailAddress').val();
|
|
Remarks = $('#remarks').val();
|
|
DocTypeId = $('#docTypeId').val();
|
|
ItemList = [];
|
|
tableElement = $('#FRRdataTable').DataTable();
|
|
tableElement.rows().every(function () {
|
|
rowData = this.data();
|
|
var prDetailsId = rowData.prDetailsId;
|
|
|
|
var itemData = {
|
|
PRDetailsId: prDetailsId,
|
|
};
|
|
ItemList.push(itemData);
|
|
});
|
|
if (ItemList.length <= 0) {
|
|
alert("You don't have a list to be closed!");
|
|
return;
|
|
}
|
|
|
|
const confirmation = confirm('Are you sure you want to Close this #P.O.:'+ PONo +'?');
|
|
|
|
if (confirmation) {
|
|
$.ajax($.extend({
|
|
url: '/PRMgmt/PutPOClose',
|
|
type: 'POST',
|
|
data: { ItemList, POTypeId, EmailAddress, PONo, DocTypeId, Remarks },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#viewRRDetailByPO').modal('hide');
|
|
receivingTableTable.ajax.reload(null, false);
|
|
alert('PO Closed Successfully!');
|
|
} else {
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
error: errorHandler
|
|
}, beforeComplete(loader)));
|
|
}
|
|
}
|
|
function postPOClosing() {
|
|
var loader = $('#overlay, #loader').css('z-index', 1060);
|
|
|
|
var PONo = document.getElementById('F-PONumber').innerText;
|
|
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
|
|
if (confirmation) {
|
|
$.ajax({
|
|
url: '/PRMgmt/PostPOClosing',
|
|
type: 'POST',
|
|
data: { PONo }, // Pass requestData array to the backend
|
|
success: function (response) {
|
|
if (response.success) {
|
|
prTable.ajax.reload();
|
|
prDataTable.ajax.reload();
|
|
$('#viewPRDetails').modal('hide');
|
|
$('#viewPRItemDetails').modal('hide');
|
|
alert('P.O. successfully closed!');
|
|
|
|
} else {
|
|
itemTable.ajax.reload();
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
// Show the loader before making the AJAX request
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
// Hide the loader after the AJAX request is complete (success or error)
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
function showDeniedRemarks() {
|
|
$('#addRemarksUpdate').modal('show');
|
|
$('#addRemarksUpdate').css('z-index', 1075);
|
|
}
|
|
function holdItem(isApprove) {
|
|
loader = $('#overlay, #loader').css('z-index', 1080);
|
|
var ItemNo = document.getElementById("itemNo").value;
|
|
var Status = isApprove;
|
|
|
|
var Remarks = document.getElementById('remarks').value;
|
|
|
|
if (isApprove === 3 && !Remarks) {
|
|
showToast('error', 'Please input remarks!', 'Rejection of P.R. failed', 4000);
|
|
return;
|
|
}
|
|
|
|
showConfirmation({
|
|
title: 'P.R. Rejection',
|
|
message: 'Are you sure you want to denied this item? This action cannot be undone.',
|
|
type: 'danger',
|
|
confirmText: 'Yes, Deny',
|
|
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) {
|
|
prDataTable.ajax.reload(null, false);
|
|
prTable.ajax.reload(null, false);
|
|
$('#viewPRItemDetails').modal('hide');
|
|
$('#addRemarksUpdate').modal('hide');
|
|
$('#remarks').val('');
|
|
showToast('success', 'Item successfully hold!', 'success', 4000);
|
|
} else {
|
|
prDataTable.ajax.reload(null, false);
|
|
prTable.ajax.reload(null, false);
|
|
showToast('error', response.response, 'Rejection of P.R. failed', 4000);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function putItemDetails(Status) {
|
|
loader = $('#overlay, #loader').css('z-index', 1065);
|
|
const uomIdInput = document.getElementById('uomId');
|
|
|
|
const itemCategoryInput = document.getElementById('itemCategoryName');
|
|
const uomNameInput = document.getElementById('uomName');
|
|
const itemQtyInput = document.getElementById('itemQty');
|
|
const itemColorIdInput = document.getElementById('itemColorId');
|
|
const itemLocalNameInput = document.getElementById('itemLocalName');
|
|
const itemLocalIdInput = document.getElementById('itemLocalId');
|
|
var Remarks = document.getElementById('itemRemarks').value;
|
|
const itemNameInput = document.getElementById('itemName');
|
|
const itemDescriptionInput = document.getElementById('itemDescription');
|
|
|
|
itemCategoryInput.addEventListener('input', removeErrorClass);
|
|
itemLocalNameInput.addEventListener('input', removeErrorClass);
|
|
uomNameInput.addEventListener('input', removeErrorClass);
|
|
itemQtyInput.addEventListener('input', removeErrorClass);
|
|
itemNameInput.addEventListener('input', removeErrorClass);
|
|
itemDescriptionInput.addEventListener('input', removeErrorClass);
|
|
|
|
const ItemCategory = itemCategoryInput.value;
|
|
const ItemColorId = itemColorIdInput.value;
|
|
const ItemLocalName = itemLocalNameInput.value;
|
|
const Qty = itemQtyInput.value;
|
|
const ItemLocalId = itemLocalIdInput.value;
|
|
const UOMId = uomIdInput.value;
|
|
const UOMName = uomNameInput.value;
|
|
const ItemName = itemNameInput.value;
|
|
const ItemDescription = itemDescriptionInput.value;
|
|
|
|
if (!ItemCategory || Qty == 0 || !ItemLocalName || !UOMName || !ItemName || !ItemDescription) {
|
|
|
|
showToast('warning', 'Please fill the required fields!', 'warning', 4000);
|
|
if (!ItemCategory) {
|
|
itemCategoryInput.classList.add('error-input');
|
|
}
|
|
if (!ItemLocalName) {
|
|
itemLocalNameInput.classList.add('error-input');
|
|
}
|
|
if (!Qty || Qty == 0) {
|
|
itemQtyInput.classList.add('error-input');
|
|
}
|
|
if (!UOMId) {
|
|
uomNameInput.classList.add('error-input');
|
|
}
|
|
if (!ItemName) {
|
|
itemNameInput.classList.add('error-input');
|
|
}
|
|
if (!ItemDescription) {
|
|
itemDescriptionInput.classList.add('error-input');
|
|
}
|
|
return;
|
|
}
|
|
showConfirmation({
|
|
title: 'Item Update',
|
|
message: 'Are you sure you want to update this item? This action cannot be undone.',
|
|
type: 'warning',
|
|
confirmText: 'Yes, Update',
|
|
cancelText: 'No'
|
|
}).then((confirmed) => {
|
|
if (confirmed) {
|
|
$.ajax({
|
|
url: endpoint.PutItemDetail,
|
|
type: 'POST',
|
|
data: { Status, PRDetailsId, UOMId, Qty, ItemLocalId, ItemColorId, Remarks, ItemName, ItemDescription },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
prTable.ajax.reload(null, false);
|
|
prDataTable.ajax.reload(null, false);
|
|
$('#viewPRItemDetails').modal('hide');
|
|
$('#addRemarksUpdate').modal('hide');
|
|
showToast('success', 'Item Successfully Updated!', 'success', 4000);
|
|
} else {
|
|
prTable.ajax.reload(null, false);
|
|
prDataTable.ajax.reload(null, false);
|
|
showToast('error', response.response, 'Rejection of P.R. failed', 4000);
|
|
}
|
|
},
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
} |