Item removal enhancement on receiving page
This commit is contained in:
parent
d23347c299
commit
199c1271a0
@ -6,7 +6,7 @@
|
||||
<script src="~/jsfunctions/receiving/ReceivingViewV4.js"></script>
|
||||
<script src="~/jsfunctions/receiving/receivingcallback.js"></script>
|
||||
<script src="~/jsfunctions/receiving/receivingbutton.js"></script>
|
||||
<script src="~/jsfunctions/receiving/ReceivingPostPutV2.js"></script>
|
||||
<script src="~/jsfunctions/receiving/ReceivingPostPutV3.js"></script>
|
||||
<script src="~/jsfunctions/utilities/searchengine.js"></script>
|
||||
<script src="~/jsfunctions/utilities/stylesv3.js"></script>
|
||||
<script src="~/jsfunctions/utilities/utilsV3.js"></script>
|
||||
@ -28,7 +28,7 @@
|
||||
$('#poNoHidden').val(data.poNo);
|
||||
$('#totalAmountSIPO').text(data.itemCategoryName + numberWithCommas(data.totalAmount));
|
||||
|
||||
let formattedDate = formatDate(data.currentDate);
|
||||
let formattedDate = formatDate(data.createdDate ?? data.currentDate);
|
||||
let formattedDelDate = formatDate(data.deliveryDate);
|
||||
|
||||
document.getElementById('C-poDate').innerText = formattedDate;
|
||||
@ -61,7 +61,7 @@ function rowApprovedSIPOCallback(row, data) {
|
||||
$('#poNoHidden').val(data.poNo);
|
||||
$('#totalAmountSIPO').text(data.itemCategoryName + numberWithCommas(data.totalAmount));
|
||||
|
||||
let formattedDate = formatDate(data.currentDate);
|
||||
let formattedDate = formatDate(data.createdDate ?? data.currentDate);
|
||||
let formattedDelDate = formatDate(data.deliveryDate);
|
||||
|
||||
document.getElementById('C-poDate').innerText = formattedDate;
|
||||
@ -12,6 +12,7 @@
|
||||
PostPutProjectCode: '/PRMgmt/PostPutProjectCode',
|
||||
PRItemRemoval: '/PRMgmt/PRItemRemoval',
|
||||
PutItemDetail: '/PRMgmt/PutItemDetail',
|
||||
PostItemInPR: '/PRMgmt/PostItemInPR',
|
||||
ApprovedSelectedPRItem: '/PRMgmt/ApprovedSelectedPRItem',
|
||||
PostPRApproveReject: '/PRMgmt/PostPRApproveReject',
|
||||
};
|
||||
@ -1,4 +1,67 @@
|
||||
function postPutProjectCode() {
|
||||
function postItemInPR() {
|
||||
loader = $('#overlay, #loader').css('z-index', 1110);
|
||||
|
||||
const selectedItems = Object.values(selectedProductsMap);
|
||||
if (selectedItems.length === 0) {
|
||||
showToast('warning', 'Please select items first!', 'Submission failed', 4000);
|
||||
return;
|
||||
}
|
||||
|
||||
const PRItemList = selectedItems.map(item => ({
|
||||
itemNo: item.itemNo,
|
||||
qty: parseFloat(item.qty) || 0
|
||||
}));
|
||||
|
||||
const invalidItems = PRItemList.filter(item => !item.qty || item.qty <= 0);
|
||||
if (invalidItems.length > 0) {
|
||||
|
||||
const invalidNames = invalidItems.map(invalid => {
|
||||
const details = selectedItems.find(i => i.itemNo === invalid.itemNo);
|
||||
return `${details.itemNo} - ${details.itemName}`;
|
||||
}).join(', ');
|
||||
|
||||
showToast('warning', `Items with 0 or empty qty: ${invalidNames}`, 'Submission failed', 8000);
|
||||
return;
|
||||
}
|
||||
|
||||
let PRNo = document.getElementById('label-pr-prNo').innerHTML;
|
||||
|
||||
if (!PRNo) {
|
||||
showToast('error', 'Server error, please re-login and try again!', 'Submission failed', 4000);
|
||||
return;
|
||||
}
|
||||
|
||||
showConfirmation({
|
||||
title: 'Add New Item',
|
||||
message: `Are you sure you want to add new item for this PRNo# ${PRNo}? This action cannot be undone.`,
|
||||
type: 'warning',
|
||||
confirmText: 'Yes',
|
||||
cancelText: 'No'
|
||||
}).then((confirmed) => {
|
||||
if (confirmed) {
|
||||
$.ajax({
|
||||
url: endpoint.PostItemInPR,
|
||||
type: 'POST',
|
||||
data: { PRItemList, PRNo },
|
||||
...beforeComplete(loader),
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
|
||||
prTable.ajax.reload(null, false);
|
||||
|
||||
$('#viewItemList, #viewPRDetails').modal('hide');
|
||||
|
||||
showToast('success', 'PR item added successfully!', 'Success', 8000);
|
||||
} else {
|
||||
showToast('error', response.response, 'Adding item failed', 8000);
|
||||
}
|
||||
},
|
||||
error: errorHandler
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function postPutProjectCode() {
|
||||
loader = $('#overlay, #loader').css('z-index', 1070);
|
||||
const modal = $('#showProjectCode');
|
||||
const mode = modal.attr('data-mode');
|
||||
@ -46,49 +46,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
/*$(document).ready(function () {
|
||||
loader = $('#overlay, #loader');
|
||||
|
||||
UserRights = document.getElementById("roleRights").value;
|
||||
|
||||
prTable = $('#PRTable').DataTable({
|
||||
ajax: {
|
||||
url: '/PRMgmt/GetAllPR', // Initial endpoint
|
||||
type: 'GET',
|
||||
beforeSend: function () {
|
||||
// Show the loader before making the AJAX request
|
||||
loader.show();
|
||||
},
|
||||
complete: function () {
|
||||
loader.hide();
|
||||
},
|
||||
error: function (xhr, error, thrown) {
|
||||
loader.hide();
|
||||
console.error('Error loading data:', error);
|
||||
|
||||
// Optional: Show error notification
|
||||
if (typeof toastr !== 'undefined') {
|
||||
toastr.error('Failed to load data. Please try again.');
|
||||
}
|
||||
}
|
||||
},
|
||||
initComplete: initCompleteCallback,
|
||||
columns: colOnPRTable,
|
||||
order: [[10, 'asc']],
|
||||
rowCallback: rowStatusColorCallback,
|
||||
responsive: true,
|
||||
language: {
|
||||
emptyTable: "No record available",
|
||||
loadingRecords: "Loading data...",
|
||||
processing: "Processing..."
|
||||
},
|
||||
error: errorHandler
|
||||
});
|
||||
|
||||
// Initialize tabs after DataTable is ready
|
||||
// The PRTabs.js script will handle tab switching and DataTable reloading
|
||||
});*/
|
||||
|
||||
// Optional: Add helper function to refresh current tab
|
||||
function refreshCurrentTab() {
|
||||
if (typeof PRTabs !== 'undefined') {
|
||||
@ -257,8 +214,7 @@ function uploadAttachment() {
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Upload error:', error);
|
||||
showToast('error', 'An error occurred during upload.', 'File Upload', 4000);
|
||||
showToast('error', 'Upload error:', error, 'File Upload', 4000);
|
||||
})
|
||||
.finally(() => {
|
||||
// Reset button state
|
||||
@ -1,4 +1,89 @@
|
||||
function showProjectCode(data = {}, isNew = true) {
|
||||
function viewItemList() {
|
||||
var loader = $('#overlay, #loader').css('z-index', 1100);
|
||||
$('#viewItemList').modal('show');
|
||||
$('#viewItemList').css('z-index', 1090);
|
||||
|
||||
tableElement = $('#ItemTable');
|
||||
tableName = '#ItemTable';
|
||||
|
||||
tableDestroy(tableElement);
|
||||
totalSelectedLabel = $('#totalSelectedItem');
|
||||
|
||||
clearTableSelection(tableName, selectedProductsMap, () => {
|
||||
totalSelectedLabel.text(0);
|
||||
}, 'selected-row', '.select-all-item-checkbox');
|
||||
|
||||
var itemListTable = tableElement.DataTable({
|
||||
ajax: $.extend({
|
||||
url: '/ItemMgmt/GetItemList',
|
||||
type: 'POST',
|
||||
}, beforeComplete(loader)),
|
||||
responsive: true,
|
||||
language: {
|
||||
emptyTable: "No record available"
|
||||
},
|
||||
initComplete: function () {
|
||||
initializeTableSelection({
|
||||
tableName: tableName,
|
||||
dataTable: itemListTable,
|
||||
selectedItemsMap: selectedProductsMap,
|
||||
idKey: 'itemNo',
|
||||
idKey2: 'itemCodeId',
|
||||
checkboxClass: '.select-item-checkbox',
|
||||
selectAllClass: '.select-all-item-checkbox',
|
||||
selectedRowClass: 'selected-row',
|
||||
updateCountCallback: function () {
|
||||
totalSelectedLabel.text(getSelectedCount(selectedProductsMap));
|
||||
}
|
||||
});
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
data: 'itemNo',
|
||||
title: '<input type="checkbox" class="select-all-item-checkbox" />',
|
||||
render: function () {
|
||||
return '<input type="checkbox" class="select-item-checkbox" style="text-align:center;"/>';
|
||||
},
|
||||
orderable: false,
|
||||
searchable: false
|
||||
},
|
||||
{ data: 'itemNo' },
|
||||
{ data: 'itemName' },
|
||||
{ data: 'itemDescription' },
|
||||
{ data: 'itemCategoryName' },
|
||||
{ data: 'qty' },
|
||||
],
|
||||
"columnDefs": [
|
||||
{
|
||||
"targets": [5],
|
||||
"render": function (data, type, row) {
|
||||
return '<input type="number" class="editable-qty" style="width:60px;" value="' + data + '" />';
|
||||
}
|
||||
}
|
||||
],
|
||||
pageLength: 5,
|
||||
lengthMenu: [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"]],
|
||||
error: errorHandler
|
||||
});
|
||||
// Add this inside viewItemList(), after the DataTable is initialized
|
||||
$('#ItemTable').on('change', '.editable-qty', function () {
|
||||
const $row = $(this).closest('tr');
|
||||
const rowData = itemListTable.row($row).data();
|
||||
if (!rowData) return;
|
||||
|
||||
const newQty = parseFloat($(this).val()) || 0;
|
||||
const itemId = `${rowData.itemNo}|${rowData.qty}`; // original key
|
||||
|
||||
// ✅ If this item is already selected, update its qty in the map
|
||||
if (selectedProductsMap[itemId]) {
|
||||
selectedProductsMap[itemId].qty = newQty;
|
||||
}
|
||||
|
||||
// Update the DataTable's internal data too
|
||||
rowData.qty = newQty;
|
||||
});
|
||||
}
|
||||
function showProjectCode(data = {}, isNew = true) {
|
||||
|
||||
const modal = $('#showProjectCode');
|
||||
|
||||
@ -817,8 +902,7 @@ function downloadPRAttachment() {
|
||||
window.URL.revokeObjectURL(url);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error downloading attachment:", error);
|
||||
alert("Error downloading attachment. Please check if the file exists.");
|
||||
showToast('error', error, 'Submission failed', 4000);
|
||||
});
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
Remarks = $('#remarks').val();
|
||||
ItemList = [];
|
||||
tableElement = $('#RRdataTable').DataTable();
|
||||
var isValid = true; // Flag to track validity
|
||||
var isValid = true;
|
||||
|
||||
const drNoInput = document.getElementById('suppDocNo');
|
||||
const docTypeIdInput = document.getElementById('docTypeId');
|
||||
@ -23,11 +23,11 @@
|
||||
|
||||
if (RRNo == 0) {
|
||||
rrNoInput.classList.add('error-input');
|
||||
alert('RRNo cannot be 0!');
|
||||
showToast('warning', 'RRNo cannot be 0!', 'Submission failed!', 4000);
|
||||
}
|
||||
|
||||
if (!DRNo || !DocTypeId || !ReceivedDate || !RRNo) {
|
||||
alert('Please fill the required fields !');
|
||||
showToast('warning', 'Please fill the required fields !', 'Submission failed!', 4000);
|
||||
if (!DRNo) {
|
||||
drNoInput.classList.add('error-input');
|
||||
}
|
||||
@ -54,17 +54,17 @@
|
||||
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.');
|
||||
if (isNaN(parseFloat(qtyReceived)) || parseFloat(qtyReceived) <= 0 || parseFloat(qtyReceived) === null) {
|
||||
showToast('warning', 'Invalid Quantity Received, Please provide a valid number.', 'Submission failed!', 4000);
|
||||
qtyReceived = rowData.quantityReceived; // Default to original if invalid
|
||||
}
|
||||
if (parseFloat(qtyReceived) > parseFloat(qtyRequest)) {
|
||||
alert('Qty Received cannot be more than Remaining Qty!');
|
||||
showToast('warning', 'Qty Received cannot be more than Remaining Qty!', 'Submission failed!', 4000);
|
||||
isValid = false;
|
||||
return false;
|
||||
}
|
||||
if (qtyReceived <= 0 || qtyReceived == null) {
|
||||
alert('Qty Received Cannot be 0 or empty!, please remove instead!');
|
||||
showToast('warning', 'Qty Received Cannot be 0 or empty!, please remove instead!', 'Submission failed!', 4000);
|
||||
isValid = false;
|
||||
return false;
|
||||
}
|
||||
@ -79,7 +79,7 @@
|
||||
return;
|
||||
}
|
||||
if (ItemList.length <= 0) {
|
||||
alert("You don't have a list to be received!");
|
||||
showToast('warning', "You don't have a list to be received!", 'Submission failed!', 4000);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -221,24 +221,31 @@ function postPOClosing() {
|
||||
}
|
||||
}
|
||||
function deleteSKUCodeRec(prDetailsId) {
|
||||
const confirmation = confirm('Are you sure you want to proceed?');
|
||||
if (confirmation) {
|
||||
var table = $('#RRdataTable').DataTable();
|
||||
var rowToRemove = null;
|
||||
showConfirmation({
|
||||
title: 'Remove Item',
|
||||
message: 'Are you sure you want to remove this item? This action cannot be undone.',
|
||||
type: 'danger',
|
||||
confirmText: 'Yes',
|
||||
cancelText: 'No'
|
||||
}).then((confirmed) => {
|
||||
if (confirmed) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
if (rowToRemove) {
|
||||
rowToRemove.remove();
|
||||
table.rows().invalidate().draw(false);
|
||||
} else {
|
||||
console.log('No matching row found for prDetailsId:', prDetailsId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user