<h2> <?php  echo  $page_title;
include('POModule/Class-ItemMaster.php');
?></h2>

<form action="" method="post">
<table width="50%" border="0">
  <tr >
  	<td>Site</td>
  	<td><select name="site" id="site">
  		<option value="">--ALL--</option>
  		<?php
  		if($_SESSION['AssignedSites']!='0')
	  {
	  	
	   	  $sql="Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in (".$_SESSION['AssignedSites'].")";
	  }
		else
			{
				$sql="select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
				
			}
  		
  		
		$sitesql=DB_query($sql,$db);
		
  		
         while($siteres=DB_fetch_array($sitesql))  	
		 {
		 	?>
		 	<option value="<?php echo $siteres['loccode'];?>"<?php echo($_REQUEST['site']==$siteres['loccode']?'selected':'')?>><?php echo $siteres['locationname'];?></option>
			
			<?php
		 }	
		 ?>
  		
  		</select>
  	</td>
    <td>Item:</td>
    <td><select name="ItemList" id="itemdata">
  <option value="">--ALL--</option>
        <?php 
	$itemSql=DB_query("Select StockID,item_name from item_master",$db);
	while($itemRow=DB_fetch_array($itemSql))
	{?>
            <option value="<?php echo $itemRow['StockID'];?>"<?php echo($_REQUEST['itemdata']==$itemRow['StockID']?'selected':'')?>><?php echo $itemRow['StockID']." - ".$itemRow['item_name'];?></option>
            <?php 	
	}
	?>
        </select>
	
	 </td>
	
	 <td>From:</td>
    <td><input name="fromdate"  class="datepicker"type="text" value="<?php echo $_REQUEST['fromdate'] ?>" readonly="true" ></td>
	
	    <td>TO:</td>
    <td><input name="todate"  class="datepicker"type="text" value="<?php  echo $_REQUEST['todate'];?>"  readonly="true" ></td>

	<td><input name="Go" type="submit" value="Go"></td>
  </tr>
   
</table>
</form>

<?php 
  if($_REQUEST['Go']){
$filter='1=1 ';

 
     if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='')
	 $filter.=" and a.date1  between '".FormatDateForSQL($_REQUEST['fromdate'])."' AND '".FormatDateForSQL($_REQUEST['todate']) ."' ";
	 
	 if($_REQUEST['ItemList']!='' ) 
	 $filter.=" and ad.itemcode='".$_REQUEST['ItemList']."' ";
	 if($_REQUEST['site']!='')
	 {
	 	$filter.=" and a.site='".$_REQUEST['site']."'";
	 }
	 else {
		 $filter.=" and 1=1";
	 }	
   $sql2 = "SELECT *  FROM `physical_stock_adj_details` AS ad , `physical_stock_adjustment` AS a WHERE a.id=ad.physical_stock_id and  $filter ";
  }else
  {
   $sql2 = "SELECT *  FROM `physical_stock_adj_details` AS ad , `physical_stock_adjustment` AS a WHERE a.id=ad.physical_stock_id ";
  }  
  $_SESSION['poreport2']=$sql2;   
  
    $fromdate=$_REQUEST['fromdate'];
     $todate=$_REQUEST['todate'];	 
	 $fromdate_brk=explode('/',$fromdate);
	 $from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
	 $todate_brk=explode('/',$todate);
	 $to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
	 $sitename=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
	
	
	if($_REQUEST['site']!='' && $_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
	$message="Showing Records of Branch ".$sitename."   From  ".$from." to ".$to."";
	}
	else if($_REQUEST['site']!='' && $_REQUEST['fromdate']=='' && $_REQUEST['todate']=='')
	{
	$message="Showing Records of Branch ".$sitename." ";
	}
	else if($_REQUEST['site']=='' && $_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
	$message="Showing Records   From  ".$from." to ".$to."";
	}
	
	$_SESSION['mess2']=$message;	
