<?php $ReqType =''; ?>
<?php $ReqType ='';
$CompanyAddress = '';
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$CurrentDate =  $dt->format('Y-m-d');
$MaxPoDate = '';
if(!empty($MaxPODate))
{
    foreach ($MaxPODate as $date)
    {
        $MaxPoDate = $date->PODate;
    }
}
if(!empty($CompanyDetails))
{
    foreach ($CompanyDetails as $Req)
    {
        $CompanyAddress = $Req->Address;
    }
}
?>
<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;
    }
    .form-control
    {
        text-align:left;
    }

</style>
<script type="text/html" id="ServiceList">
    <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='#EDITSERVICE'	data-id="<%=index%>" data-userid="<%=index%>" data-toggle="modal" href="#EDITSERVICE"><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 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';

    $(function() {


        $("#PODate").datepicker({
            minDate : 'now',
            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'
        });


var SelectedMaterialList = {
    Mat: []
};

        /* $('#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").empty();
         $("#MaterialCode").empty();
         resetTaxField();
         if(id != '0')
         {
         var y = <?php echo json_encode($RequistionDetails, JSON_PRETTY_PRINT) ?>;
         var cost = <?php echo json_encode($CostList, JSON_PRETTY_PRINT) ?>;
         var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;

         // For Binding DepartmentName
         $.each(y, function(idx, obj) {
         if(obj.ReqNo === id)
         {
         $("#deptName").val(obj.DepartmentName);

         }
         });
         // For Binding Cost center for the selected department
         $("#CostCenter").append( $('<option></option>').val("0").html("Select Cost Center") );
         $.each(cost, function(idx, obj) {
         if(obj.ReqNo === id)
         {
         $("#CostCenter").append( $('<option></option>').val(obj.CostCenterCode).html(obj.CostCenterCode + "-" + obj.CostCenterName) );

         }

         });
         // For Binding Material list center for the selected Requistion Number
         $("#MaterialCode").append( $('<option></option>').val("0").html("Select Material Code") );
         $.each(Material, function(idx, obj) {
         if(obj.ReqNo === id)
         {
         $("#MaterialCode").append( $('<option></option>').val(obj.MaterialCode).html(obj.MaterialCode + "-" + obj.MaterialName) );

         }

         });

         }
         else
         {
         alert('Please select the Requisition Number');
         return false;
         }

         });
         $('#MaterialCode').change(function() {

         var id = $('#MaterialCode').val();
         RequistQuantity = '';
         resetTaxField();
         if(id != '0')
         {
         var y = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;


         $.each(y, 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;
         }

         });

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

         var id = $('#CostCenter').val();
         $("#AvlBudAmt").val('');

         if(id != '0')
         {
         var cost = <?php echo json_encode($CostList, JSON_PRETTY_PRINT) ?>;

         $.each(cost, function(idx, obj) {
         if(obj.CostCenterCode === id)
         {
         $("#AvlBudAmt").val(obj.BudgetAmount);
         }

         });
         }
         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('');
            }

        });

        $('#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' );
                }
            }

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

            if(ExciseCalculation == '')
            {
                $('#ExciseDutyCalModel').modal('show');
            }

        });
        $('#txtVat').change(function() {

           /* if(VatCalculation == '')
            {
                $('#VatCalModel').modal('show');
            }
            */

        });
        $('#txtCST').change(function() {

            if(CSTCalculation == '')
            {
                $('#CSTCalModel').modal('hide');
            }

        });
        $('#drpFreight').change(function() {


            selValue = $("#drpFreight").val() ;

            if (selValue == NilType)
            {

                $('#txtFreight').attr('readonly', 'true');
                $('#txtFreight').val('0.00');

            }
            else
            {
                $('#txtFreight').removeAttr( 'readonly','true' );
                $('#txtFreight').val('');


            }

        });
    });

   /*
 * To calcuate the Discount  */
function calculateDiscount(isEdit)
 {  
	if(isEdit == '0')
	{
     if($('#MaterialCode').val() == "0")
	 {
		 alert('Please Select the Material Code');
		$('#MaterialCode').focus();
		 $('#txtDiscount').val('');
		return false;
	 }
	 else if($('#Rate').val() == '')
	 {
		  alert('Please Enter the Rate value');
		  $('#Rate').focus();
		  $('#txtDiscount').val('');
		  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");	 
	}
	}
	calculateVat(0);
	calculateCST(0);
		calculateTotalValue();	
	}
	else
	{
			if($('#EditRevenueMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditRevenueMaterialCode').focus();
				$('#txtEditDiscount').val('');
				return false;
			 }
			 else if($('#EditRevenueRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRevenueRate').focus();
				  $('#txtEditDiscount').val('');
				  return false;
			 }
			if($('#EditRevenueRate').val() != '' && $('#EditRevenueMaterialCode').val() != "0" )
			{
			
			 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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");	 
			}
			}
          calculateEditVatValue();
				calculateEditTotalValue();	
	}
 }
   /*
 * To calcuate the Packaging  */
