
<?php $ReqType =''; 
$CompanyAddress = '';
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));				
$CurrentDate =  $dt->format('Y-m-d');
$MaxPoDate = '';
$AvlAmount = 0;
if(!empty($MaxPODate))
{
    foreach ($MaxPODate as $date)
    {
		$MaxPoDate = $date->PODate;		
	}
}
if(!empty($CompanyDetails))
{
    foreach ($CompanyDetails as $Req)
    {
		$CompanyAddress = $Req->Address;
	}
}
if(!empty($AvlBudAmt))
{
   
		$AvlAmount = $AvlBudAmt;		
	
}
  
		$SupId = '';
        $SupName = '';
		$Address = '';
		$PODate = '';
        $Deliverydt ='';
		$DeliveryAddress ='';
		$POStatus	 = 	'';
		$PONO =  	'';
		$totBasicAmt  = 0;
		$totDiscountAmt  = 0.0;
		$totPackagingAmt  = 0.0;
		$totExciseAmt  = 0.0;
		$totVATAmt  = 0.0;
		$totCSTAmt  = 0.0;
		$totGSTAmt  = 0.0;
		
		$totOtherTaxAmt   = 0.0;
		$totFreightAmt   = 0.0;
		$totInsuranceAmt   = 0.0;
		$totOrderSummaryAmt   = 0.0;
		
		$ServiceDescription = '';

if(!empty($POMaster))
{
    foreach ($POMaster as $Req)
    {
		$SupId = $Req->SupplierID;
        $SupName = $Req->SupplierName;
		$Address = $Req->Address;
		
		$Pdt =	new DateTime($Req->PODate);
		$PODate =  $Pdt->format('Y-m-d');
		
		$Ddt =	new DateTime($Req->DeliveryDate);
		$Deliverydt =  $Ddt->format('Y-m-d');
		
		$DeliveryAddress =$Req->DeliveryAddress;
		$POStatus	 = 	$Req->StatusCode;
		$PONO = 	$Req->PONO;	
		$ServiceDescription = $Req->ServiceDescription;	
    }
}
?>
<style>
            
			#packagingcalmodel {
	margin-top:200px;
	z-index: 1080 !important;
}
		#ExciseDutyCalModel {
	margin-top:200px;
	z-index: 1080 !important;
}	
#VatCalModel {
	margin-top:200px;
	z-index: 1080 !important;
}	
#CSTCalModel {
	margin-top:200px;
	z-index: 1080 !important;
}	
.modal
{
	padding-right:30% ! important;
}

            </style>
<script src="<?php echo base_url(); ?>assets/js/CreatePOValidation.js" type="text/javascript"></script>
  <script>
 var NilType = '<?php echo NILTYPE;?>';
 var PercentageType = '<?php echo PERCENTAGE;?>';
 var POMaxDate = '<?php echo $MaxPoDate;?>';
 var PackagingCalculation = '';
 var ExciseCalculation = '';
 var StateTaxCheck = '';
 var VatCalculation = '';
 var CSTCalculation = '';
 var RequistQuantity = '';
 var IsEdit = '0';
 var d = new Date(POMaxDate);
var SelectedMaterialCode = [];
 var CollIndex = 0;	
  var SelectedMaterialList = {
    Mat: []
};
// alert(new Date(year,month,day));
$(function() {
	  
  $("#PODate").datepicker({
	minDate : d,
	maxDate : 'now',
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '-100:+0'
});
 $("#Deliverydt").datepicker({
	minDate : 'now',	
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '0:+10'
});
	
$('#drpSupplier').change(function() {
    
 var id = $('#drpSupplier').val();
 $("#SupAddress").val('');
 
		if(id != '0')
		{
			var y = <?php echo json_encode($Suplist, JSON_PRETTY_PRINT) ?>;

	 			
		$.each(y, function(idx, obj) {
			if(obj.SupplierID === id)
			{
				$("#SupAddress").val(obj.Address);
				
			}
			
		});
			
		}
		else
		{
			alert('Please select the SupplierID');
			return false;
		}
  
});	

$('#ReqNo').change(function() {
    
 var id = $('#ReqNo').val();
 $("#deptName").val('');
  $("#CostCenter").val('');
  $("#MaterialCode").empty();
  $("#ItemName").val('');
$("#UOM").val('');
$("#Quantity").val('');
$("#ItemName").val('');
$("#Rate").val('');
$("#txtBasicValue").val('');
$("#AvlBudAmt").val('');	
 resetTaxField();
		if(id != '0')
		{
			var y = <?php echo json_encode($RequistionDetails, JSON_PRETTY_PRINT) ?>;
			
			var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;
			var AvlBudAmt = '<?php echo $AvlAmount ?>';  
		// For Binding DepartmentName	           			
		$.each(y, function(idx, obj) {
			if(obj.ReqNo === id)
			{
				$("#deptName").val(obj.DepartmentName);
				$("#CostCenter").val(obj.CostCenterCode);
			}			
		});
			$("#AvlBudAmt").val(AvlBudAmt);		
		// For Binding Material list center for the selected Requistion Number	
		$("#MaterialCode").append( $('<option></option>').val("0").html("Select Material Code") );
	
		var isAdded = "0";
		 for(i=0;i<Material.length;i++)
		{
		$.each(Material[i], function(idx, obj) {
			
				if(obj.ReqNo === id )
				{
									   
						$.each(SelectedMaterialList.Mat, function(idx1, el){															
							if (id == el.ReqNo )
							{
															
								if(el.materialCode == obj.MaterialCode)
								{
										isAdded  = "1";
										return false;																		
								}
								else
								{
									isAdded  = "0";
								}
								
							}
					});
					
					 
						if(isAdded  == "0")
						{
							
							$("#MaterialCode").append( $('<option></option>').val(obj.MaterialCode).html(obj.MaterialCode + "-" + obj.MaterialName));
						}
												
				}
			
			
		});
		}
		}
		else
		{
			alert('Please select the Requisition Number');
			return false;
		}
		id = '';
  
});	
$('#MaterialCode').change(function() {
    
 var id = $('#MaterialCode').val();
 $("#ItemName").val('');
$("#UOM").val('');
$("#Quantity").val('');
$("#ItemName").val('');
$("#Rate").val('');
$("#txtBasicValue").val('');
 RequistQuantity = '';
 resetTaxField();
		if(id != '0')
		{
			var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;
			
		  for(i=0;i<Material.length;i++)
			{
				$.each(Material[i], function(idx, obj) {
					if(obj.MaterialCode === id)
					{
						$("#ItemName").val(obj.MaterialName);
						$("#UOM").val(obj.UOM);
						$("#Quantity").val(obj.Quantity);
						RequistQuantity	= 	obj.Quantity;		
					}			
				});			
			}
		}
		else
		{
			alert('Please select the MaterialCode');
			return false;
		}
  
});

$('#EditMaterialCode').change(function() {
    
 var id = $('#EditMaterialCode').val();
 $("#EditItemName").val('');
$("#EditUOM").val('');
$("#EditQuantity").val('');
$("#EditRate").val('');
$("#txtEditBasicValue").val('');
 RequistQuantity = '';
 resetTaxField();
		if(id != '0')
		{
			var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;
			
		 for(i=0;i<Material.length;i++)
			{
				$.each(Material[i], function(idx, obj) {
					if(obj.MaterialCode === id)
					{
						$("#EditItemName").val(obj.MaterialName);
						$("#EditUOM").val(obj.UOM);
						$("#EditQuantity").val(obj.Quantity);
						RequistQuantity	= 	obj.Quantity;		
					}			
				});			
			}
		}
		else
		{
			alert('Please select the MaterialCode');
			return false;
		}
  
});


/* Revenue Tax calcualation */

 $('#DiscountType').change(function() {
    selValue = $("#DiscountType").val(); 
	 $('#txtDiscount').val('');
	 $('#txtAfterDiscount').val(''); 
	if (selValue == NilType)
	{
      
		 $('#txtDiscount').attr('readonly', 'true');
		 $('#txtDiscount').val('0.00');
		 $('#txtAfterDiscount').val('0.00');
		 
	}
	else
	{
		 $('#txtDiscount').removeAttr( 'readonly','true' );
		 $('#txtDiscount').val('');
		  $('#txtAfterDiscount').val('');
	}
  
});



$('#EditDiscountType').change(function() {
    selValue = $("#EditDiscountType").val(); 
	 $('#txtEditDiscount').val('');
	 $('#txtEditAfterDiscount').val(''); 
	if (selValue == NilType)
	{
      
		 $('#txtEditDiscount').attr('readonly', 'true');
		 $('#txtEditDiscount').val('0.00');
		 $('#txtEditAfterDiscount').val('0.00');
		 
	}
	else
	{
		 $('#txtEditDiscount').removeAttr( 'readonly','true' );
		 $('#txtEditDiscount').val('');
		  $('#txtEditAfterDiscount').val('');
	}
  
});

$('#PackagingType').change(function() {
	 $('#txtPackaging').val('');
	 $('#txtAfterPackaging').val(''); 
    selValue = $("#PackagingType").val() ;
	if(selValue == PercentageType)
	{		
         var PackagingCalculation = '';
		 $('#packagingcalmodel').modal('show');
		 $('#txtPackaging').removeAttr( 'readonly','true' );
	}
	else
	{
	if (selValue == NilType)
	{
     
		 $('#txtPackaging').attr('readonly', 'true');
		 $('#txtPackaging').val('0.00');
		}
	else
	{
		 $('#txtPackaging').removeAttr( 'readonly','true' );
	}
	}
  
});
$('#EditPackagingType').change(function() {
	 $('#txtEditPackaging').val('');
	 $('#txtEditAfterPackaging').val(''); 
    selValue = $("#EditPackagingType").val() ;
	if(selValue == PercentageType)
	{		
         var PackagingCalculation = '';
		 $('#packagingcalmodel').modal('show');
		 $('#txtEditPackaging').removeAttr( 'readonly','true' );
	}
	else
	{
	if (selValue == NilType)
	{
     
		 $('#txtEditPackaging').attr('readonly', 'true');
		 $('#txtEditPackaging').val('0.00');
		}
	else
	{
		 $('#txtEditPackaging').removeAttr( 'readonly','true' );
	}
	}
  
});

$('#txtExciseDuty').change(function() {

				
		$('#ExciseDutyCalModel').modal('show');	
});
$('#txtEditExciseDuty').change(function() {
				
		$('#ExciseDutyCalModel').modal('show');	
	
	
});
$('#txtVat').change(function() {
	
				
		$('#VatCalModel').modal('show');	
	
	
});
$('#txtEditVat').change(function() {
	
				
		$('#VatCalModel').modal('show');	
	
	
});

$('#txtCST').change(function() {
			
		$('#CSTCalModel').modal('show');	
	
	
});
$('#txtEditCST').change(function() {
	
			
		$('#CSTCalModel').modal('show');
		
		});
$('#drpFreight').change(function() {
	
	
    selValue = $("#drpFreight").val() ;
	 $('#txtFreight').val('');
	  $('#txtAfterFreight').val('');
	 
	if (selValue == NilType)
	{
     
		 $('#txtFreight').attr('readonly', 'true');
		 $('#txtFreight').val('0.00');
		
	}
	else
	{
		 $('#txtFreight').removeAttr( 'readonly','true' );
		 $('#txtFreight').val('');
		
		
	}
  
});
$('#drpEditFreight').change(function() {
	
	
    selValue = $("#drpEditFreight").val() ;
	 $('#txtEditFreight').val('');
	  $('#txtEditAfterFreight').val('');
	 
	if (selValue == NilType)
	{
     
		 $('#txtEditFreight').attr('readonly', 'true');
		 $('#txtEditFreight').val('0.00');
		
	}
	else
	{
		 $('#txtEditFreight').removeAttr( 'readonly','true' );
		 $('#txtEditFreight').val('');
	}
  
});
});

/*
 * To calcuate the Discount  */
function calculateDiscount(isEdit)
 {  
	if(isEdit == '0')
	{
     if($('#MaterialCode').val() == "0")
	 {
		 alert('Please Select the Material Code');
		$('#MaterialCode').focus();
		return false;
	 }
	 else if($('#Rate').val() == '')
	 {
		  alert('Please Enter the Rate value');
		  $('#Rate').focus();
		  return false;
	 }
    if($('#Rate').val() != '' && $('#MaterialCode').val() != "0" )
	{
	
	 var basicValue = parseFloat($('#txtBasicValue').val());
	 var DiscountType =$("#DiscountType").val();
	
	 if(DiscountType == "0")
	 {
		alert('Please Select the discount Type');
		$('#txtDiscount').val('');
		$("#DiscountType").focus(); 
	 }
	 else  if ($('#txtDiscount').val() != '' && $('#txtDiscount').val() != '0')
	 {
	 var AfterDiscount = 0.0;
	  var Discountval = parseFloat($('#txtDiscount').val());
	 if(DiscountType == PercentageType)
	 {
		
		AfterDiscount = <?php echo DIS_PERCENTAGE;?>;	
		  	  
	 }
	 else if(DiscountType == NilType )
	 {
	    AfterDiscount = "0.00";				
	 }
	 else
	 {
		 AfterDiscount = <?php echo DIS_LUMPSUM;?>;			 	
	 }
		var discount = parseFloat(AfterDiscount).toFixed(2);
		$('#txtAfterDiscount').val(discount);	 
	 }
	else
	{
		$('#txtAfterDiscount').val("0.00");	 
	}
	}
		calculateTotalValue();	
	}
	else
	{
			if($('#EditMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditMaterialCode').focus();
				return false;
			 }
			 else if($('#EditRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRate').focus();
				  return false;
			 }
			if($('#EditRate').val() != '' && $('#EditMaterialCode').val() != "0" )
			{
			
			 var basicValue = parseFloat($('#txtEditBasicValue').val());
			 var DiscountType =$("#EditDiscountType").val();
			
			 if(DiscountType == "0")
			 {
				alert('Please Select the discount Type');
				$('#txtEditDiscount').val('');
				$("#EditDiscountType").focus(); 
			 }
			 else  if ($('#txtEditDiscount').val() != '' && $('#txtEditDiscount').val() != '0')
			 {
			 var AfterDiscount = 0.0;
			  var Discountval = parseFloat($('#txtEditDiscount').val());
			 if(DiscountType == PercentageType)
			 {
				
				AfterDiscount = <?php echo DIS_PERCENTAGE;?>;	
					  
			 }
			 else if(DiscountType == NilType )
			 {
				AfterDiscount = "0.00";				
			 }
			 else
			 {
				 AfterDiscount = <?php echo DIS_LUMPSUM;?>;			 	
			 }
				var discount = parseFloat(AfterDiscount).toFixed(2);
				$('#txtEditAfterDiscount').val(discount);	 
			 }
			else
			{
				$('#txtEditAfterDiscount').val("0.00");	 
			}
			}
				calculateEditTotalValue();	
	}
 }
 /*
 * To calcuate the Packaging  */
