<?php $ReqType =''; 
$CompanyAddress = '';
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));				
$CurrentDate =  $dt->format('Y-m-d');
$MaxPoDate = '';
$AvlAmount = 0;
if(!empty($MaxPODate))
{
    foreach ($MaxPODate as $date)
    {
		$MaxPoDate = $date->PODate;		
	}
}
if(!empty($CompanyDetails))
{
    foreach ($CompanyDetails as $Req)
    {
		$CompanyAddress = $Req->Address;
	}
}
if(!empty($AvlBudAmt))
{
   
		$AvlAmount = $AvlBudAmt;		
	
}
?>
<script src="<?php echo base_url(); ?>assets/js/CreatePOValidation.js" type="text/javascript"></script>
<script>
var RequistQuantity = '';
var AvilBudAmt = '';
 var POMaxDate = '<?php echo $MaxPoDate;?>';
  var d = new Date(POMaxDate);
   var SelectedMaterialCode = [];
 var CollIndex = 0;
  var SelectedMaterialList = {
    Mat: []
};
 $(function() {  
 
 $("#PODate").datepicker({
	minDate : d,
	maxDate : 'now',
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '-100:+0'
});
 $("#Deliverydt").datepicker({
	minDate : 'now',	
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '0:+10'
});	  
	
$('#drpSupplier').change(function() {
    
 var id = $('#drpSupplier').val();

 $("#SupAddress").val('');
 
		if(id != '0')
		{
			var y = <?php echo json_encode($Suplist, JSON_PRETTY_PRINT) ?>;

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

$('#ReqNo').change(function() {
    
 var id = $('#ReqNo').val();
 $("#AvlBudAmt").val('');

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


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


});	


function Ratechange(){
	 
		if($('#ReqNo').val() == "0")
		 {
			 alert('Please select the Requisition Number');
			 $('#ReqNo').focus();
			 return false;
		 }
		 else if($('#MaterialCode').val() == "0")
		 {
			alert('Please select the Material Code');
			$('#MaterialCode').focus();
		   return false;
		 }
		 else if($('#CostCenter').val() == "0")
		 {
				alert('Please select the CostCenterCode');
				$('#CostCenter').focus();
			return false;
		 }
	 ExceedQuantityCheck();
	  
	 if($('#Quantity').val() != '' && $('#Rate').val() != '')
	 {	  
      var txtQuantity = parseFloat( $('#Quantity').val());
	  var txtUnitPrice = parseFloat($('#Rate').val());
	  var Tot =  txtQuantity * txtUnitPrice
	  $('#txtBasicValue').val(Tot);
	  
	 //Service Tax calculation
	$('#AfterServiceTax').val(calculateServiceTax($('#txtBasicValue').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($('#txtBasicValue').val())); 
	 //Swachh Bharat tax
	
	$('#AfterSwachhTax').val(calculateSwachhBharattax($('#txtBasicValue').val()));
	 
	 calculateTotalOrdervalue();
	 
	 var res = ExceedBudget($('#TotalOrderValue').val(), $('#AvlBudAmt').val());
      if(!res)
	  {
		 $('#Rate').focus();
		 return false;
	  }
	 }
	 
}

function EditRatechange(){
	 
		if($('#EditCostCenter').val() == "0")
		 {
				alert('Please select the CostCenterCode');
				$('#EditCostCenter').focus();
			return false;
		 }
	 EditExceedQuantityCheck();
	  
	 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();
	 }
	 
}

function ExceedQuantityCheck()
 {
	var EnterQuantity =   $("#Quantity").val()== '' ? "0.00" :  parseFloat($("#Quantity").val());
	var ReqQuantity = parseFloat(RequistQuantity);
	//alert(ReqQuantity);
	if(EnterQuantity > ReqQuantity)
	{
		 alert('Your exceeding the Quantity from the Requisition Quantity:'+ RequistQuantity  +'.Please adjust the Quantity to proceed further.');
		
		  $('#Quantity').focus();
		 return false;
	}
	else {
		return true;
	}
 }
 function EditExceedQuantityCheck()
 {
	// RequistQuantity
	var EnterQuantity =   $("#EditQuantity").val()== '' ? "0.00" :  parseFloat($("#EditQuantity").val());
	var ReqQuantity = parseFloat(RequistQuantity);
	if(EnterQuantity > ReqQuantity)
	{
		 alert('Your exceeding the Quantity from the Requisition Quantity:'+ RequistQuantity  +'.Please adjust the Quantity to proceed further.');
		
		  $('#EditQuantity').focus();
		 return false;
	}
 }
 
 function ExceedBudget(ValuetoCheck,budgetAmount)
 {
	 var ReqAmount = parseFloat(ValuetoCheck);
	 var BudAmount = parseFloat(budgetAmount);
	 
	 if(ReqAmount > BudAmount )
	 {
		alert('Your exceeding the Avaiable Budget :'+ AvilBudAmt  +'.Please adjust the Product to proceed further.');
		return false; 
	 }
	 else
	 {
		 return true;
	 }
 }
 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($('#txtBasicValue').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 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));   
		 
 }
 
 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)); 
 }
 
