<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 2;
$title = _('Canbilization of Remaining Boxes');
?>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div id="container">
	<div class="body_contain">
		<div class="tab_div"> 
 			<h1>Canbilization of Remaining Boxes</h1>	
			<div align="left">
			<br /><br /><br />
			<?php
				$SQL="select * from log_add_mrn order by id";
        		$ErrMsg = _('No orders were returned by the SQL because');
				$purchordersResult = DB_query($SQL,$db,$ErrMsg);
				$resultpaging = DB_query($SQL, $db, $ErrMsg);
			?>
				<table border="1" cellpadding="3" cellspacing="0" width="100%">
      				<tr>
        				<th><strong>S. No.</strong></th>
        				<th><strong>GRN NO.</strong></th>
						<th><strong>GRN Date</strong></th>
						<th><strong>Remaining Item Qty</strong></th>
        				<th><strong>Remaining Boxes</strong></th>
        				<!--<th><strong>View</strong></th>-->
						<th><strong>Dispatch</strong></th>
      				</tr>
      				<?php 
					$k=0;
					if(DB_num_rows($purchordersResult)>0){
					$result =$purchordersResult;
					
					while($nrow=DB_fetch_array($result)){
				   	
					$SQLr="select SUM(reciveqty) AS treceive from log_addmrnqty where grn_id='".$nrow['id']."'";
					$resultr = DB_query($SQLr, $db);
					$resrowr=DB_fetch_array($resultr);
					
					$SQLd="select SUM(dispatchqty) AS dqty from log_dispatchgrnqty where grn_id='".$nrow['id']."'";
					$resultd = DB_query($SQLd, $db);
					$resrowd=DB_fetch_array($resultd);
					
					$SQLb="select COUNT(id) AS cou from log_addmrnbox where grn_id='".$nrow['id']."' AND dispatch=0 AND dis_id=0";
					$resultb = DB_query($SQLb, $db);
					$resrowb=DB_fetch_array($resultb);
					
					$bal=$resrowr['treceive']-$resrowd['dqty'];
					
					if($bal==0 && $resrowb['cou']>0){?>
					<?php
						$url_dis="index.php?route=LOG/transaction/canbilize_note_add".$rurl;
						$url_view="index.php?route=LOG/transaction/canbilize_note_view".$rurl;
						$view = '<a href="'.$url_view.'&ViewingOnly=1&mrnid='.$nrow['id'].'">' . "<img src='images/search.gif' height='15' width='15'>". '</a>';
						?>
						<tr class="EvenTableRows">
							<td><?php echo $k=$k+1;;?></td>
							<td><?php echo $nrow['grn_no'];?></td>
							<td><?php echo ConvertSQLDate($nrow['grn_date']);?></td>
							<td><?php echo $resrowr['treceive']-$resrowd['dqty'];?></td>
							<td><?php echo $resrowb['cou'];?></td>
							<!--<td width="4%"><?php //echo $view;?></td>-->
							<td><a href="<?php echo $url_dis.'&mrnid='.$nrow['id'];?>"><input type="button" value="Dispatch" /></a></td>
						</tr>
						<?php 
					}
					$k++;
					}
					}
					else
					{?>
				  <tr>
					<td colspan="10"><h3 align="center"><strong><font color="#FF0000">No Record Found!</font></strong></h3></td>
				  </tr>
				  <?php }
					//end of while loop ?>
				</table>
			</div>
		</div>
	</div>
</div>
<?php 
include('includes/footer.inc');
?>
