	<?php
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PR V/S PO Balance Qty Report</title>
<link href="css/purchses1.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>
<body>

<div id="page">		
<div id="form">
<form name="" id="" method="POST" action="">
	<!-- Start Header --->
 
<div style="width:38%; margin-left:auto; margin-right:auto;"> 
  <div style="50px; float:left; margin-left:30px;"><img src="images/logo_img.png" width="29" height="46" /></div>
<div style="width:auto; float:left; padding-left:10px; margin:0px;">
		<h3 style="padding-top:10"><img src="images/logo1.png" width="160" height="23" /></h3>
	  				<h3 style="border-width: 0 0 0 0px;">PR V/S PO Balance Qty Report</h3>
</div>

<div style="clear:both;"></div>
</div>

<div align="center"><strong><?php echo $_SESSION['mess']; ?></strong> </div>

 <p  id="foo" align="right" style="padding-right:40px;"> <a href="#" id="fis" onClick="javascript:toggle_visibility('foo');" >Print</a> </p>



<table width="100%" border="1" class="inborder" cellpadding="3">
  <tr>
    <th><strong>S. No.</strong></th>  
	 <th><strong>Date</strong></th>
    <th style="width:230px;"><strong>Site</strong></th>     
	<th><strong>Reqno.</strong></th>
    <!--<th width="10%">PR No. </th>
	 <th width="9%">PR Date </th>-->
    <th><strong>Item Name </strong></th>
	 <th><strong>UOM</strong></th>
	 <th><strong>PR Qty </strong></th> 
     <th><strong>PO balance </strong></th>
    </tr>
 <?php
  $poreport=$_SESSION['poreport1'];
$i=1;
	 $res = DB_query($poreport,$db);
  	 while($row = DB_fetch_array($res))
	 {
	  if($row['APPREQ']!='') 
	 { 
	 
	 ?>
     <tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
<td><?php echo $i++;?></td>
<td><?php  echo ConvertSQLDate($row['prdate']);?></td>
<td >
	<?php 
	$sitesql="select locationname from locations where loccode='".$row['sitecode']."'";
	$siteres=DB_query($sitesql,$db);
	$siterow=DB_fetch_array($siteres);
 echo $siterow['locationname']; ?> </td>
 <?php  //echo $row['APPREQ'];
  $getpodata="select orddate,orderno,PO_Orderno from purchorders where mst_reqino='".$row['requisitionno']."' and  FIND_IN_SET('".$row['mst_itemid']."',mst_vendor_pid);";
 $result = DB_query($getpodata,$db);
   $PODATA = DB_fetch_array($result);

?> 
<td><?php  echo $row['Reqno'];?></td>
<!--<td><?php  //echo $PODATA['PO_Orderno'];?></td>
<td><?php  //echo ConvertSQLDate($PODATA['orddate']);?></td>-->					
<td colspan="4">
<div style="width:100%;">
<table width="100%" border="0" cellpadding="1" cellspacing="0">
 <?php 
 
    if($_REQUEST['itemname']!=000)
     $details_sql="Select * from requisitionorderdetails where requsitionno='".$row['requsitionno']."' and mst_itemid='".$_REQUEST['itemname']."'";
	else
	  $details_sql="Select * from requisitionorderdetails where requsitionno='".$row['requsitionno']."'";
	$_SESSION['details_sql']=$details_sql;
	$details_res=DB_query($details_sql,$db);
	$issueqty[]='';
	$req_qty[]='';

	$numrow1=DB_num_rows($details_res);
	if(DB_num_rows($details_res)>0){
		$apqty='';
	while($details_row=DB_fetch_array($details_res)){
	
	
	 $poqty1=DB_query("SELECT SUM(purchorderdetails.quatity) AS qty FROM purchorderdetails
                      INNER JOIN purchorders ON purchorderdetails.orderno=purchorders.orderno
                       WHERE purchorders.mst_reqino='".$details_row['requsitionno']."'
					   AND purchorderdetails.mst_itemid='".$details_row['mst_itemid']."'",$db);
	$poqty2=DB_fetch_array($poqty1);
	
	?>
          <tr bgcolor="99CCCC">
            <td style="width:105px;">
			<?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'item_name'); ?></td>
            <td style="width:57px;"><?php 
			 $unitname1 = $s->GetFieldValue('item_master',"id='".$details_row['mst_itemid']."'",'unit');
			echo $unitname = $s->GetFieldValue('unitsofmeasure',"unitid='".$unitname1."'",'unitname') ; ?></td>
             <td style="width:76px;"><?php   echo $row['APPREQ'];
			     $apqty[]=$row['APPREQ'];
				   ?></td>
      		 <td style="width:100px;"><?php echo $row['APPREQ']-$poqty2['qty']; ?></td> 
          </tr>
          <?php } ?>
          <tr bgcolor="#FFFFFF" style="height: 25px">
        <td><strong>Total</strong></td>
		  <td>&nbsp;</td>
     <td><?php echo $a[]=array_sum($apqty); ?></td>
        <td>&nbsp;</td>
      </tr>
          <?php }  ?>
        </table>
	</div>		</td>
  </tr>
  
  <?php }  }?>
 <?php if($numrow1>0) { ?>
    <!--<tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1"><strong></strong></td>
      <?php if($_REQUEST['site']=='') { ?> <td class="jjrs_tabledata1">&nbsp;</td><?php } ?>
       <td class="jjrs_tabledata1">&nbsp;</td>
       <td class="jjrs_tabledata1"><strong>&nbsp;</strong></td>
	   <td class="jjrs_tabledata1"><strong>&nbsp;</strong></td>
      <td class="jjrs_tabledata1"><strong></strong></td>
     <td width="20%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Grand Total</strong></td>
	          <td class="jjrs_tabledata1"><strong>&nbsp;</strong></td>
			   <td  width="11%" class="jjrs_tabledata1"><strong><?php echo array_sum($a);?></strong></td>
      <td width="10%" class="jjrs_tabledata1"><?php //echo $b[]=array_sum($req_qty);?></td>
 
	  </tr> -->
      <?php } else { ?>
	   <tr bgcolor="#e7e7e7" style="height: 25px">
       <td class="jjrs_tabledata1" colspan="8" align="center"><strong>No Records</strong></td>
       </tr>	  
      <?php } ?>   
</table>
	</form>


	
	</div></div>
	
	</body></html>
