<?php 
if($_REQUEST['action']=='Delete')
{
	$cond1="physical_stock_id='".$_REQUEST['DelId']."'";
	$s->DeleteRecord('physical_stock_details',$cond1);
	$cond2="id='".$_REQUEST['DelId']."'";
	$s->DeleteRecord('physical_stock',$cond2);
	DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['DelId']."' and type='PHY'",$db);
	$s->pageLocation("index.php?route=physical_adjustment_index".$rurl);
}
 ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Physical Stock Adjustment</h1>
<p align="left">
	<a href="index.php?route=physical_adjustment<?php echo $rurl; ?>"><input type="button" value="Add New" class="search"></a>
</p>

<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0" class="thborder">
<tr>
	<th width="14%">Branch</th>
	<th width="10%">Store</th>
	<th width="10%">Voucher No.</th>
	<th>Products</th>
	<th width="5%" style="text-align:center;">Print</th>
</tr>	
<!--<tr>
	<th width="4%" style="text-align:center;">Edit</th>
	<th width="4%" style="text-align:center;">Delete</th>
	<th width="4%" style="text-align:center;">Print</th>
</tr> -->

<?php  

$SQLGet=DB_query("select * from physical_stock where CompanyId='".$_SESSION['ACGCompanyId']."' and site in('".$_SESSION['AssignedBranch']."') and date1 between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'",$db); 

       
if(DB_num_rows($SQLGet)>0){
while($FetchRec=DB_fetch_array($SQLGet)){?>
<tr>
	<td><?php echo $s->GetFieldValue('locations',"loccode='".$FetchRec['site']."'",'locationname'); ?></td>
	<td><?php echo  $s->GetFieldValue('storetype',"id='".$FetchRec['store']."'",'StoreName'); ?></td>
	<td><?php echo $FetchRec['ADJ_voucher_no']; ?></td>
    <td style="padding:0;" valign="top"><div style="overflow:auto; max-height:90px;">
    <div id="amc-tab">
    <table width="100%" border="0" cellspacing="0" cellpadding="3">
		   <?php 
			$query=DB_query("select adjustment_type, adjustment_qty, mstitemid from physical_stock_details where physical_stock_id ='".$FetchRec['id']."'",$db);
    		if(DB_num_rows($query)>0)
    		{
	 
            	while($phydata=DB_fetch_array($query)){			
			  	$proname=$s->getField('item_master','id',$phydata['mstitemid'],'item_name'); ?>
			  	<tr>
			  	<td><?php echo ">> ".$proname."   ".">>"."  Adjustment Qty. :  ".$phydata['adjustment_qty'].">>".
		      	$phydata['adjustment_type']; ?>
		      	</td>
		      	</tr>
			<?php }	 
		   		   
		  } ?>
		  </table>
		  </div></div></td>
				<!-- <td style="text-align:center;"><strong>
				<?php 
					 $check = checkEdit($FetchRec['id']);
					  if($check!=0 )
					  {
						if($_SESSION['frmEdit']=='1')  {
				 ?>
				<a href="index.php?route=physical_adjustment_Edit<?php echo $rurl;?>&action=Edit&id=<?php echo $FetchRec['id']; ?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit Document" /></a>
				<?php } else { ?>
				<a href="#" onclick="return false();" title="No Permission"><img src="images/icon-edit.png" width="15" height="15" title="No Permission to Edit Document" style="opacity:0.5;" /></a>
				<?php } 
					}
					else
					{
						echo "Physical Used";
					}
				?>
				</strong></td>
				<td style="text-align:center;"><strong>
				<?php 
				 	$check = checkEdit($FetchRec['id']);
					if($check!=0 )
					{
					 	if($_SESSION['frmDelete']=='1') { ?>
							<a onclick="popup('physical_adjustment_delete.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $FetchRec['id'];?>',600,200)" href="#"><img src="images/Icon_Delete.png" width="15" height="15" title="Delete Document" /></a>
				  <?php } 
				  else { ?>
					<a href="#" onclick="return false();" title="No Permission"><img src="images/Icon_Delete.png" width="15" height="15" title="No Permission to Delete Document" style="opacity:0.5;" /></a>
				<?php } 
					}
					else
					{
						echo "Physical Used";	
					}					
				?>
				</strong></td> -->
		<td style="text-align:center;"><?php if($_SESSION['modid']!=""){?><a target="_blank"  href="physical_adjustment_print.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Report&id=<?php echo $FetchRec['id']; ?>"><img src="images/icon_print.jpg" height="18" width="18" title="Print Document" /></a>	
	<?php }else{ ?><img src="images/icon_print.jpg" height="18" width="18" title="No Permission to Print Document" style="opacity:0.5;" /><?php }?>
	</td>
</tr>
<?php }}else{?>
<tr>
	<td style="color:#FF0000;" colspan="7">No Record Found</td>
</tr>
<?php }?>
</table>
</div>
</div>

<?php 
  function checkEdit($id)
  {
    global $db;
    $query="SELECT id FROM stock_valuation_tbl WHERE against_tra_id in( SELECT id FROM stock_valuation_tbl WHERE TYPE='PHY' AND against_voucher_main_id='".$id."') ";
    $result=Db_query($query,$db);
   
    if(DB_num_rows($result)>0)
      return 0;
    else
      return 1;
  }

?>