458 lines
17 KiB
JavaScript
458 lines
17 KiB
JavaScript
var UserRights;
|
|
var inventTable;
|
|
var inventDetailTable;
|
|
var reqDataTable;
|
|
var InventoryId;
|
|
function hasRolePermission(role) {
|
|
return UserRights.includes(role);
|
|
}
|
|
function renderApprovalbtns(data, row) {
|
|
var jsonData = JSON.stringify(row).replace(/"/g, """);
|
|
var buttonsHtml = '';
|
|
var statusNumber = parseInt(row.itemNo, 10);
|
|
if (statusNumber == 0 || statusNumber == null) {
|
|
buttonsHtml += '<button onclick="viewItemDetailOOS(' + jsonData + ')" class="btn btn-default">' +
|
|
'<i class="fa-solid fa-eye fa-xl" style="color: #008080;" aria-hidden="true"></i>' +
|
|
'</button > ';
|
|
} else {
|
|
buttonsHtml += '<button onclick="viewItemDetail(' + jsonData + ')" class="btn btn-default">' +
|
|
'<i class="fa-solid fa-eye fa-xl" style="color: #008080;" aria-hidden="true"></i>' +
|
|
'</button > ';
|
|
}
|
|
|
|
|
|
return buttonsHtml;
|
|
}
|
|
function renderItembtns(data, row) {
|
|
var jsonData = JSON.stringify(row).replace(/"/g, """);
|
|
var buttonsHtml = '';
|
|
var statusNumber = parseInt(row.itemNo, 10);
|
|
if (statusNumber == 0 || statusNumber == null) {
|
|
buttonsHtml += '<button onclick="viewItemDetailOOS(' + jsonData + ')" class="btn btn-default">' +
|
|
'<i class="fa-solid fa-eye fa-xl" style="color: #008080;" aria-hidden="true"></i>' +
|
|
'</button > ';
|
|
} else {
|
|
buttonsHtml += '<button onclick="viewItemDetail(' + jsonData + ')" class="btn btn-default">' +
|
|
'<i class="fa-solid fa-eye fa-xl" style="color: #008080;" aria-hidden="true"></i>' +
|
|
'</button > ';
|
|
}
|
|
|
|
|
|
return buttonsHtml;
|
|
}
|
|
function holdItem(isApprove) {
|
|
console.log('isApprove', isApprove);
|
|
$('#addRemarksUpdate').modal('show');
|
|
$('#addRemarksUpdate').css('z-index', 1060);
|
|
|
|
// Ensure the event listener is added only once
|
|
if (!confirmUpdateListener) {
|
|
document.getElementById('btnAddRemarks').addEventListener('click', function () {
|
|
var Remarks = document.getElementById('remarks').value;
|
|
|
|
if (isApprove === 3 && !Remarks) {
|
|
alert('Please put remarks!');
|
|
return;
|
|
}
|
|
|
|
// Show a confirmation dialog
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
|
|
if (confirmation) {
|
|
// If all validation is passed then proceed to confirmation to backend
|
|
// confirmPRApproveReject(isApprove, Remarks);
|
|
var loader = $('#overlay, #loader').css('z-index', 1060);
|
|
var ItemNo = document.getElementById("itemNo").value;
|
|
var Status = isApprove;
|
|
|
|
$.ajax({
|
|
url: '/PRMgmt/PostPRApproveReject',
|
|
type: 'POST',
|
|
data: { ItemNo: ItemNo, Status: Status, PRDetailsId: PRDetailsId, Remarks: Remarks }, // Pass requestData array to the backend
|
|
success: function (response) {
|
|
if (response.success) {
|
|
prTable.ajax.reload();
|
|
prDataTable.ajax.reload();
|
|
$('#viewPRItemDetails').modal('hide');
|
|
$('#addRemarksUpdate').modal('hide');
|
|
if (isApprove == 1) {
|
|
alert('Item Hold!');
|
|
}
|
|
} 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();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Set the flag to true to indicate that the listener is attached
|
|
confirmUpdateListener = true;
|
|
}
|
|
}
|
|
function populateLotNo(ItemNo, LotId) {
|
|
$.ajax({
|
|
url: "/InventoryMgmt/GetLotQtyByItem",
|
|
data: { ItemNo, LotId },
|
|
success: function (response) {
|
|
// Log the received data for debugging
|
|
console.log('Received data:', response);
|
|
|
|
// Check if the response is successful and has a data array
|
|
if (response.success && Array.isArray(response.data)) {
|
|
var lots = response.data;
|
|
|
|
// Clear existing options in the select element
|
|
$('#lotNo').empty();
|
|
|
|
// Add the default option
|
|
$('#lotNo').append($('<option>', {
|
|
value: 'select',
|
|
text: 'Select LotNo',
|
|
disabled: true,
|
|
selected: true
|
|
}));
|
|
|
|
// Populate the select element with options and store corresponding IDs
|
|
lots.forEach(function (lot) {
|
|
$('#lotNo').append($('<option>', {
|
|
value: lot.lotId,
|
|
text: lot.lotName,
|
|
'data-lot-type': lot.lotTypeName, // Store lotTypeName in a data attribute
|
|
'data-lot-id': lot.lotId,
|
|
'data-qty-in': lot.qtyIn,
|
|
'data-qty-out': lot.qtyOut,
|
|
'data-qty-onhand': lot.qtyOnHand
|
|
}));
|
|
});
|
|
|
|
// Add an event listener to handle selection
|
|
$('#lotNo').on('change', function () {
|
|
var selectedOption = $(this).find('option:selected');
|
|
var selectedValue = selectedOption.val();
|
|
var selectedLotTypeName = selectedOption.data('lot-type');
|
|
var inputlotId = selectedOption.data('lot-id');
|
|
var inputQtyIn = selectedOption.data('qty-in');
|
|
var inputQtyOut = selectedOption.data('qty-out');
|
|
var inputQtyOnHand = selectedOption.data('qty-onhand');
|
|
|
|
// Check if the default option is selected
|
|
if (selectedValue === 'select') {
|
|
// If yes, reset the hidden input and lotTypeName input values
|
|
$('#lotId').val('');
|
|
$('#lotTypeName').val('');
|
|
$('#qtyIn').val('0');
|
|
$('#qtyOut').val('0');
|
|
$('#qtyOnHand').val('0');
|
|
} else {
|
|
// If not, update the hidden input and lotTypeName input values
|
|
$('#lotId').val(selectedValue);
|
|
$('#lotTypeName').val(selectedLotTypeName);
|
|
$('#lotId').val(inputlotId);
|
|
$('#qtyIn').val(inputQtyIn);
|
|
$('#qtyOut').val(inputQtyOut);
|
|
$('#qtyOnHand').val(inputQtyOnHand);
|
|
|
|
console.log('lotId', inputlotId);
|
|
}
|
|
});
|
|
} else {
|
|
console.error('Invalid response format or data is not an array');
|
|
}
|
|
},
|
|
error: function (error) {
|
|
console.error('Error fetching lot numbers:', error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function postPutReqItems(IsApproved,Status) {
|
|
var loader = $('#overlay, #loader').css('z-index', 1060);
|
|
var LotId = document.getElementById('lotId').value;
|
|
var ItemNo = document.getElementById('itemNo').value;
|
|
|
|
var QtyRequest = document.getElementById('qtyRequest').value;
|
|
var QtyReceived = document.getElementById('qtyReceived').value;
|
|
var RequestItemId = document.getElementById('requestItemId').value;
|
|
|
|
console.log('RequestItemId', RequestItemId);
|
|
console.log('ItemNo', ItemNo);
|
|
|
|
// Check if the received quantity is more than the requested quantity
|
|
if (parseFloat(QtyReceived) > parseFloat(QtyRequest)) {
|
|
alert('Served Qty must not be more than Request Qty!');
|
|
return;
|
|
}
|
|
if (IsApproved == 1) {
|
|
if (!LotId || LotId==0) {
|
|
alert('LotNo not selected!');
|
|
return;
|
|
}
|
|
if (parseFloat(QtyReceived) == 0 || QtyReceived == null || QtyReceived == '') {
|
|
alert('Qty Served must not be 0 or empty!');
|
|
return;
|
|
}
|
|
}
|
|
|
|
const confirmation = confirm('Are you sure you want to proceed?');
|
|
|
|
if (confirmation) {
|
|
$.ajax({
|
|
url: '/InventoryMgmt/PostPutReqItems',
|
|
type: 'POST',
|
|
data: { IsApproved, Status, LotId, QtyReceived, ItemNo, RequestItemId },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
inventTable.ajax.reload();
|
|
$('#viewItemDetails').modal('hide');
|
|
if (isSave == 1) {
|
|
alert('Request Approved Successfully');
|
|
} else {
|
|
alert('Request Updated Successfully');
|
|
}
|
|
} 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 viewItemDetailOOS() {
|
|
var loader = $('#overlay, #loader');
|
|
|
|
/*console.log('UserRights', UserRights);*/
|
|
/* if (UserRights !== 'PRApprover2') {
|
|
let btnApprove = document.getElementById('btnApproveQueue');
|
|
btnApprove.style.display = 'none';
|
|
}*/
|
|
|
|
// Display the modal
|
|
$('#viewItemDetailOOS').modal('show');
|
|
|
|
// Set the z-index of viewArtWorkDetails modal
|
|
$('#viewItemDetailOOS').css('z-index', 1060);
|
|
|
|
// Get a reference to the table element in the modal
|
|
var tableElement = $('#RequestdataTable');
|
|
|
|
// Check if a DataTable is already initialized on the table element
|
|
if ($.fn.DataTable.isDataTable(tableElement)) {
|
|
// Destroy the DataTable
|
|
tableElement.DataTable().destroy();
|
|
}
|
|
let WithoutStocks = true;
|
|
// Initialize the DataTable inside the modal with new data
|
|
reqDataTable = tableElement.DataTable({
|
|
ajax: {
|
|
url: '/InventoryMgmt/GetRequestedItemByUserId',
|
|
type: 'POST',
|
|
data: { WithoutStocks },
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
},
|
|
initComplete: function () {
|
|
var api = this.api();
|
|
var tableData = api.ajax.json();
|
|
|
|
if (tableData && tableData.data === "No Data") {
|
|
$('.dataTables_empty').html("No record available");
|
|
}
|
|
},
|
|
columns: [
|
|
{ data: 'itemNo' },
|
|
{ data: 'itemName' },
|
|
{ data: 'itemDescription' },
|
|
{ data: 'itemCategoryName' },
|
|
{ data: 'qtyRequest' },
|
|
{ data: 'status' },
|
|
{ data: 'createdDateStr' },
|
|
{
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
return renderApprovalbtns(data, row);
|
|
}
|
|
},
|
|
{ data: 'inventoryId', visible: false },
|
|
{ data: 'requestItemId', visible: false },
|
|
|
|
],
|
|
/* rowCallback: function (row, data) {
|
|
|
|
var StatusNameCell = $('td:eq(4)', row);//next-facilitator
|
|
StatusNameCell.addClass('next-facilitator');
|
|
},*/
|
|
responsive: true,
|
|
language: {
|
|
emptyTable: "No record available"
|
|
},
|
|
error: function (xhr, error, thrown) {
|
|
console.log('DataTables error:', error);
|
|
console.log('Status:', xhr.status);
|
|
console.log('Details:', xhr.responseText);
|
|
loader.hide();
|
|
$('#viewPRDetails').modal('hide');
|
|
window.location.href = '/Home/Logout';
|
|
}
|
|
});
|
|
}
|
|
function viewItemDetail(data) {
|
|
var loader = $('#overlay, #loader').css('z-index', 1060);
|
|
if (UserRights !== 'LLISCMAdmin') {
|
|
let btnDenied = document.getElementById('btnDeniedItem');
|
|
btnDenied.style.display = 'none';
|
|
let btnApprove = document.getElementById('btnApprovedItem');
|
|
btnApprove.style.display = 'none';
|
|
}
|
|
var RequestItemId = data.requestItemId;
|
|
|
|
$.ajax({
|
|
url: '/InventoryMgmt/GetRequestedItemByUserId',
|
|
type: 'POST',
|
|
data: { RequestItemId },
|
|
beforeSend: function () {
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
},
|
|
success: function (data) {
|
|
// Check if the data is not null or undefined
|
|
if (data && data.data && data.data.length > 0) {
|
|
// Assuming the API returns an array of user profiles, take the first one
|
|
var item = data.data[0];
|
|
|
|
$('#itemName').val(item.itemName);
|
|
$('#itemDescription').val(item.itemDescription);
|
|
$('#itemCategoryName').val(item.itemCategoryName);
|
|
$('#statusName').val(item.statusName);
|
|
$('#itemNo').val(item.itemNo);
|
|
$('#uomName').val(item.uomName);
|
|
$('#itemColorName').val(item.itemColorName);
|
|
$('#createdDate').val(item.createdDate);
|
|
$('#itemLocalName').val(item.itemLocalName);
|
|
$('#qtyIn').val(item.qtyIn);
|
|
$('#qtyOut').val(item.qtyOut);
|
|
$('#qtyOnHand').val(item.qtyOnHand);
|
|
$('#lotId').val(item.lotId);
|
|
$('#lotNo').val(item.lotNo);
|
|
$('#lotTypeId').val(item.lotTypeId);
|
|
$('#lotTypeName').val(item.lotTypeName);
|
|
$('#requestItemId').val(item.requestItemId);
|
|
$('#qtyRequest').val(item.qtyRequest);
|
|
//
|
|
populateLotNo(item.itemNo, item.lotId);
|
|
// Check if item picture path is null or empty
|
|
var itemPicturePath = item.itemAttachPath;
|
|
if (!itemPicturePath || itemPicturePath === 'N/A' || itemPicturePath === 'None') {
|
|
$('#itemPictureImage').attr('src', '/Content/Common/empty.jpg'); // Default image path
|
|
} else {
|
|
var imageUrl = item.url + itemPicturePath; // Use HTTPS protocol
|
|
// Set the image source
|
|
$('#itemPictureImage').attr('src', imageUrl);
|
|
}
|
|
|
|
// Display the modal
|
|
$('#viewItemDetails').modal('show');
|
|
|
|
// Set the z-index of viewArtWorkDetails modal
|
|
$('#viewItemDetails').css('z-index', 1060);
|
|
|
|
} else {
|
|
console.log('Data is null or undefined');
|
|
// window.location.href = '/Home/Logout';
|
|
}
|
|
},
|
|
error: function (xhr, error, thrown) {
|
|
console.log('Authentication error:', error);
|
|
console.log('Details:', thrown);
|
|
window.location.href = '/Home/Logout';
|
|
}
|
|
});
|
|
}
|
|
$(document).ready(function () {
|
|
var loader = $('#overlay, #loader');
|
|
|
|
UserRights = document.getElementById("roleRights").value;
|
|
let RequestedItemId = 0;
|
|
inventTable = $('#PRTable').DataTable({
|
|
ajax: {
|
|
url: '/InventoryMgmt/GetRequestedItemByUserId', // Replace with your API endpoint
|
|
type: 'GET',
|
|
data: { RequestedItemId },
|
|
beforeSend: function () {
|
|
// Show the loader before making the AJAX request
|
|
loader.show();
|
|
},
|
|
complete: function () {
|
|
loader.hide();
|
|
}
|
|
},
|
|
// Check for the "No Data" response and display the message
|
|
initComplete: function () {
|
|
var api = this.api();
|
|
var data = api.ajax.json();
|
|
|
|
if (!data || !data.data || data.data === "No Data") {
|
|
// Display the "No record available" message
|
|
$('.dataTables_empty').html("No record available");
|
|
}
|
|
},
|
|
columns: [
|
|
{ data: 'itemNo' },
|
|
{ data: 'itemName' },
|
|
{ data: 'itemDescription' },
|
|
{ data: 'itemCategoryName' },
|
|
{ data: 'qtyRequest' },
|
|
{ data: 'statusName' },
|
|
{ data: 'createdDateStr' },
|
|
{
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
return renderItembtns(data, row);
|
|
}
|
|
},
|
|
{ data: 'inventoryId', visible: false },
|
|
{ data: 'requestItemId', visible: false },
|
|
|
|
],
|
|
order: [[9, 'asc']],
|
|
responsive: true,
|
|
language: {
|
|
emptyTable: "No record available"
|
|
},
|
|
error: function (xhr, error, thrown) {
|
|
console.log('DataTables error:', error);
|
|
console.log('Status:', Status);
|
|
console.log('Details:', xhr.responseText);
|
|
window.location.href = '/Home/Logout';
|
|
}
|
|
});
|
|
})
|
|
function removeErrorClass() {
|
|
if (this.value.trim() !== '') {
|
|
this.classList.remove('error-input');
|
|
}
|
|
} |