<?php $PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/fun-HRClass.php');
/* Get opening balance */

$dqty=$_REQUEST['dqty'];
$store=$_REQUEST['store'];
$itm=$_REQUEST['itm'];
$ci=$_REQUEST['ci'];
?> 
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
<tr>
   	<th>SRN Id</th>
    <th>Qty</th>
    <th>Dis Qty</th>
</tr> 
<?php   
$d=0;
while($d<$dqty)	{
	$avl_sql = "SELECT srn_id,transferqty FROM log_srnqty where mst_itemid='".$itm."' AND srn_id IN (select id from log_srn where store='".$store."') AND transferqty>0 order by srn_id";
	$Resulta=DB_query($avl_sql,$db);
	$dm=0;
	while($myrowa=DB_fetch_array($Resulta)){
	if($dqty==0){break;}
		$avl_sqlb = "SELECT SUM(dispatchqty) AS dqty FROM log_srndispatchgrnqty where mst_itemid='".$itm."' AND srn_id='".$myrowa['srn_id']."'";
		$Resultb=DB_query($avl_sqlb,$db);
		$myrowb =DB_fetch_array($Resultb);
		if($myrowb['dqty']==''){$myrowb['dqty']=0;}
		if($myrowa['transferqty']==''){$myrowa['transferqty']=0;}
		$bal=$myrowa['transferqty']-$myrowb['dqty'];
		if($bal>0){
?> 
<tr bgcolor="#FFFFFF">
	<td><input type="text" id="ddgrn_<?php echo $ci.$dm;?>" name="ddgrn_<?php echo $ci;?>[]" value="<?php echo $myrowa['srn_id'];?>" readonly="true" /></td>
	<td ><input type="text" id="ddqty_<?php echo $ci.$dm;?>" name="ddqty_<?php echo $ci;?>[]" value="<?php echo $bal;?>" readonly="true" /></td>
	<?php if($dqty>=$bal){?>		
	<td ><input type="text" id="dddqty_<?php echo $ci.$dm;?>" name="dddqty_<?php echo $ci;?>[]" value="<?php  echo $bal; $dqty=$dqty-$bal;?>" readonly="true" /></td>
	<?php }else{?>
	<td ><input type="text" id="dddqty_<?php echo $ci.$dm;?>" name="dddqty_<?php echo $ci;?>[]" value="<?php  echo $dqty; $dqty=0;?>" readonly="true" /></td>
	<?php } ?>
</tr>
<?php  $dm++;} ?>	
<?php  } ?>	
<?php  } ?>	
<tr><td colspan="3"><input type="hidden" id="rowcal_<?php echo $ci;?>" name="rowcal_<?php echo $ci;?>" value="<?php echo $dm;?>" /></td></tr>
</table>