function calculatePackaging(isEdit)
 {
	if(isEdit == '0')
	{ 
			  if($('#MaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#MaterialCode').focus();
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  return false;
			 }			 
			 else
			 {
			 
			 var basicValue = parseFloat($('#txtBasicValue').val());
			  
			 var PackagingType =$("#PackagingType").val();
			 
			  if(PackagingType == "0")
			  {
				  alert('Please select the Packaging Type');
				  $('#txtPackaging').val('');
				  $("#PackagingType").focus();
			  }
			
			 else if($('#txtPackaging').val() != '' && $('#txtPackaging').val() !='0')
			 {
				 var Packagingvalue = parseFloat($('#txtPackaging').val()); 
			     var AfterPackaging = 0.0;
			 
			 if(PackagingType == PercentageType)
			 {
				 if($(PackagingCalculation  != 0 && '#txtAfterDiscount').val() == '')
				{
				  alert('Please Enter the Discount value');
				  $('#txtPackaging').val('');
				  $('#DiscountType').focus();
				  
				  return false;
				}
				else
				{
					var AfterDiscount =parseFloat($('#txtAfterDiscount').val());
					AfterPackaging = PackagingCalculation == 0 ? <?php echo PACKAGING_PERCENTAGE_BYBASICVALUE ;?> : <?php echo PACKAGING_PERCENTAGE_BYDISCOUNTVALUE;?> ;
				}
				
			 }
			 else if(PackagingType == NilType )
			 {
				AfterPackaging = "0.00";
				
			 }
			 else
			 {
				 
				 
				AfterPackaging = PackagingCalculation == 0 ?  <?php echo PACKAGING_LUMPSUM_BYBASICVALUE ;?>:<?php echo PACKAGING_LUMPSUM_BYDISCOUNTVALUE;?> ;
				
			 }
				var Packaging =  parseFloat(AfterPackaging).toFixed(2);
			 
				$('#txtAfterPackaging').val(Packaging); 
			 }
			 else
			 {
				 $('#txtAfterPackaging').val("0.00"); 
			 }
		   }
		   calculateTotalValue();	
	}
	else
	{
		 if($('#EditMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditMaterialCode').focus();
				return false;
			 }
			 else if($('#EditRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRate').focus();
				  return false;
			 }
			 
			 else
			 {
			 
			 var basicValue = parseFloat($('#txtEditBasicValue').val());
			  
			 var PackagingType =$("#EditPackagingType").val();
			 
			  if(PackagingType == "0")
			  {
				  alert('Please select the Packaging Type');
				  $('#txtEditPackaging').val('');
				  $("#EditPackagingType").focus();
			  }
			
			 else if($('#txtEditPackaging').val() != '' && $('#txtEditPackaging').val() !='0')
			 {
				 var Packagingvalue = parseFloat($('#txtEditPackaging').val()); 
				var AfterPackaging = 0.0;
			 
			 if(PackagingType == PercentageType)
			 {
				if(PackagingCalculation  != 0 &&$('#txtEditAfterDiscount').val() == '')
				{
				  alert('Please Enter the Discount value');
				  $('#EditDiscountType').focus();
				  $('#txtEditPackaging').val('');
				  return false;
				}
				else
				{
					var AfterDiscount =parseFloat($('#txtEditAfterDiscount').val());
					AfterPackaging = PackagingCalculation == 0 ? <?php echo PACKAGING_PERCENTAGE_BYBASICVALUE ;?> : <?php echo PACKAGING_PERCENTAGE_BYDISCOUNTVALUE;?> ;
				}
				
			 }
			 else if(PackagingType == NilType )
			 {
				AfterPackaging = "0.00";
			 }
			 else
			 {
				 				 
				AfterPackaging = PackagingCalculation == 0 ?  <?php echo PACKAGING_LUMPSUM_BYBASICVALUE ;?>:<?php echo PACKAGING_LUMPSUM_BYDISCOUNTVALUE;?> ;
				
			 }
				var Packaging =  parseFloat(AfterPackaging).toFixed(2);
			 
				$('#txtEditAfterPackaging').val(Packaging); 
			 }
			 else
			 {
				 $('#txtEditAfterPackaging').val("0.00"); 
			 }
		   }
		   calculateEditTotalValue();	
	}
 }
 
 function calculateExcise(isEdit)
 {
	 if(isEdit == '0')
	{ 
	
	if($('#MaterialCode').val() == "0")
	 {
		 alert('Please Select the Material Code');
		$('#MaterialCode').focus();
		$('#txtExciseDuty').val('');
		return false;
	 }
	 else if($('#Rate').val() == '')
	 {
		  alert('Please Enter the Rate value');
		  $('#txtExciseDuty').val('');
		  $('#Rate').focus();
		  return false;
	 }
	 
	 else
	 {
		 var basicValue = parseFloat($('#txtBasicValue').val());	
		
		
		 if($('#txtExciseDuty').val() != '' && $('#txtExciseDuty').val() != '0')
		 {
		 var AfterExciseDuty = 0.0;  
		 var ExciseDuty = parseFloat($('#txtExciseDuty').val());
		if(ExciseCalculation == '0')
		{
			AfterExciseDuty = <?php echo EXCISE_ONBASICVALUE; ?>;
		}
		else if(ExciseCalculation == '1')
		{
			 if($('#txtAfterDiscount').val() == '')
			{
				alert('Please Enter the Discount value');
				$('#DiscountType').focus();
				$('#txtExciseDuty').val('');
			return false;
			}
			else
			{
			 var AfterDiscount =parseFloat($('#txtAfterDiscount').val());
			 AfterExciseDuty = <?php echo EXCISE_ONBASIC_DISCOUNT; ?>;
			}
		}
		else if(ExciseCalculation == '2')
		{
			 if($('#txtAfterDiscount').val() == '')
			{
				alert('Please Enter the Discount value');
				$('#DiscountType').focus();
				$('#txtExciseDuty').val('');
			   return false;
			}
			 else if($('#txtAfterPackaging').val() == '')
			{
				alert('Please Enter the Packaging value');
				$('#PackagingType').focus();
				$('#txtExciseDuty').val('');
				return false;
				
			}
			else
			{
				var AfterDiscount =parseFloat($('#txtAfterDiscount').val());
				 var AfterPackaging = parseFloat($('#txtAfterPackaging').val());
				AfterExciseDuty = <?php echo EXCISE_ONBASIC_DISCOUNT_PACKAGING; ?>;
			}
		}
		else
		{
			if($('#txtAfterPackaging').val() == '')
			{
				alert('Please Enter the Packaging value');
				$('#PackagingType').focus();
				$('#txtExciseDuty').val('');
				return false;
			}
			else
			{
				 AfterExciseDuty = <?php echo EXCISE_ONBASIC_PACKAGING; ?>;
				 var AfterPackaging = parseFloat($('#txtAfterPackaging').val());
			}
		}
		var ExciseVal =  parseFloat(AfterExciseDuty).toFixed(2);
	 
		$('#txtAfterExciseDuty').val(ExciseVal); 
		 }
		 else
		 {
			 $('#txtAfterExciseDuty').val("0.00"); 
		 }
		
	 } 
	    calculateTotalValue();	
	}
	else
	{
		if($('#EditMaterialCode').val() == "0")
	 {
		 alert('Please Select the Material Code');
		$('#EditMaterialCode').focus();
		return false;
	 }
	 else if($('#EditRate').val() == '')
	 {
		  alert('Please Enter the Rate value');
		  $('#EditRate').focus();
		  return false;
	 }
	 
	 else
	 {
		 
		 var basicValue = parseFloat($('#txtEditBasicValue').val());
		
		
		
		 if($('#txtEditExciseDuty').val() != '' && $('#txtEditExciseDuty').val() != '0')
		 {
			var AfterExciseDuty = 0.0;  
		  var ExciseDuty = parseFloat($('#txtEditExciseDuty').val());
		if(ExciseCalculation == '0')
		{
			AfterExciseDuty = <?php echo EXCISE_ONBASICVALUE; ?>;
		}
		else if(ExciseCalculation == '1')
		{
			 if($('#txtEditAfterDiscount').val() == '')
			{
				alert('Please Enter the Discount value');
				$('#EditDiscountType').focus();
				$('#txtEditExciseDuty').val('');
				return false;
			}
			else
			{
				 var AfterDiscount =parseFloat($('#txtEditAfterDiscount').val());
				 AfterExciseDuty = <?php echo EXCISE_ONBASIC_DISCOUNT; ?>;
			}
		}
		else if(ExciseCalculation == '2')
		{
			 if($('#txtEditAfterDiscount').val() == '')
			{
				alert('Please Enter the Discount value');
				$('#EditDiscountType').focus();
				$('#txtEditExciseDuty').val('');
				return false;
			}
			else if($('#txtEditAfterPackaging').val() == '')
			{
				alert('Please Enter the Packaging value');
				$('#EditPackagingType').focus();
				$('#txtEditExciseDuty').val('');
				return false;
			}
			else
			{
				var AfterDiscount =parseFloat($('#txtEditAfterDiscount').val());
				 var AfterPackaging = parseFloat($('#txtEditAfterPackaging').val());
				AfterExciseDuty = <?php echo EXCISE_ONBASIC_DISCOUNT_PACKAGING; ?>;
			}
		}
		else
		{
			if($('#txtEditAfterPackaging').val() == '')
			{
				alert('Please Enter the Packaging value');
				$('#EditPackagingType').focus();
				$('#txtEditExciseDuty').val('');
				return false;
			}
			else
			{
				var AfterPackaging = parseFloat($('#txtEditAfterPackaging').val());
				AfterExciseDuty = <?php echo EXCISE_ONBASIC_PACKAGING; ?>;
			}
		}
		var ExciseVal =  parseFloat(AfterExciseDuty).toFixed(2);
	 
		$('#txtEditAfterExciseDuty').val(ExciseVal); 
		 }
		 else
		 {
			 $('#txtEditAfterExciseDuty').val("0.00"); 
		 }
		
	 } 
	 calculateEditTotalValue();	
	}
	 
 }
 
 function calculateVat(isEdit)
 {
	 if(isEdit == '0')
	{ 
		if($('#MaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#MaterialCode').focus();
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  return false;
		 }	 
		
		 else
		 {		
        	 var basicValue = parseFloat($('#txtBasicValue').val());			
				var AfterVat = 0.0;
			 if(VatCalculation != 0 && $('#txtVat').val() != '' )
			 {
			  
					if($('#txtAfterExciseDuty').val() == '')
						{
							alert('Please Enter the Excise value');
							$('#txtExciseDuty').focus();
							$('#txtVat').val('');
							return false;
						}
						else
						{
							var ExciseDuty = parseFloat($('#txtAfterExciseDuty').val()); 
							vatValue = parseFloat($('#txtVat').val());
							AfterVat = <?php echo VAT_ONEXICSEVALUE; ?>;
							var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
							$('#txtAfterVat').val(Vatval); 
						}
			 }
			 else if(VatCalculation == 0 && $('#txtVat').val() != '')
			 {
					vatValue = parseFloat($('#txtVat').val());
					AfterVat =  <?php echo VAT_ONBASICVALUE; ?>;
					var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
					$('#txtAfterVat').val(Vatval); 
			 }				
			 
			 else
			 {
				 $('#txtAfterVat').val("0.00"); 
			 }
		  	calculateTotalValue();		
		 } 
		 
	}
	else
	{
		if($('#EditMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditMaterialCode').focus();
			return false;
		 }
		 else if($('#EditRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRate').focus();
			  return false;
		 }	 
		 
		 else
		 {
			 var basicValue = parseFloat($('#txtEditBasicValue').val());
			 var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val());
			  var AfterVat = 0.0; 
			  if(VatCalculation != 0 && $('#txtEditVat').val() != '' )
			 {
			  
					if($('#txtEditAfterExciseDuty').val() == '')
						{
							alert('Please Enter the Excise value');
							$('#txtEditAfterExciseDuty').focus();
							$('#txtEditVat').val('');
							return false;
						}
						else
						{
							var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val()); 
							vatValue = parseFloat($('#txtEditVat').val());
							AfterVat = <?php echo VAT_ONEXICSEVALUE; ?>;
							var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
							$('#txtEditAfterVat').val(Vatval); 
						}
			 }
			 else if(VatCalculation == 0 && $('#txtEditVat').val() != '')
			 {
					vatValue = parseFloat($('#txtEditVat').val());
					AfterVat =  <?php echo VAT_ONBASICVALUE; ?>;
					var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
					$('#txtEditAfterVat').val(Vatval); 
			 }				
			 
			 else
			 {
				 $('#txtEditAfterVat').val("0.00"); 
			 }
			 
			calculateEditTotalValue();	
		 } 
		 
	}
 }
 function calculateCST(isEdit)
 {
	 if(isEdit == '0')
	{ 
			if($('#MaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#MaterialCode').focus();
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  return false;
			 }	 
			 
			 else
			 {
				 var basicValue = parseFloat($('#txtBasicValue').val());
				  var AfterCST = 0.0; 
				  if(CSTCalculation != 0 && $('#txtCST').val() != '' )
				{
			  
					if($('#txtAfterExciseDuty').val() == '')
						{
							alert('Please Enter the Excise value');
							$('#txtExciseDuty').focus();
							$('#txtAfterCST').val('');
							return false;
						}
						else
						{
							var ExciseDuty = parseFloat($('#txtAfterExciseDuty').val()); 
							var CSTValue= parseFloat($('#txtCST').val()); 
							AfterCST = <?php echo CST_ONBASICVALUE; ?>;
							var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
							$('#txtAfterCST').val(Vatval); 
						}
			 }
			 else if(CSTCalculation == 0 && $('#txtCST').val() != '')
			 {
					var CSTValue= parseFloat($('#txtCST').val()); 
					AfterCST =  <?php echo CST_ONBASICVALUE; ?>;
					var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
					$('#txtAfterCST').val(Vatval); 
			 }				
			 
			 else
			 {
				 $('#txtAfterCST').val("0.00"); 
			 }				
				calculateTotalValue();
			 }
		
		}
		else
		{
			if($('#EditMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditMaterialCode').focus();
				return false;
			 }
			 else if($('#EditRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRate').focus();
				  return false;
			 }	 
			 
			 else
			 {
				 
				 var basicValue = parseFloat($('#txtEditBasicValue').val());
				  var AfterCST = 0.0; 
				  if(CSTCalculation != 0 && $('#txtEditCST').val() != '' )
				{
			  
					if($('#txtEditAfterExciseDuty').val() == '')
						{
							alert('Please Enter the Excise value');
							$('#txtEditAfterExciseDuty').focus();
							$('#txtEditCST').val('');
							return false;
						}
						else
						{
							var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val()); 
							var CSTValue= parseFloat($('#txtEditCST').val()); 
							AfterCST = <?php echo CST_ONBASICVALUE; ?>;
							var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
							$('#txtEditAfterCST').val(Vatval); 
						}
			 }
			 else if(CSTCalculation == 0 && $('#txtEditCST').val() != '')
			 {
				 var CSTValue= parseFloat($('#txtEditCST').val()); 
					AfterCST =  <?php echo CST_ONBASICVALUE; ?>;
					var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
					$('#txtEditAfterCST').val(Vatval); 
			 }				
			 
			 else
			 {
				 $('#txtEditAfterCST').val("0.00"); 
			 }				
				 
				calculateEditTotalValue();
			 }
		
		}
 }
 function calculateGST(isEdit)
 {
	 if(isEdit == '0')
	{ 
			if($('#MaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#MaterialCode').focus();
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  return false;
			 }		
			 else
			 {
				 var basicValue = parseFloat($('#txtBasicValue').val());
				
				 if($('#txtGST').val() != "0"  && 	 $('#txtGST').val() != '')
				 {	
					var GSTValue =  parseFloat($('#txtGST').val());
				 
				  var AfterGST = 0.0;  	 
					AfterGST = <?php echo GSTTAX; ?>;
				
					var GSTval =  parseFloat(AfterGST).toFixed(2);
			 
					$('#txtAfterGST').val(GSTval); 
				 }
				 else
				 {
					$('#txtAfterGST').val("0.00");  
				 }	 
				
			 } 
			 calculateTotalValue();	
	}
	else
	{
		if($('#EditMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditMaterialCode').focus();
				return false;
			 }
			 else if($('#EditRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRate').focus();
				  return false;
			 }		
			 else
			 {
				 var basicValue = parseFloat($('#txtEditBasicValue').val());
				
				 if($('#txtEditGST').val() != "0"  && 	 $('#txtEditGST').val() != '')
				 {	
					var GSTValue =  parseFloat($('#txtEditGST').val());
				 
				  var AfterGST = 0.0;  	 
					AfterGST = <?php echo GSTTAX; ?>;
				
					var GSTval =  parseFloat(AfterGST).toFixed(2);
			 
					$('#txtEditAfterGST').val(GSTval); 
				 }
				 else
				 {
					$('#txtEditAfterGST').val("0.00");  
				 }	 
				
			 } 
			 calculateEditTotalValue();	
		
	}
 }
  function calculateOtherTaxes(isEdit)
 {
	 if(isEdit == '0')
	{ 
		if($('#MaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#MaterialCode').focus();
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtBasicValue').val());
			
			 
			 if($('#txtOtherTax').val() != "0"  && 	 $('#txtOtherTax').val() != '')
			 {	
				var OtherTaxValue =  parseFloat($('#txtOtherTax').val());
			 
				var AfterOtherTaxes = 0.0;	 
				AfterOtherTaxes = <?php echo OTHERTAX; ?>;
			
				var Otherval =  parseFloat(AfterOtherTaxes).toFixed(2);
		 
				$('#txtAfterOtherTax').val(Otherval); 
			 }
			 else
			 {
				$('#txtAfterOtherTax').val("0.00");  
			 }
			  calculateTotalValue();
			
		 } 
	}
	else
	{
		if($('#EditMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditMaterialCode').focus();
			return false;
		 }
		 else if($('#EditRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRate').focus();
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtEditBasicValue').val());
			
			 
			 if($('#txtEditOtherTax').val() != "0"  && 	 $('#txtEditOtherTax').val() != '')
			 {	
				var OtherTaxValue =  parseFloat($('#txtEditOtherTax').val());
			 
				var AfterOtherTaxes = 0.0;	 
				AfterOtherTaxes = <?php echo OTHERTAX; ?>;
			
				var Otherval =  parseFloat(AfterOtherTaxes).toFixed(2);
		 
				$('#txtEditAfterOtherTax').val(Otherval); 
			 }
			 else
			 {
				$('#txtEditAfterOtherTax').val("0.00");  
			 }
			   calculateEditTotalValue();
			
		 } 
		
	}
 }
 
 function calculateFreight(isEdit)
 {
	 if(isEdit == '0')
	{ 
		if($('#MaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#MaterialCode').focus();
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtBasicValue').val());
			 var FreightType =$("#drpFreight").val();
			 if(FreightType == "0")
			 {
				 alert('Please select Freight Type');
				 $('#txtFreight').val('');
				 $("#drpFreight").focus();
			 }
			 else if( $('#txtFreight').val() != "0"  && 	 $('#txtFreight').val() != '')
			 {	
				var FreightValue =  parseFloat($('#txtFreight').val());
				var UOM          = parseFloat($('#UOM').val());
				var Quantity          = parseFloat($('#Quantity').val());
				//alert(FreightType);
				var AfterFreight = 0.0;	
				if(FreightType == PercentageType)
				{		
					AfterFreight = <?php echo FREIGHT_PERCENTAGE;?>;		  	  
				}
				else if(FreightType == NilType)
				{		
					AfterFreight = 0.0;	 		  	  
				}
				else if(FreightType == '<?php echo LUMPSUM;?>')
				{		
					AfterFreight = <?php echo FREIGHT_LUMPSUM;?>;		  	  
				}
				else if(FreightType == '<?php echo PERUOM;?>')
				{		
					AfterFreight = <?php echo FREIGHT_PERUOM;?>;		  	  
				}
				else if(FreightType == '<?php echo PERTRIP;?>')
				{		
					AfterFreight = <?php echo FREIGHT_PERTRIP;?>;		  	  
				}	
				var AfterFreightval =  parseFloat(AfterFreight).toFixed(2);
		 
				$('#txtAfterFreight').val(AfterFreightval); 
			 }
			 else
			 {
				$('#txtAfterFreight').val("0.00");  
			 }
			
		 } 
		 calculateTotalValue();	
	}
	else
	{
		if($('#EditMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditMaterialCode').focus();
			return false;
		 }
		 else if($('#EditRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRate').focus();
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtEditBasicValue').val());
			 var FreightType =$("#drpEditFreight").val();
			 if(FreightType == "0")
			 {
				 alert('Please select Freight Type');
				 $('#txtEditFreight').val('');
				 $("#drpEditFreight").focus();
			 }
			 else if( $('#txtEditFreight').val() != "0"  && 	 $('#txtEditFreight').val() != '')
			 {	
				var FreightValue =  parseFloat($('#txtEditFreight').val());
				var UOM          = parseFloat($('#EditUOM').val());
				var Quantity          = parseFloat($('#EditQuantity').val());
				//alert(FreightType);
				var AfterFreight = 0.0;	
				if(FreightType == PercentageType)
				{		
					AfterFreight = <?php echo FREIGHT_PERCENTAGE;?>;		  	  
				}
				else if(FreightType == NilType)
				{		
					AfterFreight = 0.0;	 		  	  
				}
				else if(FreightType == '<?php echo LUMPSUM;?>')
				{		
					AfterFreight = <?php echo FREIGHT_LUMPSUM;?>;		  	  
				}
				else if(FreightType == '<?php echo PERUOM;?>')
				{		
					AfterFreight = <?php echo FREIGHT_PERUOM;?>;		  	  
				}
				else if(FreightType == '<?php echo PERTRIP;?>')
				{		
					AfterFreight = <?php echo FREIGHT_PERTRIP;?>;		  	  
				}	
				var AfterFreightval =  parseFloat(AfterFreight).toFixed(2);
		 
				$('#txtEditAfterFreight').val(AfterFreightval); 
			 }
			 else
			 {
				$('#txtEditAfterFreight').val("0.00");  
			 }
			
		 } 
		 calculateEditTotalValue();	

	}
 }
 
 /* Set the Packaging calculation option for calculating Packaging */
 function SetPackagingOption()
 {
	 PackagingCalculation = $("input:radio[name='optPackaging']:checked").val();
	 $('#packagingcalmodel').modal('hide');	
	 calculatePackaging($('#isEdit').val());
 }
 /* Set the Packaging calculation option for calculating Packaging */
 function SetExciseCalculation()
 {
	 ExciseCalculation = $("input:radio[name='optExcise']:checked").val();
	 $('#ExciseDutyCalModel').modal('hide');	
	 calculateExcise($('#isEdit').val());
 }
 /* Set the Packaging calculation option for calculating Packaging */
 function SetVatorCST()
 {
	  StateTaxCheck = $("input:radio[name='Range']:checked").val();
	  $('#txtPoRange').val(StateTaxCheck) ; 
	  //alert('Radio clicke:'+StateTaxCheck);
	  if(StateTaxCheck == "0")
	  {
		  // style="display:none;"
			$('#Vat').removeAttr("style");
			$('#TotVat').removeAttr("style");
		   $('#CST').attr("style","display:none;");
		    $('#TotCST').attr("style","display:none;");
	  }
	  else
	  {
		   $('#CST').removeAttr("style");
		   $('#TotCST').removeAttr("style");
		   $('#Vat').attr("style","display:none;");
		   $('#TotVat').attr("style","display:none;");
	  }
 }
 function SetVatCalculation()
 {
	  VatCalculation = $("input:radio[name='optVat']:checked").val();
	 $('#VatCalModel').modal('hide');	
	  calculateVat($('#isEdit').val());
 }
 function SetCSTCalculation()
 {
	  CSTCalculation = $("input:radio[name='optCST']:checked").val();
	  $('#CSTCalModel').modal('hide');	
	  calculateCST($('#isEdit').val());
 }
 
 function ExceedQuantityCheck()
 {
	// RequistQuantity
	var EnterQuantity =   $("#Quantity").val()== '' ? "0.00" :  parseFloat($("#Quantity").val());
	var ReqQuantity = parseFloat(RequistQuantity);
	if(EnterQuantity > ReqQuantity)
	{
		 alert('Your exceeding the Quantity from the Requisition Quantity:'+ RequistQuantity  +'.Please adjust the Quantity to proceed further.');
		 //$('#Quantity').val(RequistQuantity);
		  $('#Quantity').focus();
		 return false;
	}
 }
 
 function ExceedEditQuantityCheck()
 {
	// RequistQuantity
	var EnterQuantity =   $("#EditQuantity").val()== '' ? "0.00" :  parseFloat($("#EditQuantity").val());
	var ReqQuantity = parseFloat(RequistQuantity);
	if(EnterQuantity > ReqQuantity)
	{
		 alert('Your exceeding the Quantity from the Requisition Quantity:'+ RequistQuantity  +'.Please adjust the Quantity to proceed further.');
		  $('#EditQuantity').focus();
		 return false;
	}
 }
 // To Reset the Tax calculation
 function resetTaxField()
 {

		 $("#ItemName").val('');
		$("#UOM").val('');
		$("#Quantity").val('');
		$("#Rate").val('');
		$("#DiscountType").val("0");
		$("#txtDiscount").val('');
		$('#txtAfterDiscount').val('');
		 $("#PackagingType").val("0")
		$("#txtPackaging").val('');
		$('#txtAfterPackaging').val('');
		$("#txtExciseDuty").val('');
		$('#txtAfterExciseDuty').val('');
		$("#txtVat").val('');
		$('#txtAfterVat').val('');
		$("#txtCST").val('');
		$('#txtAfterCST').val('');
		$("#txtGST").val('');
		$('#txtAfterGST').val('');
		$("#txtOtherTax").val('');
		$('#txtAfterOtherTax').val('');
		$("#drpFreight").val("0")
		$("#txtFreight").val('');
		$('#txtAfterFreight').val('');
		$('#txtInsurance').val('');
		$('#txtTotalOrderValue').val('');
		ExciseCalculation = '';
		PackagingCalculation = '';
		VatCalculation = '';
		CSTCalculation = '';
 }
 
 function Editchange(){
	  ExceedEditQuantityCheck();	  
	 if($('#EditQuantity').val() != '' && $('#EditRate').val() != '')
	 {	  
		  var txtQuantity = parseFloat( $('#EditQuantity').val());
		  var txtUnitPrice = parseFloat($('#EditRate').val());
		  var Tot =  txtQuantity * txtUnitPrice
		  $('#txtEditBasicValue').val(Tot);
		  calculateEditTotalValue($('#isEdit').val());
 
	}
} 

