NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/Canvass/CanvassViewV7.js

555 lines
20 KiB
JavaScript

function viewFormLink(data) {
if (token) {
window.open(data.token, '_blank');
} else {
showToast('warning', 'No token for this item', 'warning', 4000);
}
}
function viewSupplierAlterOfferDetails(PRDetailsId) {
const loader = $('#overlay, #loader');
tableElement = $('#altarnativeTable');
tableDestroy(tableElement);
altarnativeTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetAlternativeOfferByPRDetailId,
type: 'GET',
data: { PRDetailsId },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: [
{
data: 'alternativeOfferId',
render: function (data, type, row) {
let checked = row.isApproved ? "checked" : "";
return `<input type="checkbox" class="choose-alternative-checkbox" data-id="${data}" ${checked} />`;
},
},
{ data: 'description' },
{ data: 'supplierName' }
],
reponsive: true,
createdRow: function (row, data) {
if (data.isApproved) {
$(row).css({
'color': 'white',
'background-color': 'green'
});
}
},
error: errorHandler
});
}
function viewDeniedForm() {
$('#viewDeniedForm').modal('show');
$('#viewDeniedForm').css('z-index', 1080);
}
function viewPRListByPRNo(PRNo) {
loader = $('#overlay, #loader');
$('#overlay, #loader').css('z-index', 1070);
tableElement = $('#PRListDataTable');
document.getElementById('label-pr-prNo2').innerHTML = PRNo;
tableDestroy(tableElement);
prListByPRNoTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetPRListByPRNo,
type: 'POST',
data: { PRNo },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colPRItemList,
rowCallback: rowPRCallback,
responsive: true,
error: errorHandler
});
}
function viewItemDetail(data) {
loader = $('#overlay, #loader').css('z-index', 1060);
ItemCodeId = data.itemCodeId;
PRDetailsId = data.prDetailsId;
$.ajax($.extend({
url: endpoint.GetMyPR,
type: 'POST',
data: { ItemCodeId, PRDetailsId },
success: function (data) {
if (data && data.data && data.data.length > 0) {
var item = data.data[0];
$('#itemCodeId').val(item.itemCodeId);
$('#itemName').val(item.itemName);
$('#itemDescription').val(item.itemDescription);
$('#department').val(item.department);
$('#itemCategoryName').val(item.itemCategoryName);
$('#ItemCategory2Id').val(item.itemCategoryId);
$('#statusName').val(item.statusName);
$('#itemNo').val(item.itemNo);
$('#itemTypeName').val(item.itemTypeName);
$('#itemTypeId').val(item.itemTypeId);
$('#itemClassId').val(item.itemClassId);
$('#uomName').val(item.uomName);
$('#uomId').val(item.uomId);
$('#itemColorName').val(item.itemColorName);
$('#itemColorId').val(item.itemColorId);
$('#createdDate').val(item.createdDate);
$('#itemLocalName').val(item.itemLocalName);
$('#itemLocalId').val(item.itemLocalId);
$('#itemQty').val(numberWithCommas(item.qty));
$('#itemAttachId').val(item.itemAttachId);
$('#itemRemarks').val(item.remarks);
// 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');
} else {
var imageUrl = item.url + itemPicturePath;
// Set the image source
$('#itemPictureImage').attr('src', imageUrl);
}
$('#viewPRItemDetails').modal('show');
$('#viewPRItemDetails').css('z-index', 1060);
} else {
console.log('Data is null or undefined');
// window.location.href = '/Home/Logout';
}
},
error: errorHandler
}, beforeComplete(loader)));
}
function viewSupplierById(data) {
loader = $('#overlay, #loader').css('z-index', 1070);
SupplierId = data.supplierId;
$.ajax($.extend({
url: endpoint.GetSupplierById,
type: 'POST',
data: { SupplierId },
success: function (data) {
if (data && data.data && data.data.length > 0) {
var item = data.data[0];
$('#supplierId').val(item.supplierId);
$('#supplierName').val(item.supplierName);
$('#emailAddress').val(item.emailAddress);
$('#address').val(item.address);
$('#contactNo').val(item.contactNo);
$('#contactPerson').val(item.contactPerson);
const isActiveValue = item.isActive.toString();
$('#isActive').val(isActiveValue);
$('#tinNo').val(item.tinNo);
$('#leadTime').val(item.leadTime);
$('#vatInc').prop('checked', item.vatInc);
$('#currencyId').val(item.currencyId);
$('#C-paymentTerms').val(item.paymentTerms);
$('#C-paymentTermsId').val(item.paymentTermsId);
$("#C-paymentTerms").on('keyup', function () {
populateTerms();
});
showHideLabelButtons(0);
$('#addNewEditSupplier').modal('show');
$('#addNewEditSupplier').css('z-index', 1070);
} else {
console.log('Data is null or undefined');
// window.location.href = '/Home/Logout';
}
},
error: errorHandler
}, beforeComplete(loader)));
}
function viewItemWOEmail(data) {
var loader = $('#overlay, #loader');
$('#viewItemWOEmail').modal('show');
$('#viewItemWOEmail').css('z-index', 1060);
var tableElement = $('#SupplierWODataTable');
tableDestroy(tableElement);
ItemNo = data.ItemNo;
prWOEDataTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetPRItem,
type: 'POST',
data: { ItemNo },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colPRItem,
responsive: true,
error: errorHandler
});
}
function viewItem(data) {
loader = $('#overlay, #loader');
$('#viewItemList').modal('show');
$('#viewItemList').css('z-index', 1050);
tableName = '#ItemDataTable';
totalSelectedLabel = $('#totalSelCanvass');
clearTableSelection(tableName, selectedProductsMap, () => {
totalSelectedLabel.text(0);
}, 'selected-row', '.select-all-CanvassItem-checkbox');
tableElement = $(tableName);
tableDestroy(tableElement);
cleanupColumnSearch('#ItemDataTable');
EmailAddress = data.emailAddress;
CanvassId = data.canvassId;
$('#email-Address').val(EmailAddress);
$('#supplierId').val(data.supplierId);
SupplierId = data.supplierId;
document.getElementById('supplierEmail').innerText = data.supplierName;
prDataTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetCanvassPerSupplierId,
type: 'POST',
data: { SupplierId },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: function () {
initializeTableSelection({
tableName: tableName,
dataTable: prDataTable,
selectedItemsMap: selectedProductsMap,
idKey: 'prDetailsId',
idKey2: 'batchNo',
checkboxClass: '.select-CanvassItem-checkbox',
selectAllClass: '.select-all-CanvassItem-checkbox',
selectedRowClass: 'selected-row',
updateCountCallback: function () {
totalSelectedLabel.text(getSelectedCount(selectedProductsMap));
}
});
initializeColumnSearch({
tableId: '#ItemDataTable',
dataTable: prDataTable,
searchableColumns: [
{
columnIndex: 1,
columnName: 'PR No',
placeholder: 'Enter PR Number...',
searchType: 'text',
searchMode: 'exact',
width: '150px'
},
{
columnIndex: 2,
columnName: 'Item No',
placeholder: 'Enter Item Number...',
searchType: 'text',
searchMode: 'exact',
width: '150px'
},
{
columnIndex: 3,
columnName: 'Item Name',
placeholder: 'Enter Item Name...',
searchType: 'text',
searchMode: 'contains',
width: '200px'
},
{
columnIndex: 5,
columnName: 'Category',
placeholder: 'Select Category...',
searchType: 'select',
searchMode: 'exact',
width: '150px'
}
]
});
const uniqueSearchClass = 'column-search-input-ItemDataTable';
populateSelectOptions(prDataTable, 5, '.' + uniqueSearchClass + '[data-column="5"]');
},
columns: colCanvassPerSuppEmail,
responsive: true,
error: errorHandler
});
}
function viewSuppDetail(data) {
loader = $('#overlay, #loader').css('z-index', 1080);
$('#viewItemSuppliers').modal('show');
$('#viewItemSuppliers').css('z-index', 1065);
console.log('dito diba???');
tableName = '#SupplierDataTable';
totalSelectedLabel = $('#totalSelected');
clearTableSelection(tableName, selectedProductsMap, () => {
totalSelectedLabel.text(0);
}, 'selected-row', '.select-all-CanvassItem-checkbox');
tableElement = $(tableName);
tableDestroy(tableElement);
ItemNo = data.itemNo;
document.getElementById('item-Name').innerText = data.itemName;
document.getElementById('item-No').innerText = ItemNo;
supplierDataTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetSupplierItemWOEmail,
type: 'POST',
data: { ItemNo },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: function () {
initializeTableSelection({
tableName: tableName,
dataTable: supplierDataTable,
selectedItemsMap: selectedProductsMap,
idKey: 'supplierId',
idKey2: 'batchNo',
checkboxClass: '.select-CanvassItem-checkbox',
selectAllClass: '.select-all-CanvassItem-checkbox',
selectedRowClass: 'selected-row',
updateCountCallback: function () {
totalSelectedLabel.text(getSelectedCount(selectedProductsMap));
}
});
},
columns: colSupplierItemWOEmail,
scrollX: true,
rowCallback: function (row, data) {
var statusCell = $('td:eq(9)', row);
var myStatus = statusCell.text().trim();
if (myStatus === 'Yes' || myStatus === 'true' || myStatus === true) {
statusCell.text('Yes').addClass('status-active');
} else {
statusCell.text('No').addClass('status-partial');
}
},
error: errorHandler
});
}
function viewWOResponseBySuppId(data) {
loader = $('#overlay, #loader').css('z-index', 1065);
$('#viewWOResponseBySuppId').modal('show');
$('#viewWOResponseBySuppId').css('z-index', 1065);
tableElement = $('#WORespModalDataTable');
tableDestroy(tableElement);
SupplierId = data.supplierId;
document.getElementById('supplierName').innerText = data.supplierName;
woRespModaTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetWOResponseBySuppId,
type: 'POST',
data: { SupplierId },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colWOResponseById,
responsive: true,
error: errorHandler
});
}
function viewSuppBidding(data) {
var loader = $('#overlay, #loader').css('z-index', 1060);
var CanvassDetailId = data.canvassDetailId;
$.ajax($.extend({
url: endpoint.GetSupplierBidById,
type: 'POST',
data: { CanvassDetailId },
success: function (data) {
if (data && data.data && data.data.length > 0) {
var item = data.data[0];
$('#itemName').val(item.itemName);
$('#specification').val(item.specification);
$('#itemDescription').val(item.itemDescription);
$('#itemNo').val(item.itemNo);
$('#supplierId').val(item.supplierId);
$('#canvassId').val(item.canvassId);
$('#canvassDetailId').val(item.canvassDetailId);
$('#itemQty').val(numberWithCommas(item.qty));
$('#uom').val(item.uomName);
$('#unitPrice').val(parseFloat(item.price).toFixed(2));
$('#terms').val(item.terms);
$('#supplierRemarks').val(item.remarks);
$('#manufacturer').val(item.manufacturer);
$('#currencyId').val(item.currencyId);
$('#prDetailsId').val(item.prDetailsId);
const commitmentDate = new Date(item.commitmentDate);
const formattedDate = commitmentDate.toISOString().split('T')[0];
$('#commitmentDate').val(formattedDate);
// 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;
// Set the image source
$('#itemPictureImage').attr('src', imageUrl);
}
// Display the modal
$('#viewSupplierBid').modal('show');
$('#viewSupplierBid').css('z-index', 1070);
} else {
console.log('Data is null or undefined');
}
},
error: errorHandler
}, beforeComplete(loader)));
}
function viewSuppBidPrice(data) {
loader = $('#overlay, #loader');
$('#viewByItemSupplier').modal('show');
$('#viewByItemSupplier').css('z-index', 1050);
tableElement = $('#BiddingSuggestDataTable');
toggleCanvassButton();
tableDestroy(tableElement);
ItemNo = data.itemNo;
CanvassId = data.canvassId;
$('#canvassDetailId').val(data.canvassDetailId);
$('#canvassId').val(data.canvassId);
$('#itemNo').val(data.itemNo);
$('#prNo').val(data.prNo);
$('#prDetailsId').val(data.prDetailsId);
PRDetailsId = data.prDetailsId;
document.getElementById('label-itemNo').innerHTML = data.itemNo;
document.getElementById('label-prNo').innerHTML = data.prNo;
document.getElementById('label-itemName').innerHTML = data.itemName;
document.getElementById('label-qty').innerHTML = data.qty;
console.log('dito wew?');
bidDataTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetSupplierBidByItem,
type: 'POST',
data: { ItemNo, CanvassId, PRDetailsId, IsHistory },
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colSupplierBidByItem,
rowCallback: function (row, data) {
if (data.suggestedSupplier === true) {
$(row).css('color', 'white');
$(row).css('background-color', 'green');
hasAnySuggestedSupplier = true;
}
viewSupplierAlterOfferDetails(PRDetailsId);
},
drawCallback: function () {
toggleCanvassButton();
hasAnySuggestedSupplier = false;
},
error: errorHandler
});
}
function viewByItemSuppPRNo(data) {
var loader = $('#overlay, #loader');
$('#viewByItemSuppPRNo').modal('show');
$('#viewByItemSuppPRNo').css('z-index', 1080);
var tableElement = $('#WPRDataTable');
tableDestroy(tableElement);
ItemNo = data.itemNo;
document.getElementById('supplierName').innerText = data.supplierName;
$('#canvassId').val(data.canvassId);
$('#itemNo').val(data.itemNo);
let Status = 1;
bidWPRDataTable = tableElement.DataTable({
ajax: $.extend({
url: endpoint.GetSupplierBidByItem,
type: 'POST',
data: { ItemNo, Status, CanvassId,PRDetailsId },
}, beforeComplete(loader)),
responsive: true,
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colSupplierBidByItemWithPR,
error: errorHandler
});
}
function toggleCanvassButton() {
var btnSubmitPO = document.getElementById('btnCanvassApproved');
var btnSuggest = document.getElementById('btnSuggest');
if (IsHistory) {
if (UserRights !== 'CnvssAppver') {
btnSubmitPO.style.display = 'block';
btnSuggest.style.display = 'block';
} else {
btnSubmitPO.style.display = 'none';
btnSuggest.style.display = 'none';
}
} else {
if (hasAnySuggestedSupplier) {
btnSubmitPO.style.display = 'block';
btnSuggest.style.display = 'block';
} else {
btnSubmitPO.style.display = 'none';
}
}
}
function refreshBidTable() {
canvassTable.ajax.reload(null, false);
bidDataTable.ajax.reload(null, false);
}
function showHideLabelButtons(isNewOrUpdate) {
if (isNewOrUpdate == 1) {
let labelHeaderUpdate = document.getElementById('headerUpdate');
let btnUpdateSupplier = document.getElementById('btnUpdateSupplier');
labelHeaderUpdate.style.display = 'none';
btnUpdateSupplier.style.display = 'none';
let labelHeaderAddNew = document.getElementById('headerNew');
let btnAddNewSupplier = document.getElementById('btnaddNewSupplier');
labelHeaderAddNew.style.display = 'block';
btnAddNewSupplier.style.display = 'block';
} else {
let labelHeaderAddNew = document.getElementById('headerNew');
let btnAddNewSupplier = document.getElementById('btnaddNewSupplier');
if (labelHeaderAddNew) {
labelHeaderAddNew.style.display = 'none';
}
if (btnAddNewSupplier) {
btnAddNewSupplier.style.display = 'none';
}
let labelHeaderUpdate = document.getElementById('headerUpdate');
let btnUpdateSupplier = document.getElementById('btnUpdateSupplier');
if (labelHeaderUpdate) {
labelHeaderUpdate.style.display = 'block';
}
if (btnUpdateSupplier) {
btnUpdateSupplier.style.display = 'block';
}
}
}