244 lines
8.4 KiB
JavaScript
244 lines
8.4 KiB
JavaScript
function postPutReceiving(IsCompleted) {
|
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
|
PONo = $('#poNo').val();
|
|
POTypeId = $('#poTypeId').val();
|
|
EmailAddress = $('#emailAddress').val();
|
|
Remarks = $('#remarks').val();
|
|
ItemList = [];
|
|
tableElement = $('#RRdataTable').DataTable();
|
|
var isValid = true; // Flag to track validity
|
|
|
|
const drNoInput = document.getElementById('suppDocNo');
|
|
const docTypeIdInput = document.getElementById('docTypeId');
|
|
const receivedDateInput = document.getElementById('receivedDate');
|
|
const rrNoInput = document.getElementById('rrNo');
|
|
|
|
drNoInput.addEventListener('input', removeErrorClass);
|
|
docTypeIdInput.addEventListener('input', removeErrorClass);
|
|
receivedDateInput.addEventListener('input', removeErrorClass);
|
|
DRNo = drNoInput.value;
|
|
DocTypeId = docTypeIdInput.value;
|
|
RRNo = parseFloat(rrNoInput.value);
|
|
var ReceivedDate = receivedDateInput.value;
|
|
|
|
if (RRNo == 0) {
|
|
rrNoInput.classList.add('error-input');
|
|
alert('RRNo cannot be 0!');
|
|
}
|
|
|
|
if (!DRNo || !DocTypeId || !ReceivedDate || !RRNo) {
|
|
alert('Please fill the required fields !');
|
|
if (!DRNo) {
|
|
drNoInput.classList.add('error-input');
|
|
}
|
|
if (!DocTypeId) {
|
|
docTypeIdInput.classList.add('error-input');
|
|
}
|
|
if (!ReceivedDate) {
|
|
receivedDateInput.classList.add('error-input');
|
|
}
|
|
if (!RRNo) {
|
|
rrNoInput.classList.add('error-input');
|
|
}
|
|
return;
|
|
}
|
|
tableElement.rows().every(function () {
|
|
rowData = this.data();
|
|
var $row = $(this.node());
|
|
var prDetailsId = rowData.prDetailsId;
|
|
qtyRequest = rowData.remainingQty;
|
|
// Get the edited value from the input field and remove commas for calculation/posting
|
|
var qtyReceived = $row.find('.editable-qty').eq(0).val().replace(/,/g, '');
|
|
|
|
// Convert qtyReceived to a number to avoid it being a string
|
|
qtyReceived = parseFloat(qtyReceived);
|
|
|
|
// Ensure the value is valid (check for NaN)
|
|
if (isNaN(qtyReceived) || qtyReceived <= 0 || qtyReceived === null) {
|
|
alert('Invalid Quantity Received. Please provide a valid number.');
|
|
qtyReceived = rowData.quantityReceived; // Default to original if invalid
|
|
}
|
|
if (parseFloat(qtyReceived) > parseFloat(qtyRequest)) {
|
|
alert('Qty Received cannot be more than Remaining Qty!');
|
|
isValid = false;
|
|
return false;
|
|
}
|
|
if (qtyReceived <= 0 || qtyReceived == null) {
|
|
alert('Qty Received Cannot be 0 or empty!, please remove instead!');
|
|
isValid = false;
|
|
return false;
|
|
}
|
|
var itemData = {
|
|
PRDetailsId: prDetailsId,
|
|
QuantityReceived: qtyReceived,
|
|
};
|
|
ItemList.push(itemData);
|
|
});
|
|
|
|
if (!isValid) {
|
|
return;
|
|
}
|
|
if (ItemList.length <= 0) {
|
|
alert("You don't have a list to be received!");
|
|
return;
|
|
}
|
|
|
|
showConfirmation({
|
|
title: 'Receiving',
|
|
message: 'Are you sure you want to receive this item? This action cannot be undone.',
|
|
type: 'warning',
|
|
confirmText: 'Yes',
|
|
cancelText: 'No'
|
|
}).then((confirmed) => {
|
|
if (confirmed) {
|
|
$.ajax($.extend({
|
|
url: '/Receiving/PostPutReceiving',
|
|
type: 'POST',
|
|
data: { ItemList, POTypeId, EmailAddress, PONo, DocTypeId, Remarks, DRNo, ReceivedDate, RRNo, IsCompleted },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#viewRRDetailByPO').modal('hide');
|
|
receivingTable.ajax.reload();
|
|
|
|
showToast('success', 'Item Received Successfully!', 'Receiving', 4000);
|
|
} else {
|
|
showToast('error', response.response, 'Updating failed!', 4000);
|
|
}
|
|
},
|
|
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: '/Receiving/PutPOClose',
|
|
type: 'POST',
|
|
data: { ItemList, POTypeId, EmailAddress, PONo, DocTypeId, Remarks },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#viewRRDetailByPO').modal('hide');
|
|
receivingTableTable.ajax.reload();
|
|
alert('PO Closed Successfully!');
|
|
} else {
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
error: errorHandler
|
|
}, beforeComplete(loader)));
|
|
}
|
|
}
|
|
function putRRNoSeries() {
|
|
loader = $('#overlay, #loader').css('z-index', 1075);
|
|
const rrNo = document.getElementById('rrNoSeries');
|
|
rrNo.addEventListener('input', removeErrorClass);
|
|
const RRNo = rrNo.value;
|
|
if (!RRNo) {
|
|
alert('Please fill the required fields !');
|
|
rrNo.classList.add('error-input');
|
|
return;
|
|
}
|
|
var oldRRNo= $('#rrNo').val();
|
|
const confirmation = confirm('Are you sure you want to change this #RRNo:'+ oldRRNo + ' into: ' + RRNo + '?');
|
|
|
|
if (confirmation) {
|
|
$.ajax($.extend({
|
|
url: '/Receiving/PutRRNoSeries',
|
|
type: 'POST',
|
|
data: { RRNo },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
$('#rrNo').val(parseFloat(RRNo) + 1);
|
|
$('#viewRRNo').modal('hide');
|
|
alert('RRNo has been updated!');
|
|
} else {
|
|
alert('Failed: ' + response.response);
|
|
}
|
|
},
|
|
error: errorHandler
|
|
}, beforeComplete(loader)));
|
|
}
|
|
}
|
|
function postPOClosing() {
|
|
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: '/Receiving/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 deleteSKUCodeRec(prDetailsId) {
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
if (confirmation) {
|
|
var table = $('#RRdataTable').DataTable();
|
|
var rowToRemove = null;
|
|
|
|
table.rows().every(function (rowIdx) {
|
|
var data = this.data();
|
|
if (data && data.prDetailsId == prDetailsId) {
|
|
rowToRemove = this;
|
|
return false;
|
|
}
|
|
});
|
|
|
|
if (rowToRemove) {
|
|
rowToRemove.remove();
|
|
table.rows().invalidate().draw(false);
|
|
} else {
|
|
console.log('No matching row found for prDetailsId:', prDetailsId);
|
|
}
|
|
}
|
|
} |