function validateEditExceedLimit()
 {
	 var avalbudAmt = parseFloat($('#EditAvlBudAmt').val());
	 var basicAmountRate = parseFloat($('#txtEditBasicValue').val()); 
	 var totalAmount =  parseFloat($('#txtEditTotalOrderValue').val()); 
	 
	 if(basicAmountRate > avalbudAmt || totalAmount > avalbudAmt)
	 {
		 alert('Basic amount is exceeding the Budget Limit.Please adjust the product value.');
		 $('#EditRate').focus();
		 return false;
	 }
	 else
	 {
		return true; 
	 }
	  
 }
 function calculateEditTotalValue()
 {
	 var Packaging = $('#txtEditAfterPackaging').val() == '' ? '0.00' : $('#txtEditAfterPackaging').val();
	 var ExciseDuty = $('#txtEditAfterExciseDuty').val() == '' ? '0.00' : $('#txtEditAfterExciseDuty').val();
	  var Vat = $('#txtEditAfterVat').val() == '' ? '0.00' : $('#txtEditAfterVat').val();
	   var CST = $('#txtEditAfterCST').val() == '' ? '0.00' : $('#txtEditAfterCST').val();
	    var GST = $('#txtEditAfterGST').val() == '' ? '0.00' : $('#txtEditAfterGST').val();
		var OtherTax = $('#txtEditAfterOtherTax').val() == '' ? '0.00' : $('#txtEditAfterOtherTax').val();
		var Freight = $('#txtEditAfterFreight').val() == '' ? '0.00' : $('#txtEditAfterFreight').val();
		var Insurance = $('#txtEditInsurance').val() == '' ? '0.00' : $('#txtEditInsurance').val();
		var Discount = $('#txtEditAfterDiscount').val() == '' ? '0.00' : $('#txtEditAfterDiscount').val();
		var BasicVal = $('#txtEditBasicValue').val() == '' ? '0.00' : $('#txtEditBasicValue').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);
	    		
	 $('#txtEditTotalOrderValue').val(tot);
	 validateEditExceedLimit();
	 ExceedEditQuantityCheck();
 }
function calculateEditTaxValue()
 {
	 var Packaging = $('#txtEditAfterPackaging').val() == '' ? '0.00' : $('#txtEditAfterPackaging').val();
	 var ExciseDuty = $('#txtEditAfterExciseDuty').val() == '' ? '0.00' : $('#txtEditAfterExciseDuty').val();
	  var Vat = $('#txtEditAfterVat').val() == '' ? '0.00' : $('#txtEditAfterVat').val();
	   var CST = $('#txtEditAfterCST').val() == '' ? '0.00' : $('#txtEditAfterCST').val();
	    var GST = $('#txtEditAfterGST').val() == '' ? '0.00' : $('#txtEditAfterGST').val();
		var OtherTax = $('#txtEditAfterOtherTax').val() == '' ? '0.00' : $('#txtEditAfterOtherTax').val();
		var Freight = $('#txtEditAfterFreight').val() == '' ? '0.00' : $('#txtEditAfterFreight').val();
		var Insurance = $('#txtEditInsurance').val() == '' ? '0.00' : $('#txtEditInsurance').val();
		var Discount = $('#txtEditAfterDiscount').val() == '' ? '0.00' : $('#txtEditAfterDiscount').val();
		
	
	 var totvalue = parseFloat(Discount) -( parseFloat(Packaging)+ parseFloat(ExciseDuty)+ parseFloat(Vat) + parseFloat(CST)+ parseFloat(GST) +  parseFloat(OtherTax) + parseFloat(Freight) + parseFloat(Insurance))  ;
	 
	 var tot =  parseFloat(totvalue).toFixed(2);
	    //alert('tot:'+tot);		
	return tot;
 } 
