<?php $PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/stockcalculation.php');
include('includes/function_lib.php');
 //echo $_GET['type'];
  

 if(isset($_REQUEST['type']))
 {
     $store_sql = "Select id,issue_slipno from addissue where to_store='".$_REQUEST['store']."' and cancel_issue='0' and status='Pending'";
    	$store_result = DB_query($store_sql,$db);
    	?>
    		<option value="0">Select</option>
    		<?php 
    		while($store_row = DB_fetch_array($store_result))
			{?>
				<option value="<?php echo $store_row['id'] ; ?>" ><?php echo $store_row['issue_slipno'] ; ?></option>
	  <?php }
	   
		exit;
 }

  if(isset($_REQUEST['type1']))
 {
     $store_sql = "Select store,StoreName,storetype.id as id from addissue inner join storetype on storetype.StoreCode=addissue.store where addissue.id='".$_REQUEST['issueid']."' and cancel_issue='0' and status='Pending'";
      $store_result = DB_query($store_sql,$db);
      ?>
        <?php 
        while($store_row = DB_fetch_array($store_result))
      {?>
        <option value="<?php echo $store_row['id'] ; ?>" ><?php echo $store_row['StoreName'] ; ?></option>
    <?php }
     
    exit;
 }
 ?>


 <?php 
 	if(isset($_REQUEST['showitems']))
 	{?>
 		<div style="overflow:auto; width:100%; margin:8px 0; height:auto">
    <div id="itemdata">
      <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
        <tr>
          <th colspan="2">S. No.</th>
          <th width="10%">Item Code</th>
          <th>Item Name</th>
          <th width="10%">Batch No.</th>
          <!--<th width="10%" bgcolor="#CCCCCC">UOM</th>
          <th width="10%" bgcolor="#CCCCCC" colspan="2"><center>Specification</center></th>-->		 
    		  <th width="10%">Issue Qty.</th> 
    		  <th style='text-align:center;' colspan='6'>Qty. to be Receive</th>		 
    		  <!-- <td width="10%" bgcolor="#CCCCCC"><strong>Issue Rate</strong></td>
		      <td width="10%" bgcolor="#CCCCCC"><strong>Total Amt</strong></td>-->
        </tr>
        <tbody id="dataTable">
        	<?php
        	$i=1;
         // echo "select * from issueqty where issue_id='".$_REQUEST['issueid']."'";
          //exit;
             $sql_details=DB_query("select * from issueqty where issue_id='".$_REQUEST['issueid']."'",$db);
             while($r_dtl=DB_fetch_array($sql_details))
             {
                $itemname=$s->getField('item_master','id',$r_dtl['mst_itemid'],'item_name');
                $itemcode=$s->getField('item_master','id',$r_dtl['mst_itemid'],'StockId');
                $confac=$s->getField('item_master','id',$r_dtl['mst_itemid'],'conv_factor');

                $conv_unit=$s->getField('item_master','id',$r_dtl['mst_itemid'],'conv_factor');

            $check_pending_qty=DB_query("SELECT SUM(B.receiveqty) AS qty FROM `material_return_details` B INNER JOIN `material_return` A 
              ON A.id=B.parentId WHERE A.issue_slipno='".$_REQUEST['issueid']."' and B.itemid='".$r_dtl['mst_itemid']."'",$db);
            if(DB_num_rows($check_pending_qty)>0)
            {
             $row1=DB_fetch_array($check_pending_qty);

             $pending_qty=$r_dtl['issueqty']-$row1['qty'];           
            }
            else
            {
               $pending_qty=$r_dtl['issueqty'];
            } 
           //echo $pending_qty."##".$confac;
               
   	 ?>
  <tr>
  <td width="3%"><input name="delitem[]" type="checkbox" value="<?php echo $r_dtl['id'];?>" id="delitem" /></td>
  <td width="1"><input  type="hidden"   readonly=""  id="itemid_<?php echo $i; ?>"  name="itemdataid[]" value="<?php echo $r_dtl['mst_itemid'];?>" /></td>
  <td><input type="text" value="<?php echo $itemcode; ?>" tabindex=""   id="itemcode_<?php echo $i; ?>" name="itemcode[]" style="width:100%;" readonly /> </td>
  <td><input type="text" name="desc[]" readonly id="itemname_<?php echo $i; ?>" value="<?php echo $itemname; ?>" style="width:100%;"/></td>            
  <td><input  type="text" name="batchno[]" style="width:100%;" id="batchno_<?php echo $i;?>" value="<?php echo $r_dtl['batch_no'];?>" readonly /></td>
   <td><input type="text" name="pending_qty[]"  style="width:100%;"id="Stockbalance_<?php echo $i; ?>" 
    value="<?php  echo $pending_qty;?>" readonly/></td>		 	
  <td width="7%"><input  type="text" name="issueqty[]" style="width:100%;" id="issueqty_<?php echo $i; ?>" value="<?php echo $pending_qty; ?>" onkeyup="calamtNew(this.value,this.id)" onkeypress="return isNumberKey(event)"  /></td>
  <td width="7%"><select  name="uom[]"   id="uom_<?php echo $i; ?>"   > <?php $r_unit=DB_query("select * from unitsofmeasure where unitid='".$r_dtl['mst_unitid']."'",$db);
                   while($runit=DB_fetch_array($r_unit))
                   {
                   	$u='';
                   	if($runit['unitid']==$r_dtl['mst_unitid'])
                   		$u="selected";
        	 ?>
  <option value="<?php echo $runit['unitid']; ?>" <?php echo $u; ?>><?php echo $runit['unitname']; ?></option>
        	 <?php } ?></select></td>
<td width="1"><input  type="hidden" name="confac[]" style="width:100%;" id="confac_<?php echo $i; ?>" value="<?php echo $r_dtl['confac']; ?>"   /></td>
<td width="7%"><input  type="text" name="secondaryqty[]" style="width:100%;" readonly="" id="secondary_<?php echo $i; ?>" value="<?php echo $pending_qty*$confac; ?>"   /></td>
<td width="7%"><select  name="uom1[]"   id="uom1_<?php echo $i; ?>"   >  
        	<?php $r_unit=DB_query("select * from unitsofmeasure where unitid='".$conv_unit."'",$db);
                   while($runit=DB_fetch_array($r_unit))
                   {
                   	$u='';
                   	if($runit['unitid']==$r_dtl['conv_unit'])
                   		$u="selected";
        	 ?>
        	 <option value="<?php echo $runit['unitid']; ?>" <?php echo $u; ?>><?php echo $runit['unitname']; ?></option>
        	 <?php } ?>
            </select></td>
		 	 <td width="1"><input type='hidden' id="confactor_<?php echo $i; ?>" value='<?php echo $confac; ?>'></td>
          </tr>
          <?php $i++; } ?>
        </tbody>
      </table>
    </div>
  </div>  
 	<?php 
 	}?>

 

 
        
          
       