<h2>TDS Account Linking</h2>
<script type="text/javascript">
  function fillSection(str,i){
  
 		var classsificationId =str; 
		 //document.getElementById("classsification").options[document.getElementById("classsification").selectedIndex].value;
 //
	//alert(classsificationId);
	
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
						
    			document.getElementById("section_"+i).value=xmlhttp.responseText;
    		}
  		}
       
		xmlhttp.open("POST","item.php?classsificationId="+classsificationId,true);
		xmlhttp.send();
 //
  }
</script>

<?php 
	if($_REQUEST['action']=='insert'){
	
   $cont_item = count($_POST['classsification']);
	
	$_POST['section'];
	$_POST['tdsRate'];
	$_POST['eCessRate'];
	$_POST['sheCessRate'];
	
	for($r=0; $r<$cont_item; $r++)
	{
		if($_POST['section'][$r] !=""){
			$data['classsification']  =$_POST['classsification'][$r];
			$data['section']  =$_POST['section'][$r];
			$data['tdsRate']  =$_POST['tdsRate'][$r];
			$data['CessRate']  =$_POST['eCessRate'][$r];
			$data['sheCessRate']  =$_POST['sheCessRate'][$r];
			//echo '<pre>'; print_r($data); exit;
			$s->RecordInsert('tds_post', $data);
		}
	
	
	}
	//print_r($data);

	
	
	
	}


?>



<form method="post" action="" name="tdsForm" >
<input type="hidden" name="action" value="insert" />
<table width="100%" border="1" cellspacing="1" cellpadding="2">
  <tr>
    <th width="7%" align="center">S. No.</th>
	<th width="20%" align="center">Classification</th>
    <th width="15%" align="center">Section</th>
	<th align="center" width="20%">TDS  Rate</th>
    <th align="center" width="20%">E. Cess Rate</th>
    <th align="center">SHE. Cess Rate</th>
  </tr>
  <?php 
  
	$query1=DB_query("SELECT * FROM tds_master GROUP BY classification",$db); 
	while($result1=DB_fetch_array($query1)) {
		$classificationData[] = $result1;
	}
	$queryData=DB_query("SELECT acledg.AccountsID, acledg.AccountName, acgrp.GroupName FROM accountledger acledg  INNER JOIN accountgroupmaster acgrp ON acledg.UnderGroup =acgrp.GroupId WHERE  acgrp.GroupName='Duty And Taxes'",$db);
	while($ledger=DB_fetch_array($queryData)) {
		$ledgerInfo[]= $ledger;
	
	}
	//echo '<pre>'; print($classificationData[0]['classification']); exit;
	?>
	<?php for($rowcount=0;$rowcount<count($classificationData);$rowcount++){ ?>
  <tr style="background-color:#fff;">
    <td><?php echo $rowcount+1; ?>.</td>
    <td>
		<select name="classsification[]" id="classsification_<?php echo $rowcount; ?>" style="width:100%;" onchange="fillSection(this.value,<?php echo $rowcount; ?>);">
			<?php for($rowdata=0; $rowdata<count($classificationData); $rowdata++){ ?>
			
				<option value="<?php echo $classificationData[$rowdata]['id']?>"><?php echo $classificationData[$rowdata]['classification']?> </option>
				
			<?php }?>	  
  			
  		</select>
	</td>
	<td>
		<input type="text" name="section[]" id="section_<?php echo $rowcount; ?>" value="" style="width:100%;" />
	</td>
    <td>
		<select name="tdsRate[]" id="tdsRate_<?php echo $rowcount; ?>" style="width:100%;">
		
		<?php for($rows=0;$rows<count($ledgerInfo);$rows++) { ?> 
		<option value="<?php echo $ledgerInfo[$rows]['AccountsID']; ?>" ><?php echo $ledgerInfo[$rows]['AccountName']; ?></option>
		<?php } ?>
  		</select>
	</td>
    <td>
		<select name="eCessRate[]" id="eCessRate_<?php echo $rowcount; ?>" style="width:100%;">	  
  		<?php for($rows=0;$rows<count($ledgerInfo);$rows++) { ?> 
		<option value="<?php echo $ledgerInfo[$rows]['AccountsID']; ?>" ><?php echo $ledgerInfo[$rows]['AccountName']; ?></option>
		<?php } ?>
  		</select>
	</td>
    <td><select name="sheCessRate[]" id="sheCessRate_<?php echo $rowcount; ?>" style="width:100%;">	  
  		<?php for($rows=0;$rows<count($ledgerInfo);$rows++) { ?> 
		<option value="<?php echo $ledgerInfo[$rows]['AccountsID']; ?>" ><?php echo $ledgerInfo[$rows]['AccountName']; ?></option>
		<?php } ?>
  		</select>
	</td>
  </tr>
  <?php } ?>
  
</table>
<input type="submit" name="submit" value="save" />

</form>