ria/public/assets/js/CreatePOValidation.js
2025-03-10 03:20:47 +00:00

556 lines
18 KiB
JavaScript
Executable File

/**
/**
* File : CreatePOValidation.js
*
* This file contain the validation of edit Create Po
*
* @author Gandhimathi
*/
$(document).ready(function(){
//Initialize Select2 Elements
$("#drpSupplier").select2();
});
function myFunction() {
if(validate())
{
var input = $('#POType').val();
$('#' + input).modal('show');
}
}
function disableButtons() {
document.querySelectorAll('.Save, .Submit').forEach(function(button) {
button.classList.add('disabled');
button.setAttribute('disabled', 'disabled');
});
}
function enableButtons() {
document.querySelectorAll('.Save, .Submit').forEach(function(button) {
button.classList.remove('disabled');
button.removeAttribute('disabled');
});
}
function revenueValidate(){
var radioValue = parseInt($("input[name='DateRange']:checked").val());
var scheduleBy = $('#Scheduleby').val(); // Get the value
if ($('#drpSupplier').val() == "0") {
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
}else if ($('#PODate').val().trim() == '') {
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
}else if ($('#DeliveryAddr').val().trim() == '') {
alert('Please Enter the Delivery Address');
$('#DeliveryAddr').focus();
return false;
}else if (radioValue === 0 && $('#Deliverydt').val() == '') {
alert('Please Select the Delivery Date');
$('#Deliverydt').focus();
return false;
}else if (radioValue == 1 && (!scheduleBy || scheduleBy.trim() == '')) {
alert('Please Enter the Schedule By');
$('#Scheduleby').focus();
return false;
}else if($('#PODate').val() == ''){
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
}else if ($('#PoTypeOptions').val() == "0") {
alert('Please Select Revenue Type');
$('#PoTypeOptions').focus();
return false;
}else if ($('#Otherpayment').val() == '' && $('#PaymentTerms').val() == 'PT08') {
alert('Please Enter Payable Terms Description');
$('#Otherpayment').focus();
return false;
}else if($('#insuranceStatus').val() == "1" && $('#InsuranceNumber').val().trim() == ''){
alert('Please Enter the Insurance No / Insurance Details');
$('#InsuranceNumber').focus();
return false;
}else if ($('#BudgetType').val() == "0") {
alert('Please Select Budget Type');
$('#BudgetType').focus();
return false;
}else if ($('#revenueTax tbody tr').length < 1) {
alert('Atleast One Line needed');
return false;
}else {
return true;
}
}
function serviceValidate(){
var radioValue = parseInt($("input[name='DateRange']:checked").val());
var scheduleBy = $('#Scheduleby').val(); // Get the value
if ($('#drpSupplier').val() == "0") {
console.log('Please Select the Supplier details');
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
}else if ($('#workstatus').val() == "0") {
console.log('Please Select the Work Status');
alert('Please Select the Work Status');
$('#workstatus').focus();
return false;
}else if ($('#PODate').val().trim() == '') {
console.log('Please Enter the Purchase Order date');
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
}else if ($('#DeliveryAddr').val().trim() == '') {
console.log('Please Enter the Delivery Address');
alert('Please Enter the Delivery Address');
$('#DeliveryAddr').focus();
return false;
}else if (radioValue === 0 && $('#Deliverydt').val() == '') {
console.log('Please Select the Delivery Date');
alert('Please Select the Delivery Date');
$('#Deliverydt').focus();
return false;
}else if (radioValue == 1 && (!scheduleBy || scheduleBy.trim() == '')) {
console.log('Please Enter the Schedule By');
alert('Please Enter the Schedule By');
$('#Scheduleby').focus();
return false;
}else if($('#PODate').val() == ''){
console.log('Please Enter the Purchase Order date');
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
}else if ($('#PoTypeOptions').val() == "0") {
console.log('Please Select Service Type');
alert('Please Select Service Type');
$('#PoTypeOptions').focus();
return false;
}else if ($('#Otherpayment').val() == '' && $('#PaymentTerms').val() == 'PT08') {
console.log('Please Enter Payable Terms Description');
alert('Please Enter Payable Terms Description');
$('#Otherpayment').focus();
return false;
}else if($('#insuranceStatus').val() == "1" && $('#InsuranceNumber').val().trim() == ''){
console.log('Please Enter the Insurance No / Insurance Details');
alert('Please Enter the Insurance No / Insurance Details');
$('#InsuranceNumber').focus();
return false;
}else if ($('#BudgetType').val() == "0") {
console.log('Please Select Budget Type');
alert('Please Select Budget Type');
$('#BudgetType').focus();
return false;
}
else {
console.log("JS else part");
return true;
}
// else if ($('#ServiceTable tbody tr').length < 1) {
// alert('Atleast One Line needed');
// return false;
// } else if ($('#descofpo').val().trim() == '') {
// alert('Please Enter Description Of Service');
// $('#descofpo').focus();
// return false;
// }
}
function capitalValidate(){
var radioValue = parseInt($("input[name='DateRange']:checked").val());
var PoType = $('#POType').val();
if(PoType=='CAPITAL' && capitalType=='International'){
if ($('#drpSupplier').val() == "0") {
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
} else if ($('#currencytype').val() == '0') {
alert('Please Select the Currency Type');
$('#currencytype').focus();
return false;
} else if ($('#PODate').val() == '') {
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
} else if (radioValue == 0 && $('#Deliverydate').val() == '') {
alert('Please Select the Delivery Date');
$('#Deliverydate').focus();
return false;
} else if (radioValue == 1 && $('#Scheduleby').val() == '') {
alert('Please Enter the Schedule By');
$('#Deliverydate').focus();
return false;
} else if (radioValue == 2 && $('#Dispatch').val().trim() == '') {
alert('Please Enter the Dispatch Instruction');
$('#Deliverydate').focus();
return false;
} else if ($('#ExchangeRt').val() == '') {
alert('Please Enter the Exchange Rate');
$('#ExchangeRt').focus();
return false;
} else if ($('#ExchangeRt').val() == 0) {
alert('Please Enter the Exchange Rate');
$('#ExchangeRt').focus();
return false;
} else if ($('#PlaceOforigin').val() == '') {
alert('Please Enter Place Of Origin');
$('#PlaceOforigin').focus();
return false;
} else if ($('#PoTypeOptions').val() == "0") {
alert('Please Select Capital Type');
$('#PoTypeOptions').focus();
return false;
} else if ($('#PaymentTerms').val() == '') {
alert('Please Select Payment Terms');
$('#PaymentTerms').focus();
return false;
} else if ($('#Otherpayment').val() == '' && $('#PaymentTerms').val() == 'PT08') {
alert('Please Enter Payable Terms Description');
$('#Otherpayment').focus();
return false;
} else if ($('#BudgetType').val() == "0") {
alert('Please Select Budget Type');
$('#BudgetType').focus();
return false;
} else if ($('#serviceTax tbody tr').length < 1) {
alert('Atleast One Line needed');
return false;
} else { return true; }
}
if(PoType=='CAPITAL' && capitalType=='Domestic'){
if ($('#drpSupplier').val() == "0") {
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
} else if ($('#PODate').val() == '') {
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
} else if (radioValue == 0 && $('#Deliverydate').val() == '') {
alert('Please Select the Delivery Date');
$('#Deliverydate').focus();
return false;
} else if (radioValue == 1 && $('#Scheduleby').val() == '') {
alert('Please Enter the Schedule By');
$('#Deliverydate').focus();
return false;
} else if (radioValue == 2 && $('#Dispatch').val().trim() == '') {
alert('Please Enter the Dispatch Instruction');
$('#Deliverydate').focus();
return false;
} else if ($('#PoTypeOptions').val() == "0") {
alert('Please Select Capital Type');
$('#PoTypeOptions').focus();
return false;
} else if ($('#PaymentTerms').val() == '') {
alert('Please Select Payment Terms');
$('#PaymentTerms').focus();
return false;
} else if ($('#Otherpayment').val() == '' && $('#PaymentTerms').val() == 'PT08') {
alert('Please Enter Payable Terms Description');
$('#Otherpayment').focus();
return false;
} else if ($('#BudgetType').val() == "0") {
alert('Please Select Budget Type');
$('#BudgetType').focus();
return false;
} else if ($('#serviceTax tbody tr').length < 1) {
alert('Atleast One Line needed');
return false;
} else { return true; }
}
}
function importValidate(){
var radioValue = parseInt($("input[name='DateRange']:checked").val());
if ($('#drpSupplier').val() == "0") {
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
} else if ($('#currencytype').val() == '0') {
alert('Please Select the Currency Type');
$('#currencytype').focus();
return false;
} else if ($('#PODate').val() == '') {
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
} else if ($('#DeliveryAddr').val() == '') {
alert('Please Enter the Delivery Address');
$('#DeliveryAddr').focus();
return false;
} else if (radioValue === 1 && $('#Scheduleby').val() == '') {
alert('Please Enter Schedule By');
$('#Scheduleby').focus();
return false;
} else if (radioValue === 2 && $('#Dispatch').val() == '') {
alert('Please Enter Dispatch Instruction');
$('#Dispatch').focus();
return false;
} else if ($('#ExchangeRate').val() == '') {
alert('Please Enter the Exchange Rate');
$('#ExchangeRate').focus();
return false;
} else if ($('#ExchangeRate').val() == 0) {
alert('Please Enter the Exchange Rate');
$('#ExchangeRate').focus();
return false;
} else if ($('#PlaceOforigin').val() == '') {
alert('Please Enter Place Of Origin');
$('#PlaceOforigin').focus();
return false;
} else if ($('#Importoption').val() == "0") {
alert('Please Select Import Type');
$('#Importoption').focus();
return false;
} else if ($('#PaymentTerms').val() == '') {
alert('Please Select Payment Terms');
$('#PaymentTerms').focus();
return false;
} else if ($('#Otherpayment').val() == '' && $('#PaymentTerms').val() == 'PT08') {
alert('Please Enter Payable Terms Description');
$('#Otherpayment').focus();
return false;
} else if ($('#BudgetType').val() == "0") {
alert('Please Select Budget Type');
$('#BudgetType').focus();
return false;
} else if ($('#ImportTax tbody tr').length < 1) {
alert('Atleast One Line needed');
return false;
}else {
return true;
}
}
function validate()
{
var radioValue = $("input[name='DateRange']:checked").val();
var PoType = $('#POType').val();
var currencyType = $('#currencytype').val();
if($('#drpSupplier').val() == "0")
{
alert('Please Select the Supplier details');
$('#drpSupplier').focus();
return false;
}
else if($('#PODate').val() == '')
{
alert('Please Enter the Purchase Order date');
$('#PODate').focus();
return false;
}
else if(radioValue==0 && $('#Deliverydate').val()==''){
alert('Please Select the Delivery Date');
$('#Deliverydate').focus();
return false;
}
else if(radioValue==1 && $('#Scheduleby').val().trim()==''){
alert('Please Enter the Schedule By');
$('#Deliverydate').focus();
return false;
}
else if($('#DeliveryAddr').val() == '')
{
alert('Please Enter the Delivery Address');
$('#DeliveryAddr').focus();
return false;
}
else if($('#insuranceStatus').val() == "1" && $('#InsuranceNumber').val().trim() == ''){
alert('Please Enter the Insurance No / Insurance Details');
$('#InsuranceNumber').focus();
return false;
}
else if(PoType=='CAPITAL' && capitalType=='International'){
if(currencyType=='0'){
alert('Please Select the Currency Type');
$('#currencytype').focus();
return false;
}
else if(radioValue==2 && $('#Dispatch').val().trim()==''){
alert('Please Enter the Dispatch Instruction');
$('#Deliverydate').focus();
return false;
}
else if($('#PlaceOforigin').val().trim() == ''){
alert('Please Enter the Place Of Origin');
$('#PlaceOforigin').focus();
return false;
}
else if($('#ExchangeRt').val()==''){
alert('Please Enter the Exchange Rate');
$('#ExchangeRt').focus();
return false;
}
else{
return true;
}
}
else
{
return true;
}
}
function validateRevenueTax()
{
if($('#ReqNo').val() == "0")
{
alert('Please select the Requisition Number');
$('#ReqNo').focus();
return false;
}
else if($('#CostCenter').val() == "0")
{
alert('Please select the Cost center');
$('#CostCenter').focus();
return false;
}
else if($('#MaterialCode').val() == "0")
{
alert('Please select the Material Code');
$('#MaterialCode').focus();
return false;
}
else if($('#Quantity').val() == '')
{
alert('Please Enter the Quantity value');
$('#Quantity').focus();
return false;
}
else if($('#Quantity').val() == "0")
{
alert('Please Enter the Valid Quantity value');
$('#Quantity').focus();
return false;
}
else if($('#Rate').val() == '')
{
alert('Please Enter the Rate of the Item');
$('#Rate').focus();
return false;
}
else if($('#Rate').val() == "0")
{
alert('Please Enter the Valid Rate of the Item');
$('#Rate').focus();
return false;
}
else
{
return true;
}
}
function calculateTotalValue()
{
var Packaging = $('#txtAfterPackaging').val() == '' ? '0.00' : $('#txtAfterPackaging').val();
var ExciseDuty = $('#txtAfterExciseDuty').val() == '' ? '0.00' : $('#txtAfterExciseDuty').val();
var Vat = $('#txtAfterVat').val() == '' ? '0.00' : $('#txtAfterVat').val();
var CST = $('#txtAfterCST').val() == '' ? '0.00' : $('#txtAfterCST').val();
var GST = $('#txtAfterGST').val() == '' ? '0.00' : $('#txtAfterGST').val();
var OtherTax = $('#txtAfterOtherTax').val() == '' ? '0.00' : $('#txtAfterOtherTax').val();
var Freight = $('#txtAfterFreight').val() == '' ? '0.00' : $('#txtAfterFreight').val();
var Insurance = $('#txtInsurance').val() == '' ? '0.00' : $('#txtInsurance').val();
var Discount = $('#txtAfterDiscount').val() == '' ? '0.00' : $('#txtAfterDiscount').val();
var BasicVal = $('#txtBasicValue').val() == '' ? '0.00' : $('#txtBasicValue').val();
var totvalue = ( parseFloat(BasicVal) + parseFloat(Packaging)+ parseFloat(ExciseDuty)+ parseFloat(Vat) + parseFloat(CST)+ parseFloat(GST) + parseFloat(OtherTax) + parseFloat(Freight) + parseFloat(Insurance)) - parseFloat(Discount);
var tot = parseFloat(totvalue).toFixed(2);
$('#txtTotalOrderValue').val(tot);
validateExceedLimit();
ExceedQuantityCheck();
}
function calculateTaxValue()
{
var Packaging = $('#txtAfterPackaging').val() == '' ? '0.00' : $('#txtAfterPackaging').val();
var ExciseDuty = $('#txtAfterExciseDuty').val() == '' ? '0.00' : $('#txtAfterExciseDuty').val();
var Vat = $('#txtAfterVat').val() == '' ? '0.00' : $('#txtAfterVat').val();
var CST = $('#txtAfterCST').val() == '' ? '0.00' : $('#txtAfterCST').val();
var GST = $('#txtAfterGST').val() == '' ? '0.00' : $('#txtAfterGST').val();
var OtherTax = $('#txtAfterOtherTax').val() == '' ? '0.00' : $('#txtAfterOtherTax').val();
var Freight = $('#txtAfterFreight').val() == '' ? '0.00' : $('#txtAfterFreight').val();
var Insurance = $('#txtInsurance').val() == '' ? '0.00' : $('#txtInsurance').val();
var Discount = $('#txtAfterDiscount').val() == '' ? '0.00' : $('#txtAfterDiscount').val();
var totvalue = ( parseFloat(Packaging)+ parseFloat(ExciseDuty)+ parseFloat(Vat) + parseFloat(CST)+ parseFloat(GST) + parseFloat(OtherTax) + parseFloat(Freight) + parseFloat(Insurance)) - parseFloat(Discount) ;
var tot = parseFloat(totvalue).toFixed(2);
//alert('tot:'+tot);
return tot;
}
function validateExceedLimit()
{
// alert("add budget");
var avalbudAmt = parseFloat($('#AvlBudAmt').val());
var basicAmountRate = parseFloat($('#txtBasicValue').val());
// var totalAmount = parseFloat($('#txtTotalOrderValue').val());
//alert(basicAmountRate);
if(basicAmountRate > avalbudAmt)// || totalAmount > avalbudAmt)
{
alert('Basic amount is exceeding the Budget Limit.Please adjust the product value.');
$('#Rate').focus();
return false;
}
else
{
return true;
}
}
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
return true;
}
function change(){
ExceedQuantityCheck();
if($('#Quantity').val() != '' && $('#Rate').val() != '')
{
var txtQuantity = parseFloat( $('#Quantity').val());
var txtUnitPrice = parseFloat($('#Rate').val());
var Tot = txtQuantity * txtUnitPrice
$('#txtBasicValue').val(Tot);
calculateTotalValue();
}
}