</script>
<style>
.content {
	Padding:0% ! important;
}
body {
	background-color: #ecf0f5;
}
.pagination {
	margin :0px ! important;
}
.box-body {
	padding:0px ! important;
} 
</style>
<div class="content-wrapper">
     <?php
                      $attributes = array('class' => 'form-label-left CreatePO ','name'  => 'CreatePO','id'  => 'CreatePO');
                        
                        echo form_open($this->config->base_url().'/purchaseorder/addPO/',$attributes); ?>
 
	 <section class="content">
	  
	 <div>
         <center><b><h2>Siddharth Industries - Edit Revenue Purchase Order - <?php echo $PONO;?></h2></b></center></div><br/><br/>
         <div class="container-fluid">		
	<div class="row">
		<div class="col-md-12">
		<div class="col-md-3">
			<label>Requistion No</label>
						<?php							 
							  $options = array("0"=>'Selected Requisition Numbers'); 
								 if(!empty($ReqList))
						{
						foreach ($ReqList as $SID):
					 
						   $options[$SID->ReqNo] = $SID->ReqNo ;
                           //$ReqType = $SID->ReqType;
						endforeach;
						}							 
							echo form_multiselect('RequistionNo', $options,set_value('RequistionNo'),'id="RequistionNo"' ,'required="true"' , 'height="400px"' );
							?>						 
		</div>
		<div class="col-md-9">
			<div class="row">
				<div class="col-md-4">
					<label>Select Supplier</label> 
						 <?php
						$options = array("0"=>'Select Supplier');     
						//print_r(  $options);
						
						if(!empty($Suplist))
						{
						foreach ($Suplist as $SID):
						  
					   
						  $options[$SID->SupplierID] =  $SID->SupplierID.' '.' - '.' '.$SID->SupplierName;

						endforeach;
						}										
			
						echo form_dropdown('drpSupplier', $options,set_value('drpSupplier',$SupId),'id="drpSupplier"'  ,'required="true"' ,'class="form-control select2');

						?>						 					 
				</div>
				<div class="col-md-4">
					 <label>Purchase Order Type</label>
						<div class="form-group">
						
									<?php
							 $data = array('name' => 'POType','value' => set_value('POType',REVENUE),'id'=>'POType',  'class' => 'form-control' ,'readonly' => 'true');
							echo form_input($data);
							?>   
						</div>
				</div>
				<div class="col-md-4">					
					 	
						<div id="div1" style="display:block;">
							<b><u>Select Tax Range</u></b><br/> 
							<tr>
							<td>
							<?php echo form_label('Local', 'Local') ."&nbsp;&nbsp;". form_radio(array("name"=>"Range","id"=>"Local","value"=>"0", 'checked'=>set_radio('Range', '0', TRUE),'onchange'=>'SetVatorCST();')); ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td><?php echo form_label('Inter state', 'Inter state') ."&nbsp;&nbsp;". form_radio(array("name"=>"Range","id"=>"Inter_state","value"=>"1", 'checked'=>set_radio('Range', '1', FALSE),'onchange'=>'SetVatorCST();')); ?> 										
							</td> 
							</tr>
						</div>
						<div id="div2" style="display:none;">    
						</div>
						<div id="div4" style="display:none;">
						</div>
					 
							
				</div>
			</div>
			<div class="row">
				<div class="col-md-4">
					 <label>Supplier Address</label>
					<div class="form-group">
								<?php
						 $data = array('name' => 'SupAddress','value' => set_value('SupAddress',$Address),'id'=>'SupAddress',  'class' => 'form-control' ,'readonly' => 'true' ,'rows' => '3', 'cols' => '40');
						echo Form_textarea($data);
						?>   
					</div>
				</div>
				<div class="col-md-4">
					<label>Delivery Address</label>
					<div class="form-group">
								<?php
						 $data = array('name' => 'DeliveryAddr','value' => set_value('DeliveryAddr',$DeliveryAddress),'id'=>'DeliveryAddr',  'class' => 'form-control' ,'required' => 'true' ,'rows' => '3', 'cols' => '40');
						echo Form_textarea($data);
						?>   <input type="hidden" name="txtDeliveryAddress" id="txtDeliveryAddress"  value="<?php echo $DeliveryAddress;?>">
					</div>
				</div>
				<div class="col-md-2">
					 <label>Purchase Order Date</label>
						<div class="form-group">
									<?php
							 $data = array('name' => 'PODate','value' => set_value('PODate',$PODate),'id'=>'PODate',  'class' => 'form-control' ,'required' => 'true','onkeypress'=>'return false;');
							echo form_input($data);
							?>   
						</div>
					</div> 
					<div class="col-md-2">
					 <label>Delivery Date</label>		
						<div class="form-group">
								<?php
						 $data = array('name' => 'Deliverydt','value' => set_value('Deliverydt',$Deliverydt),'id'=>'Deliverydt',  'class' => 'form-control' ,'required' => 'true','onkeypress'=>'return false;');
						echo form_input($data);
						?>   
					
						</div>
					</div> 
				
			</div>
		</div>
		 	 
		</div>
    </div>
	 <!-- Modal for Packing Calculation -->
  <div  id="packagingcalmodel" class="modal fade" data-backdrop-limit="1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Packing Calculation On</h4>
        </div>
        <div class="modal-body">
          <form>
    
      <div class="radio">
      <label><input type="radio" name="optPackaging" checked="checked" value='0'  id="optPackaging"> Basic Amount</label>
    </div>
    <div class="radio">
      <label><input type="radio" name="optPackaging" id="optPackaging" value='1' > After Discount Amount</label>
    </div>
  </form>
        </div>
        <div class="modal-footer">
        
		  <a class="btn btn-primary"  ID="PackagingOption" onclick="SetPackagingOption();"  style="margin-top: -24px;">&nbsp;&nbsp;<span class="bold">Ok</span></a>
			<a class="btn btn-primary" data-dismiss="modal" style="margin-top: -24px;" value="Cancel">Cancel</a>
        </div>
      </div>
      
    </div>
  </div>
  
  <!-- Modal for Excise Duty Calculation-->
  <div class="modal fade" id="ExciseDutyCalModel" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Excise Duty Calculation On</h4>
        </div>
        <div class="modal-body">
          <form>
		  <div class="radio">
      <label><input type="radio" name="optExcise" checked="checked" value="0"  id="optExcise">From Basic Amount</label>
    </div>
    <div class="radio">
      <label><input type="radio" name="optExcise" value="1"  id="optExcise">Basic Amount - Discount Amount</label>
    </div>
	<div class="radio">
      <label><input type="radio" name="optExcise" value="2"  id="optExcise">(Basic Amount - Discount Amount ) + Packing Cost</label>
    </div>
    <div class="radio">
      <label><input type="radio" name="optExcise" value="3"  id="optExcise">Basic Amount + Packing Cost</label>
    </div>
     
  </form>
        </div>
        <div class="modal-footer">
           <a class="btn btn-primary"  ID="ExciseOption" onclick="SetExciseCalculation();"  style="margin-top: -24px;">&nbsp;&nbsp;<span class="bold">Ok</span></a>
			<a class="btn btn-primary" data-dismiss="modal" style="margin-top: -24px;" value="Cancel">Cancel</a>
        </div>
      </div>
      
    </div>
  </div>
  
  
   <!-- Modal for Vat Calculation -->
  <div class="modal fade" id="VatCalModel" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Vat Calculation On</h4>
        </div>
        <div class="modal-body">
          <form>
     
     <div class="radio">
      <label><input type="radio" name="optVat" checked="checked" value="0"  id="optVat">Basic Amount</label>
    </div>
    <div class="radio">
      <label><input type="radio" name="optVat" value="1"  id="optVat">Excise Duty</label>
    </div>
  </form>
        </div>
        <div class="modal-footer">
         <a class="btn btn-primary"  ID="VatOption" onclick="SetVatCalculation();"  style="margin-top: -24px;">&nbsp;&nbsp;<span class="bold">Ok</span></a>
			<a class="btn btn-primary" data-dismiss="modal" style="margin-top: -24px;" value="Cancel">Cancel</a>
        </div>
      </div>
      
    </div>
  </div>
   <!-- Modal for CST Calculation -->
  <div class="modal fade" id="CSTCalModel" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal for CST Calculation-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">CST Calculation On</h4>
        </div>
        <div class="modal-body">
          <form>
     
     <div class="radio">
      <label><input type="radio" name="optCST" checked="checked" value="0"  id="optCST">Basic Amount</label>
    </div>
    <div class="radio">
      <label><input type="radio" name="optCST" value="1"  id="optCST">Excise Duty</label>
    </div>
  </form>
        </div>
        <div class="modal-footer">
         <a class="btn btn-primary"  ID="CSTOption" onclick="SetCSTCalculation();"  style="margin-top: -24px;">&nbsp;&nbsp;<span class="bold">Ok</span></a>
			<a class="btn btn-primary" data-dismiss="modal" style="margin-top: -24px;" value="Cancel">Cancel</a>
        </div>
      </div>
      
    </div>
  </div>
          <div class="container-fluid">  
 	 <table>
  <div align="right">
	<div align="right">
	  <a data-toggle="modal" ><button type="submit"  onclick="myFunction();" class="btn btn-primary" id="abcd" >Add Line Item</button> </a> 
	</div> 
  
  <!-- Model for revenue po -->
     <div  id="REVENUE" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
	   <!-- Modal content-->
	 <form>
		  <div class="modal-content" style="width:1000px;">
			<div class="modal-header" style="background-color: #3c8dbc;color:#fff;">			   
			  <center><h4>Select Revenue Purchase Order Line Item </h4></center>				
			</div>
		 	<div align="left"> 
				<div>
					<div class="col-md-12" >
								 <div class="col-md-3">
								 <label>Req No</label>
											<div >
												 <?php
													$RL = array("0"=>'Select Req No');     
													if(!empty($RequistionDetails))
													{
													foreach ($RequistionDetails as $SID):			   
														$RL[$SID->ReqNo] =  $SID->ReqNo.' '.' - '.' '.$SID->DepartmentName;
													endforeach;
													}
									
													echo form_dropdown('ReqNo', $RL,set_value('ReqNo'),'id="ReqNo"' ,'class="form-control"');

												?>						 
											</div>
										</div>
								 
								  <div class="col-md-3">
								   <label>Department Name</label>
											<div class="form-group">
														<?php
												 $data = array('name' => 'deptName','value' => set_value('deptName'),'id'=>'deptName',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);
												?>   
											</div>
								 </div>
								  <div class="col-md-3">
								   <label>Cost Center Name</label>
											<div class="form-group">
														<?php
								$data = array('name' => 'CostCenter','value' => set_value('CostCenter'),'id'=>'CostCenter',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);

								?>		
											</div>
								 </div>
								  <div class="col-md-2">
								   <label>Avl Bud Amt</label>
											<div class="form-group">
														<?php
												 $data = array('name' => 'AvlBudAmt','value' => set_value('AvlBudAmt'),'id'=>'AvlBudAmt',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);
												?>   
											</div>
								 </div>
						</div>		
					<div class="col-md-12">
							  <div class="col-md-2">
							  <label>Item Code</label>
										<div  >
											 <?php
											$options = array("0"=>'Item Code');     
																	
								
											echo form_dropdown('MaterialCode', $options,set_value('MaterialCode'),'id="MaterialCode"' ,'class="form-control"');

											?>						 
										</div>
						   </div>
						  
							 <div class="col-md-2">
							  <label>Item Name</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'ItemName','value' => set_value('ItemName'),'id'=>'ItemName',  'class' => 'form-control'  ,'readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>UOM</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'UOM','value' => set_value('UOM'),'id'=>'UOM',  'class' => 'form-control' ,'readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Quantity</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'Quantity','value' => set_value('Quantity'),'id'=>'Quantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'change()');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Rate</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'Rate','value' => set_value('Rate'),'id'=>'Rate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'change()' );
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Basic Amount</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'txtBasicValue','value' => set_value('txtBasicValue'),'id'=>'txtBasicValue',  'class' => 'form-control' ,'readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
				</div>
				</div><br/>				
				<div class="col-md-12" style="border : 1px solid">		 	 				 
					<div class="row">
					 <div class="col-md-12">
											<div class="col-md-4">
									  <label>Discount Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Discount Type');     
													//print_r(  $options);
													
													if(!empty($TaxType))
													{
													foreach ($TaxType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('DiscountType', $options,set_value('DiscountType'),'id="DiscountType"' ,'class="form-control"');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Discount Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtDiscount','value' => set_value('txtDiscount'),'id'=>'txtDiscount',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);' ,'onchange'=>'calculateDiscount(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Discounted Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterDiscount','value' => set_value('txtAfterDiscount'),'id'=>'txtAfterDiscount',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div> 
					</div>
					<div id="Vat" >
					 <div class="col-md-2"  >
									  <label>Vat in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtVat','value' => set_value('txtVat'),'id'=>'txtVat',  'class' => 'form-control','onchange'=>'calculateVat(0);' );
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2" >
									  <label>Vat Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterVat','value' => set_value('txtAfterVat'),'id'=>'txtAfterVat',  'class' => 'form-control' ,'readonly' => 'true','onkeypress'=>'return isNumberKey(event);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 </div>
					  <div style="display:none;"  id="CST">
					  <div class="col-md-2 col-md-offset-2" >
									  <label>CST in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtCST','value' => set_value('txtCST'),'id'=>'txtCST',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateCST(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2" >
									  <label>CST Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterCST','value' => set_value('txtAfterCST'),'id'=>'txtAfterCST',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div> 
					</div>
					</div>
					</div> 
					</div>
					<div class="row">
					 <div class="col-md-12" style="text-align:left;">
											<div class="col-md-4">
									  <label>Packaging Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Packaging Type');     
													//print_r(  $options);
													
													if(!empty($TaxType))
													{
													foreach ($TaxType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('PackagingType', $options,set_value('PackagingType'),'id="PackagingType"' ,'class="form-control "');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Packaging Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtPackaging','value' => set_value('txtPackaging'),'id'=>'txtPackaging',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculatePackaging(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Packaging Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterPackaging','value' => set_value('txtAfterPackaging'),'id'=>'txtAfterPackaging',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div> 
					</div>  
					<div class="col-md-2">
									  <label>GST in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtGST','value' => set_value('txtGST'),'id'=>'txtGST',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>' calculateGST(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>GST Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterGST','value' => set_value('txtAfterGST'),'id'=>'txtAfterGST',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div> 
					</div>
					
					</div> 
					</div>
					<div class="row">
					<div class="col-md-12 "  >
					<div class="col-md-2 col-md-offset-4">
									  <label>Excise Duty in %	</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtExciseDuty','value' => set_value('txtExciseDuty'),'id'=>'txtExciseDuty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateExcise(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label> Excise Duty Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterExciseDuty','value' => set_value('txtAfterExciseDuty'),'id'=>'txtAfterExciseDuty',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div>
					</div>
					<div class="col-md-2">
									  <label>Other  Taxes in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtOtherTax','value' => set_value('txtOtherTax'),'id'=>'txtOtherTax',  'class' => 'form-control','onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateOtherTaxes(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Other Taxes Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterOtherTax','value' => set_value('txtAfterOtherTax'),'id'=>'txtAfterOtherTax',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>  
												</div> 
												
					</div>
					 
					</div>
					</div>
					<div class="row">
					<div class="col-md-12"  >
									<div class="col-md-4">
									  <label>Freight Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Freight Type');     
													//print_r(  $options);
													
													if(!empty($FreightType))
													{
													foreach ($FreightType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('drpFreight', $options,set_value('drpFreight'),'id="drpFreight"' ,'class="form-control "');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Freight Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtFreight','value' => set_value('txtFreight'),'id'=>'txtFreight',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateFreight(0);');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Freight Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtAfterFreight','value' => set_value('txtAfterFreight'),'id'=>'txtAfterFreight',  'class' => 'form-control' ,'readonly' => 'true');
													echo form_input($data);
													?>   
												</div> 
					</div> 
					 <div class="col-md-4">
									  <label> Insurance if Any</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtInsurance','value' => set_value('txtInsurance'),'id'=>'txtInsurance',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateTotalValue(0);');
													echo form_input($data);
													?>   
												</div>
					</div>
					
					
					</div>
					</div><hr/>
					<div class="row">
					 <div class="col-md-12" >
					 
						<div class="col-md-4" align="right"> <label>Total Order Amount :</label></div>
						<div class="col-md-4 ">  
							<div class="form-group">
											<?php
									 $data = array('name' => 'txtTotalOrderValue','value' => set_value('txtTotalOrderValue'),'id'=>'txtTotalOrderValue',  'class' => 'form-control' ,'readonly' => 'true');
									echo form_input($data);
									?>   
							</div> 
						</div>
					 <div class="col-md-4 ">
					
					<a class="btn btn-primary font AddRevenue"  ID="AddRevenue"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add Revenue</span></a>
					<a class="btn btn-primary" data-dismiss="modal"  value="Cancel">Cancel</a>					 
					</div>
					</div> 
					</div>			 				
					</div>
				<br/><br/>				
				<!-- footer for revenue po -->
			<div class="modal-footer">
					
			</div>
			</div>
 		  
		 </div>
		 </form>			 
	</div>	  
	</div>	   
   
   <br/>
     <div  id="EDITREVENUE" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
	   <!-- Modal content-->
	 <form>
		  <div class="modal-content" style="width:1000px;">
			<div class="modal-header" style="background-color: #3c8dbc;color:#fff;">			   
			  <center><h4>Edit Revenue Purchase Order Line Item </h4></center>				
			</div>
		 	<div align="left"> 
				<div>
					<div class="col-md-12" >
								 <div class="col-md-3">
								 <label>Req No</label>
											<div >
												 <?php													
													
													 $data = array('name' => 'EditReqNo','value' => set_value('EditReqNo'),'id'=>'EditReqNo',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);

												?>						 
											</div>
										</div>
								 
								  <div class="col-md-3">
								   <label>Department Name</label>
											<div class="form-group">
														<?php
												 $data = array('name' => 'EditdeptName','value' => set_value('EditdeptName'),'id'=>'EditdeptName',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);
												?>   
											</div>
								 </div>
								  <div class="col-md-3">
								   <label>Cost Center Name</label>
											<div class="form-group">
														<?php
								$data = array('name' => 'EditCostCenter','value' => set_value('EditCostCenter'),'id'=>'EditCostCenter',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);

								?>		
											</div>
								 </div>
								  <div class="col-md-2">
								   <label>Avl Bud Amt</label>
											<div class="form-group">
														<?php
												 $data = array('name' => 'EditAvlBudAmt','value' => set_value('EditAvlBudAmt'),'id'=>'EditAvlBudAmt',  'class' => 'form-control' ,'readonly' => 'true');
												echo form_input($data);
												?>   
											</div>
								 </div>
						</div>		
					<div class="col-md-12">
							  <div class="col-md-2">
							  <label>Item Code</label>
										<div  >
											 <?php
											$options = array("0"=>'Item Code');     
																	
								
											echo form_dropdown('EditMaterialCode', $options,set_value('EditMaterialCode'),'id="EditMaterialCode"' ,'class="form-control"');

											?>						 
										</div>
						   </div>
						  
							 <div class="col-md-2">
							  <label>Item Name</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'EditItemName','value' => set_value('EditItemName'),'id'=>'EditItemName',  'class' => 'form-control'  ,'readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>UOM</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'EditUOM','value' => set_value('EditUOM'),'id'=>'EditUOM',  'class' => 'form-control' ,'readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Quantity</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'EditQuantity','value' => set_value('EditQuantity'),'id'=>'EditQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'Editchange()','style'=>'text-align:right;');
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Rate</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'EditRate','value' => set_value('EditRate'),'id'=>'EditRate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'Editchange()','style'=>'text-align:right;' );
											echo form_input($data);
											?>   
										</div>
							 </div>
							 <div class="col-md-2">
							  <label>Basic Amount</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'txtEditBasicValue','value' => set_value('txtEditBasicValue'),'id'=>'txtEditBasicValue',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
											echo form_input($data);
											?>   
										</div>
							 </div>
				</div>
				</div><br/>				
				<div class="col-md-12" style="border : 1px solid">		 	 				 
					<div class="row">
					 <div class="col-md-12">
											<div class="col-md-4">
									  <label>Discount Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Discount Type');     
													//print_r(  $options);
													
													if(!empty($TaxType))
													{
													foreach ($TaxType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('EditDiscountType', $options,set_value('EditDiscountType'),'id="EditDiscountType"' ,'class="form-control"');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Discount Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditDiscount','value' => set_value('txtEditDiscount'),'id'=>'txtEditDiscount',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);' ,'onchange'=>'calculateDiscount(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Discounted Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterDiscount','value' => set_value('txtEditAfterDiscount'),'id'=>'txtEditAfterDiscount',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>					
					<div id="Vat" >
					 <div class="col-md-2"  >
									  <label>Vat in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditVat','value' => set_value('txtEditVat'),'id'=>'txtEditVat',  'class' => 'form-control','onchange'=>'calculateVat(1);' ,'style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
												
					</div>
					 <div class="col-md-2" >
									  <label>Vat Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterVat','value' => set_value('txtEditAfterVat'),'id'=>'txtEditAfterVat',  'class' => 'form-control' ,'readonly' => 'true','onkeypress'=>'return isNumberKey(event);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					
					</div>
					</div>
					  <div style="display:none;"  id="CST">
					 <div class="col-md-2"  >
									  <label>CST in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditCST','value' => set_value('txtEditCST'),'id'=>'txtEditCST',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateCST(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2" >
									  <label>CST Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterCST','value' => set_value('txtEditAfterCST'),'id'=>'txtEditAfterCST',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					
					</div>
					 </div>
					</div>
					</div> 
					</div>
					<div class="row">
					 <div class="col-md-12" style="text-align:left;">
											<div class="col-md-4">
									  <label>Packaging Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Packaging Type');     
													//print_r(  $options);
													
													if(!empty($TaxType))
													{
													foreach ($TaxType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('EditPackagingType', $options,set_value('EditPackagingType'),'id="EditPackagingType"' ,'class="form-control "');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Packaging Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditPackaging','value' => set_value('txtEditPackaging'),'id'=>'txtEditPackaging',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculatePackaging(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Packaging Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterPackaging','value' => set_value('txtEditAfterPackaging'),'id'=>'txtEditAfterPackaging',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>  
					<div class="col-md-2">
									  <label>GST in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditGST','value' => set_value('txtEditGST'),'id'=>'txtEditGST',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>' calculateGST(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>GST Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterGST','value' => set_value('txtEditAfterGST'),'id'=>'txtEditAfterGST',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					
					</div> 
					</div>
					<div class="row">
					<div class="col-md-12 "  >
					<div class="col-md-2 col-md-offset-4">
									  <label>Excise Duty in %	</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditExciseDuty','value' => set_value('txtEditExciseDuty'),'id'=>'txtEditExciseDuty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateExcise(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label> Excise Duty Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterExciseDuty','value' => set_value('txtEditAfterExciseDuty'),'id'=>'txtEditAfterExciseDuty',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div>
					</div>
					<div class="col-md-2">
									  <label>Other  Taxes in %</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditOtherTax','value' => set_value('txtEditOtherTax'),'id'=>'txtEditOtherTax',  'class' => 'form-control','onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateOtherTaxes(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Other Taxes Amount</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterOtherTax','value' => set_value('txtEditAfterOtherTax'),'id'=>'txtEditAfterOtherTax',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>  
												</div> 
												
					</div>
					 
					</div>
					</div>
					<div class="row">
					<div class="col-md-12"  >
									<div class="col-md-4">
									  <label>Freight Type </label>
												<div>
													 <?php
													$options = array("0"=>'Select Freight Type');     
													//print_r(  $options);
													
													if(!empty($FreightType))
													{
													foreach ($FreightType as $SID):
													  
												   
													  $options[$SID->ConfigValue] =  $SID->ConfigValue;

													endforeach;
													}										
										
													echo form_dropdown('drpEditFreight', $options,set_value('drpEditFreight'),'id="drpEditFreight"' ,'class="form-control "');

													?>						 
												</div>
					 </div>
					 <div class="col-md-2">
									  <label>Freight Rate </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditFreight','value' => set_value('txtEditFreight'),'id'=>'txtEditFreight',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateFreight(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div>
					 <div class="col-md-2">
									  <label>Freight Amount </label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditAfterFreight','value' => set_value('txtEditAfterFreight'),'id'=>'txtEditAfterFreight',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div> 
					</div> 
					 <div class="col-md-4">
									  <label> Insurance if Any</label>
									  <div class="form-group">
															<?php
													 $data = array('name' => 'txtEditInsurance','value' => set_value('txtEditInsurance'),'id'=>'txtEditInsurance',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);','onchange'=>'calculateEditTotalValue(1);','style'=>'text-align:right;');
													echo form_input($data);
													?>   
												</div>
					</div>
					
					
					</div>
					</div><hr/>
					<div class="row">
					 <div class="col-md-12" >
					 
						<div class="col-md-4" align="right"> <label>Total Order Amount :</label></div>
						<div class="col-md-4">  
							<div class="form-group">
											<?php
									 $data = array('name' => 'txtEditTotalOrderValue','value' => set_value('txtEditTotalOrderValue'),'id'=>'txtEditTotalOrderValue',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
									echo form_input($data);
									?>   
							</div> 
						</div>
					 <div class="col-md-4">
					 		<a class="btn btn-primary EditRevenue"  ID="EditRevenue"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Edit Revenue</span></a>
					<a class="btn btn-primary" data-dismiss="modal"  value="Cancel">Cancel</a>					 
					</div>
					</div> 
					</div>			 				
					</div>
				<br/><br/>				
				<!-- footer for revenue po -->
			<div class="modal-footer">
					
			</div>
			</div>
 		  
		 </div>
		 </form>			 
	</div>	  
	</div>	   
	    </br>           
            <div class="box-body" style="margin-top: -5%;">
              <table id="revenueTax" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
                <thead style="background-color:#ddf">
                <tr>
					<th>SNo</th>
					<th>Requisition No</th>
					<th>Item Name</th>
					<th>Quantity</th>
					<th>UOM</th>
					<th>Rate</th>
					<th>Basic Amount</th>
					 <th>Tax Amount</th>
					<th>Total Order Amount</th>
					<th>Action</th>
                </tr>
                </thead>				
               
             <tbody id='RevenueAppend'>     
     <?php
    if(!empty($POItem))
                    {
						 $index = 0;
						
                        foreach($POItem as $record)
                        {
							$index = $index + 1;
                    ?>
					<tr id="<?php echo $index ; ?>">
					<td align="left"><?php echo $index ; ?></td> 
					<td><?php echo $record->ReqNo ?></td> 
					<td><?php echo $record->MaterialName ?></td> 
					<td align="right"><?php echo $record->Quantity ?></td>   					
					<td><?php echo $record->UOM ?></td>                     
					<td align="right"><?php echo $record->Rate ?></td>                     
					
					<td><?php echo $record->BasicValue ?></td>    
					  
					<td align="right"><?php echo $record->Taxamount ?></td>
					<td align="right"><?php echo $record->TotalValue ?></td>
					 <input type="hidden" name="<?php echo 'Reqnumber'.$index ?>" id="<?php echo 'Reqnumber'.$index ?>" value="<?php echo $record->ReqNo ; ?>" />
					 <input type="hidden" name="<?php echo 'departmentName'.$index ?>" id="<?php echo 'departmentName'.$index ?>" value="<?php echo $record->DepartmentName ; ?>" />
					<input type="hidden" name="<?php echo 'AvilBudget'.$index ?>" id="<?php echo 'AvilBudget'.$index ?>" />					
					<input type="hidden" name="<?php echo 'LineItemNo'.$index ?>" id="<?php echo 'LineItemNo'.$index ?>" value="<?php echo $record->LineItemNo ; ?>" />
 <input type="hidden" name="<?php echo 'costCode'.$index ?>" id="<?php echo 'costCode'.$index ?>" value="<?php echo $record->CostCenterCode ; ?>" />
 <input type="hidden" name="<?php echo 'materialCode'.$index ?>" id="<?php echo 'materialCode'.$index ?>" value="<?php echo $record->MaterialCode ; ?>" />
 <input type="hidden" name="<?php echo 'materialName'.$index ?>" id="<?php echo 'materialName'.$index ?>" value="<?php echo $record->MaterialName ; ?>" />
 <input type="hidden" name="<?php echo 'uom'.$index ?>" id="<?php echo 'uom'.$index ?>" value="<?php echo $record->UOM ; ?>" />
 <input type="hidden" name="<?php echo 'quantity'.$index ?>" id="<?php echo 'quantity'.$index ?>" value="<?php echo $record->Quantity ; ?>" />
 
  <input type="hidden" name="<?php echo 'itemRate'.$index ?>" id="<?php echo 'itemRate'.$index ?>" value="<?php echo $record->Rate ; ?>" />
  
 <input type="hidden" name="<?php echo 'DisType'.$index ?>" id="<?php echo 'DisType'.$index ?>" value="<?php echo $record->DiscountType ; ?>" />
 <input type="hidden" name="<?php echo 'DisVal'.$index ?>" id="<?php echo 'DisVal'.$index ?>" value="<?php echo $record->DiscountValue ; ?>" />
 <input type="hidden" name="<?php echo 'AfterDisVal'.$index ?>" id="<?php echo 'AfterDisVal'.$index ?>" value="<?php echo $record->AfterDiscount ; ?>" />
 <input type="hidden" name="<?php echo 'PackOption'.$index ?>" id="<?php echo 'PackOption'.$index ?>" value="<?php echo $record->PackagingCalulatedOn ; ?>" />
  <input type="hidden" name="<?php echo 'PackType'.$index ?>" id="<?php echo 'PackType'.$index ?>" value="<?php echo $record->PackagingType ; ?>" />
  <input type="hidden" name="<?php echo 'PackVal'.$index ?>" id="<?php echo 'PackVal'.$index ?>" value="<?php echo $record->PackagingValue ; ?>" />
 <input type="hidden" name="<?php echo 'AfterPackVal'.$index ?>" id="<?php echo 'AfterPackVal'.$index ?>" value="<?php echo $record->AfterPackagingValue ; ?>" />
 <input type="hidden" name="<?php echo 'ExciseOption'.$index ?>" id="<?php echo 'ExciseOption'.$index ?>" value="<?php echo $record->ExciseDutyCalulatedOn ; ?>" />
 <input type="hidden" name="<?php echo 'ExciseVal'.$index ?>" id="<?php echo 'ExciseVal'.$index ?>" value="<?php echo $record->ExciseDuty ; ?>" />
  <input type="hidden" name="<?php echo 'AfterExciseVal'.$index ?>" id="<?php echo 'AfterExciseVal'.$index ?>" value="<?php echo $record->AfterExciseDuty ; ?>" />
  <input type="hidden" name="<?php echo 'VatOption'.$index ?>" id="<?php echo 'VatOption'.$index ?>" value="<?php echo $record->VatCalulatedOn ; ?>" />
 <input type="hidden" name="<?php echo 'VatVal'.$index ?>" id="<?php echo 'VatVal'.$index ?>" value="<?php echo $record->Vat ; ?>" />
 <input type="hidden" name="<?php echo 'AfterVatVal'.$index ?>" id="<?php echo 'AfterVatVal'.$index ?>" value="<?php echo $record->AfterVAT ; ?>" />
 <input type="hidden" name="<?php echo 'CSTOption'.$index ?>" id="<?php echo 'CSTOption'.$index ?>" value="<?php echo $record->CSTCalulatedOn ; ?>" />
  <input type="hidden" name="<?php echo 'CSTVal'.$index ?>" id="<?php echo 'CSTVal'.$index ?>" value="<?php echo $record->CST ; ?>" />
  <input type="hidden" name="<?php echo 'AfterCSTVal'.$index ?>" id="<?php echo 'AfterCSTVal'.$index ?>" value="<?php echo $record->AfterCST ; ?>" />
 <input type="hidden" name="<?php echo 'GSTVal'.$index ?>" id="<?php echo 'GSTVal'.$index ?>" value="<?php echo $record->GST ; ?>" />
 <input type="hidden" name="<?php echo 'AfterGSTVal'.$index ?>" id="<?php echo 'AfterGSTVal'.$index ?>" value="<?php echo $record->AfterGST ; ?>" />
 <input type="hidden" name="<?php echo 'OtherTaxVal'.$index ?>" id="<?php echo 'OtherTaxVal'.$index ?>" value="<?php echo $record->OtherTaxes ; ?>" />
  <input type="hidden" name="<?php echo 'AfterOtherTaxVal'.$index ?>" id="<?php echo 'AfterOtherTaxVal'.$index ?>" value="<?php echo $record->AfterOtherTaxes ; ?>" />
  <input type="hidden" name="<?php echo 'FreightType'.$index ?>" id="<?php echo 'FreightType'.$index ?>" value="<?php echo $record->FreightType ; ?>" />
 <input type="hidden" name="<?php echo 'FreightVal'.$index ?>" id="<?php echo 'FreightVal'.$index ?>" value="<?php echo $record->FreightValue ; ?>" />
 <input type="hidden" name="<?php echo 'AfterFreightVal'.$index ?>" id="<?php echo 'AfterFreightVal'.$index ?>" value="<?php echo $record->AfterFreightValue ; ?>" />
  <input type="hidden" name="<?php echo 'basicval'.$index ?>" id="<?php echo 'basicval'.$index ?>"   value="<?php echo $record->BasicValue ; ?>"/> 
  <input type="hidden" name="<?php echo 'Insval'.$index ?>" id="<?php echo 'Insval'.$index ?>" value="<?php echo $record->Insurance ; ?>" />
 <input type="hidden" name="<?php echo 'TotalOrderValue'.$index ?>" id="<?php echo 'TotalOrderValue'.$index ?>" value="<?php echo $record->TotalValue ; ?>" />
                    <?php 
					        
							if($POStatus == PO_DRAFT) 
							{?>					
					<td>    <a    data-target='#EDITREVENUE'	data-id="<?php echo $index ; ?>" data-userid="<?php echo $index ; ?>" data-toggle="modal" href="#EDITREVENUE"><i class="fa fa-pencil" data-toggle="tooltip" title="Click here to view/Edit the  <?php echo $record->ReqNo ; ?> Requisition details"></i>&nbsp;&nbsp;&nbsp;</a> <a href='#' onclick = "DeleteRow(<?php echo $index ; ?>)" class="link" data-id="<?php echo $index ; ?>" data-userid="<?php echo $index ; ?>"  id="Del" ><span class="glyphicon glyphicon-trash"></span></a>
                      <?php
                        } else {?>	
						<td>   <a  	data-toggle="tooltip"  href="#"><i class="fa fa-eye" data-toggle="tooltip" title="<?php echo $record->ReqNo; ?>  -  Click here to view Requistion details"></i>&nbsp;&nbsp;&nbsp;</a>  </td>  
						 <?php  
                        }?>	
                    </tr>
					 <?php
								
								
								$totBasicAmt  = $totBasicAmt + $record->BasicValue;
								$totDiscountAmt  = $totDiscountAmt + $record->AfterDiscount;
								$totPackagingAmt  = $totPackagingAmt + $record->AfterPackagingValue;
								$totExciseAmt  = $totExciseAmt + $record->AfterExciseDuty;
								$totVATAmt  = $totVATAmt + $record->AfterVAT;
								$totCSTAmt  = $totCSTAmt + $record->AfterCST;
								$totGSTAmt  = $totGSTAmt +$record->AfterGST;
								
								$totOtherTaxAmt   = $totOtherTaxAmt + $record->AfterOtherTaxes;
								$totFreightAmt   = $totFreightAmt + $record->AfterFreightValue;
								$totInsuranceAmt   = $totInsuranceAmt + $record->Insurance;
								$totOrderSummaryAmt   = $totOrderSummaryAmt +$record->TotalValue;
								
                        }
						?> <input type="hidden" name="txtRowCount" id="txtRowCount"  value="<?php echo $index;?>">
						<?php 
						   
                    }
                    ?>
			</tbody>
              </table>
            </div>
            <!-- /.box-body -->
         

      
    
	 </div>  

 <div class="container">
 <div class="row" style="border:1px solid;">	 
	<div class="col-md-12">
		<div class="col-md-3">
			  <label >Basic Amount  :</label> 
				 								
							<?php
						 $data = array('name' => 'txtTotBasicAmount','value' => set_value('txtTotBasicAmount',$totBasicAmt),'id'=>'txtTotBasicAmount',  'class' => 'form-control'  ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   
					
				 	
		</div>
		<div class="col-md-3">
			  <label >Total Discount Amount   :</label> 
				 							
							<?php
						 $data = array('name' => 'txtTotalDiscount','value' => set_value('txtTotalDiscount',$totDiscountAmt),'id'=>'txtTotalDiscount',  'class' => 'form-control'   ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3" id="TotVat">
			 <label >Total Vat Amount  :</label> 
				 							
							<?php
						 $data = array('name' => 'txtTotalVat','value' => set_value('txtTotalVat',$totVATAmt),'id'=>'txtTotalVat',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3"  id="TotCST" style="display:none;">
			  <label >Total CST Amount  :</label> 
				 							
							<?php
						 $data = array('name' => 'txtTotCST','value' => set_value('txtTotCST',$totCSTAmt),'id'=>'txtTotCST',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3">
			  <label >Total Packaging Amount  :</label> 
				 								
							<?php
						 $data = array('name' => 'txtTotalPackaing','value' => set_value('txtTotalPackaing',$totPackagingAmt),'id'=>'txtTotalPackaing',  'class' => 'form-control'  ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   				
				 
		</div>
	</div>
	<div class="col-md-12">
		<div class="col-md-3">
			 <label >Total Excise Duty Amount   :</label> 
				 								
							<?php
						 $data = array('name' => 'txtTotExciseDuty','value' => set_value('txtTotExciseDuty',$totExciseAmt),'id'=>'txtTotExciseDuty',  'class' => 'form-control'   ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3">
			  <label >Total GST Rate  :</label> 
				 								
							<?php
						 $data = array('name' => 'txtTotalGST','value' => set_value('txtTotalGST',$totCSTAmt),'id'=>'txtTotalGST',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3">
		  <label >Total Insurance Amount  :</label> 
				 						
							<?php
						 $data = array('name' => 'txtTotalInsurance','value' => set_value('txtTotalInsurance',$totInsuranceAmt),'id'=>'txtTotalInsurance',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
		<div class="col-md-3">
			  <label >Total Freight Amount  :</label> 
				 								
							<?php
						 $data = array('name' => 'txtTotalFreight','value' => set_value('txtTotalFreight',$totFreightAmt),'id'=>'txtTotalFreight',  'class' => 'form-control' ,'readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
				 
		</div>
	</div>
	<div class="col-md-12">
		<div class="col-md-3">
		  <label >Other Taxes Amount  :</label> 
 							<?php
						 $data = array('name' => 'txtTotalOtherTaxes','value' => set_value('txtTotalOtherTaxes',$totOtherTaxAmt),'id'=>'txtTotalOtherTaxes',  'class' => 'form-control','readonly' => 'true','style'=>'text-align:right;');
						echo form_input($data);
						?>   					
 		</div>
		<div class="col-md-3">&nbsp;</div>
		<div class="col-md-3"  align="right"> <br/><label>Total Order Amount   :</label></div><br/>
		<div class="col-md-3">								
					<?php
				 $data = array('name' => 'txtTotalOrderValueSummary','value' => set_value('txtTotalOrderValueSummary',$totOrderSummaryAmt),'id'=>'txtTotalOrderValueSummary',  'class' => 'form-control'  ,'readonly' => 'true','style'=>'text-align:right;');
				echo form_input($data);
				?>   					
		</div> 
	</div>
	<div class="col-md-12">
		<div class="col-md-12">
							<label>Comments for Special Instructions :</label>	<?php
						 $data = array('name' => 'txtSpcialInstruction','value' => set_value('txtSpcialInstruction',$ServiceDescription),'id'=>'txtSpcialInstruction',  'class' => 'form-control','rows' => '3', 'cols' => '40' );
						echo form_textarea($data);
						?>   <input type="hidden" name="SpcialInstruction" id="SpcialInstruction"  value="<?php echo $ServiceDescription;?>"> 
		</div>	 
	</div> 
	<div class="row" style="padding: 2% 0%">
	   <div class="col-md-3 col-md-offset-9"><br/>
	   <input type="hidden" name="txtPoRange" id="txtPoRange" /> 
	    <input type="hidden" name="isEdit" id="isEdit" value="0" /> 
	  <input type="hidden" name="txtStatus" id="txtStatus" /> 
    <input type="hidden" name="txtRowCount" id="txtRowCount" />
   <input type="hidden" name="txtDeletedRow" id="txtDeletedRow" />   
   <input type="hidden" name="txtPONO" id="txtPONO"  value="<?php  echo $PONO; ?>"/> 
	 <?php if($POStatus == PO_DRAFT) {?>   
	<a class="btn btn-primary Save"  ID="Save" onclick="Save(0)" >&nbsp;&nbsp;<span class="bold">Save</span></a> 
	<a class="btn btn-primary Save"  ID="Submit" onclick="Save(1)" >&nbsp;&nbsp;<span class="bold">Submit</span></a> 
    <input type="reset" class="btn btn-primary" value="Reset">
    <?php }else {?>
      <input type="reset" class="btn btn-primary" value = "OK">  <?php } ?>
 
    
   
	   </div><br/>
	   </div>
</div>
</div>
         </div>
       
</div>
<script type="text/html" id="RevenueList">
<tr  id="<%=index%>">
<td align="left"><%=index%></td>
 <td align="left"><%=ReqNo%></td>
 
  <td align="left"><%=MaterialName%></td>
  <td align="left"><%=Quantity%></td> 
  <td align="left"><%=UOM%></td>
   <td align="left"><%=Rate%></td>
    <td align="left"><%=BasicAmount%></td>
	<td align="left"><%=Taxvalue%></td>
	<td align="left"><%=TotalValue%></td>
	
   <td>
                          <a    data-target='#EDITREVENUE'	data-id="<%=index%>" data-userid="<%=index%>" data-toggle="modal" href="#EDITREVENUE"><i class="fa fa-pencil" data-toggle="tooltip" title="Click here to view/Edit the  <%=ReqNo%> Requisition details"></i>&nbsp;&nbsp;&nbsp;</a> <a href='#' onclick = "DeleteRow(<%=index%>)" class="link" data-id="<%=index%>" data-userid="<%=index%>"  id="Del" ><span class="glyphicon glyphicon-trash"></span></a>
						 
						  
                      </td>
</tr>
</script>
<script>
var index     = '1';
var userid  = '';

$("#REVENUE").on("shown.bs.modal", function(e) {
	
	$('#isEdit').val(0);
});
$("#EDITREVENUE").on("shown.bs.modal", function(e) {
	
		userid = $(e.relatedTarget).data('userid');
		$('#isEdit').val(1);
	    //alert(userid);
		var tr= document.getElementById(userid);
		var cellval = tr.cells;
		var id= $('#Reqnumber'+userid).val();
		
		$('#EditReqNo').val($('#Reqnumber'+userid).val());
		$('#EditdeptName').val($('#departmentName'+userid).val());
		$("#EditCostCenter").val($('#costCode'+userid).val());
		$('#EditAvlBudAmt').val($('#AvilBudget'+userid).val());
		//
		
		$('#EditItemName').val($('#materialName'+userid).val());
		$('#EditUOM').val($('#uom'+userid).val());
		$('#EditQuantity').val($('#quantity'+userid).val());
		$('#EditRate').val($('#itemRate'+userid).val());
		$('#txtEditBasicValue').val(cellval[6].innerHTML);
		RequistQuantity = $('#quantity'+userid).val();
		$('#txtEditDiscount').val($('#DisVal'+userid).val());
		$('#txtEditAfterDiscount').val($('#AfterDisVal'+userid).val());
		$('#txtEditVat').val($('#VatVal'+userid).val());
		$('#txtEditAfterVat').val($('#AfterVatVal'+userid).val());
		$('#txtEditCST').val($('#CSTVal'+userid).val());
		$('#txtEditAfterCST').val($('#AfterCSTVal'+userid).val());
		
		$('#txtEditPackaging').val($('#PackVal'+userid).val());
		$('#txtEditAfterPackaging').val($('#AfterPackVal'+userid).val());
		$('#txtEditGST').val($('#GSTVal'+userid).val());
		$('#txtEditAfterGST').val($('#AfterGSTVal'+userid).val());
		$('#txtEditExciseDuty').val($('#ExciseVal'+userid).val()); 
		$('#txtEditAfterExciseDuty').val($('#AfterExciseVal'+userid).val()); 
		$('#txtEditOtherTax').val($('#OtherTaxVal'+userid).val());
		$('#txtEditAfterOtherTax').val($('#AfterOtherTaxVal'+userid).val());
		$('#txtEditFreight').val($('#FreightVal'+userid).val());
		$('#txtEditAfterFreight').val($('#AfterFreightVal'+userid).val());
		$('#txtEditInsurance').val($('#Insval'+userid).val());
		
		$('#txtEditTotalOrderValue').val($('#TotalOrderValue'+userid).val());
		
		
		
		
		$("#EditMaterialCode").empty();
		var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;
		 // For Binding Material list center for the selected Requistion Number	
		$("#EditMaterialCode").append( $('<option></option>').val($('#materialCode'+userid).val()).html($('#materialCode'+userid).val() + "-" + $('#materialName'+userid).val()  ) );
		var isAdded = "0";
		 for(i=0;i<Material.length;i++)
		{
		$.each(Material[i], function(idx, obj) {
			
				if(obj.ReqNo === id )
				{
								   
						$.each(SelectedMaterialList.Mat, function(idx1, el){															
							if (id == el.ReqNo )
							{
								
								if(el.materialCode == obj.MaterialCode)
								{
									
										isAdded  = "1";
										return false;																		
								}
								else
								{
									isAdded  = "0";
								}
								
							}
												
					
					});
					
					
						if(isAdded  == "0")
						{
							
							$("#EditMaterialCode").append( $('<option></option>').val(obj.MaterialCode).html(obj.MaterialCode + "-" + obj.MaterialName));
						}
												
				}
			
			
		});
		}
		
		$("#EditDiscountType").val($('#DisType'+userid).val());
		$("#drpEditFreight").val($('#FreightType'+userid).val());
		$("#EditPackagingType").val($('#PackType'+userid).val())
		
		$("input:radio[name='optPackaging'][value='"+$('#PackOption'+userid).val()+"']").prop('checked', 'checked');
		$("input:radio[name='optExcise'][value='"+$('#ExciseOption'+userid).val()+"']").prop('checked', 'checked');
		$("input:radio[name='optVat'][value='"+$('#VatOption'+userid).val()+"']").prop('checked', 'checked');
		$("input:radio[name='optCST'][value='"+$('#CSTOption'+userid).val()+"']").prop('checked', 'checked');
		
	   
});
$('.AddRevenue').click(function(){
         
      if(validateRevenueTax() && validateExceedLimit())
	  {
		 var temp = index;
		 var Reqnumber = $('#ReqNo').val();
		 var departmentName = $('#deptName').val();
		 var AvilBudget = $('#AvlBudAmt').val();
		 var costCode = $('#CostCenter').val();
         var materialCode =$('#MaterialCode').val();
         var materialName =  $("#ItemName").val();
         var uom = $("#UOM").val();
		 var quantity = $("#Quantity").val();
		 var itemRate = $("#Rate").val();
		  
		  var DisType = $("#DiscountType").val();
		  var DisVal = $("#txtDiscount").val();
		  var AfterDisVal = $("#txtAfterDiscount").val();
		  
		  var PackOption = PackagingCalculation ;
		  var PackType = $("#PackagingType").val();
		  var PackVal = $("#txtPackaging").val();
		  var AfterPackVal = $("#txtAfterPackaging").val();
		  
		  var ExciseOption = ExciseCalculation ;
		  var ExciseVal = $("#txtExciseDuty").val();
		  var AfterExciseVal = $("#txtAfterExciseDuty").val();
		  
		  var VatOption = VatCalculation ;
		  var VatVal = $("#txtVat").val();
		  var AfterVatVal = $("#txtAfterVat").val();
			
		  var CSTOption = CSTCalculation ;
		  var CSTVal = $("#txtCST").val();
		  var AfterCSTVal = $("#txtAfterCST").val();
		  
		  var GSTVal = $("#txtGST").val();
		  var AfterGSTVal = $("#txtAfterGST").val();
		  
		   var OtherTaxVal = $("#txtOtherTax").val();
		  var AfterOtherTaxVal = $("#txtAfterOtherTax").val();
		  
	      var FreightType = $("#drpFreight").val();
		  var FreightVal = $("#txtFreight").val();
		  var AfterFreightVal = $("#txtAfterFreight").val();
		  
		 var basicval = $("#txtBasicValue").val();
		 var Insval = $("#txtInsurance").val();
		 var TotalOrderValue = $("#txtTotalOrderValue").val();
		 
		 var TotalTaxValue = calculateTaxValue();
		 
	    // $('#ReqNo').val(Reqnumber).remove();
		// $('#ReqNo option[value='+Reqnumber+']').remove();
		 $('#MaterialCode option[value='+materialCode+']').remove();
		  SelectedMaterialCode[CollIndex] = materialCode;
			CollIndex = CollIndex + 1;	
			 SelectedMaterialList.Mat.push({ 
        "materialCode" :  materialCode,
        "ReqNo"  : Reqnumber,
      
		});	
			index = parseInt(index)+1;		
		 
	      var template = jQuery("#RevenueList").html();
	   
	     
          $('#RevenueAppend').append(_.template(template,{index:temp,ReqNo:Reqnumber,MaterialName:materialName,Quantity:quantity,UOM:uom,Rate:itemRate,BasicAmount:basicval,Taxvalue:TotalTaxValue,TotalValue:TotalOrderValue}));
		  
		  	clearRevenueModalFields();
		  var theForm = $(".CreatePO");
		
		 addHidden(theForm,"Reqnumber"+temp,Reqnumber );
		 addHidden(theForm,"departmentName"+temp,departmentName );
	     addHidden(theForm,"AvilBudget"+temp,AvilBudget );
		 addHidden(theForm,"costCode"+temp,costCode );		
		  addHidden(theForm,"materialCode"+temp,materialCode );
		 addHidden(theForm,"materialName"+temp,materialName );
	     addHidden(theForm,"uom"+temp,uom);
		 addHidden(theForm,"quantity"+temp,quantity);
		  addHidden(theForm,"itemRate"+temp,itemRate);
		 addHidden(theForm,"DisType"+temp,DisType);
	     addHidden(theForm,"DisVal"+temp,DisVal);
		 addHidden(theForm,"AfterDisVal"+temp,AfterDisVal);
		  addHidden(theForm,"PackOption"+temp,PackOption);
		 addHidden(theForm,"PackType"+temp,PackType);
	     addHidden(theForm,"PackVal"+temp,PackVal);
		 addHidden(theForm,"AfterPackVal"+temp,AfterPackVal);
		  addHidden(theForm,"ExciseOption"+temp,ExciseOption);
		 addHidden(theForm,"ExciseVal"+temp,ExciseVal);
	     addHidden(theForm,"AfterExciseVal"+temp,AfterExciseVal);
		 addHidden(theForm,"VatOption"+temp,VatOption); 
		  addHidden(theForm,"VatVal"+temp,VatVal);
	     addHidden(theForm,"AfterVatVal"+temp,AfterVatVal);
		 addHidden(theForm,"CSTOption"+temp,CSTOption);
		  addHidden(theForm,"CSTVal"+temp,CSTVal);
		 addHidden(theForm,"AfterCSTVal"+temp,AfterCSTVal);
	     addHidden(theForm,"GSTVal"+temp,GSTVal);
		 addHidden(theForm,"AfterGSTVal"+temp,AfterGSTVal);
		  addHidden(theForm,"OtherTaxVal"+temp,OtherTaxVal);
		 addHidden(theForm,"AfterOtherTaxVal"+temp,AfterOtherTaxVal);
	     addHidden(theForm,"FreightType"+temp,FreightType);
		 addHidden(theForm,"FreightVal"+temp,FreightVal);
		 addHidden(theForm,"AfterFreightVal"+temp,AfterFreightVal);
		 addHidden(theForm,"basicval"+temp,basicval);
	     addHidden(theForm,"Insval"+temp,Insval);
		 addHidden(theForm,"TotalOrderValue"+temp,TotalOrderValue);		
		
		 $('#txtRowCount').val(temp); 	
		// $('#REVENUE').modal('hide');	
		  populateValueMainFormForRevenue();
      	  }	  
   
 });
 $('.EditRevenue').click(function(){
         
   		
       if(validateEditRevenueTax() && validateEditExceedLimit())	  
        {
            //alert('inside Add');			
            var CostCode =  $("#EditCostCenter").val();
			 var AvilBudget = $('#EditAvlBudAmt').val();
			var editMaterialCode =  $("#EditMaterialCode").val();
			var editDescription = $("#EditItemName").val();		
			var editUOM = $('#EditUOM').val();
			var editQuantity = $('#EditQuantity').val();
			
			 var itemRate = $("#EditRate").val();
		  
		
		  var DisType = $("#EditDiscountType").val();
		  var DisVal = $("#txtEditDiscount").val();
		  var AfterDisVal = $("#txtEditAfterDiscount").val();
		  
		  var PackOption = PackagingCalculation ;
		  var PackType = $("#EditPackagingType").val();
		  var PackVal = $("#txtEditPackaging").val();
		  var AfterPackVal = $("#txtEditAfterPackaging").val();
		  
		  var ExciseOption = ExciseCalculation ;
		  var ExciseVal = $("#txtEditExciseDuty").val();
		  var AfterExciseVal = $("#txtEditAfterExciseDuty").val();
		  
		  var VatOption = VatCalculation ;
		  var VatVal = $("#txtEditVat").val();
		  var AfterVatVal = $("#txtEditAfterVat").val();
			
		  var CSTOption = CSTCalculation ;
		  var CSTVal = $("#txtCST").val();
		  var AfterCSTVal = $("#txtEditAfterCST").val();
		  
		  var GSTVal = $("#txtEditCST").val();
		  var AfterGSTVal = $("#txtEditAfterCST").val();
		  
		   var OtherTaxVal = $("#txtEditOtherTax").val();
		  var AfterOtherTaxVal = $("#txtEditAfterOtherTax").val();
		  
	      var FreightType = $("#drpEditFreight").val();
		  var FreightVal = $("#txtEditFreight").val();
		  var AfterFreightVal = $("#txtEditAfterFreight").val();
		  
		 var basicval = $("#txtEditBasicValue").val();
		 var Insval = $("#txtEditInsurance").val();
		 var TotalOrderValue = $("#txtEditTotalOrderValue").val();
		 
		  var TotalTaxValue = calculateEditTaxValue();
	
					
		
		 
            var tr= document.getElementById(userid);
			var cellval = tr.cells;   
			
			cellval[2].innerHTML = editDescription;			
			cellval[3].innerHTML = editQuantity;
			cellval[4].innerHTML =editUOM;
			cellval[5].innerHTML =itemRate;
			cellval[6].innerHTML =basicval;
			cellval[7].innerHTML =TotalTaxValue;
			cellval[8].innerHTML =TotalOrderValue;
					
			
			$('#materialCode'+userid).val(editMaterialCode);
			$('#materialName'+userid).val(editDescription);
			$('#uom'+userid).val(editUOM);
			$('#quantity'+userid).val(editQuantity);
            $('#itemRate'+userid).val(itemRate);
			$('#DisType'+userid).val(DisType);
			$('#DisVal'+userid).val(DisVal);
			$('#AfterDisVal'+userid).val(AfterDisVal);	
			$('#PackOption'+userid).val(PackOption);
			$('#PackType'+userid).val(PackType);
			$('#PackVal'+userid).val(PackVal);
			$('#AfterPackVal'+userid).val(AfterPackVal);
			$('#ExciseOption'+userid).val(ExciseOption);
			$('#ExciseVal'+userid).val(ExciseVal);
			$('#AfterExciseVal'+userid).val(AfterExciseVal);
            $('#VatOption'+userid).val(VatOption);
			$('#VatVal'+userid).val(VatVal);
			$('#AfterVatVal'+userid).val(AfterVatVal);
			$('#CSTOption'+userid).val(CSTOption);	
			$('#CSTVal'+userid).val(CSTVal);
			$('#AfterCSTVal'+userid).val(AfterCSTVal);
			$('#GSTVal'+userid).val(GSTVal);
			$('#AfterGSTVal'+userid).val(AfterGSTVal);
			$('#OtherTaxVal'+userid).val(OtherTaxVal);	
			$('#AfterOtherTaxVal'+userid).val(AfterOtherTaxVal);
			$('#FreightType'+userid).val(FreightType);
			$('#FreightVal'+userid).val(FreightVal);	
			$('#AfterFreightVal'+userid).val(AfterFreightVal);	
			$('#basicval'+userid).val(basicval);
			$('#Insval'+userid).val(Insval);
			$('#AvilBudget'+userid).val(AvilBudget);	
			$('#costCode'+userid).val(CostCode);
			$('#TotalOrderValue'+userid).val(TotalOrderValue);	

  				
		  populateValueMainFormForEditRevenueTax();	 
      }
    
 });
 function addHidden(theForm, key, value) {
    // Create a hidden input element, and append it to the form:
    var input = document.createElement('input');
    input.type = 'hidden';
    input.name = key;'name-as-seen-at-the-server';
    input.id = key;'name-as-seen-at-the-server';
    input.value = value;
    theForm.append(input);
}
function populateValueMainFormForRevenue()
{
		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 TotalVal = $('#txtTotalOrderValue').val() == '' ? '0.00' : $('#txtTotalOrderValue').val();
		
		var TotalOrderValueSummary = $('#txtTotalOrderValueSummary').val() == '' ? '0.00' : $('#txtTotalOrderValueSummary').val();
		
		var totBasicAmt = $('#txtTotBasicAmount').val() == '' ? '0.00' : $('#txtTotBasicAmount').val();
		var totDiscountAmt = $('#txtTotalDiscount').val() == '' ? '0.00' : $('#txtTotalDiscount').val();
		var totPackagingAmt = $('#txtTotalPackaing').val() == '' ? '0.00' : $('#txtTotalPackaing').val();
		var totExciseAmt = $('#txtTotExciseDuty').val() == '' ? '0.00' : $('#txtTotExciseDuty').val();
		var totVATAmt = $('#txtTotalVat').val() == '' ? '0.00' : $('#txtTotalVat').val();
		var totCSTAmt = $('#txtTotCST').val() == '' ? '0.00' : $('#txtTotCST').val();
		var totGSTAmt = $('#txtTotalGST').val() == '' ? '0.00' : $('#txtTotalGST').val();
		var totOtherTaxAmt = $('#txtTotalOtherTaxes').val() == '' ? '0.00' : $('#txtTotalOtherTaxes').val();
		var totFreightAmt = $('#txtTotalFreight').val() == '' ? '0.00' : $('#txtTotalFreight').val();
		var totInsuranceAmt = $('#txtTotalInsurance').val() == '' ? '0.00' : $('#txtTotalInsurance').val();
		var totOrderSummaryAmt = $('#txtTotalOrderValueSummary').val() == '' ? '0.00' : $('#txtTotalOrderValueSummary').val();
		
		$('#txtTotBasicAmount').val(parseFloat(totBasicAmt) + parseFloat(BasicVal) );
		$('#txtTotalDiscount').val(parseFloat(totDiscountAmt) + parseFloat(Discount) );
		$('#txtTotalPackaing').val(parseFloat(totPackagingAmt) + parseFloat(Packaging) );
		$('#txtTotExciseDuty').val(parseFloat(totExciseAmt) + parseFloat(ExciseDuty) );
		$('#txtTotalVat').val(parseFloat(totVATAmt) + parseFloat(Vat) );
		$('#txtTotCST').val(parseFloat(totCSTAmt) + parseFloat(CST) );
		$('#txtTotalGST').val(parseFloat(totGSTAmt) + parseFloat(GST) );
		$('#txtTotalOtherTaxes').val(parseFloat(totOtherTaxAmt) + parseFloat(OtherTax) );
		$('#txtTotalFreight').val(parseFloat(totFreightAmt) + parseFloat(Freight) );
		$('#txtTotalInsurance').val(parseFloat(totInsuranceAmt) + parseFloat(Insurance) );
		$('#txtTotalOrderValueSummary').val(parseFloat(totOrderSummaryAmt) + parseFloat(TotalVal) );
		
}
function populateValueMainFormForEditRevenueTax()
{
	  
		var rows =  document.getElementById('revenueTax').rows.length;
        //alert(rows);
		var totBasicAmt = 0;
		var totDiscountAmt = 0;
		var totPackagingAmt = 0;
		var totExciseAmt = 0;
		var totVATAmt = 0;
		var totCSTAmt = 0;
		var totGSTAmt = 0;
		var totOtherTaxAmt = 0;
		var totFreightAmt = 0;
		var totInsuranceAmt = 0;
		var totOrderSummaryAmt = 0;
		var i = 0;
	   do {
		   i += 1;
		    
			 
			 var tr= document.getElementById(i);
			 //alert(tr);
			 if(tr != null)
			 {
			 cells = tr.getElementsByTagName('td');
					
			
		     var rowid = cells[0].innerHTML;
			// alert(rowid);
		var Packaging = $('#AfterPackVal'+rowid).val() == '' ? '0.00' : $('#AfterPackVal'+rowid).val();
		var ExciseDuty = $('#AfterExciseVal'+rowid).val() == '' ? '0.00' : $('#AfterExciseVal'+rowid).val();
		var Vat  = $('#AfterVatVal'+rowid).val() == '' ? '0.00' : $('#AfterVatVal'+rowid).val();
		var CST  =$('#AfterCSTVal'+rowid).val() == '' ? '0.00' : $('#AfterCSTVal'+rowid).val();
	    var GST  = $('#AfterGSTVal'+rowid).val() == '' ? '0.00' : $('#AfterGSTVal'+rowid).val();
		var OtherTax  = $('#AfterOtherTaxVal'+rowid).val() == '' ? '0.00' : $('#AfterOtherTaxVal'+rowid).val();
		var Freight  = $('#AfterFreightVal'+rowid).val() == '' ? '0.00' : $('#AfterFreightVal'+rowid).val();
		var Insurance    = $('#Insval'+rowid).val() == '' ? '0.00' : $('#Insval'+rowid).val();
		var Discount   =$('#AfterDisVal'+rowid).val() == '' ? '0.00' : $('#AfterDisVal'+rowid).val();
	    var BasicVal   = $('#basicval'+rowid).val() == '' ? '0.00' : $('#basicval'+rowid).val();
		var TotalVal =$('#TotalOrderValue'+rowid).val() == '' ? '0.00' : $('#TotalOrderValue'+rowid).val();
		//alert(TotalVal);
		
		
		totBasicAmt  = parseFloat(totBasicAmt ) + parseFloat(BasicVal);
		totDiscountAmt  = parseFloat(totDiscountAmt ) + parseFloat(Discount);
		totPackagingAmt  = parseFloat(totPackagingAmt) + parseFloat(Packaging);
		totExciseAmt  = parseFloat(totExciseAmt) + parseFloat(ExciseDuty);
		totVATAmt  = parseFloat(totVATAmt ) + parseFloat(Vat);
		totCSTAmt  = parseFloat(totCSTAmt ) + parseFloat(CST);
		totGSTAmt  = parseFloat(totGSTAmt ) + parseFloat(GST);
		totOtherTaxAmt  = parseFloat(totOtherTaxAmt ) + parseFloat(OtherTax);
		totFreightAmt  = parseFloat(totFreightAmt ) + parseFloat(Freight);
		totInsuranceAmt  = parseFloat(totInsuranceAmt ) + parseFloat(Insurance);
		totOrderSummaryAmt  = parseFloat(totOrderSummaryAmt ) + parseFloat(TotalVal);
			 }
		
 }		while (i < rows);  
	  		
       alert(totOrderSummaryAmt);
		$('#txtTotBasicAmount').val(parseFloat(totBasicAmt).toFixed(2)  );
		$('#txtTotalDiscount').val(parseFloat(totDiscountAmt).toFixed(2)  );
		$('#txtTotalPackaing').val(parseFloat(totPackagingAmt).toFixed(2)  );
		$('#txtTotExciseDuty').val(parseFloat(totExciseAmt).toFixed(2)  );
		$('#txtTotalVat').val(parseFloat(totVATAmt).toFixed(2)  );
		$('#txtTotCST').val(parseFloat(totCSTAmt).toFixed(2) );
		$('#txtTotalGST').val(parseFloat(totGSTAmt).toFixed(2)  );
		$('#txtTotalOtherTaxes').val(parseFloat(totOtherTaxAmt).toFixed(2) );
		$('#txtTotalFreight').val(parseFloat(totFreightAmt).toFixed(2) );
		$('#txtTotalInsurance').val(parseFloat(totInsuranceAmt).toFixed(2) );
		$('#txtTotalOrderValueSummary').val(parseFloat(totOrderSummaryAmt).toFixed(2)  );
		
}
function clearRevenueModalFields()
{
		// To reset the Modal controls
		$('#ReqNo').val('0'); 	
		$('#deptName').val('');	
		$('#CostCenter').val("0");
		$('#AvlBudAmt').val('');
		$('#MaterialCode').val("0")	;
		$("#ItemName").val('');		
		$('#UOM').val(''); 
		$('#Quantity').val('');       
		$("#Rate").val('');

		$("#DiscountType").val('0');
		$("#txtDiscount").val('');
		$("#txtAfterDiscount").val('');


		$("#PackagingType").val('0');
		$("#txtPackaging").val('');
		$("#txtAfterPackaging").val('');

		$("input:radio[name='optPackaging'][value='0']").prop('checked', 'checked');
		$("input:radio[name='optExcise'][value='0']").prop('checked', 'checked');
		$("input:radio[name='optVat'][value='0']").prop('checked', 'checked');
		$("input:radio[name='optCST'][value='0']").prop('checked', 'checked');

		ExciseOption = '';
		PackOption = '';
		CSTOption = '';
		VatOption = '';
		
		$("#txtExciseDuty").val('');
		$("#txtAfterExciseDuty").val('');


		$("#txtVat").val('');
		$("#txtAfterVat").val('');


		$("#txtCST").val('');
		$("#txtAfterCST").val('');

		$("#txtGST").val('');
		$("#txtAfterGST").val('');

		$("#txtOtherTax").val('');
		$("#txtAfterOtherTax").val('');

		$("#drpFreight").val('0');
		$("#txtFreight").val('');
		$("#txtAfterFreight").val('');

		$("#txtBasicValue").val('');
		$("#txtInsurance").val('');
		$("#txtTotalOrderValue").val('');
}
function validateEditRevenueTax()
 {  
	 if($('#EditCostCenter').val() == "0")
	{
		alert('Please select the Cost center');
		$('#EditCostCenter').focus();
		return false;
	}
	else if($('#EditMaterialCode').val() == "0")
	{
		alert('Please select the Material Code');
		$('#EditMaterialCode').focus();
		return false;
	}		
	else if($('#EditQuantity').val() == '')
	{
		alert('Please Enter the Quantity value');
		$('#EditQuantity').focus();
		return false;
	}
	else if($('#EditRate').val() == '')
	{
		alert('Please Enter the Rate of the Item');
		$('#EditRate').focus();
		return false;
	}
	else
	{
		return true;
	}	
 }
</script>
<script>
function validateBudgetExceedLimit()
 {
	 var rows  = document.getElementById('revenueTax').rows.length;
	 var ReqType = '<?php echo REVENUE ?>';
	 
	  for (i = 1; i < rows; i++) { 
		var costcode = 	$('#costCode'+i).val();
		var basicAmountRate  = 	parseFloat($('#basicval'+i).val());
		var totalAmount =  parseFloat($('#TotalOrderValue'+i).val());
		var avalbudAmt = '';
		$.ajax({ 
			data:{id:costcode},
			type:"POST",
			url:"<?php echo base_url() ?>servicepurchaseorder/AvilBudgetAmount?ReqType="+ReqType, 
			success:function(data) {
			if(data)
			{
				//alert(data);
				avalbudAmt = parseFloat(data);
				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 DeleteRow(rowid)
{
		var id = [];
	   var DelRows  = $('#txtDeletedRow').val();
	  //alertMaterialListrowid);
	   var tr = document.getElementById(rowid);
	  // var cellval = tr.cells;
	   var MaterialCode = $('#materialCode'+rowid).val();
	   var LineItemNo =$('#LineItemNo'+rowid).val();
	   var ReqNo =$('#Reqnumber'+rowid).val();
	   var POType ='<?php echo REVENUE ?>';
		id[0]= LineItemNo;
	    id[1]= ReqNo;
		id[2]= MaterialCode;
		id[3]= POType;
		
	   var answer = confirm(" Do you want to delete the Item from the List?")
		if (answer) 
		{ 			
			
			tr.parentNode.removeChild(tr);
			
			var removeItem = $('#materialCode'+rowid).val();		
		  
		   SelectedMaterialCode.splice( SelectedMaterialCode.indexOf('removeItem'), 1 );
		   $.each(SelectedMaterialList.Mat, function(i, el){
	    
			if (this.materialCode == removeItem){//Type = '';
		          SelectedMaterialList.Mat.splice(i, 1);
		}
		});
		   var x = <?php echo json_encode($POItem, JSON_PRETTY_PRINT) ?>; 
		  
		   var result = '0';
		   $.each(x, function(idx, obj) {
			 
						if(obj.LineItemNo === LineItemNo)
						{			 
						   result = '1';
						   return  false;	
						}
						
					   });
					   
					  // alert(result);
			if(result == '0')
			{
				var DelRows  = $('#txtDeletedRow').val();
				//tr.parentNode.removeChild(tr);
				if(DelRows != '')
					{
					DelRows = DelRows + ":" + rowid;
					}
				else
					{
					DelRows=  "0" + ":" + rowid;
					}
				$('#txtDeletedRow').val(DelRows);
			}
           	// To delete the value from Tables
			else  if(result == '1')
			{
				var DelRows  = $('#txtDeletedRow').val();
				//tr.parentNode.removeChild(tr);
				if(DelRows != '')
					{
					DelRows = DelRows + ":" + rowid;
					}
				else
					{
					DelRows=  "0" + ":" + rowid;
					}
				$('#txtDeletedRow').val(DelRows);				
				
			 $.ajax({ 
			data:{id:id},
			type:"POST",
			url:"<?php echo base_url() ?>purchaseorder/DeletePODetails", 
			success:function(data) {
			if(data)
			{
				$('#content').loader('hide'); 
				alert(data);			
			}
			else
			{
				alert("Error");	
			}			
		
		}});  
			}		   
		
		   populateValueMainFormForDeleteItem(rowid);	
		  
		}
       	
} 
function populateValueMainFormForDeleteItem(rowid)
{
	  
		
       // alert(rows);
		var totBasicAmt = $('#txtTotBasicAmount').val();
		var totDiscountAmt = $('#txtTotalDiscount').val();;
		var totPackagingAmt = $('#txtTotalPackaing').val();;
		var totExciseAmt = $('#txtTotExciseDuty').val();;
		var totVATAmt = $('#txtTotalVat').val();;
		var totCSTAmt = $('#txtTotCST').val();;
		var totGSTAmt = $('#txtTotalGST').val();;
		var totOtherTaxAmt = $('#txtTotalOtherTaxes').val();;
		var totFreightAmt = $('#txtTotalFreight').val();;
		var totInsuranceAmt = $('#txtTotalInsurance').val();;
		var totOrderSummaryAmt = $('#txtTotalOrderValueSummary').val();;
		
	  
			
		var Packaging = $('#AfterPackVal'+rowid).val() == '' ? '0.00' : $('#AfterPackVal'+rowid).val();
		var ExciseDuty = $('#AfterExciseVal'+rowid).val() == '' ? '0.00' : $('#AfterExciseVal'+rowid).val();
		var Vat  = $('#AfterVatVal'+rowid).val() == '' ? '0.00' : $('#AfterVatVal'+rowid).val();
		var CST  =$('#AfterCSTVal'+rowid).val() == '' ? '0.00' : $('#AfterCSTVal'+rowid).val();
	    var GST  = $('#AfterGSTVal'+rowid).val() == '' ? '0.00' : $('#AfterGSTVal'+rowid).val();
		var OtherTax  = $('#AfterOtherTaxVal'+rowid).val() == '' ? '0.00' : $('#AfterOtherTaxVal'+rowid).val();
		var Freight  = $('#AfterFreightVal'+rowid).val() == '' ? '0.00' : $('#AfterFreightVal'+rowid).val();
		var Insurance    = $('#Insval'+rowid).val() == '' ? '0.00' : $('#Insval'+rowid).val();
		var Discount   =$('#AfterDisVal'+rowid).val() == '' ? '0.00' : $('#AfterDisVal'+rowid).val();
	    var BasicVal   = $('#basicval'+rowid).val() == '' ? '0.00' : $('#basicval'+rowid).val();
		var TotalVal =$('#TotalOrderValue'+rowid).val() == '' ? '0.00' : $('#TotalOrderValue'+rowid).val();
		//alert(TotalVal);
		
		
		totBasicAmt  = parseFloat(totBasicAmt ) - parseFloat(BasicVal);
		totDiscountAmt  = parseFloat(totDiscountAmt ) - parseFloat(Discount);
		totPackagingAmt  = parseFloat(totPackagingAmt) - parseFloat(Packaging);
		totExciseAmt  = parseFloat(totExciseAmt) - parseFloat(ExciseDuty);
		totVATAmt  = parseFloat(totVATAmt ) - parseFloat(Vat);
		totCSTAmt  = parseFloat(totCSTAmt ) - parseFloat(CST);
		totGSTAmt  = parseFloat(totGSTAmt ) - parseFloat(GST);
		totOtherTaxAmt  = parseFloat(totOtherTaxAmt ) - parseFloat(OtherTax);
		totFreightAmt  = parseFloat(totFreightAmt ) - parseFloat(Freight);
		totInsuranceAmt  = parseFloat(totInsuranceAmt ) - parseFloat(Insurance);
		totOrderSummaryAmt  = parseFloat(totOrderSummaryAmt ) - parseFloat(TotalVal);
		
		   
				

		$('#txtTotBasicAmount').val(parseFloat(totBasicAmt).toFixed(2)  );
		$('#txtTotalDiscount').val(parseFloat(totDiscountAmt).toFixed(2)  );
		$('#txtTotalPackaing').val(parseFloat(totPackagingAmt).toFixed(2)  );
		$('#txtTotExciseDuty').val(parseFloat(totExciseAmt).toFixed(2)  );
		$('#txtTotalVat').val(parseFloat(totVATAmt).toFixed(2)  );
		$('#txtTotCST').val(parseFloat(totCSTAmt).toFixed(2) );
		$('#txtTotalGST').val(parseFloat(totGSTAmt).toFixed(2)  );
		$('#txtTotalOtherTaxes').val(parseFloat(totOtherTaxAmt).toFixed(2) );
		$('#txtTotalFreight').val(parseFloat(totFreightAmt).toFixed(2) );
		$('#txtTotalInsurance').val(parseFloat(totInsuranceAmt).toFixed(2) );
		$('#txtTotalOrderValueSummary').val(parseFloat(totOrderSummaryAmt).toFixed(2)  );
		
}
function Save(status)
{  
if(status == '0')
{
	stat = '<?php echo PO_DRAFT; ?>';
}
else
{
	stat = '<?php echo PO_CREATED; ?>';
}
var splinstr = $('#txtSpcialInstruction').val();
var deladd = $('#DeliveryAddr').val();
$('#txtStatus').val(stat);


$('#SpcialInstruction').val(splinstr);
$('#txtDeliveryAddress').val(deladd);


	if(validate())
		{ 	
		if(document.getElementById('revenueTax').rows.length < 2)
			{
				alert('Please Select Line item to Create PO');
				$('#Deliverydt').focus();
				return false;
			}
			else if(validateBudgetExceedLimit())
			{
				return false;
			}
			else
			{
			$('#content').loader('show');
		  $.ajax({ 
			data:$('.CreatePO').serialize(),
			type:"POST",
			url:"<?php echo base_url() ?>purchaseorder/EditRevenuePurchaseOrder", 
			success:function(data) {
			if(data)
			{
				$('#content').loader('hide'); 
				alert(data);
				$('#txtRowCount').val('');
				$('#txtDeletedRow').val('');
				$('#txtStatus').val('');
				$('#SpcialInstruction').val('');
				$('#txtDeliveryAddress').val('')
				window.location =	"purchaseorderListing";
			
			}
			else
			{
				$('#content').loader('hide'); 
				alert("Error");	
			}			
		
		}
  
});
			}

}
}
<!-- script for table , It works uned the datatable plugin-->
 $(function () {
   //$("#revenueTax").DataTable();
    $('#revenueTax').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": false,
      //"ordering": true,
     // "info": true,
      "autoWidth": true
	   
    }); 
  });
</script>