function clearTaxField()
{
	$('#txtBasicValue').val('');
	$('#AfterServiceTax').val('');
	$('#AfterEduCess').val('');
	$('#AfterSecHighTax').val('');
	$('#AfterKrishiTax').val('');
	$('#AfterSwachhTax').val('');
	$('#TotalOrderValue ').val('');
	$('#Rate').val('');
	
	$("#ItemName").val('');
	$("#UOM").val('');
	$("#Quantity").val('');
	RequistQuantity	= 	'';	
	
}
function clearEditTaxField()
{
	$('#txtEditBasicValue').val('');
	$('#EditAfterEduCess').val('');
	$('#EditAfterSecHighTax').val('');
	$('#EditAfterServiceTax').val('');
	$('#EditAfterKrishiTax').val('');
	$('#EditAfterSwachhTax').val('');
	$('#EditTotalOrderValue ').val('');
	$('#EditRate').val('');
	
	$("#EditItemName").val('');
	$("#EditUOM").val('');
	$("#EditQuantity").val('');
	RequistQuantity	= 	'';	
	
}
$(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();
                });
            });
</script>
<style>
.modal
{
	padding-right:25% ! important;
}
.dataTables_paginate
{
	    margin-top: -5%;
}
.dataTables_wrapper {
    padding-bottom: 0px;
}
</style>
<div class="content-wrapper">
     <?php
                      $attributes = array('class' => 'form-label-left ServicePO ','name'  => 'ServicePO','id'  => 'ServicePO');
                        
                        echo form_open($this->config->base_url().'/purchaseorder/addPO/',$attributes); ?>
 
	 <section class="content" >
	 <div style="border:2px solid #333">
	  <div id="content"></div>
	 <div>
         <center><b><h2>Siddharth Industries - Service Purchase Order</h2></b></center></div>
         <div class="container-fluid">
		
	<div class="row">
	<div class="col-md-12">
	<div class="col-md-3">
	<div class="col-md-12">
	<label>Requistion No</label>
						 
						
							 <?php
							 
							  $options = array("0"=>'Selected Requisition Numbers'); 
								 if(!empty($ReqList))
						{
						foreach ($ReqList as $SID):
						  
					  // print_r($SID->ReqNo);
						   $options[$SID->ReqNo] = $SID->ReqNo ."-". $SID->ReqBy;
                           $ReqType = $SID->ReqType;
						endforeach;
						}	
							echo form_multiselect('RequistionNo', $options,set_value('RequistionNo'),'id="RequistionNo"' , 'required="true"');

							?>
	</div>
	<div class="col-md-12">
		<label>Purchase Order Date</label>
						<div class="form-group">
									<?php
							 $data = array('name' => 'PODate','value' => set_value('PODate',$CurrentDate),'id'=>'PODate',  'class' => 'form-control' ,'required' => 'true', 'onkeypress'=>'return false;');
							echo form_input($data);
							?>   
						</div>
	</div>							
						 
	</div>
	<div class="col-md-9">
		<div class="col-md-4">
			<div class="col-md-12">
				<label>Supplier</label>
					 
						 <?php
						$options = array("0"=>'Select Supplier');     
						//print_r(  $options);
						
						if(!empty($Suplist))
						{
						foreach ($Suplist as $SID):
						  
					   
						  $options[$SID->SupplierID] =  $SID->SupplierID.' '.' - '.' '.$SID->SupplierName;

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

						?>						 
					 
			</div>
			<div class="col-md-12"><br/>
				<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>
		<div class="col-md-4">
			<div class="col-md-12">
				 <label>Purchase Order Type</label>
						<div class="form-group">
						
									<?php
							 $data = array('name' => 'POType','value' => set_value('POType',SERVICE),'id'=>'POType',  'class' => 'form-control' ,'readonly' => 'true');
							echo form_input($data);
							?>   
						</div>
			</div>
			<div class="col-md-12">
				 <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>
		<div class="col-md-4">
			<div class="col-md-12">
				 <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 class="col-md-12" id="Deliverydtdiv"><br/>
				<label>Delivery Date</label>
					<div class="form-group">
								<?php
						 $data = array('name' => 'Deliverydt','value' => set_value('Deliverydt',$CurrentDate),'id'=>'Deliverydt',  'class' => 'form-control' ,'required' => 'true', 'onkeypress'=>'return false;');
						echo form_input($data);
						?>   
					</div>
			</div>
			<div class="col-md-12" id="Schedulediv" style="display:none;"><br/>
					<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>
		
	</div>
	</div>	   
    </div>
	
          <div class="container-fluid">  
 	 <table class="table table-bordered" style="border:1px solid #333" id="ServiceTable">
  <div style="padding-right:10px">
<div align="right">
  <a data-toggle="modal" ><button type="submit"  onclick="myFunction();" class="btn btn-primary" id="abcd" >Select Line Item</button> </a> 
 
  
  
<!-- Model for servicepo -->
    <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-3">
						 <label>Req No</label>
									<div>
										 <?php
											$RL = array("0"=>'Select Req No');     
											if(!empty($RequistionDetails))
											{
											foreach ($RequistionDetails as $SID):			   
												$RL[$SID->ReqNo] =  $SID->ReqNo.' '.' - '.' '.$SID->DepartmentName;
											endforeach;
											}
							
											echo form_dropdown('ReqNo', $RL,set_value('ReqNo'),'id="ReqNo"' ,'class="form-control"');

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

						?>		
									</div>
						 </div>
						  <div class="col-md-3">
						   <label>Available Budget Amount</label>
									<div class="form-group">
												<?php
										 $data = array('name' => 'AvlBudAmt','value' => set_value('AvlBudAmt'),'id'=>'AvlBudAmt',  'class' => 'form-control' ,'readonly' => 'true');
										echo form_input($data);
										?>   
									</div>
						 </div>
		 </div>
		 <div class="col-md-12">
						  <div class="col-md-2">
						  <label>Item Code</label>
									<div>
										 <?php
										$options = array("0"=>'Item Code');     
										//print_r(  $options);
										
																			
							
										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'=>'Ratechange()');
										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'=>'Ratechange()' );
										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 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' => '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-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' => '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-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' => 'AfterSecHighTax','value' => set_value('AfterSecHighTax'),'id'=>'AfterSecHighTax',  'class' => 'form-control' ,'placeholder' => 'After High Edu.','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' => 'AfterKrishiTax','value' => set_value('AfterKrishiTax'),'id'=>'AfterKrishiTax',  'class' => 'form-control' ,'placeholder' => 'After Krishi Kalyan tax.','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' => '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-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' => 'TotalOrderValue','value' => set_value('TotalOrderValue'),'id'=>'TotalOrderValue',  'class' => 'form-control' ,'placeholder' => 'Total value','readonly' => 'true');
											echo form_input($data);
											?>   
										</div>
							 </div>
		 </div>
		 
			</div>
		
			
			  <br/>
			   <br/>
			<div class="modal-footer">
			<a class="btn btn-primary font AddService"  ID="AddService" ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add Service</span></a>
			<a class="btn btn-primary" data-dismiss="modal"  value="Cancel">Cancel</a>
			
			</div>
		  </div>
		 </form>
			 
		  </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>
									<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>	
    
   <br/>
  
	<div class="box-body" style="margin-top: -8%;">
              <table id="serviceTax" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
                <thead style="background-color:#ddf">
                <tr>
					<th>SNo</th>
					<th>Requisition No</th>
					<th>Item Name</th>
					<th>Quantity</th>
					<th>UOM</th>
					<th>Rate</th>
					<th>Basic Amount</th>
					 <th>Tax Amount</th>
					<th>Total Order Amount</th>
					<th>Action</th>
                </tr>
                </thead>				
               
             <tbody id='ServiceAppend'>     
    
			</tbody>
              </table>
            </div>
	   
  </table>
	<div class="row" style="border: 1px solid">
		<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' => '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="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 Save"  ID="Save"onclick="Save(0)" >&nbsp;&nbsp;<span class="bold">Save</span></a> 
					<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><br/>
 </div>
       
</div> 
</div>
</div>
</section>
</div>
<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>
var index     = '1';
var userid  = '';
$("#EDITSERVICE").on("shown.bs.modal", function(e) {
		userid = $(e.relatedTarget).data('userid');
		// alert(userid);
		var tr= document.getElementById(userid);
		var cellval = tr.cells;
		var id= $('#Reqnumber'+userid).val();
		
		$('#EditReqNo').val($('#Reqnumber'+userid).val());
		$('#EditdeptName').val($('#departmentName'+userid).val());
		$("#EditCostCenter").val($('#costCode'+userid).val());
		$('#EditAvlBudAmt').val($('#AvilBudget'+userid).val());
		
		$('#EditItemName').val($('#materialName'+userid).val());
		$('#EditUOM').val($('#uom'+userid).val());
		$('#EditQuantity').val($('#quantity'+userid).val());
		RequistQuantity = $('#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);
		
		
		
		$("#EditMaterialCode").empty();
		var Material = <?php echo json_encode($MaterialList, JSON_PRETTY_PRINT) ?>;
		 // For Binding Material list center for the selected Requistion Number	
		$("#EditMaterialCode").append( $('<option></option>').val($('#materialCode'+userid).val()).html($('#materialCode'+userid).val() + "-" + $('#materialName'+userid).val()  ) );
		var isAdded = "0";
		 for(i=0;i<Material.length;i++)
		{
		$.each(Material[i], function(idx, obj) {
			
				if(obj.ReqNo === id )
				{
								   
						$.each(SelectedMaterialList.Mat, function(idx1, el){															
							if (id == el.ReqNo )
							{
								
								if(el.materialCode == obj.MaterialCode)
								{
									
										isAdded  = "1";
										return false;																		
								}
								else
								{
									isAdded  = "0";
								}
								
							}
												
					
					});
					
					
						if(isAdded  == "0")
						{
							
							$("#EditMaterialCode").append( $('<option></option>').val(obj.MaterialCode).html(obj.MaterialCode + "-" + obj.MaterialName));
						}
												
				}
			
			
		});
		}
	   
});

$('.AddService').click(function(){
        
		
      if(validateServiceTax())
	  {
		// alert('inside Addservice');
		 var temp = index;
		 var Reqnumber = $('#ReqNo').val();
		 var departmentName = $('#deptName').val();
		 var AvilBudget = $('#AvlBudAmt').val();
		 var costCode = $('#CostCenter').val();
         var materialCode =$('#MaterialCode').val();
         var materialName =  $("#ItemName").val();
         var uom = $("#UOM").val();
		 var quantity = $("#Quantity").val();
		 var itemRate = $("#Rate").val();
		  
		
		  var 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 = $("#txtBasicValue").val();
	
		
		 var TotalTaxValue = calculateTaxValue();		 
	   
		 $('#MaterialCode option[value='+materialCode+']').remove();
		 
		  SelectedMaterialCode[CollIndex] = materialCode;
			CollIndex = CollIndex + 1;
			
			SelectedMaterialList.Mat.push({ 
        "materialCode" :  materialCode,
        "ReqNo"  : Reqnumber,
      
		});	
		 
		 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}));
		  
		
		 
		 var theForm = $(".ServicePO");
		
		 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); 
		   clearServiceModalFields();
		 
      	  }	  
   
 });

 $('.EditService').click(function(){
         
   		
        if( validateEditServiceTax())
        {
            //alert('inside Add');			
            var CostCode =  $("#EditCostCenter").val();
			 var AvilBudget = $('#EditAvlBudAmt').val();
			var editMaterialCode =  $("#EditMaterialCode").val();
			var editDescription = $("#EditItemName").val();		
			var editUOM = $('#EditUOM').val();
			var editQuantity = $('#EditQuantity').val();
			
			 var itemRate = $("#EditRate").val();
		  
		
		  var 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();	 			
		
      }
    
 });
 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 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 = $('#txtBasicValue').val() == '' ? '0.00' : $('#txtBasicValue').val();
		
		
		var TotalOrderValueSummary = $('#txtTotalOrderValueSummary').val() == '' ? '0.00' : $('#txtTotalOrderValueSummary').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) );	
		$('#txtTotalOrderValueSummary').val((parseFloat(TotalOrderValueSummary) + parseFloat(TotalVal)).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;
	  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;
			
		var AfterServiceTax = $('#ServiceTax'+rowid).val() == '' ? '0.00' : $('#ServiceTax'+rowid).val();
		var AfterEduCess = $('#EduCess'+rowid).val() == '' ? '0.00' : $('#EduCess'+rowid).val();
		var AfterSecHighTax = $('#SecHighTax'+rowid).val() == '' ? '0.00' : $('#SecHighTax'+rowid).val();
		var AfterKrishiTax =$('#KrishiTax'+rowid).val() == '' ? '0.00' : $('#KrishiTax'+rowid).val();
	    var AfterSwachhTax = $('#SwachhTax'+rowid).val() == '' ? '0.00' : $('#SwachhTax'+rowid).val();
		var TotalVal =$('#TotalOrderValue'+rowid).val() == '' ? '0.00' : $('#TotalOrderValue'+rowid).val();
		
		var Quantity = $('#quantity'+rowid).val() == '' ? '0.00' : $('#quantity'+rowid).val();
		var ItemRate = $('#itemRate'+rowid).val() == '' ? '0.00' : $('#itemRate'+rowid).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);
		
		}    
			
		
 }		while (i < rows);  	

		$('#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) );
		$('#txtTotalOrderValueSummary').val(parseFloat(TotSummary).toFixed(2) );
		
}
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 clearServiceModalFields()
{
	// 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('');			 

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

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 removeItem = $('#materialCode'+rowid).val();      
		
		
			
		  SelectedMaterialCode.splice( SelectedMaterialCode.indexOf('removeItem'), 1 );
			$.each(SelectedMaterialList.Mat, function(i, el){
	    
			if (this.materialCode == removeItem){//Type = '';
		          SelectedMaterialList.Mat.splice(i, 1);
		}
		});
		
		  if(DelRows != '')
		  {
		  DelRows = DelRows + ":" + rowid;
		  }
		  else
		  {
			  DelRows=  "0" + ":" + rowid;
		  }
		  $('#txtDeletedRow').val(DelRows);
		   populateValueMainFormForDeleteItem(rowid);
		}
       	
} 

