<?php 
$PageSecurity = 4;
include('includes/session.inc');
include('includes/DefineSuppTransClass.php');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
$function_filter[0]=$_POST['site'];
$function_filter[1]=$_POST['store'];
$function_filter[2]=date('Y-m-d');

?>

<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
      <tr>
        <th width="9%">Item Code</th>
        <th width="1"></th>
        <th>Name</th>
        <th width="12%">Pkg Description</th>
        <th width="5%">Batch No.</th>
        <th width="6%">MFG.</th>
        <th width="6%">Expiry</th>
        <th width="5%">Stock Balance</th>
        <th colspan="2" style="text-align:center">Issue Qty.</th>
        <th colspan="2" style="text-align:center">Pending Qty.</th>
        <th colspan="7" style="text-align:center">Received Qty.</th>       
      </tr>
      <?php
            $receivedQty=array();
            $receivedQty1=array();
            $receivedQtym2=array();

            $resultIssue=DB_query("select itemid,uom,uom1, SUM(reciveqty) as receivedQty, SUM(stock_qty2) as receivedQty1 from transfer_receipt_details
             where issue_slip_no='".$_POST['id']."' group by itemid",$db);
            while($rowreceived=DB_fetch_array($resultIssue))
            {
             $receivedQty[$rowreceived['itemid']]=$rowreceived['receivedQty'];
              $receivedQty1[$rowreceived['itemid']]=$rowreceived['receivedQty1'];            
            }   

	  $i=0;
	  $sql=DB_query("select * from transfer_issue_details where transfer_issue_id='".$_POST['id']."' and status=0",$db);

	  while($row=DB_fetch_array($sql))
	  {
	    $itemcode=$s->getField('item_master','id',$row['itemid'],'StockID');
	    $itemname=$s->getField('item_master','id',$row['itemid'],'item_name');
	    $unitid=$row['uom'];
      $unitid1=$row['uom1'];
      $unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
      $unit1=$s->getField('unitsofmeasure','unitid',$unitid1,'unitname');
        
      /*  $op=openingBalance($function_filter,$row['itemid']);
        $in_1=receivedMRN($function_filter,$row['itemid']);
        $out_1=issueSlip($function_filter,$row['itemid']);
        $out_2=issueSiteToSite($function_filter,$row['itemid']);    
        $in_2=receivedSiteToSite($function_filter,$row['itemid']);
        $out_3=issueMatarialReturn($function_filter,$row['itemid']);
        $in_3=receivedReturn($function_filter,$row['itemid']);  
        $out_4=Rgpchallan($function_filter,$row['itemid']);
        $out_5=Nrgp($function_filter,$row['itemid']);
        $in_4=Rgpreturn($function_filter,$row['itemid']);  
        $in_5=FinishedMR($function_filter,$row['itemid']);
        $in_6=MaterialConReceived($function_filter,$row['itemid']);
        $out_6=MaterialConIssue($function_filter,$row['itemid']);
        $in_7=PhysicalStockPlus($function_filter,$row['itemid']);
        $out_7=PhysicalStockMinus($function_filter,$row['itemid']);
        $out_8=dispatchIssue($function_filter,$row['itemid']);
        $out_9=jobWorkChallan57Issue($function_filter,$row['itemid']);
        $in_8=jobWorkChallan57Received($function_filter,$row['itemid']);
        $in_9=directPurchase($function_filter,$row['itemid']);
        $in_10=saleReturn($function_filter,$row['itemid']);
        $out_10=invoice($function_filter,$row['itemid']);
        $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9 + $in_10);
        $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9 + $out_10);
        $tot=$invalue-$outvalue;
        $stockallitems=$tot;
        $total_current=$tot;	  */

        $sql_cur_stock="select sum(inwardqty_primary),sum(outwardqty_primary) from stock_valuation_tbl where site='".$_POST['site']."' and store='".$_POST['store']."' and mst_itemid='".$row['itemid']."' and batch_no='".$row['batch_no']."' ";
        $result_cur_stock=DB_query($sql_cur_stock,$db);
        $rs_cur_stock=DB_fetch_array($result_cur_stock);
        $cur_stock=$rs_cur_stock[0]-$rs_cur_stock[1];

	   ?>
	  	  <?php
 ?>
<tr bgcolor="#fff">
  <td><?php //print_r($receivedQtym1);?><input type="text" value="<?php echo $itemcode; ?>" tabindex="" id="itemcode_<?php echo $i; ?>" name="delitem[]" style="width:100%;" readonly/></td>
  <td><input type="hidden" readonly="" value="<?php echo $row['itemid']; ?>" id="itemdataid_<?php echo $i; ?>" name="itemdataid[]" /></td>
  <td><input type="text" name="itemname[]"  id="itemname<?php echo $i; ?>" style="width:100%;"  value="<?php echo $itemname; ?>" readonly/></td>
  <td><input type="text" name="desc[]"  id="desc<?php echo $i; ?>" size="25" style="width:100%;"  value="<?php echo $row['item_description']; ?>" readonly/></td>
  <td><input type="text"  name="batch_no[]" style="width:100%" value="<?php echo $row['batch_no']; ?>" name="batch_no[<?php echo $row['itemid']; ?>]" readonly></td>
  <td><input type="text" name="mfg[]" style="width:100%" readonly="" value="<?php echo ConvertSQLDate($row['mfg']); ?>"></td>
  <td><input type="text" name="expiry[]" style="width:100%" readonly="" value="<?php echo ConvertSQLDate($row['expiry']); ?>"></td>
  <td><input type="text" name="stock[]"  id="Stockbalance_<?php echo $i; ?>"  style="width:100%;" value="<?php echo $cur_stock; ?>"   readonly/></td>
  <td width="5%"><input  type="text" name="issueqty[]" readonly value="<?php echo $row['issueqty']; ?>"  id="issueqty_<?php echo $i; ?>" style="width:100%;" /></td> 
  <td width="5%"><input  type="text" name="issueqtyfec[]" readonly value="<?php echo $row['issueqty1']; ?>"  id="issueqtyfec_<?php echo $i; ?>" style="width:100%;" /></td>  
  <td width="5%"><input  type="text" name="pending_qty[]" readonly value="<?php echo ($row['issueqty'] - $receivedQty[$row['itemid']] ); ?>"  style="width:100%;" /></td>  
  <td width="5%"><input  type="text" name="pending_qtyfec[]" readonly value="<?php echo ($row['issueqty1'] - $receivedQty1[$row['itemid']] ); ?>"  style="width:100%;" /></td>    
  <td width="5%"><input  type="text"  onkeyup="chk_recived_qty(this,<?php echo $i; ?>)" onkeypress="return isNumberKey(event)" name="receivedQty[]" value="<?php echo ($row['issueqty'] - $receivedQty[$row['itemid']] ); ?>"  id="receivedQty_<?php echo $i; ?>" style="width:100%;" /></td>
  <td width="5%"><input  type="text" name="uom[]" style="width:100%;"  id="uom_<?php echo $i; ?>" value="<?php echo $unit; ?>"   /></td>
  <td width="1"><input  type="hidden" name="confac[]" style="width:100%;"  id="confac_<?php echo $i; ?>" value="<?php echo $row['conv_fac']; ?>"   /></td>
     <?php $secondary_qty=($row['issueqty']-$receivedQty[$row['itemid']])*$row['conv_fac']; ?>
  <td width="5%"><input  type="text" name="secondaryqty[]" style="width:100%;"  id="secondary_<?php echo $i; ?>" value="<?php echo $secondary_qty; ?>"  readonly /></td>
  <td width="5%"><input  type="text" name="uom1[]" style="width:100%;"  id="uom1_<?php echo $i; ?>" value="<?php echo $unit1; ?>" readonly  /></td>
  <td width="1"><input  type="hidden" name="uomid1[]" style="width:100%;"  id="uomid1_<?php echo $i; ?>" value="<?php echo $unitid1; ?>"   /></td>
  <td width="1"><input  type="hidden" name="uomid[]" style="width:100%;"  id="uomid_<?php echo $i; ?>" value="<?php echo $unitid; ?>"   /></td>  
</tr>
		<?php $i++; } ?>
     
    </table>
    <br>
    <table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td align="right" width="13%"><strong>Remarks</strong></td>
    <td><textarea name="remarks" id="remarks" cols="" rows="" style="width:99%; height:60px;"></textarea></td>
  </tr>
</table>
    <p align="center"><input type="submit" name="Save" value="Save" class="search" /></p>


	
	