?>
<?php if($_REQUEST['Go']!=''){?>
<p align="right"><a href="stockadjustment_print.php?loccode=<?php echo $_REQUEST['site'];?>&itemname=<?php echo $_REQUEST['ItemList'];?>&todate=<?php echo $_REQUEST['todate'];?>&fromdate=<?php echo $_REQUEST['fromdate'];?>" target="_blank">Print</a>&nbsp;&nbsp;&nbsp;&nbsp;<!--<a href="tcpdf/Pdf_POReport.php?loccode=<?php echo $_REQUEST['site'];?>&itemname=<?php echo $_REQUEST['ItemList'];?>&todate=<?php echo $_REQUEST['todate'];?>&fromdate=<?php echo $_REQUEST['fromdate'];?>">PDF</a>
<a href="Export_POReport.php?loccode=<?php echo $_REQUEST['site'];?>&itemname=<?php echo $_REQUEST['ItemList'];?>&todate=<?php echo $_REQUEST['todate'];?>&fromdate=<?php echo $_REQUEST['fromdate'];?>">Export</a>-->
</p>
<div align="center"><strong><?php echo $message; ?></strong> </div>
</br>
<table width="100%" border="1" class="inborder" cellpadding="3">
  <tr>
    <th width="67">SNo.</th>  
	 <th width="67">Date</th>
    <th width="57">Site</th>     
	<th width="125">Store.</th>
     <th width="248" style="width:150px;">Item Name 11 </th>
	 <th style="width:25px;" >UOM</th>
	 <th  style="width:20px;">Adj. Qty</th> 
     <th style="width:25px;">Store Qty</th>
	  <th style="width:15px;">Adj.Type</th>
  </tr>
  
   <?php

	 $i=1;
	 $res = DB_query($sql2,$db);
	 
  	 while($row = DB_fetch_array($res))
	 {
	  
	 ?>
  <tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
<td style="padding-left:5px;"><?php echo $i++;?></td>
<td><?php  echo ConvertSQLDate($row['date1']);?></td>
<td >
	<?php 
	$sitesql="select locationname from locations where loccode='".$row['site']."'";
	$siteres=DB_query($sitesql,$db);
	$siterow=DB_fetch_array($siteres);
 echo $siterow['locationname']; ?>
 </td>

<td> <?php   echo $row['store']; ?> </td> 			
<td colspan="5"><table width="100%" border="0" cellpadding="0" cellspacing="0">
 <?php 
 
    if($_REQUEST['ItemList']!='')
       $details_sql="Select * from physical_stock_adj_details where itemcode='".$_REQUEST['ItemList']."'";
	else
	    $details_sql="Select * from physical_stock_adj_details where itemcode='".$row['itemcode']."'";
	$_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)){?>
          <tr bgcolor="99CCCC">
            <td width="45%" class="jjrs_tabledata1" >
			<?php echo $s->getField('item_master','StockID',$details_row['itemcode'],'item_name'); ?></td>
            <td width="13%" class="jjrs_tabledata1"><?php 
			 $unitname1 = $s->GetFieldValue('item_master',"StockID='".$details_row['itemcode']."'",'unit');
			echo $unitname = $s->GetFieldValue('unitsofmeasure',"unitid='".$unitname1."'",'unitname') ; ?> </td>
             <td width="12%"  valign="center" style="padding-left:8px;"> <?php   echo $row['adjustment_qty'];
			     $apqty[]=$row['adjustment_qty'];
				   ?></td>
      		  <td width="13%" style="padding-left:3px;"><?php echo $row['stock'];?></td>
			  <td width="17%" style="padding-left:3px;"><?php echo $row['adjustment_type'];?></td>  
          </tr>
          <?php } ?>
          <tr bgcolor="#FFFFFF" style="height: 25px">
        <td class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Total</strong></td>
		  <td style="padding-left:5px; padding-right:5px; white-space:nowrap;" class="jjrs_tabledata1">&nbsp;</td>
     <td class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><span class="jjrs_tabledata1" style="white-space:nowrap;"><strong><?php echo $a[]=array_sum($apqty); ?></strong></span></td>
        <td style="padding-left:5px; padding-right:5px; white-space:nowrap;" class="jjrs_tabledata1">&nbsp;</td>
 
      </tr>
          <?php } ?>
        </table></td>

  </tr>
  
  
  <?php  }?>
  
    <?php if($numrow1>0) { ?>
   <?php if(!empty($a)) { ?>
   
<!--<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border:solid 1px #666666;">
  <tr style="background-color:#CCCCCC; height: 30px">
	<td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="8%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="19%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
		<td width="8%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
        <td width="24%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Grand Total</strong></td>
        <td width="25%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><span class="jjrs_tabledata1" style=" white-space:nowrap;"><strong><?php  echo array_sum($a); ?></strong></span></td>
        <td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
        <td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"></td>
  </tr>
</table> -->

      <?php } } else { ?>
	   <tr bgcolor="#e7e7e7" style="height: 25px">
       <td class="jjrs_tabledata1" colspan="8" align="center"><strong>No Records</strong></td>
       </tr>	  
      <?php } ?>   
</table>

 <? } ?>