function populateValueMainFormForDeleteItem(rowid)
{
	  
		
       // alert(rows);
		var TotServiceTax = $('#txtTotalServiceTax'+rowid).val();
		var TotEduCess = $('#txtTotalEducess'+rowid).val();
		var TotSecHighTax = $('#txtTotHigherEdu'+rowid).val();
		var TotKrishiTax = $('#txtTotalKrishiKalyan'+rowid).val();
		var TotSwachhTax = $('#txtTotSwachhBharat'+rowid).val();
		var TotSummary = $('#TotalOrderValue'+rowid).val();
		var TotBasicAmout = $('#txtTotalOrderValueSummary'+rowid).val();
		
	  
			
		var AfterServiceTax = $('#ServiceTax'+rowid).val() == '' ? '0.00' : $('#ServiceTax'+rowid).val();
		var AfterEduCess = $('#EduCess'+rowid).val() == '' ? '0.00' : $('#EduCess'+rowid).val();
		var AfterSecHighTax = $('#SecHighTax'+rowid).val() == '' ? '0.00' : $('#SecHighTax'+rowid).val();
		var AfterKrishiTax =$('#KrishiTax'+rowid).val() == '' ? '0.00' : $('#KrishiTax'+rowid).val();
	    var AfterSwachhTax = $('#SwachhTax'+rowid).val() == '' ? '0.00' : $('#SwachhTax'+rowid).val();
		var TotalVal =$('#TotalOrderValue'+rowid).val() == '' ? '0.00' : $('#TotalOrderValue'+rowid).val();
		
		var Quantity = $('#quantity'+rowid).val() == '' ? '0.00' : $('#quantity'+rowid).val();
		var ItemRate = $('#itemRate'+rowid).val() == '' ? '0.00' : $('#itemRate'+rowid).val();	
		var BasicVal = parseFloat(Quantity) * parseFloat(ItemRate);
		//alert(TotalVal);
		
		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) );
		$('#txtTotalOrderValueSummary').val(parseFloat(TotSummary).toFixed(2) );	

		
		
}

