NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/Common/PostPutV4.js

151 lines
4.9 KiB
JavaScript

function putItemDetails() {
loader = $('#overlay, #loader').css('z-index', 1075);
if (!poValidateParameters(1, 'item', true)) {
return false;
}
PRDetailsId = $('#prDetailsId').val();
const confirmation = confirm('Are you sure you want to proceed?');
if (confirmation) {
$.ajax($.extend({
url: '/POMgmt/PutPRItemDetails',
type: 'POST',
data: { PRDetailsId, UOMId, ItemName, Specification, Qty, UOMName },
success: function (response) {
if (response.success) {
$('#viewItemDetail').modal('hide');
if (typeof PRItemTable !== "undefined"
&& $.isFunction(PRItemTable.ajax.reload)) {
PRItemTable.ajax.reload();
}
if (typeof updatePOItemTable !== "undefined"
&& $.isFunction(updatePOItemTable.ajax.reload)) {
updatePOItemTable.ajax.reload();
}
alert('PR Item Details Updated!');
} else {
PRItemTable.ajax.reload();
alert('Failed: ' + response.response);
}
},
error: errorHandler
}, beforeComplete(loader)));
}
}
function poValidateParameters(poTypeId, method, isItem) {
var isValid = true;
const commonInputs = parameters(method);
inputs = { ...commonInputs };
if (!isItem) {
if (poTypeId == 3) {
Object.assign(inputs, {
incotermsId: document.getElementById('incoTermsId'),
profInvoiceNo: document.getElementById('piNo'),
profInvoiceDate: document.getElementById('piDate'),
shippingInstructionId: document.getElementById('shippingInstructionId'),
podId: document.getElementById('podId'),
countryOrigin: document.getElementById('countryOrigin'),
});
} else {
// Fields specific to other poTypeId values
inputs.deliverTo = document.getElementById('deliverTo');
}
}
// Attach event listeners for removing error class
attachEventListeners(inputs);
// Validate required fields
isValid = validateInputs(inputs);
// If valid, update the shared variables
if (isValid) {
updateSharedVariables(inputs, customPOConfig);
}
poDTO(customPOConfig);
return isValid;
}
function parameters(method) {
var paramValue = {};
if (method == 'item') {
paramValue = {
itemName: document.getElementById('itemName'),
specification: document.getElementById('specification'),
qty: document.getElementById('itemQty'),
uomName: document.getElementById('uomName'),
uomId: document.getElementById('uomId'),
};
} else {
paramValue = {
supplierName: document.getElementById('supplierName'),
supplierId: document.getElementById('supplierId'),
deliveryDate: document.getElementById('deliveryDate'),
paymentTermsId: document.getElementById('C-paymentTermsId'),
currencyId: document.getElementById('currencyId')
};
}
return paramValue;
}
function clearCustomPOParam() {
customPOConfig = {
incotermsId: 0,
profInvoiceNo: 0,
profInvoiceDate: new Date().toISOString().split('T')[0],
shippingInstructionId: 0,
podId: 0,
currencyId: 0,
paymentTermsId: 0,
supplierId: 0,
supplierName: '',
countryOrigin: '',
deliveryDate: new Date().toISOString().split('T')[0],
deliverTo: ''
};
$('#poNo').val('');
$('#poType').val(0);
$('#supplierName').val('');
$('#supplierId').val('');
$('#deliverTo').val('');
$('#remarks').val('');
$('#grossAmount').val(0.00);
$('#finalAmount').val(0.00);
$('#docRequiredId').val('');
$('#discount').val('');
$('#currency').val('');
$('#grossAmountPHP').val(0.00);
$('#finalAmountPHP').val(0.00);
$('#grossAmountUSD').val(0.00);
$('#finalAmountUSD').val(0.00);
isLoaded = false;//TO REFRESH
poDataTable.clear().draw();
toggleSubmitButton();
$('#DestChargesTable tbody').empty();
}
function poDTO(config) {
IncotermsId = config.incotermsId;
ProfInvoiceNo = config.profInvoiceNo;
ProfInvoiceDate = config.profInvoiceNo;
ShippingInstructionId = config.shippingInstructionId;
PodId = config.podId;
PaymentTermsId = config.paymentTermsId;
SupplierId = config.supplierId;
DeliverTo = config.deliverTo;
DeliveryDate = config.deliveryDate;
ItemName = config.itemName;
CountryOrigin = config.countryOrigin;
Specification = config.specification;
Qty = config.qty;
UOMName = config.uomName;
UOMId = config.uomId;
CurrencyId = config.currencyId;
}