function calculatePackaging(isEdit)
 {
	if(isEdit == '0')
	{ 
			  if($('#MaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#MaterialCode').focus();
				$('#txtPackaging').val('');
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  $('#txtPackaging').val('');
				  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"); 
			 }
		   }
		   calculateVat(0);
	calculateCST(0);
		   calculateTotalValue();	
	}
	else
	{
		 if($('#EditRevenueMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditRevenueMaterialCode').focus();
				$('#txtEditPackaging').val('');
				return false;
			 }
			 else if($('#EditRevenueRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRate').focus();
				  $('#txtEditPackaging').val('');
				  return false;
			 }
			 
			 else
			 {
			 
			 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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"); 
			 }
		   }
		   calculateEditVatValue();
		   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"); 
		 }
		
	 } 
	 calculateVat(0);
	calculateCST(0);
	    calculateTotalValue();	
	}
	else
	{
		if($('#EditRevenueMaterialCode').val() == "0")
	 {
		 alert('Please Select the Material Code');
		$('#EditRevenueMaterialCode').focus();
		return false;
	 }
	 else if($('#EditRevenueRate').val() == '')
	 {
		  alert('Please Enter the Rate value');
		  $('#EditRevenueRate').focus();
		  return false;
	 }
	 
	 else
	 {
		 
		 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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"); 
		 }
		
	 } 
	 calculateEditVatValue();
	 calculateEditTotalValue();	
	}
	 
 }

   function calculateVat(isEdit)
 {
	 if(isEdit == '0')
	{ 
		if($('#MaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#MaterialCode').focus();
			$('#txtVat').val('');
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
		 	
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  $('#txtVat').val('');
			  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());

			var discountValue = parseFloat($('#txtAfterDiscount').val());
             var packageValue = parseFloat($('#txtAfterPackaging').val());
							AfterVat = <?php echo VAT_ONEXICSEVALUE; ?>;
							
							var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
							$('#txtAfterVat').val(Vatval); 
						}
			 }
			 else if(VatCalculation == 0 && $('#txtVat').val() != '')
			 {
			 	
			 	var ExciseDuty = parseFloat($('#txtAfterExciseDuty').val()); 
					vatValue = parseFloat($('#txtVat').val());
					
			var discountValue = parseFloat($('#txtAfterDiscount').val());
             var packageValue = parseFloat($('#txtAfterPackaging').val());
            
					AfterVat =  <?php echo VAT_ONEXICSEVALUE; ?>;
				
					
					var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
					$('#txtAfterVat').val(Vatval); 
			 }				
			 
			 else
			 {
			 	
				 $('#txtAfterVat').val("0.00"); 
			 }
			 
		  	calculateTotalValue();		
		 } 
		 
	}
	else
	{
		if($('#EditRevenueMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditRevenueMaterialCode').focus();
			$('#txtEditVat').val('');
			return false;
		 }
		 else if($('#EditRevenueRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRevenueRate').focus();
			  $('#txtEditVat').val('');
			  return false;
		 }	 
		 
		 else
		 {
			 var basicValue = parseFloat($('#txtEditRevenueBasicValue').val());
			
			 var discountValue = parseFloat($('#txtEditAfterDiscount').val());
			  var packageValue = parseFloat($('#txtEditAfterPackaging').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() != '')
			 {
			 	var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val()); 
					vatValue = parseFloat($('#txtEditVat').val());
					AfterVat =  <?php echo VAT_ONEXICSEVALUE; ?>;
					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();
				 $('#txtCST').val('');
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  $('#txtCST').val('');
				  return false;
			 }	 
			 
			 else
			 {
				 var basicValue = parseFloat($('#txtBasicValue').val());
				 var discountValue = parseFloat($('#txtAfterDiscount').val());
             var packageValue = parseFloat($('#txtAfterPackaging').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_ONEXICSEVALUE; ?>;
							
							var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
							$('#txtAfterCST').val(Vatval); 
						}
			 }
			 else if(CSTCalculation == 0 && $('#txtCST').val() != '')
			 {
			 	
              var ExciseDuty = parseFloat($('#txtAfterExciseDuty').val()); 
					var CSTValue= parseFloat($('#txtCST').val()); 
					
					AfterCST =  <?php echo CST_ONEXICSEVALUE; ?>;
					var Vatval =  parseFloat(AfterCST).toFixed(2);
		
					$('#txtAfterCST').val(Vatval); 
			 }				
			 
			 else
			 {
				 $('#txtAfterCST').val("0.00"); 
			 }				
				calculateTotalValue();
			 }
		
		}
		else
		{
			if($('#EditRevenueMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditRevenueMaterialCode').focus();
				$('#txtEditCST').val('');
				return false;
			 }
			 else if($('#EditRevenueRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRevenueRate').focus();
				  $('#txtEditCST').val('');
				  return false;
			 }	 
			 
			 else
			 {
				 
				 var basicValue = parseFloat($('#txtEditRevenueBasicValue').val());
				  var discountValue = parseFloat($('#txtEditAfterDiscount').val());
			  var packageValue = parseFloat($('#txtEditAfterPackaging').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_ONEXICSEVALUE; ?>;
							var Vatval =  parseFloat(AfterCST).toFixed(2);
		 
							$('#txtEditAfterCST').val(Vatval); 
						}
			 }
			 else if(CSTCalculation == 0 && $('#txtEditCST').val() != '')
			 {
			 	var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val()); 
				 var CSTValue= parseFloat($('#txtEditCST').val()); 
					AfterCST =  <?php echo CST_ONEXICSEVALUE; ?>;
					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();
				$('#txtGST').val('');
				return false;
			 }
			 else if($('#Rate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#Rate').focus();
				  $('#txtGST').val('');
				  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($('#EditRevenueMaterialCode').val() == "0")
			 {
				 alert('Please Select the Material Code');
				$('#EditRevenueMaterialCode').focus();
				$('#txtEditGST').val('');
				return false;
			 }
			 else if($('#EditRevenueRate').val() == '')
			 {
				  alert('Please Enter the Rate value');
				  $('#EditRevenueRate').focus();
				  $('#txtEditGST').val('');
				  return false;
			 }		
			 else
			 {
				 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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();
			$('#txtOtherTax').val('');
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  $('#txtOtherTax').val('');
			  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($('#EditRevenueMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditRevenueMaterialCode').focus();
			$('#txtEditOtherTax').val('');
			return false;
		 }
		 else if($('#EditRevenueRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRevenueRate').focus();
			  $('#txtEditOtherTax').val('');
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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();
			$('#txtFreight').val('') ;
			return false;
		 }
		 else if($('#Rate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#Rate').focus();
			  $('#txtFreight').val('') ;
			  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;?>;		  	  
				}
				else {
				AfterFreight = $("#txtFreight").val();
				}	
				var AfterFreightval =  parseFloat(AfterFreight).toFixed(2);
		 
				$('#txtAfterFreight').val(AfterFreightval); 
			 }
			 else
			 {
				$('#txtAfterFreight').val("0.00");  
			 }
			
		 } 
		 calculateTotalValue();	
	}
	else
	{
		if($('#EditRevenueMaterialCode').val() == "0")
		 {
			 alert('Please Select the Material Code');
			$('#EditRevenueMaterialCode').focus();
			$('#txtEditFreight').val('');
			return false;
		 }
		 else if($('#EditRevenueRate').val() == '')
		 {
			  alert('Please Enter the Rate value');
			  $('#EditRevenueRate').focus();
			  $('#txtEditFreight').val('');
			  return false;
		 }		
		 else
		 {
			 var basicValue = parseFloat($('#txtEditRevenueBasicValue').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($('#EditRevenueUOM').val());
				var Quantity          = parseFloat($('#EditRevenueQuantity').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;?>;		  	  
				}
				else {
				AfterFreight = $("#txtEditFreight").val();
				}		
				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');
    }
    /* 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 Editchange(){
  	var isEdit=1;
	 // ExceedEditQuantityCheck();	  
	 if($('#EditRevenueQuantity').val() != '' && $('#EditRevenueRate').val() != '')
	 {	  
		  var txtQuantity = parseFloat( $('#EditRevenueQuantity').val());
		  var txtUnitPrice = parseFloat($('#EditRevenueRate').val());
		  var Tot =  txtQuantity * txtUnitPrice
		  $('#txtEditRevenueBasicValue').val(Tot);
		  calculateDiscount(isEdit);
	calculatePackaging(isEdit);
	calculateExcise(isEdit);
	calculateCST(isEdit);
	calculateGST(isEdit);
	calculateOtherTaxes(isEdit);
	calculateFreight(isEdit)
		  calculateEditVatValue();
		  calculateEditTotalValue();
 
	}
	
}
 function change(){
  	var isEdit=0;
	 // ExceedEditQuantityCheck();	  
	 if($('#Quantity').val() != '' && $('#Rate').val() != '')
	 {	  
		  var txtQuantity = parseFloat( $('#Quantity').val());
		  var txtUnitPrice = parseFloat($('#Rate').val());
		  var Tot =  txtQuantity * txtUnitPrice
		  $('#txtBasicValue').val(Tot);

		  if ($("#DiscountType").val()!=0) {
		  	  calculateDiscount(isEdit);
		  }
		  if ($("#PackagingType").val()!=0) {
		  	calculatePackaging(isEdit);
		  }
		
	if($("#txtVat").val()!=''){
		calculateVat(isEdit);
	}
	if($("#txtCST").val()!=''){
		
		calculateCST(isEdit);
	}
		if($("#txtExciseDuty").val()!=''){
		calculateExcise(isEdit);
		
	}
	if($("#txtGST").val()!=''){
		calculateGST(isEdit);
		
	}
	if($("#txtOtherTax").val()!=''){
		calculateOtherTaxes(isEdit);
		
	}
	
	if($("#drpFreight").val()!=0){
		calculateFreight(isEdit);
		
	}
	
	
	
	
	
		  
		  calculateTotalValue($('#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 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 = $('#txtEditRevenueBasicValue').val() == '' ? '0.00' : $('#txtEditRevenueBasicValue').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);
	    		
	 $('#txtEditRevenueTotalOrderValue').val(tot);
	 validateEditExceedLimit();
 }
 // calculate vat rate
   
    function calculateEditVatValue()
 {
	  var basicValue = parseFloat($('#txtEditRevenueBasicValue').val());
			
			 var discountValue = parseFloat($('#txtEditAfterDiscount').val());
			  var packageValue = parseFloat($('#txtEditAfterPackaging').val());
			 
			 
							var ExciseDuty = parseFloat($('#txtEditAfterExciseDuty').val()); 
							vatValue = parseFloat($('#txtEditVat').val());
							AfterVat = <?php echo VAT_ONEXICSEVALUE; ?>;
							var Vatval =  parseFloat(AfterVat).toFixed(2);
		 
							$('#txtEditAfterVat').val(Vatval); 
	 
	 
 }
    // 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 showmodel() {
        

        var input = document.getElementById('purpose').value;
        var avaBud=document.getElementById('AvalBuget').value;
        var getLocal = document.getElementById('Local').value;
               StateTaxCheck = $("input:radio[name='Range']:checked").val();
              
       // $('#txtPoRange').val(StateTaxCheck) ;
        //alert('Radio clicke:'+StateTaxCheck);
      
        if (input == -1)
        {
            alert ("Select Request Type");
        }
        else if(avaBud==''){
        alert ("Select Cost Center Name");
        }
        else
        {
            $("#" + input  ).modal('show');
            $('#isEdit').val(0);
              if(StateTaxCheck == "0")
        {
            // style="display:none;"
          //  $('#Vat').removeAttr("style");
           // $('#TotVat').removeAttr("style");
          //  $('#CST').attr("style","display:none;");
         //   $('#TotCST').attr("style","display:none;");
         $('#Vat').show();
         $('#CST').hide();

        }
        else
        {
          //  $('#CST').removeAttr("style");
          //  $('#TotCST').removeAttr("style");
           // $('#Vat').attr("style","display:none;");
           // $('#TotVat').attr("style","display:none;");
            $('#Vat').hide();
         $('#CST').show();

        }
        }
    }
    $(document).ready(function(){

        //Initialize Select2 Elements
        $("#purpose").select2();
        $("#DepartmentName").select2();
        $("#CostCenterName").select2();
    });
    function DeleteRevenueRow(rowid)
{
	   var DelRows  = $('#txtDeletedRow1').val();
	 
	  //alertMaterialListrowid);
	   
	   var answer = confirm(" Do you want to delete the Item from the List?")
		if (answer) 
		{ 			
			var td = document.getElementById(rowid);
			td.parentNode.removeChild(td);
			 var materialCode = $('#materialCode'+rowid).val();
			var removeItem = $('#materialCode'+rowid).val();      
		
	
        //This function is used to add material list after delete           
      $.each(JSON.parse(materialData), function (index, value) {
      	if (value.MaterialCode==materialCode) {
      		                                    $("#MaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );
      	}
      	});

 SelectedMaterialCode.splice( SelectedMaterialCode.indexOf('removeItem'), 1 );
		 
		
		  if(DelRows != '')
		  {
		  DelRows = DelRows + ":" + rowid;
		  }
		  else
		  {
			  DelRows=  "0" + ":" + rowid;
		  }
		
		 $('#txtDeletedRow1').val(DelRows);
		 populateValueMainFormForDeleteItem(rowid);
		  
		}
       	
} 

function populateValueMainFormForDeleteItem(rowid)
{
	  
		
       // alert(rows);
		var totBasicAmt = $('#txtTotBasicAmountRevenue').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);
		
		   
				

		$('#txtTotBasicAmountRevenue').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)  );
		
}
</script>
<div class="content-wrapper">
    <?php
    $attributes = array('class' => 'form-label-left CreatealterPO ','name'  => 'CreatealterPO','id'  => 'CreatealterPO');

    echo form_open($this->config->base_url().'/purchaseorder/addalterPO/',$attributes); ?>

    <section class="content">
        <div id="content"></div>
        <div>
            <center><b><h2>Siddharth Industries - Emergency Purchase Order</h2></b></center></div>
        <div class="container-fluid">

            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-3">
                            <label>Request Type </label>
                            <?php
                            $options = array("-1"=>'Select Request Type');

                            if(!empty($RequestType))
                            {
                                foreach ($RequestType as $RID):


                                    $options[$RID->ConfigValue] =  $RID->ConfigValue;

                                endforeach;
                            }

                            echo form_dropdown('RequestType', $options,set_value('ConfigValue'),'id="purpose"' ,'class = "form-control select2"','required="true"');

                            ?>

                        </div>
                        <div class="col-md-3">
                            <label>Purchase Order Date</label>
                            <div class="form-group">
                                <?php
                                $data = array('name' => 'PODate','value' => set_value('PODate'),'id'=>'PODate',  'class' => 'form-control' ,'required' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <label>Purchase Order Type</label>
                            <div class="form-group">

                                <?php
                                $data = array('name' => 'POType','value' => set_value('POType',$ReqType),'id'=>'POType',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                       

							<div class="col-md-3">

                            <b><u>Select Delivery By</u></b><br/>
                            <tr>
                                <td>
                                    <?php echo form_label('Date', 'Date') ."&nbsp;&nbsp;". form_radio(array("name"=>"DateRange", "id"=>"Date", "value"=>"0", 'checked'=>set_radio('DateRange', '0', TRUE))); ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <td>
                                    <?php echo form_label('Schedule', 'Schedule') ."&nbsp;&nbsp;". form_radio(array("name"=>"DateRange", "id"=>"Schedule", "value"=>"1", 'checked'=>set_radio('DateRange', '1', FALSE))); ?>

                                </td>
                            </tr>
                        </div>


                    </div>
					<div class="row">
                        <div class="col-md-3">
                            <label>Supplier</label>
                            <div >
                                <?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'),'id="drpSupplier"'  ,'required="true"' ,'class="form-control select2"');

                                ?>
                            </div>
                        </div>

                        <div class="col-md-3">
                            <label>Address</label>
                            <div class="form-group">
                                <?php
                                $data = array('name' => 'SupAddress','value' => set_value('SupAddress'),'id'=>'SupAddress',  'class' => 'form-control' ,'readonly' => 'true' ,'rows' => '3', 'cols' => '40');
                                echo Form_textarea($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <label>Delivery Address</label>
                            <div class="form-group">
                                <?php
                                $data = array('name' => 'DeliveryAddr','value' => set_value('DeliveryAddr',$CompanyAddress),'id'=>'DeliveryAddr',  'class' => 'form-control' ,'required' => 'true' ,'rows' => '3', 'cols' => '40');
                                echo Form_textarea($data);
                                ?>

                            </div>
                        </div>
						  <div class="col-md-3">
 
								 <div class="col-md-12" id="Schedulediv" style="display:none;">
                                <label >Schedule :</label>
                                 
								<?php
                                $data = array('name' => 'Scheduleby','value' => set_value('Scheduleby'),'id'=>'Scheduleby',  'class' => 'form-control' ,'required' => 'true' ,'rows' => '3', 'cols' => '40');
                                echo Form_textarea($data);
                                ?>

                            </div>
						 <div class="col-md-12" id="Deliverydtdiv">
                            <label>Delivery Date</label>
                             
                                <?php
                                $data = array('name' => 'Deliverydt','value' => set_value('Deliverydt'),'id'=>'Deliverydt',  'class' => 'form-control'  ,'required' => 'true');
                                echo form_input($data);
                                ?>
                             
                        </div>

                        </div>
                       
                    </div>
                    <div class="row">
                        <div class="col-md-3">
                            <label>Department Name</label>
                            <div >
                                <?php
                                $options = array("0"=>'Select Department Name');

                                if(!empty($DeptList))
                                {
                                    foreach ($DeptList as $DID):


                                        $options[$DID->DEPCode] =  $DID->DEPCode.' '.' - '.' '.$DID->DepartmentName;

                                    endforeach;
                                }

                                echo form_dropdown('drpDepartment', $options,set_value('drpDepartment'),'id="DepartmentName"' ,'class = "form-control select2"','required="true"');

                                ?>
 
                            </div>
                        </div>
                        <div class="col-md-3">
                            <label>Cost Center Name</label>
                            <div >
                                <?php
                                $options = array("0"=>'Cost Center Name');
                                //print_r(  $options);

                                if(!empty($POType))
                                {
                                    foreach ($SupplierName as $SID):


                                        $options[$SID->SupplierID] =  $SID->SupplierID.' '.' - '.' '.$SID->SupplierName;

                                    endforeach;
                                }

                                echo form_dropdown('CostCenterName', $options,set_value('CostCenterName'),'id="CostCenterName"','class="form-control select2"' , 'required="true"' ,'multiple="true"');

                                ?>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <label>Available Buget</label><img id="AlertImg"  src="<?php echo base_url(); ?>assets/dist/img/red.png" alt="your image" width="25px"  style="display:none;"/>
                            <div class="form-group">
                                <?php
                                $data = array('name' => 'AvalBuget','value' => set_value('AvalBuget'),'id'=>'AvalBuget',  'class' => 'form-control' ,'required' => 'true' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
					
						 <div class="col-md-3" style='display:none;' id='txtPoRange'>

                            <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))); ?>&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))); ?>

                                </td>
                            </tr>


                        </div>
						 <div class="col-md-3" id="currencyexchange" style='display:none;'>
                            <div class="col-md-6">
                                <label>Currency Type</label>
                                 
                                    <?php
                                    $data = array('name' => 'txtcurrencytype','value' => set_value('txtcurrencytype'),'id'=>'txtcurrencytype',  'class' => 'form-control' ,'required' => 'true');
                                    echo form_input($data);
                                    ?>
                                 
                            </div>
                            <div class="col-md-6">
                                <label>Exchange Rate</label>
                                 
                                    <?php
                                    $data = array('name' => 'txtexachangerate','value' => set_value('txtexachangerate'),'id'=>'txtexachangerate',  'class' => 'form-control' ,'required' => 'true');
                                    echo form_input($data);
                                    ?>
                                 
                            </div>
                            <div class="col-md-12">
                                <a href="http://www.xe.com/" target="_blank"><u>To check Today's Foreign Exchange value</u></a>
                            </div>
                        </div>
                           
                        
                    </div>
                </div>
				<div class="col-md-12">
					<div  class="col-md-1 col-md-offset-11" align="right" >
                            <a data-toggle="modal"  onclick="showmodel();" class=" btn btn-primary"> Add Line Item  </a>
                        </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>
            <!-- Edit Modal content-->
            <div class="modal fade" id="EDITSERVICE" role="dialog">
                <div class="modal-dialog">
                    <!-- Modal content-->
                    <form>
                        <div class="modal-content" style="width:900px;">
                            <div class="modal-header" style="background-color: #3c8dbc;color:#fff;">
                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                <center><h4>Edit Service Purchase Order Item </h4></center>
                            </div>
                            <div align="left">

                                <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-3">
                                        <label>Available Budget Amount</label><img id="AlertImg"  src="<?php echo base_url(); ?>assets/dist/img/red.png" alt="your image" width="25px"  style="display:none;"/>
                                        <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');
                                            //print_r(  $options);

                                            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'=>'EditRatechange()');
                                            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'=>'EditRatechange()' );
                                            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');
                                            echo form_input($data);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-12" style="border:1px solid">
                                    <br/>
                                    <div class="col-md-12">
                                        <div class="col-md-5  col-md-offset-4" align="right">

                                            Service Tax @14% :
                                        </div>

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

                                        </div>

                                    </div>
                                    <div class="col-md-12">
                                        <div class="col-md-5 col-md-offset-4" align="right">
                                            Edu. cess @2% on service Tax 	:

                                        </div>

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

                                        </div>

                                    </div>
                                    <div class="col-md-12">

                                        <div class="col-md-5 col-md-offset-4" align="right">
                                            Sec. & Higher Edu. cess @1 % on service Tax  :

                                        </div>

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

                                        </div>
                                    </div>
                                    <div class="col-md-12">

                                        <div class="col-md-5 col-md-offset-4" align="right">
                                            Krishi Kalyan tax  @.5 % on Basic Amount:

                                        </div>

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

                                        </div>
                                    </div>
                                    <div class="col-md-12">

                                        <div class="col-md-5 col-md-offset-4" align="right">
                                            Swachh Bharat tax @.5 % on Basic Amount:

                                        </div>

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

                                        </div>
                                    </div>

                                    <div class="col-md-12">
                                        <div class="col-md-5 col-md-offset-4" align="right">
                                            Total Order value :
                                        </div>
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <?php
                                                $data = array('name' => 'EditTotalOrderValue','value' => set_value('EditTotalOrderValue'),'id'=>'EditTotalOrderValue',  'class' => 'form-control' ,'readonly' => 'true');
                                                echo form_input($data);
                                                ?>
                                            </div>
                                        </div>
                                    </div>

                                </div>


                                <br/>
                                <br/>
                                <div class="modal-footer">
                                    <a class="btn btn-primary font EditService"  ID="Edit"  style="margin-top: -24px;">&nbsp;&nbsp;<span class="bold">Update Service</span></a>
                                    <a class="btn btn-primary" data-dismiss="modal" style="margin-top: -24px;" value="Cancel">Cancel</a>

                                </div>
                            </div>
                    </form>

                </div>
            </div>
        </div>
        
           
	 

            <div class="container-fluid">
                <table class="table table-bordered" style="border:1px solid #333">
                    <div align="right" style="padding-right:10px">

                        <!-- 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-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 id="CST">
                                                            <div class="col-md-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>

                        <!-- Model for service PO -->
                        <div class="modal fade" id="SERVICE" role="dialog">
                            <div class="modal-dialog">
                                <!-- Modal content-->
                                <form>
                                    <div class="modal-content" style="width:900px;">
                                        <div class="modal-header" style="background-color: #3c8dbc;color:#fff;">
                                            <center><h4>Add Service Purchase Order Item </h4></center>
                                        </div>
                                        <div align="left">

                                            <div class="col-md-12">
                                                <div class="col-md-2">
                                                    <label>Item Code</label>
                                                    <div>
                                                        <?php
                                                        $options = array("0"=>'Item Code');
                                                        //print_r(  $options);

                                                        if(!empty($MaterialList))
                                                        {
                                                            foreach ($MaterialList as $SID):


                                                                $options[$SID->MaterialCode] =  $SID->MaterialCode.' '.' - '.' '.$SID->MaterialName;

                                                            endforeach;
                                                        }

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

                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-2">
                                                    <label>Item Name</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ServiceDescription','value' => set_value('ServiceDescription'),'id'=>'ServiceDescription',  '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' => 'ServiceUOM','value' => set_value('ServiceUOM'),'id'=>'ServiceUOM',  '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' => 'ServiceQuantity','value' => set_value('ServiceQuantity'),'id'=>'ServiceQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Rate</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ServiceRate','value' => set_value('ServiceRate'),'id'=>'ServiceRate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);' ,'onchange'=>'Ratechange()');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Basic Amount</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ServiceBasAmt','value' => set_value('ServiceBasAmt'),'id'=>'ServiceBasAmt',  'class' => 'form-control' ,'readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="col-md-12">
                                                <div class="col-md-4" align="right">

                                                    
                                                    </div>
                                                    <div class="col-md-4" align="right">

                                                        Service Tax @14% :
                                                    </div>
                                                   
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <?php
                                                            $data = array('name' => 'AfterServiceTax','value' => set_value('AfterServiceTax'),'id'=>'AfterServiceTax',  'class' => 'form-control' ,'placeholder' => 'After  Service Tax','readonly' => 'true');
                                                            echo form_input($data);
                                                            ?>
                                                        </div>

                                                    </div>

                                                </div>
                                                <div class="col-md-12">
                                                  <div class="col-md-4" align="right">

                                                    
                                                    </div>
                                                    <div class="col-md-4" align="right">
                                                        Edu. cess @2% on service Tax 	:

                                                    </div>
                                                  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <?php
                                                            $data = array('name' => 'AfterEduCess','value' => set_value('AfterEduCess'),'id'=>'AfterEduCess',  'class' => 'form-control' ,'placeholder' => 'After Edu.','readonly' => 'true');
                                                            echo form_input($data);
                                                            ?>
                                                        </div>

                                                    </div>

                                                </div>
                                                <div class="col-md-12">
                                                  <div class="col-md-4" align="right">

                                                    
                                                    </div>

                                                    <div class="col-md-4" align="right">
                                                        Sec. & Higher Edu. cess @1 % on service Tax  :

                                                    </div>
                                                  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <?php
                                                            $data = array('name' => 'AfterSecHighTax','value' => set_value('AfterSecHighTax'),'id'=>'AfterSecHighTax',  'class' => 'form-control' ,'placeholder' => 'After High Edu.','required' => 'true','readonly' => 'true');
                                                            echo form_input($data);
                                                            ?>
                                                        </div>

                                                    </div>
                                                </div>
                                                <div class="col-md-12">
                                                  <div class="col-md-4" align="right">

                                                    
                                                    </div>

                                                    <div class="col-md-4" align="right">
                                                        Krishi Kalyan tax  :

                                                    </div>
                                                  
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <?php
                                                            $data = array('name' => 'AfterKrishiTax','value' => set_value('AfterKrishiTax'),'id'=>'AfterKrishiTax',  'class' => 'form-control' ,'placeholder' => 'After Krishi Kalyan tax.','required' => 'true','readonly' => 'true');
                                                            echo form_input($data);
                                                            ?>

                                                        </div>

                                                    </div>
                                                </div>
                                                <div class="col-md-12">
                                                  <div class="col-md-4" align="right">

                                                    
                                                    </div>

                                                    <div class="col-md-4" align="right">
                                                        Swachh Bharat tax  :

                                                    </div>
                                                   
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <?php
                                                            $data = array('name' => 'AfterSwachhTax','value' => set_value('AfterSwachhTax'),'id'=>'AfterSwachhTax',  'class' => 'form-control' ,'placeholder' => 'After High Edu.','readonly' => 'true');
                                                            echo form_input($data);
                                                            ?>
                                                        </div>

                                                    </div>
                                                </div>
                                                
                                                <div class="col-md-6 col-md-offset-6" >
                                                    <label>Total Order value</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'TotalOrderValue','value' => set_value('TotalOrderValue'),'id'=>'TotalOrderValue',  'class' => 'form-control' ,'placeholder' => 'Total value','readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                        <br/>
                                        <div class="modal-footer">
                                            <a class="btn btn-info font AddService"  ID="AddService"  style="margin-top: -1%;"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add Service</span></a>
                                            <a class="btn btn-info" data-dismiss="modal" style="margin-top: -1%;" value="Cancel">Cancel</a>

                                        </div>
                                    </div>
                                </form>

                            </div>
                        </div>


                        <!-- model for import PO -->

                        <div class="modal fade" id="IMPORT" role="dialog">
                            <div class="modal-dialog">
                                <!-- Modal content-->
                                <form>
                                    <div class="modal-content" style="width:900px;">
                                        <div class="modal-header" style="background-color: #3c8dbc;color:#fff;">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <center><h4>Add Import Purchase Order Item </h4></center>
                                        </div>
                                        <div align="left">

                                            <div class="col-md-12">
                                                <div class="col-md-3">
                                                    <label>Req No</label>
                                                    <div>
                                                        <?php
                                                        $options = array("0"=>'Req No');
                                                        echo form_dropdown('ImportMaterialCode', $options,set_value('ImportMaterialCode'),'id="ImportMaterialCode"' ,'class="form-control required"');

                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-3">
                                                    <label>Department Name</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ImportDepartmentName','value' => set_value('ImportDepartmentName'),'id'=>'ImportDepartmentName',  '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
                                                        $options = array("0"=>'Select Cost Center');

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

                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <label>Available Budget Amount</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'importbudAmt','value' => set_value('importbudAmt'),'id'=>'importbudAmt',  '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');

                                                        if(!empty($MaterialList))
                                                        {
                                                            foreach ($MaterialList as $SID):


                                                                $options[$SID->MaterialCode] =  $SID->MaterialCode.' '.' - '.' '.$SID->MaterialName;

                                                            endforeach;
                                                        }

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

                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-2">
                                                    <label>Item Name</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ImportItemName','value' => set_value('ImportItemName'),'id'=>'ImportItemName',  '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' => 'ImUOM','value' => set_value('ImUOM'),'id'=>'ImUOM',  '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' => 'imQuantity','value' => set_value('imQuantity'),'id'=>'imQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Rate </label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imRate','value' => set_value('imRate'),'id'=>'imRate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);' );
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Basic Amount	</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imTotalAmount','value' => set_value('imTotalAmount'),'id'=>'imTotalAmount',  'class' => 'form-control'  ,'readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">

                                                <div class="col-md-3">

                                                    Basic Price in US $ per Ton :


                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imBasicPrice','value' => set_value('imBasicPrice'),'id'=>'imBasicPrice',  'class' => 'form-control' ,'placeholder '=>'basic price','onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-3">

                                                    Exchange Rate :


                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ExchangeRt','value' => set_value('ExchangeRt'),'id'=>'ExchangeRt',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>

                                                </div>

                                                <div class="col-md-3">

                                                    Basic value in INR :



                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'INRBasicvalue','value' => set_value('INRBasicvalue'),'id'=>'INRBasicvalue',  'class' => 'form-control' ,'readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <!--<div class="col-md-3">
                                             <a href="http://www.xe.com/" target="_blank"><u>Click nere to check Today's Foreign Exchange value</u></a>
                                     </div>-->

                                                <div class="col-md-12"  style="border:1px solid #000;padding:0px;">
                                                    <br/>
                                                    <div class="col-md-6" style="padding:0px;">
                                                        <div class="col-md-12">
                                                            <div class="col-md-4" >
                                                                Basic Price:
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'BasicPriceTax','value' => set_value('BasicPriceTax'),'id'=>'BasicPriceTax',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterBasicPriceTax','value' => set_value('AfterBasicPriceTax'),'id'=>'AfterBasicPriceTax',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Landing charge
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'LandingCharge','value' => set_value('LandingCharge'),'id'=>'LandingCharge',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterLandingCharge','value' => set_value('AfterLandingCharge'),'id'=>'AfterLandingCharge',  'class' => 'form-control'  ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                High seas sales charge
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Highseas ','value' => set_value('Highseas'),'id'=>'Highseas',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterHighseas','value' => set_value('AfterHighseas'),'id'=>'AfterHighseas',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom duty : (a)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Customduty','value' => set_value('Customduty'),'id'=>'Customduty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomduty','value' => set_value('AfterCustomduty'),'id'=>'AfterCustomduty',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty : (b)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutyTax','value' => set_value('ExcisedutyTax'),'id'=>'ExcisedutyTax',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutyTax','value' => set_value('AfterExcisedutyTax'),'id'=>'AfterExcisedutyTax',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty ED_cess : (C)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutyEDcess','value' => set_value('ExcisedutyEDcess'),'id'=>'ExcisedutyEDcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutyEDcess','value' => set_value('AfterExcisedutyEDcess'),'id'=>'AfterExcisedutyEDcess',  'class' => 'form-control','readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty S & H cess :(d)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutySHcess','value' => set_value('ExcisedutySHcess'),'id'=>'ExcisedutySHcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutySHcess','value' => set_value('AfterExcisedutySHcess'),'id'=>'AfterExcisedutySHcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom ED_cess : (e)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomEDcess','value' => set_value('CustomEDcess'),'id'=>'CustomEDcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomEDcess','value' => set_value('AfterCustomEDcess'),'id'=>'AfterCustomEDcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom S & H cess : (f)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomSHcess','value' => set_value('CustomSHcess'),'id'=>'CustomSHcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomSHcess','value' => set_value('AfterCustomSHcess'),'id'=>'AfterCustomSHcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6" style="padding:0px;">
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Additional Excise duty : (g)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AdditionalExciseduty ','value' => set_value('AdditionalExciseduty'),'id'=>'AdditionalExciseduty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterAdditionalExciseduty','value' => set_value('AfterAdditionalExciseduty'),'id'=>'AfterAdditionalExciseduty',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-8">
                                                                Gross duty payable
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Grossdutypayable ','value' => set_value('Grossdutypayable'),'id'=>'Grossdutypayable',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-8">
                                                                Available Modvat set-off on import :
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AvailableModvat','value' => set_value('AvailableModvat'),'id'=>'AvailableModvat',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>   (b + c + d + g)
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">

                                                            <div class="col-md-8">
                                                                Gross expenses due to custom duty:
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Grossexpenses','value' => set_value('Grossexpenses'),'id'=>'Grossexpenses',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="col-md-12">
                                                            <center> <label>Cost of the product Per KG</label></center>
                                                            <hr/>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                purchase rate [Basic]
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'purchaserate','value' => set_value('purchaserate'),'id'=>'purchaserate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4"  style="margin-top: -4.8%">
                                                                <span>Quantity</span>
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'PurQuantity','value' => set_value('PurQuantity'),'id'=>'PurQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">

                                                            <div class="col-md-4">
                                                                Custom Duty Expenses
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomDutyExpenses ','value' => set_value('CustomDutyExpenses'),'id'=>'CustomDutyExpenses',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                RMC Including Customers
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'RMCIncludingCustomers','value' => set_value('RMCIncludingCustomers'),'id'=>'RMCIncludingCustomers',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>


                                                        </div>


                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="modal-footer">
                                            <a class="btn btn-info font AddImport"  ID="AddImport"  ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add Import</span></a>
                                            <a class="btn btn-info" data-dismiss="modal"  value="Cancel">Cancel</a>

                                        </div>
                                    </div>
                                </form>

                            </div>
                        </div>

                        <!-- Model for Capital PO -->
                        <div class="modal fade" id="CAPITAL" role="dialog">
                            <div class="modal-dialog">
                                <!-- Modal content-->
                                <form>
                                    <div class="modal-content" style="width:900px;">
                                        <div class="modal-header" style="background-color: #3c8dbc;color:#fff;">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <center><h4>Add Capital Purchase Order Item </h4></center>
                                        </div>
                                        <div align="left">

                                            <div class="col-md-12">
                                                <div class="col-md-2">
                                                    <label>Item Code</label>
                                                    <div>
                                                        <?php
                                                        $options = array("0"=>'Item Code');

                                                        if(!empty($MaterialList))
                                                        {
                                                            foreach ($MaterialList as $SID):


                                                                $options[$SID->MaterialCode] =  $SID->MaterialCode.' '.' - '.' '.$SID->MaterialName;

                                                            endforeach;
                                                        }

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

                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-2">
                                                    <label>Item Name</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ImportItemName','value' => set_value('ImportItemName'),'id'=>'ImportItemName',  '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' => 'ImUOM','value' => set_value('ImUOM'),'id'=>'ImUOM',  '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' => 'imQuantity','value' => set_value('imQuantity'),'id'=>'imQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Rate </label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imRate','value' => set_value('imRate'),'id'=>'imRate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);' );
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Basic Amount	</label>
                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imTotalAmount','value' => set_value('imTotalAmount'),'id'=>'imTotalAmount',  'class' => 'form-control'  ,'readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">

                                                <div class="col-md-3">

                                                    Basic Price in US $ per Ton :


                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'imBasicPrice','value' => set_value('imBasicPrice'),'id'=>'imBasicPrice',  'class' => 'form-control' ,'placeholder '=>'basic price','onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>

                                                <div class="col-md-3">

                                                    Exchange Rate :


                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'ExchangeRt','value' => set_value('ExchangeRt'),'id'=>'ExchangeRt',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>

                                                </div>

                                                <div class="col-md-3">

                                                    Basic value in INR :



                                                    <div class="form-group">
                                                        <?php
                                                        $data = array('name' => 'INRBasicvalue','value' => set_value('INRBasicvalue'),'id'=>'INRBasicvalue',  'class' => 'form-control' ,'readonly' => 'true');
                                                        echo form_input($data);
                                                        ?>
                                                    </div>
                                                </div>
                                                <!--<div class="col-md-3">
                                             <a href="http://www.xe.com/" target="_blank"><u>Click nere to check Today's Foreign Exchange value</u></a>
                                     </div>-->

                                                <div class="col-md-12"  style="border:1px solid #000;padding:0px;">
                                                    <br/>
                                                    <div class="col-md-6" style="padding:0px;">
                                                        <div class="col-md-12">
                                                            <div class="col-md-4" >
                                                                Basic Price:
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'BasicPriceTax','value' => set_value('BasicPriceTax'),'id'=>'BasicPriceTax',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterBasicPriceTax','value' => set_value('AfterBasicPriceTax'),'id'=>'AfterBasicPriceTax',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Landing charge
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'LandingCharge','value' => set_value('LandingCharge'),'id'=>'LandingCharge',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterLandingCharge','value' => set_value('AfterLandingCharge'),'id'=>'AfterLandingCharge',  'class' => 'form-control'  ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                High seas sales charge
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Highseas ','value' => set_value('Highseas'),'id'=>'Highseas',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterHighseas','value' => set_value('AfterHighseas'),'id'=>'AfterHighseas',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom duty : (a)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Customduty','value' => set_value('Customduty'),'id'=>'Customduty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomduty','value' => set_value('AfterCustomduty'),'id'=>'AfterCustomduty',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty : (b)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutyTax','value' => set_value('ExcisedutyTax'),'id'=>'ExcisedutyTax',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutyTax','value' => set_value('AfterExcisedutyTax'),'id'=>'AfterExcisedutyTax',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty ED_cess : (C)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutyEDcess','value' => set_value('ExcisedutyEDcess'),'id'=>'ExcisedutyEDcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutyEDcess','value' => set_value('AfterExcisedutyEDcess'),'id'=>'AfterExcisedutyEDcess',  'class' => 'form-control','readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Excise duty S & H cess :(d)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'ExcisedutySHcess','value' => set_value('ExcisedutySHcess'),'id'=>'ExcisedutySHcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterExcisedutySHcess','value' => set_value('AfterExcisedutySHcess'),'id'=>'AfterExcisedutySHcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom ED_cess : (e)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomEDcess','value' => set_value('CustomEDcess'),'id'=>'CustomEDcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomEDcess','value' => set_value('AfterCustomEDcess'),'id'=>'AfterCustomEDcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Custom S & H cess : (f)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomSHcess','value' => set_value('CustomSHcess'),'id'=>'CustomSHcess',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterCustomSHcess','value' => set_value('AfterCustomSHcess'),'id'=>'AfterCustomSHcess',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6" style="padding:0px;">
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                Additional Excise duty : (g)
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AdditionalExciseduty ','value' => set_value('AdditionalExciseduty'),'id'=>'AdditionalExciseduty',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AfterAdditionalExciseduty','value' => set_value('AfterAdditionalExciseduty'),'id'=>'AfterAdditionalExciseduty',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-8">
                                                                Gross duty payable
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Grossdutypayable ','value' => set_value('Grossdutypayable'),'id'=>'Grossdutypayable',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-8">
                                                                Available Modvat set-off on import :
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'AvailableModvat','value' => set_value('AvailableModvat'),'id'=>'AvailableModvat',  'class' => 'form-control' ,'readonly' => 'true');
                                                                    echo form_input($data);
                                                                    ?>   (b + c + d + g)
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">

                                                            <div class="col-md-8">
                                                                Gross expenses due to custom duty:
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'Grossexpenses','value' => set_value('Grossexpenses'),'id'=>'Grossexpenses',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="col-md-12">
                                                            <center> <label>Cost of the product Per KG</label></center>
                                                            <hr/>
                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                purchase rate [Basic]
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'purchaserate','value' => set_value('purchaserate'),'id'=>'purchaserate',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4"  style="margin-top: -4.8%">
                                                                <span>Quantity</span>
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'PurQuantity','value' => set_value('PurQuantity'),'id'=>'PurQuantity',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">

                                                            <div class="col-md-4">
                                                                Custom Duty Expenses
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'CustomDutyExpenses ','value' => set_value('CustomDutyExpenses'),'id'=>'CustomDutyExpenses',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-md-12">
                                                            <div class="col-md-4">
                                                                RMC Including Customers
                                                            </div>
                                                            <div class="col-md-4">
                                                                <div class="form-group">
                                                                    <?php
                                                                    $data = array('name' => 'RMCIncludingCustomers','value' => set_value('RMCIncludingCustomers'),'id'=>'RMCIncludingCustomers',  'class' => 'form-control' ,'onkeypress'=>'return isNumberKey(event);');
                                                                    echo form_input($data);
                                                                    ?>
                                                                </div>
                                                            </div>


                                                        </div>


                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="modal-footer">
                                            <a class="btn btn-info font AddImport"  ID="AddImport"  ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add Capital</span></a>
                                            <a class="btn btn-info" data-dismiss="modal"  value="Cancel">Cancel</a>

                                        </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' => 'EditRevenueReqNo','value' => set_value('EditReqNo'),'id'=>'EditRevenueReqNo',  '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' => 'EditRevenuedeptName','value' => set_value('EditdeptName'),'id'=>'EditRevenuedeptName',  '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' => 'EditRevenueCostCenter','value' => set_value('EditCostCenter'),'id'=>'EditRevenueCostCenter',  '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' => 'EditRevenueAvlBudAmt','value' => set_value('EditAvlBudAmt'),'id'=>'EditRevenueAvlBudAmt',  '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('EditRevenueMaterialCode', $options,set_value('EditMaterialCode'),'id="EditRevenueMaterialCode"' ,'class="form-control"');

											?>						 
										</div>
						   </div>
						  
							 <div class="col-md-2">
							  <label>Item Name</label>
										<div class="form-group">
													<?php
											 $data = array('name' => 'EditRevenueItemName','value' => set_value('EditItemName'),'id'=>'EditRevenueItemName',  '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' => 'EditRevenueUOM','value' => set_value('EditUOM'),'id'=>'EditRevenueUOM',  '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' => 'EditRevenueQuantity','value' => set_value('EditQuantity'),'id'=>'EditRevenueQuantity',  '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' => 'EditRevenueRate','value' => set_value('EditRate'),'id'=>'EditRevenueRate',  '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' => 'txtEditRevenueBasicValue','value' => set_value('txtEditBasicValue'),'id'=>'txtEditRevenueBasicValue',  '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="EditVat" >
					 <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="EditCST">
					 <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' => 'txtEditRevenueTotalOrderValue','value' => set_value('txtEditTotalOrderValue'),'id'=>'txtEditRevenueTotalOrderValue',  '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>


                        <div class="box-body" style="margin-top:-5%;">
                            <table id="serviceTax" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px">
                                <thead>
                                <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="ServiceAppend">

                                </tbody>
                                 <tbody id="RevenueAppend">

                                </tbody>

                            </table>
                        </div>
                       
                        <!-- /.box-body -->

   

                        
                    </div>
                </table>
                <div class="row">
                    <!-- Revenue po taxes -->
                    <div class="col-md-12"  style='border : 1px solid; display:none;' id="revenuepotaxes">
                        <br/>
                        <div class="col-md-12">
                            <div class="col-md-3">
                                <label >Basic Amount  :</label>
                                <?php
                                $data = array('name' => 'txtTotBasicAmountRevenue','value' => set_value('txtTotBasicAmountRevenue'),'id'=>'txtTotBasicAmountRevenue',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>

                            </div>
                            <div class="col-md-3">
                                <label >Total Discount   :</label>
                                <?php
                                $data = array('name' => 'txtTotalDiscount','value' => set_value('txtTotalDiscount'),'id'=>'txtTotalDiscount',  'class' => 'form-control'   ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>

                            <div class="col-md-3" id="TotVat">
                                <label >Total Vat   :</label>
                                <?php
                                $data = array('name' => 'txtTotalVat','value' => set_value('txtTotalVat'),'id'=>'txtTotalVat',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-3" id="TotCST" style="display:none;">
                                <label >Total CST   :</label>
                                <?php
                                $data = array('name' => 'txtTotCST','value' => set_value('txtTotCST'),'id'=>'txtTotCST',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>

                            </div>
                            <div class="col-md-3">
                                <label >Total Excise Duty   :</label>
                                <?php
                                $data = array('name' => 'txtTotExciseDuty','value' => set_value('txtTotExciseDuty'),'id'=>'txtTotExciseDuty',  'class' => 'form-control'   ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="col-md-3">
                                <label >Total GST   :</label>
                                <?php
                                $data = array('name' => 'txtTotalGST','value' => set_value('txtTotalGST'),'id'=>'txtTotalGST',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>

                            <div class="col-md-3">
                                <label >Total Packaging   :</label>
                                <?php
                                $data = array('name' => 'txtTotalPackaing','value' => set_value('txtTotalPackaing'),'id'=>'txtTotalPackaing',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>

                            <div class="col-md-3">
                                <label >Total Insurance   :</label>
                                <?php
                                $data = array('name' => 'txtTotalInsurance','value' => set_value('txtTotalInsurance'),'id'=>'txtTotalInsurance',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-3">
                                <label >Other Taxes   :</label>
                                <?php
                                $data = array('name' => 'txtTotalOtherTaxes','value' => set_value('txtTotalOtherTaxes'),'id'=>'txtTotalOtherTaxes',  'class' => 'form-control','readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-12">

                            <div class="col-md-3">
                                <label >Total Freight   :</label>
                                <?php
                                $data = array('name' => 'txtTotalFreight','value' => set_value('txtTotalFreight'),'id'=>'txtTotalFreight',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            
                            <div class="col-md-3">
                                <label >Total Order Value   :</label>
                                <?php
                                $data = array('name' => 'txtTotalOrderValueSummary','value' => set_value('txtTotalOrderValueSummary'),'id'=>'txtTotalOrderValueSummary',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
						<div class="col-md-12">
                        <div class="col-md-12">
                            <label>Comments Of Special Instructions :</label>
                            <?php
                            $data = array('name' => 'txtSpcialInstruction','value' => set_value('txtSpcialInstruction'),'id'=>'txtSpcialInstruction',  'class' => 'form-control','rows' => '4', 'cols' => '40' );
                            echo form_textarea($data);
                            ?>
                        </div>
						</div>
                        <div class="col-md-12">
                            <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="txtStatus1" id="txtStatus1" />
                                <input type="hidden" name="txtRowCount1" id="txtRowCount1" />
                                <input type="hidden" name="txtDeletedRow1" id="txtDeletedRow1" />
                                <input type="hidden" name="CheckLocalInter" id="CheckLocalInter" />
                              <!-- <a class="btn btn-primary Save"  ID="Save" onclick="Save()" >&nbsp;&nbsp;<span class="bold">Save</span></a> -->

                                <a class="btn btn-primary Submit"  ID="Submit" onclick="RevenueSave(1)" >&nbsp;&nbsp;<span class="bold">Submit</span></a>
                                    <input type="reset" class="btn btn-primary">
                               
                                
                            </div>
                        </div>
                    </div>

                    <!-- Service po taxes need to work-->
                    <div class="col-md-12  " style='border : 1px solid; display:none;' id="servicepotaxes">
                        <div class="col-md-12">
                            <div class="col-md-4">
                                <label>Basic Amount  :</label>
                                <?php
                                $data = array('name' => 'txtTotBasicAmount','value' => set_value('txtTotBasicAmount'),'id'=>'txtTotBasicAmount',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-4">
                                <label>Total Service Tax @14%   :</label>
                                <?php
                                $data = array('name' => 'txtTotalServiceTax','value' => set_value('txtTotalServiceTax'),'id'=>'txtTotalServiceTax',  'class' => 'form-control'   ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-4">
                                <label >Total Edu. cess @2% on service Tax  :</label>
                                <?php
                                $data = array('name' => 'txtTotalEducess','value' => set_value('txtTotalEducess'),'id'=>'txtTotalEducess',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="col-md-4">
                                <label >Total Sec. & Higher Edu. cess @1 % on service Tax   :</label>
                                <?php
                                $data = array('name' => 'txtTotHigherEdu','value' => set_value('txtTotHigherEdu'),'id'=>'txtTotHigherEdu',  'class' => 'form-control' ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-4">
                                <label >Total Krishi Kalyan tax  @.5 % on Basic Amount  :</label>
                                <?php
                                $data = array('name' => 'txtTotalKrishiKalyan','value' => set_value('txtTotalKrishiKalyan'),'id'=>'txtTotalKrishiKalyan',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                            <div class="col-md-4">
                                <label >Total Swachh Bharat tax  @.5 % on Basic Amount:</label>
                                <?php
                                $data = array('name' => 'txtTotSwachhBharat','value' => set_value('txtTotSwachhBharat'),'id'=>'txtTotSwachhBharat',  'class' => 'form-control'   ,'readonly' => 'true');
                                echo form_input($data);
                                ?>
                            </div>
                        </div>
                        <div class="col-md-6 col-md-offset-6">
                            <br/>
                            <div class="col-md-6" align="right"> <label >Total Order Value   :</label></div>
                            <div class="col-md-6">
                                <?php
                                $data = array('name' => 'txtTotalOrderValueSummaryService','value' => set_value('txtTotalOrderValueSummaryService'),'id'=>'txtTotalOrderValueSummaryService',  'class' => 'form-control'  ,'readonly' => 'true');
                                echo form_input($data);
                                ?>

                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="col-md-12">
                                <label>Comments Of Special Instructions :</label>	<?php
                                $data = array('name' => 'txtSpcialInstruction','value' => set_value('txtSpcialInstruction'),'id'=>'txtSpcialInstruction',  'class' => 'form-control' ,'rows' => '4', 'cols' => '40' );
                                echo form_textarea($data); ?>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="row">
                                <br/>
                                <div align="right" style="padding-right:10px">
                                    <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="SpcialInstruction" id="SpcialInstruction" >
                                    <input type="hidden" name="txtDeliveryAddress" id="txtDeliveryAddress" >
                                     
                                    <a class="btn btn-primary Submit"  ID="Submit" onclick="Save(1)" >&nbsp;&nbsp;<span class="bold">Submit</span></a>
                                    <input type="reset" class="btn btn-primary">
                                </div><br/>
                            </div>
                        </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 = "DeleteRevenueRow(<%=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  = '';
            $('.AddRevenue').click(function(){
            
                if(validateRevenueTax() && validateExceedLimit())
                {
               	
                	
                    var temp = index;
                    var Reqnumber = $('#purpose').val();
                    var departmentName = $('#DepartmentName').val();
                    var AvilBudget = $('#AvalBuget').val();
                    var costCode = $('#CostCenterName').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 CheckLocalInter = $("input:radio[name='Range']:checked").val();
                 

                    var TotalTaxValue = AfterOtherTaxVal;

                    // $('#ReqNo').val(Reqnumber).remove();
                    // $('#ReqNo option[value='+Reqnumber+']').remove();
                    $('#MaterialCode option[value='+materialCode+']').remove();
                  

                    populateValueMainFormForRevenue();



                    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 = $(".CreatealterPO");

                    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);
                     addHidden(theForm,"CheckLocalInter"+temp,CheckLocalInter);

                    $('#txtRowCount1').val(temp);
                    
                    // $('#REVENUE').modal('hide');

                }

            });
            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 = $('#txtTotBasicAmountRevenue').val() == '' ? '0.00' : $('#txtTotBasicAmountRevenue').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();
                $('#txtTotBasicAmountRevenue').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 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('');


                $("#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('');
            }
        </script>
        <script>
            var SelectedMaterialCode = [];
            var CollIndex = 0;
            function Save()
            {
                $('#txtStatus').val('<?php echo PO_DRAFT;?>');
                if(validate())
                {
                    $('#content').loader('show');
                    $.ajax({
                        data:$('.CreatePO').serialize(),
                        type:"POST",
                        url:"<?php echo base_url() ?>purchaseorder/addNewPurchaseOrder",
                        success:function(data) {
                            if(data)
                            {
                                $('#content').loader('hide');
                                alert(data);
                                //$('#txtRowCount').val('');
                                //$('#txtDeletedRow').val('');

                                //window.location =	"Requisition";

                            }
                            else
                            {
                                alert("Error");
                            }

                        }

                    });

                }
            }

            $(function () {

                $('#TaxesTabel').DataTable({
                    "paging": false,
                    "lengthChange": false,
                    "searching": false,
                    "ordering": false,
                    "info": false,
                    "autoWidth": false
                });
            });
            $(document).ready(function(){
                $('#purpose').on('change', function() {
                    if ( this.value == 'REVENUE') //Revenue po
                    {
                        $("#txtPoRange").show();
                        $("#revenuepotaxes").show();
                        $("#currencyexchange").hide();
                        $("#servicepotaxes").hide();
                    }
                    else if ( this.value == 'SERVICE') // Service po
                    {
                        $("#servicepotaxes").show();
                        $("#currencyexchange").hide();
                        $("#txtPoRange").hide();
                        $("#revenuepotaxes").hide();
                    }
                    else if ( this.value == 'IMPORT') // Import pop
                    {
                        $("#currencyexchange").show();
                        $("#txtPoRange").hide();
                        $("#revenuepotaxes").hide();
                        $("#servicepotaxes").hide();
                    }
                    else if ( this.value == 'CAPITAL') // Capital po
                    {
                        $("#currencyexchange").show();
                        $("#txtPoRange").hide();
                        $("#revenuepotaxes").hide();
                        $("#servicepotaxes").hide();
                    }
                    else // Default
                    {
                        $("#currencyexchange").hide();
                        $("#txtPoRange").hide();
                        $("#revenuepotaxes").hide();
                        $("#servicepotaxes").hide();
                    }
                });
            });
            $(document).ready(function () {
                $('#Local').click(function () {
                    //for local tax range selection
                    $('#TotCST').hide();
                    $('#TotVat').show();
                });
                $('#Inter_state').click(function () {
                    //for inter state tax range selection
                    $('#TotVat').hide();
                    $('#TotCST').show();
                });
            });
			$(document).ready(function () {
                $('#Date').click(function () {
                    //for Date range selection
                    $('#Schedulediv').hide();
                    $('#Deliverydtdiv').show();
                });
                $('#Schedule').click(function () {
                    //for schedule range selection
                    $('#Deliverydtdiv').hide();
                    $('#Schedulediv').show();
                });
            });

            $('#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;
                }

            });
            /*get cost center name using department*/
           var CostArray='';
            $('#DepartmentName').change(function() {
                $("#AvalBuget").val('');
                $('#AlertImg').attr("style","display:none;");
                CostArray='';
                var id = $('#DepartmentName').val();
                if(id != '0')
                {
                     $('#content').loader('show');


                    $.ajax({
                        data:{id:id},
                        type:"POST",
                        url:"<?php echo base_url() ?>emergencypurchaseorder/getCostCenterName",
                        success:function(data) {
                            if(data)
                            {
                            	CostArray=data;
                                $('#CostCenterName').empty();
                                $("#CostCenterName").append( $('<option></option>').val("0").html("Select Cost Center") );

                                $.each(JSON.parse(data), function (index, value) {
                                             
                                            $("#CostCenterName").append( $('<option></option>').val(value.CostCenterCode).html(value.CostCenterCode + "-" + value.CostCenterName) );


                        });
                                $('#content').loader('hide');


                            }
                            else
                            {
                                alert("Error");
                            }

                        }

                    });




                }
                else
                {
                    alert('Please select the Department');
                    return false;
                }

            });
            /**
             * update available budget calculation using regNo and cost center  
             */
            $('#CostCenterName').change(function() {

                var id = $('#CostCenterName').val();
                $("#AvlBudAmt").val('');
                var ReqType =$('#purpose').val();
                if(id != '0')
                {
                    $('#content').loader('show');
                    $.ajax({
                        data:{id:id},
                        type:"POST",
                        url:"<?php echo base_url() ?>servicepurchaseorder/AvilBudgetAmount?ReqType="+ReqType,
                        success:function(data) {
                            if(data)
                            {
                                $('#content').loader('hide');
                                $("#AvalBuget").val(data);
                                if(parseFloat($("#AvalBuget").val()) <= 0)
                                {
                                    $('#AlertImg').removeAttr("style");
                                    isExceed = 1;
                                }
                                else
                                {
                                    $('#AlertImg').attr("style","display:none;");
                                    isExceed =0;
                                }
                            }
                            else
                            {
                                $('#content').loader('hide');
                                alert("Error");
                            }

                        }
                    });
                }
                else
                {
                    alert('Please select the MaterialCode');
                    return false;
                }

            });
            /**
             * getting item name and uom using global variable materialData each change
             */
            $('#ServiceMaterialCode').change(function(){
                var selectedMaterialCode='';
                selectedMaterialCode=$("#ServiceMaterialCode").val();
                $.each(JSON.parse(materialData), function (index, value) {
                     if(selectedMaterialCode==value.MaterialCode){
                         $("#ServiceDescription").val(value.MaterialName);
                         $("#ServiceUOM").val(value.UOM);
                         
                     }

                });
                
            });
             /**
             * getting item name and uom using global variable materialData each change in revenue
             */
              $('#MaterialCode').change(function(){
                var selectedRevenueMaterialCode='';
                selectedRevenueMaterialCode=$("#MaterialCode").val();
                $.each(JSON.parse(materialData), function (index, value) {
                     if(selectedRevenueMaterialCode==value.MaterialCode){
                         $("#ItemName").val(value.MaterialName);
                         $("#UOM").val(value.UOM);
                         
                     }

                });
                
            });

            /**
             * get material list when selecting the request type
             */
            var materialData;

            $('#purpose').change(function(){
                var input='';
                input=$("#purpose").val();
if(input == -1){
    $("#POType").val('');

}
                else {
                    $("#POType").val(input);
                   // $('#content').loader('show');
                    $.ajax({
                        data:{input:input},
                        type:"POST",
                        url:"<?php echo base_url() ?>emergencypurchaseorder/getMaterialCode?input="+input,
                        success:function(data) {

                            if(data)
                            {
                                materialData=data;
                                if (input=='SERVICE') {
                            
                                	 $('#ServiceMaterialCode').empty();
                                $("#ServiceMaterialCode").append( $('<option></option>').val("0").html("Select Item Code") );

                                $.each(JSON.parse(data), function (index, value) {
                                    $("#ServiceMaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );


                                });
                                }
                                else if (input=='REVENUE') {
                                	 	 $('#MaterialCode').empty();
                                $("#MaterialCode").append( $('<option></option>').val("0").html("Select Item Code") );

                                $.each(JSON.parse(data), function (index, value) {
                                    $("#MaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );


                                });
                                }
                                else {
                                	
                                }
                               
                                $('#content').loader('hide');

                            }

                        }
                    });

                }

            });
            /**
             * calculating taxes using quanty and rate
             */
            function Ratechange(){
                if($('#ServiceMaterialCode').val() == "0")
                {
                    alert('Please Select Item Code ');
                    $('#ServiceMaterialCode').focus();
                    return false;
                }



                if($('#ServiceQuantity').val() != '' && $('#ServiceRate').val() != '')
                {
                    var txtQuantity = parseFloat( $('#ServiceQuantity').val());
                    var txtUnitPrice = parseFloat($('#ServiceRate').val());
                    var Tot =  txtQuantity * txtUnitPrice
                    $('#ServiceBasAmt').val(Tot);

                    //Service Tax calculation
                    $('#AfterServiceTax').val(calculateServiceTax($('#ServiceBasAmt').val())); // calculateServiceTax();

                    //Edu. cess @2% on service Tax
                    $('#AfterEduCess').val( calculateEduess($('#AfterServiceTax').val()));

                    //Sec. & Higher Edu. cess @1 % on service Tax

                    $('#AfterSecHighTax').val(calculateHigherEdu($('#AfterServiceTax').val()));
                    //Krishi Kalyan tax
                    $('#AfterKrishiTax').val(calculateKrishiKalyantax($('#ServiceBasAmt').val()));

                    //Swachh Bharat tax

                    $('#AfterSwachhTax').val(calculateSwachhBharattax($('#ServiceBasAmt').val()));
                    calculateTotalOrdervalue();

                    var res = ExceedBudget($('#TotalOrderValue').val(), $('#AvalBuget').val());
                    if(!res)
                    {
                        $('#ServiceRate').focus();
                        return false;
                    }
                }

            }
            function calculateServiceTax(varBasicValue)
            {

                var basicValue = parseFloat(varBasicValue);

                var ServiceTaxValue = 0.0;

                ServiceTaxValue = <?php echo SERVICETAX_SERVICETAX_14PERCENT; ?>;

                var TAXval =  parseFloat(ServiceTaxValue).toFixed(2);

                return   TAXval;//  $('#AfterServiceTax').val(TAXval);

            }
            function calculateEduess(varAfterServiceTax)
            {
                var ServiceTaxAmount = parseFloat(varAfterServiceTax);

                var ServiceTaxValue = 0.0;

                ServiceTaxValue = <?php echo SERVICETAX_EDUCESS_2PERCENT; ?>;

                var TAXval =  parseFloat(ServiceTaxValue).toFixed(2);

                return TAXval;// $('#AfterEduCess').val(TAXval);
            }
            function calculateHigherEdu(varAfterServiceTax)
            {
                var ServiceTaxAmount = parseFloat(varAfterServiceTax);

                var ServiceTaxValue = 0.0;

                ServiceTaxValue = <?php echo SERVICETAX_HIGHEREDUCESS_1PERCENT; ?>;

                var TAXval =  parseFloat(ServiceTaxValue).toFixed(2);

                return TAXval;//$('#AfterSecHighTax').val(TAXval);
            }
            function calculateKrishiKalyantax(varBasicValue)
            {
                var basicValue = parseFloat(varBasicValue);

                var ServiceTaxValue = 0.0;

                ServiceTaxValue = <?php echo SERVICETAX_KRISHIKALYAN; ?>;

                var TAXval =  parseFloat(ServiceTaxValue).toFixed(2);
                return TAXval;//$('#AfterKrishiTax').val(TAXval);
            }
            function calculateSwachhBharattax(varBasicValue)
            {
                var basicValue = parseFloat(varBasicValue);

                var ServiceTaxValue = 0.0;

                ServiceTaxValue = <?php echo SERVICETAX_SWACHHBHARAT; ?>;

                var TAXval =  parseFloat(ServiceTaxValue).toFixed(2);

                return TAXval; //$('#AfterSwachhTax').val(TAXval);
            }

            function calculateTotalOrdervalue()
            {
                var basicValue = parseFloat($('#ServiceBasAmt').val());
                var ServiceTaxAmount = parseFloat($('#AfterServiceTax').val());
                var EduCessTaxAmount = parseFloat($('#AfterEduCess').val());
                var SecHighTaxAmount = parseFloat($('#AfterSecHighTax').val());
                var KrishiTaxAmount = parseFloat($('#AfterKrishiTax').val());
                var SwachhTaxAmount = parseFloat($('#AfterSwachhTax').val());

                var TotAmt = basicValue + ServiceTaxAmount+ EduCessTaxAmount + SecHighTaxAmount+ KrishiTaxAmount + SwachhTaxAmount;

                $('#TotalOrderValue').val( parseFloat(TotAmt).toFixed(2));

            }
            function ExceedBudget(ValuetoCheck,budgetAmount)
            {
                var ReqAmount = parseFloat(ValuetoCheck);
                var BudAmount = parseFloat(budgetAmount);

                if(ReqAmount > BudAmount )
                {
                    alert('Your exceeding the Avaiable Budget :'+ budgetAmount  +'.Please adjust the Product to proceed further.');
                    return false;
                }
                else
                {
                    return true;
                }
            }
            /**
             * This function is used when clicking add service button that time store the info for submit
             */

            $('.AddService').click(function(){
                if(validateServiceTax())
                {
                    // alert('inside Addservice');
                    var temp = index;
                    var Reqnumber = $('#purpose').val();
                    var departmentName = $('#DepartmentName').val();
                    var AvilBudget = $('#AvalBuget').val();
                    var costCode = $('#CostCenterName').val();
                    var materialCode =$('#ServiceMaterialCode').val();
                    var materialName =  $("#ServiceDescription").val();
                    var uom = $("#ServiceUOM").val();
                    var quantity = $("#ServiceQuantity").val();
                    var itemRate = $("#ServiceRate").val();


                    var AfterServiceTax = $("#AfterServiceTax").val();


                    var AfterEduCess = $("#AfterEduCess").val();


                    var AfterSecHighTax = $("#AfterSecHighTax").val();


                    var AfterKrishiTax = $("#AfterKrishiTax").val();


                    var AfterSwachhTax = $("#AfterSwachhTax").val();

                    var TotalOrderValue = $("#TotalOrderValue ").val();


                    var basicval = $("#ServiceBasAmt").val();


                    var TotalTaxValue = calculateTaxValue();

                    $('#ServiceMaterialCode option[value='+materialCode+']').remove();

                    SelectedMaterialCode[CollIndex] = materialCode;
                    CollIndex = CollIndex + 1;

                    populateValueMainFormForServiceTax();


                    index = parseInt(index)+1;

                    var template = jQuery("#ServiceList").html();


                    $('#ServiceAppend').append(_.template(template,{index:temp,ReqNo:Reqnumber,MaterialName:materialName,Quantity:quantity,UOM:uom,Rate:itemRate,BasicAmount:basicval,Taxvalue:TotalTaxValue,TotalValue:TotalOrderValue}));

                    clearServiceModalFields();

                    var theForm = $(".CreatealterPO");

                    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,"ServiceTax"+temp,AfterServiceTax);
                    addHidden(theForm,"EduCess"+temp,AfterEduCess);
                    addHidden(theForm,"SecHighTax"+temp,AfterSecHighTax);
                    addHidden(theForm,"KrishiTax"+temp,AfterKrishiTax);
                    addHidden(theForm,"SwachhTax"+temp,AfterSwachhTax);
                    addHidden(theForm,"TotalOrderValue"+temp,TotalOrderValue);
                   
                    $('#txtRowCount').val(temp);
                   
                }

            });
            /**
             * validate fields when clicking add service button
             */
            function validateServiceTax()
            {

                 if($('#ServiceMaterialCode').val() == "0")
                {
                    alert('Please select the Material Code');
                    $('#ServiceMaterialCode').focus();
                    return false;
                }
                else if($('#ServiceQuantity').val() == '')
                {
                    alert('Please Enter the Quantity value');
                    $('#ServiceQuantity').focus();
                    return false;
                }
                else if($('#ServiceRate').val() == '')
                {
                    alert('Please Enter the Rate of the Item');
                    $('#ServiceRate').focus();
                    return false;
                }

                else if(ExceedBudget($('#TotalOrderValue').val(),$('#AvalBuget').val()) == false)
                {
                    $('#ServiceRate').focus();
                    return false;
                }
                else
                {
                    return true;
                }

            }
            function populateValueMainFormForServiceTax()
            {
                var AfterServiceTax = $('#AfterServiceTax').val() == '' ? '0.00' : $('#AfterServiceTax').val();
                var AfterEduCess = $('#AfterEduCess').val() == '' ? '0.00' : $('#AfterEduCess').val();
                var AfterSecHighTax = $('#AfterSecHighTax').val() == '' ? '0.00' : $('#AfterSecHighTax').val();
                var AfterKrishiTax = $('#AfterKrishiTax').val() == '' ? '0.00' : $('#AfterKrishiTax').val();
                var AfterSwachhTax = $('#AfterSwachhTax').val() == '' ? '0.00' : $('#AfterSwachhTax').val();
                var TotalVal = $('#TotalOrderValue ').val() == '' ? '0.00' : $('#TotalOrderValue').val();
                var BasicVal = $('#ServiceBasAmt').val() == '' ? '0.00' : $('#ServiceBasAmt').val();

                var TotalOrderValueSummary = $('#txtTotalOrderValueSummaryService').val() == '' ? '0.00' : $('#txtTotalOrderValueSummaryService').val();

                var totBasicAmt = $('#txtTotBasicAmount').val() == '' ? '0.00' : $('#txtTotBasicAmount').val();
                var TotalServiceTax = $('#txtTotalServiceTax').val() == '' ? '0.00' : $('#txtTotalServiceTax').val();
                var TotHigherEdu = $('#txtTotHigherEdu').val() == '' ? '0.00' : $('#txtTotHigherEdu').val();
                var TotalEducess = $('#txtTotalEducess').val() == '' ? '0.00' : $('#txtTotalEducess').val();
                var TotalKrishiKalyan = $('#txtTotalKrishiKalyan').val() == '' ? '0.00' : $('#txtTotalKrishiKalyan').val();
                var TotSwachhBharat = $('#txtTotSwachhBharat').val() == '' ? '0.00' : $('#txtTotSwachhBharat').val();
                $('#txtTotBasicAmount').val((parseFloat(totBasicAmt) + parseFloat(BasicVal)).toFixed(2) );
                $('#txtTotalServiceTax').val((parseFloat(TotalServiceTax) + parseFloat(AfterServiceTax)).toFixed(2) );
                $('#txtTotHigherEdu').val((parseFloat(TotHigherEdu) + parseFloat(AfterSecHighTax)).toFixed(2) );
                $('#txtTotalEducess').val((parseFloat(TotalEducess) + parseFloat(AfterEduCess)).toFixed(2) );
                $('#txtTotalKrishiKalyan').val((parseFloat(TotalKrishiKalyan) + parseFloat(AfterKrishiTax)).toFixed(2) );
                $('#txtTotSwachhBharat').val((parseFloat(TotSwachhBharat) + parseFloat(AfterSwachhTax)).toFixed(2) );
                $('#txtTotalOrderValueSummaryService').val((parseFloat(TotalOrderValueSummary) + parseFloat(TotalVal)).toFixed(2) );

            }
            function calculateTaxValue()
            {
                var ServiceTaxAmount = parseFloat($('#AfterServiceTax').val());
                var EduCessTaxAmount = parseFloat($('#AfterEduCess').val());
                var SecHighTaxAmount = parseFloat($('#AfterSecHighTax').val());
                var KrishiTaxAmount = parseFloat($('#AfterKrishiTax').val());
                var SwachhTaxAmount = parseFloat($('#AfterSwachhTax').val());

                var TottaxAmt = ServiceTaxAmount+ EduCessTaxAmount + SecHighTaxAmount+ KrishiTaxAmount + SwachhTaxAmount;
                return parseFloat(TottaxAmt.toFixed(2));
            }
            <!-- script for table , It works under the datatable plugin-->
            $(function () {
                $('#serviceTax').DataTable({
                    "paging": true,
                    "lengthChange": true,
                    "searching": false,
                    //"ordering": true,
                    // "info": true,
                    "autoWidth": true

                });
            });
            /**
             * clear the seleted fields after clicking add service
             */
            function clearServiceModalFields()
            {
                // To reset the Modal controls

                $('#ServiceMaterialCode').val("0")	;
                $("#ServiceDescription").val('');
                $('#ServiceUOM').val('');
                $('#ServiceQuantity').val('');
                $("#ServiceRate").val('');

                $("#ServiceBasAmt").val('');
                $("#AfterServiceTax").val('');
                $("#AfterEduCess").val('');
                $("#AfterSecHighTax").val('');
                $("#AfterKrishiTax").val('');
                $("#AfterSwachhTax").val('');
                $("#TotalOrderValue ").val('');

            }
            /**
             * This function is used to edit the service seleted po
             */
             var EditGetMaterialData;
           
            $("#EDITSERVICE").on("shown.bs.modal", function(e) {
         
            	EditGetMaterialData='';

                userid = $(e.relatedTarget).data('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());


                $('#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);
                $('#EditAfterServiceTax').val($('#ServiceTax'+userid).val());
                $('#EditAfterEduCess').val($('#EduCess'+userid).val());
                $('#EditAfterSecHighTax').val($('#SecHighTax'+userid).val());
                $('#EditAfterKrishiTax').val($('#KrishiTax'+userid).val());
                $('#EditAfterSwachhTax').val($('#SwachhTax'+userid).val());
                $('#EditTotalOrderValue').val(cellval[8].innerHTML);

                 
 
                  

                                $.each(JSON.parse(CostArray), function (index, value) {
                                	if ($('#costCode'+userid).val()==value.CostCenterCode) {
                 $('#EditCostCenter').val($('#costCode'+userid).val() + '-'+ value.CostCenterName);
                                		
                                	}
                                	
                                
                                $("#EditMaterialCode").empty();
                               
                          $("#EditMaterialCode").append( $('<option></option>').val($('#materialCode'+userid).val()).html($('#materialCode'+userid).val() + "-" + $('#materialName'+userid).val()) );
                                $.each(JSON.parse(materialData), function (index, value) {
                         

                                 if($('#materialCode'+userid).val() != value.MaterialCode)
						 {

						                                    $("#EditMaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );

						}
						

		
                                });
                                           



                        });                 
                 
 				/*get Material list while editing
 				
                     var EditPoType=$('#Reqnumber'+userid).val();
                   
                    $.ajax({
                        data:{input:EditPoType},
                        type:"POST",
                        url:"<?php echo base_url() ?>emergencypurchaseorder/getMaterialCode?input="+EditPoType,
                        success:function(data) {
$('#content').loader('hide');
                            if(data)
                            {
                            	EditGetMaterialData=data;
                             
                                $("#EditMaterialCode").empty();
                               
                          $("#EditMaterialCode").append( $('<option></option>').val($('#materialCode'+userid).val()).html($('#materialCode'+userid).val() + "-" + $('#materialName'+userid).val()) );
                                $.each(JSON.parse(data), function (index, value) {
                         

                                 if($('#materialCode'+userid).val() != value.MaterialCode)
						 {

						                                    $("#EditMaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );

						}
						

		
                                });
                               

                            }

                        }
                    });*/

      
 

		
	    
          
            });

            /**
             * edit emenergency service po validations
             */

            function EditRatechange(){


                if($('#EditQuantity').val() != '' && $('#EditRate').val() != '')
                {
                    var txtQuantity = parseFloat( $('#EditQuantity').val());
                    var txtUnitPrice = parseFloat($('#EditRate').val());
                    var Tot =  txtQuantity * txtUnitPrice
                    $('#txtEditBasicValue').val(Tot);
                    ExceedBudget(Tot, $('#EditAvlBudAmt').val());

                    //Service Tax calculation
                    $('#EditAfterServiceTax').val(calculateServiceTax($('#txtEditBasicValue').val())); // calculateServiceTax();

                    //Edu. cess @2% on service Tax
                    $('#EditAfterEduCess').val( calculateEduess($('#EditAfterServiceTax').val()));

                    //Sec. & Higher Edu. cess @1 % on service Tax

                    $('#EditAfterSecHighTax').val(calculateHigherEdu($('#EditAfterServiceTax').val()));
                    //Krishi Kalyan tax

                    $('#EditAfterKrishiTax').val(calculateKrishiKalyantax($('#txtEditBasicValue').val()));
                    //Swachh Bharat tax

                    $('#EditAfterSwachhTax').val(calculateSwachhBharattax($('#txtEditBasicValue').val()));

                    calculateTotalEditOrdervalue();
                }

            }
            /**
             * calculate total edit order value
             */
            function calculateTotalEditOrdervalue()
            {
                var basicValue = parseFloat($('#txtEditBasicValue').val());
                var ServiceTaxAmount = parseFloat($('#EditAfterServiceTax').val());
                var EduCessTaxAmount = parseFloat($('#EditAfterEduCess').val());
                var SecHighTaxAmount = parseFloat($('#EditAfterSecHighTax').val());
                var KrishiTaxAmount = parseFloat($('#EditAfterKrishiTax').val());
                var SwachhTaxAmount = parseFloat($('#EditAfterSwachhTax').val());

                var TotAmt = basicValue + ServiceTaxAmount+ EduCessTaxAmount + SecHighTaxAmount+ KrishiTaxAmount + SwachhTaxAmount;

                $('#EditTotalOrderValue').val( parseFloat(TotAmt).toFixed(2));

            }
            /**
             * This function is used for update service
             */
            $('.EditService').click(function(){

                if( validateEditServiceTax())
                {
                   
                   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 AfterServiceTax = $("#EditAfterServiceTax").val();


                    var AfterEduCess = $("#EditAfterEduCess").val();


                    var AfterSecHighTax = $("#EditAfterSecHighTax").val();


                    var AfterKrishiTax = $("#EditAfterKrishiTax").val();


                    var AfterSwachhTax = $("#EditAfterSwachhTax").val();

                    var TotalOrderValue = $("#EditTotalOrderValue ").val();


                    var basicval = $("#txtEditBasicValue").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);
                    $('#ServiceTax'+userid).val(AfterServiceTax);
                    $('#EduCess'+userid).val(AfterEduCess);
                    $('#SecHighTax'+userid).val(AfterSecHighTax);
                    $('#KrishiTax'+userid).val(AfterKrishiTax);
                    $('#SwachhTax'+userid).val(AfterSwachhTax);
                    $('#TotalOrderValue'+userid).val(TotalOrderValue);

                    populateValueMainFormForEditServiceTax();

                }

            });
            /**
             * This function is used for validate while update
             */
            function validateEditServiceTax()
            {
                
                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 if(ExceedBudget($('#EditTotalOrderValue').val(),$('#EditAvlBudAmt').val()) == false)
                {
                    $('#EditRate').focus();
                    return false;
                }
                else
                {
                    return true;
                }

            }
            function calculateEditTaxValue()
            {
                var ServiceTaxAmount = parseFloat($('#EditAfterServiceTax').val());
                var EduCessTaxAmount = parseFloat($('#EditAfterEduCess').val());
                var SecHighTaxAmount = parseFloat($('#EditAfterSecHighTax').val());
                var KrishiTaxAmount = parseFloat($('#EditAfterKrishiTax').val());
                var SwachhTaxAmount = parseFloat($('#EditAfterSwachhTax').val());

                var TottaxAmt = ServiceTaxAmount+ EduCessTaxAmount + SecHighTaxAmount+ KrishiTaxAmount + SwachhTaxAmount;
                return parseFloat(TottaxAmt.toFixed(2));
            }
            function populateValueMainFormForEditServiceTax()
            {

                var rows =  document.getElementById('serviceTax').rows.length;
                var TotServiceTax = 0;
                var TotEduCess = 0;
                var TotSecHighTax = 0;
                var TotKrishiTax = 0;
                var TotSwachhTax = 0;
                var TotSummary = 0;
                var TotBasicAmout = 0;
                for (i = 1; i < rows-1; i++) {

                    var AfterServiceTax = $('#ServiceTax'+i).val() == '' ? '0.00' : $('#ServiceTax'+i).val();
                    var AfterEduCess = $('#EduCess'+i).val() == '' ? '0.00' : $('#EduCess'+i).val();
                    var AfterSecHighTax = $('#SecHighTax'+i).val() == '' ? '0.00' : $('#SecHighTax'+i).val();
                    var AfterKrishiTax =$('#KrishiTax'+i).val() == '' ? '0.00' : $('#KrishiTax'+i).val();
                    var AfterSwachhTax = $('#SwachhTax'+i).val() == '' ? '0.00' : $('#SwachhTax'+i).val();
                    var TotalVal =$('#TotalOrderValue'+i).val() == '' ? '0.00' : $('#TotalOrderValue'+i).val();
                    var Quantity = $('#quantity'+i).val() == '' ? '0.00' : $('#quantity'+i).val();
                    var ItemRate = $('#itemRate'+i).val() == '' ? '0.00' : $('#itemRate'+i).val();
                    var BasicVal = parseFloat(Quantity) * parseFloat(ItemRate);

                    TotServiceTax = parseFloat(TotServiceTax) + parseFloat(AfterServiceTax);
                    TotEduCess = parseFloat(TotEduCess) + parseFloat(AfterEduCess);
                    TotSecHighTax = parseFloat(TotSecHighTax) + parseFloat(AfterSecHighTax);
                    TotKrishiTax = parseFloat(TotKrishiTax) + parseFloat(AfterKrishiTax);
                    TotSwachhTax = parseFloat(TotSwachhTax) + parseFloat(AfterSwachhTax);
                    TotSummary = parseFloat(TotSummary) + parseFloat(TotalVal);
                    TotBasicAmout = parseFloat(TotBasicAmout) + parseFloat(BasicVal);

                }


                $('#txtTotBasicAmount').val(parseFloat(TotBasicAmout).toFixed(2) );
                $('#txtTotalServiceTax').val(parseFloat(TotServiceTax).toFixed(2) );
                $('#txtTotHigherEdu').val(parseFloat(TotSecHighTax).toFixed(2) );
                $('#txtTotalEducess').val(parseFloat(TotEduCess).toFixed(2) );
                $('#txtTotalKrishiKalyan').val(parseFloat(TotKrishiTax).toFixed(2) );
                $('#txtTotSwachhBharat').val(parseFloat(TotSwachhTax).toFixed(2) );
                $('#txtTotalOrderValueSummaryService').val(parseFloat(TotSummary).toFixed(2) );
                

            }
            /**
             * This function is used for delete list of tem from selected list
             */
            function DeleteRow(rowid)
            {
                var DelRows  = $('#txtDeletedRow').val();

                var answer = confirm(" Do you want to delete the Item from the List?")
                if (answer)
                {
                    var td = document.getElementById(rowid);
                    td.parentNode.removeChild(td);
                    
                   var materialCode = $('#materialCode'+rowid).val();
                  
                   var removeItem = $('#materialCode'+rowid).val();

                  
      $.each(JSON.parse(materialData), function (index, value) {
      	if (value.MaterialCode==materialCode) {
      		                                    $("#ServiceMaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );
      	}



                                });
                    SelectedMaterialCode.splice( SelectedMaterialCode.indexOf('removeItem'), 1 );

                    if(DelRows != '')
                    {
                        DelRows = DelRows + ":" + rowid;
                        populateValueMainFormForDeleteServiceTax(rowid);
                    }
                    else
                    {
                        DelRows=  "0" + ":" + rowid;
                        populateValueMainFormForDeleteServiceTax(rowid);

                    }
                    $('#txtDeletedRow').val(DelRows);
                }

            }
            /**
             * This function is used to submit and save the emergency service Po list
             */
            function Save(status)
            {
                if(status == '0')
                {
                    stat = '<?php echo PO_DRAFT; ?>';
                }
                else
                {
                    stat = '<?php echo REQITEM_Emergency_PO_CREATED; ?>';
                }


                var splinstr = $('#txtSpcialInstruction').val();
                var deladd = $('#DeliveryAddr').val();
                $('#SpcialInstruction').val(splinstr);
                $('#txtDeliveryAddress').val(deladd);
                $('#txtStatus').val(stat);
                var TextRowCount = $('#txtRowCount').val();
                var TextDeletedRowCount = $('#txtDeletedRow').val();
               var TextTotalOrderValueSummaryService = $('#txtTotalOrderValueSummaryService').val();
                var TextSpcialInstruction = $('#txtSpcialInstruction').val();
                var TextStatus = stat;
             
                if(validate())
                {
                	
                    if(document.getElementById('serviceTax').rows.length < 3)
                    {
                        alert('Please Select Line item to Create PO');
                        $('#Deliverydt').focus();
                        return false;
                    }
                    else
                    {
                        $('#content').loader('show');
                        $.ajax({
                            data:$('.CreatealterPO').serialize()+"&TextRowCount="+TextRowCount+"&TextDeletedRowCount="+TextDeletedRowCount+"&TextTotalOrderValueSummaryService="+TextTotalOrderValueSummaryService+"&TextSpcialInstruction="+TextSpcialInstruction+"&TextStatus="+TextStatus,
                            type:"POST",
                            url:"<?php echo base_url() ?>emergencypurchaseorder/addNewServicePurchaseOrder",
                            success:function(data) {
                                if(data)
                                {
                                    $('#content').loader('hide');
                                    alert(data);
                                    $('#txtRowCount').val('');
                                    $('#txtDeletedRow').val('');
                                    $('#SpcialInstruction').val('');
                                    $('#txtDeliveryAddress').val('');
                                    window.location =	"purchaseorderListing";

                                }
                                else
                                {
                                    $('#content').loader('hide');
                                    alert("Error");
                                }

                            }

                        });
                    }

                }
            }
            
            
            /**
             * This function is used to submit and save the emergency Revenue Po list
             */
            function RevenueSave(status)
            {
                if(status == '0')
                {
                    stat = '<?php echo PO_DRAFT; ?>';
                }
                else
                {
                    stat = '<?php echo REQITEM_Emergency_PO_CREATED; ?>';
                }


                var splinstr = $('#txtSpcialInstruction').val();
                var deladd = $('#DeliveryAddr').val();
                $('#SpcialInstruction').val(splinstr);
                $('#txtDeliveryAddress').val(deladd);
                $('#txtStatus1').val(stat);
                var TextRowCount = $('#txtRowCount1').val();
                var TextDeletedRowCount = $('#txtDeletedRow1').val();
               var txtTotalOrderValueSummary = $('#txtTotalOrderValueSummary').val();
                var TextSpcialInstruction = $('#txtSpcialInstruction').val();
                var TextStatus = stat;
              
                if(validate())
                {
                    if(document.getElementById('serviceTax').rows.length < 3)
                    {
                        alert('Please Select Line item to Create PO');
                        $('#Deliverydt').focus();
                        return false;
                    }
                    else
                    {
                        $('#content').loader('show');
                        $.ajax({
                            data:$('.CreatealterPO').serialize()+"&TextRowCount="+TextRowCount+"&TextDeletedRowCount="+TextDeletedRowCount+"&txtTotalOrderValueSummary="+txtTotalOrderValueSummary+"&TextSpcialInstruction="+TextSpcialInstruction+"&TextStatus="+TextStatus,
                            type:"POST",
                            url:"<?php echo base_url() ?>emergencypurchaseorder/addNewRevenuePurchaseOrder",
                            success:function(data) {
                                if(data)
                                {
                                    $('#content').loader('hide');
                                    alert(data);
                                    $('#txtRowCount').val('');
                                    $('#txtDeletedRow').val('');
                                    $('#SpcialInstruction').val('');
                                    $('#txtDeliveryAddress').val('');
                                    window.location =	"purchaseorderListing";

                                }
                                else
                                {
                                    $('#content').loader('hide');
                                    alert("Error");
                                }

                            }

                        });
                    }

                }
            }
            /**
             * This function is used to calculate the total amounts after delete the row
             */
            function populateValueMainFormForDeleteServiceTax(deletedRow)
            {
                var rows =  document.getElementById('serviceTax').rows.length+1;
                var TotServiceTax = 0;
                var TotEduCess = 0;
                var TotSecHighTax = 0;
                var TotKrishiTax = 0;
                var TotSwachhTax = 0;
                var TotSummary = 0;
                var TotBasicAmout = 0;
                for (var i = 1; i < rows; i++) {
                    if(deletedRow==i){
                        $('#ServiceTax'+i).val('');
                        $('#EduCess'+i).val('');
                        $('#SecHighTax'+i).val('');
                        $('#KrishiTax'+i).val('');
                        $('#SwachhTax'+i).val('');
                        $('#ServiceTax'+i).val('');
                        $('#TotalOrderValue'+i).val('');
                        $('#quantity'+i).val('');
                        $('#itemRate'+i).val('');

                        var AfterServiceTax = $('#ServiceTax'+i).val() == '' ? '0.00' : $('#ServiceTax'+i).val();
                        var AfterEduCess = $('#EduCess'+i).val() == '' ? '0.00' : $('#EduCess'+i).val();
                        var AfterSecHighTax = $('#SecHighTax'+i).val() == '' ? '0.00' : $('#SecHighTax'+i).val();
                        var AfterKrishiTax =$('#KrishiTax'+i).val() == '' ? '0.00' : $('#KrishiTax'+i).val();
                        var AfterSwachhTax = $('#SwachhTax'+i).val() == '' ? '0.00' : $('#SwachhTax'+i).val();
                        var TotalVal =$('#TotalOrderValue'+i).val() == '' ? '0.00' : $('#TotalOrderValue'+i).val();

                        var Quantity = $('#quantity'+i).val() == '' ? '0.00' : $('#quantity'+i).val();
                        var ItemRate = $('#itemRate'+i).val() == '' ? '0.00' : $('#itemRate'+i).val();
                        var BasicVal = parseFloat(Quantity) * parseFloat(ItemRate);

                        TotServiceTax = parseFloat(TotServiceTax) + parseFloat(AfterServiceTax);
                        TotEduCess = parseFloat(TotEduCess) + parseFloat(AfterEduCess);
                        TotSecHighTax = parseFloat(TotSecHighTax) + parseFloat(AfterSecHighTax);
                        TotKrishiTax = parseFloat(TotKrishiTax) + parseFloat(AfterKrishiTax);
                        TotSwachhTax = parseFloat(TotSwachhTax) + parseFloat(AfterSwachhTax);
                        TotSummary = parseFloat(TotSummary) + parseFloat(TotalVal);
                        TotBasicAmout = parseFloat(TotBasicAmout) + parseFloat(BasicVal);
                    }
                    else if(deletedRow!=i){
                        var AfterServiceTax = $('#ServiceTax'+i).val() == '' ? '0.00' : $('#ServiceTax'+i).val();
                        var AfterEduCess = $('#EduCess'+i).val() == '' ? '0.00' : $('#EduCess'+i).val();
                        var AfterSecHighTax = $('#SecHighTax'+i).val() == '' ? '0.00' : $('#SecHighTax'+i).val();
                        var AfterKrishiTax =$('#KrishiTax'+i).val() == '' ? '0.00' : $('#KrishiTax'+i).val();
                        var AfterSwachhTax = $('#SwachhTax'+i).val() == '' ? '0.00' : $('#SwachhTax'+i).val();
                        var TotalVal =$('#TotalOrderValue'+i).val() == '' ? '0.00' : $('#TotalOrderValue'+i).val();

                        var Quantity = $('#quantity'+i).val() == '' ? '0.00' : $('#quantity'+i).val();
                        var ItemRate = $('#itemRate'+i).val() == '' ? '0.00' : $('#itemRate'+i).val();
                        var BasicVal = parseFloat(Quantity) * parseFloat(ItemRate);
                        if(AfterServiceTax!=undefined){
                            TotServiceTax = parseFloat(TotServiceTax) + parseFloat(AfterServiceTax);
                            TotEduCess = parseFloat(TotEduCess) + parseFloat(AfterEduCess);
                            TotSecHighTax = parseFloat(TotSecHighTax) + parseFloat(AfterSecHighTax);
                            TotKrishiTax = parseFloat(TotKrishiTax) + parseFloat(AfterKrishiTax);
                            TotSwachhTax = parseFloat(TotSwachhTax) + parseFloat(AfterSwachhTax);
                            TotSummary = parseFloat(TotSummary) + parseFloat(TotalVal);
                            TotBasicAmout = parseFloat(TotBasicAmout) + parseFloat(BasicVal);
                        }

                    }
                    else{
                        
                    }
                  

                }


                $('#txtTotBasicAmount').val(parseFloat(TotBasicAmout).toFixed(2) );
                $('#txtTotalServiceTax').val(parseFloat(TotServiceTax).toFixed(2) );
                $('#txtTotHigherEdu').val(parseFloat(TotSecHighTax).toFixed(2) );
                $('#txtTotalEducess').val(parseFloat(TotEduCess).toFixed(2) );
                $('#txtTotalKrishiKalyan').val(parseFloat(TotKrishiTax).toFixed(2) );
                $('#txtTotSwachhBharat').val(parseFloat(TotSwachhTax).toFixed(2) );
                $('#txtTotalOrderValueSummaryService').val(parseFloat(TotSummary).toFixed(2) );


            }
              /**
             * update available budget calculation using regNo and cost center while editing 
             */
            $('#EditCostCenter').change(function() {

                var getCostId = $('#EditCostCenter').val();
                $("#EditAvlBudAmt").val('');
                var EditReqType =$('#EditReqNo').val();
                if(getCostId != '0')
                {
                
                    $('#content').loader('show');
                    $.ajax({
                        data:{id:getCostId},
                        type:"POST",
                        url:"<?php echo base_url() ?>servicepurchaseorder/AvilBudgetAmount?ReqType="+EditReqType,
                        success:function(data) {
                            if(data)
                            {
                                $('#content').loader('hide');
                                $("#EditAvlBudAmt").val(data);
                                if(parseFloat($("#EditAvlBudAmt").val()) <= 0)
                                {
                                    $('#AlertImg').removeAttr("style");
                                    isExceed = 1;
                                }
                                else
                                {
                                    $('#AlertImg').attr("style","display:none;");
                                    isExceed =0;
                                }
                            }
                            else
                            {
                                $('#content').loader('hide');
                                alert("Error");
                            }

                        }
                    });
                }
                else
                {
                    alert('Please select the MaterialCode');
                    return false;
                }

            });
             /**
             * getting item name and uom using global variable materialData each change ehile editing
             */
            $('#EditMaterialCode').change(function(){
            
                var editselectedMaterialCode='';
                editselectedMaterialCode=$("#EditMaterialCode").val();
              
                $.each(JSON.parse(materialData), function (index, value) {
                     if(editselectedMaterialCode==value.MaterialCode){
                     	$("#EditMaterialCode").val(value.MaterialCode);
                         $("#EditItemName").val(value.MaterialName);
                         $("#EditItemUOM").val(value.UOM);
                         
                     }

                });
                
            });
            $("#EDITREVENUE").on("shown.bs.modal", function(e) {
            
           
	
		userid = $(e.relatedTarget).data('userid');
		
		 var CheckLocalInter = $('#CheckLocalInter'+userid).val();
		       if(CheckLocalInter == "0")
        {
            // style="display:none;"
          //  $('#Vat').removeAttr("style");
           // $('#TotVat').removeAttr("style");
          //  $('#CST').attr("style","display:none;");
         //   $('#TotCST').attr("style","display:none;");
         $('#EditVat').show();
         $('#EditCST').hide();

        }
        else
        {
          //  $('#CST').removeAttr("style");
          //  $('#TotCST').removeAttr("style");
           // $('#Vat').attr("style","display:none;");
           // $('#TotVat').attr("style","display:none;");
            $('#EditVat').hide();
         $('#EditCST').show();

        }
		
		$('#isEdit').val(1);
	    //alert(userid);
		var tr= document.getElementById(userid);
		
		var cellval = tr.cells;

		var id= $('#Reqnumber'+userid).val();
		
		$('#EditRevenueReqNo').val($('#Reqnumber'+userid).val());
		$('#EditRevenuedeptName').val($('#departmentName'+userid).val());
		//$("#EditRevenueCostCenter").val($('#costCode'+userid).val());
		$('#EditRevenueAvlBudAmt').val($('#AvilBudget'+userid).val());
		
		$('#EditRevenueItemName').val($('#materialName'+userid).val());
		$('#EditRevenueUOM').val($('#uom'+userid).val());
		$('#EditRevenueQuantity').val($('#quantity'+userid).val());
		$('#EditRevenueRate').val($('#itemRate'+userid).val());
		$('#txtEditRevenueBasicValue').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());
		
		$('#txtEditRevenueTotalOrderValue').val($('#TotalOrderValue'+userid).val());
		
		
		     $.each(JSON.parse(CostArray), function (index, value) {
                                	if ($('#costCode'+userid).val()==value.CostCenterCode) {
                 $('#EditRevenueCostCenter').val($('#costCode'+userid).val() + '-'+ value.CostCenterName);
                                		
                                	}
                                	
                                
                                $("#EditRevenueMaterialCode").empty();
                               
                          $("#EditRevenueMaterialCode").append( $('<option></option>').val($('#materialCode'+userid).val()).html($('#materialCode'+userid).val() + "-" + $('#materialName'+userid).val()) );
                                $.each(JSON.parse(materialData), function (index, value) {
                         

                                 if($('#materialCode'+userid).val() != value.MaterialCode)
						 {

						                                    $("#EditRevenueMaterialCode").append( $('<option></option>').val(value.MaterialCode).html(value.MaterialCode + "-" + value.MaterialName) );

						}
						

		
                                });
                                           



                        }); 
                        $("#EditDiscountType").val($('#DisType'+userid).val());
		$("#drpEditFreight").val($('#FreightType'+userid).val());
		$("#EditPackagingType").val($('#PackType'+userid).val())
		
		
		
	   
});
 $('#EditRevenueMaterialCode').change(function(){
            
                var editselectedMaterialCode='';
                editselectedMaterialCode=$("#EditRevenueMaterialCode").val();
              
                $.each(JSON.parse(materialData), function (index, value) {
                     if(editselectedMaterialCode==value.MaterialCode){
                     	$("#EditRevenueMaterialCode").val(value.MaterialCode);
                         $("#EditRevenueItemName").val(value.MaterialName);
                         $("#EditRevenueUOM").val(value.UOM);
                         
                     }

                });
                
            });
$('.EditRevenue').click(function(){
         
   		
       if(validateEditRevenueTax() && validateEditExceedLimit())	  
        {
            //alert('inside Add');			
            var CostCode =  $("#EditRevenueCostCenter").val();
			 var AvilBudget = $('#EditRevenueAvlBudAmt').val();
			var editMaterialCode =  $("#EditRevenueMaterialCode").val();
			var editDescription = $("#EditRevenueItemName").val();		
			var editUOM = $('#EditRevenueUOM').val();
			var editQuantity = $('#EditRevenueQuantity').val();
			
			 var itemRate = $("#EditRevenueRate").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 = $("#txtEditGST").val();
		  var AfterGSTVal = $("#txtEditAfterGST").val();
		 
		  
		   var OtherTaxVal = $("#txtEditOtherTax").val();
		  var AfterOtherTaxVal = $("#txtEditAfterOtherTax").val();
		  
	      var FreightType = $("#drpEditFreight").val();
		  var FreightVal = $("#txtEditFreight").val();
		  var AfterFreightVal = $("#txtEditAfterFreight").val();
		  
		 var basicval = $("#txtEditRevenueBasicValue").val();
		 var Insval = $("#txtEditInsurance").val();
		 var TotalOrderValue = $("#txtEditRevenueTotalOrderValue").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 =AfterOtherTaxVal;
			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);
			$('#TotalOrderValue'+userid).val(TotalOrderValue);			
		    populateValueMainFormForEditRevenueTax();	 
      }
    
 });
 function validateEditRevenueTax()
 {  
	 if($('#EditRevenueCostCenter').val() == "0")
	{
		alert('Please select the Cost center');
		$('#EditRevenueCostCenter').focus();
		return false;
	}
	else if($('#EditRevenueMaterialCode').val() == "0")
	{
		alert('Please select the Material Code');
		$('#EditRevenueMaterialCode').focus();
		return false;
	}		
	else if($('#EditRevenueQuantity').val() == '')
	{
		alert('Please Enter the Quantity value');
		$('#EditRevenueQuantity').focus();
		return false;
	}
	else if($('#EditRevenueRate').val() == '')
	{
		alert('Please Enter the Rate of the Item');
		$('#EditRevenueRate').focus();
		return false;
	}
	else
	{
		return true;
	}	
 }
 function validateEditExceedLimit()
 {
	 var avalbudAmt = parseFloat($('#EditRevenueAvlBudAmt').val());
	 var basicAmountRate = parseFloat($('#txtEditRevenueBasicValue').val()); 
	 var totalAmount =  parseFloat($('#txtEditRevenueTotalOrderValue').val()); 
	 
	 if(basicAmountRate > avalbudAmt || totalAmount > avalbudAmt)
	 {
		 alert('Basic amount is exceeding the Budget Limit.Please adjust the product value.');
		 $('#EditRevenueRate').focus();
		 return false;
	 }
	 else
	 {
		return true; 
	 }
	  
 }
 function populateValueMainFormForEditRevenueTax()
{
	  
		var rows =  document.getElementById('serviceTax').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);  
	  		
      
		$('#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)  );
		
}
// this function is used to clear data changing schedule option
$('#Scheduleby').change(function(){
            
             $("#Deliverydt").datepicker({
            minDate : 'now',
            dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '0:+10'
        });
                
            });
            $('#Deliverydt').change(function(){
            
           $('#Scheduleby').val('');
                
            });


        </script>
      