function validateServiceTax()
 {  

	if($('#ReqNo').val() == "0")
	{
		alert('Please select the Requisition Number');
		$('#ReqNo').focus();
		return false;
	}
	else if($('#CostCenter').val() == "0")
	{
		alert('Please select the Cost center');
		$('#CostCenter').focus();
		return false;
	}
	else if($('#MaterialCode').val() == "0")
	{
		alert('Please select the Material Code');
		$('#MaterialCode').focus();
		return false;
	}		
	else if($('#Quantity').val() == '')
	{
		alert('Please Enter the Quantity value');
		$('#Quantity').focus();
		return false;
	}
	else if($('#Rate').val() == '')
	{
		alert('Please Enter the Rate of the Item');
		$('#Rate').focus();
		return false;
	}
	else if(ExceedQuantityCheck() ==  false)
	{  
		return false;
	}
	else if(ExceedBudget($('#TotalOrderValue').val(),$('#AvlBudAmt').val()) == false)
	{
		 $('#Rate').focus(); 
				return false;
	}
	else
	{
		return true;
	}
		
 }
 function validateEditServiceTax()
 {  

	if($('#EditCostCenter').val() == "0")
	{
		alert('Please select the Cost center');
		$('#EditCostCenter').focus();
		return false;
	}
	else if($('#EditMaterialCode').val() == "0")
	{
		alert('Please select the Material Code');
		$('#EditMaterialCode').focus();
		return false;
	}		
	else if($('#EditQuantity').val() == '')
	{
		alert('Please Enter the Quantity value');
		$('#EditQuantity').focus();
		return false;
	}
	else if($('#EditRate').val() == '')
	{
		alert('Please Enter the Rate of the Item');
		$('#EditRate').focus();
		return false;
	}
	else if(EditExceedQuantityCheck() ==  false)
	{  
		return false;
	}
	else if(ExceedBudget($('#EditTotalOrderValue').val(),$('#EditAvlBudAmt').val()) == false)
	{
		 $('#EditRate').focus(); 
		 return false;
	}
	else
	{
		return true;
	}
		
 }
// 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>
<script>
function Save(status)
{  
if(status == '0')
{
	stat = '<?php echo PO_DRAFT; ?>';
}
else
{
	stat = '<?php echo PO_CREATED; ?>';
}

var splinstr = $('#txtSpcialInstruction').val();
var deladd = $('#DeliveryAddr').val();
$('#SpcialInstruction').val(splinstr);
$('#txtDeliveryAddress').val(deladd);
$('#txtStatus').val(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:$('.ServicePO').serialize(),
			type:"POST",
			url:"<?php echo base_url() ?>servicepurchaseorder/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");	
				}				
		
				}
  
				});
			}

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



</script>

