<?php

/* $Revision: 1.43 $ */

$PageSecurity = 5;

include('includes/session.inc');

$title = _('Dead Material Stock');

include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
$date = date($_SESSION['DefaultDateFormat']);
$SQL = "Select * from  locations Where loccode='".$_SESSION[UserStockLocation]."' ";
$Result = DB_query($SQL,$db,$Err);
$row = DB_fetch_array($Result);
$location_name = $row['locationname'];

echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Search') . '" alt="">' . ' ' . _('Dead Material Stock') . '';
echo '<table width="90%" border="1">
	  <tr>
		<td colspan="6">'."Project Name".':- '.$location_name.'</td>
		
		<td>'."Date".':- '.$date.'</td>
	  </tr>
	  <tr>
		<th width="6%">'."S.NO.".'</th>
		<th width="30%">'."Description".'</th>
		<th width="9%">'."UOM".'</th>
		<th width="9%">'."Qty.".'</th>
		<th width="13%">'."Rate".'</th>
		<th width="13%">'."Amount".'</th>
		<th width="20%">'."Remarks".'</th>
	  </tr>';
	  ?>
	  <?php    
	  $Stock_SQL   = "Select stockid, description from stockmaster";
	$Stock_Result  = DB_query($Stock_SQL,$db,$Err);
	   $j=1;
	if(DB_num_rows($Stock_Result)>0)
	 { 
	while($Stock_row = DB_fetch_array($Stock_Result))
	{
	$Stock_Code = $Stock_row['stockid'];
	 
      $SQL = "Select qualityposting.ItemCode, 
		qualityposting.Shortage, 
		qualityposting.Usable, 
		qualityposting.RejectedQty,
		qualityposting.PassedQty,
		qualityposting.site_puraches, 
		qualityposting.Unit,
		qualityposting.date,
		Sum(qualityposting.PassedQty) as passquantity,
		Sum(qualityposting.RejectedQty) as Rejectquantity,
		addmrnqty.itemprice,
		stockmaster.stockid,
		stockmaster.description, 
		addmrn.Remarks
		from qualityposting Inner Join stockmaster on(qualityposting.ItemCode =stockmaster.stockid)
		Inner Join addmrnqty on(addmrnqty.itemcode=stockmaster.stockid) 
		Inner Join addmrn on(addmrnqty.issue_id=addmrn.id) 
		Where stockid='$Stock_Code' And site_puraches='".$_SESSION[UserStockLocation]."'";
		$Result = DB_query($SQL,$db);
	   while($row = DB_fetch_array($Result))
	  		{
		$SQL_query = "Select Sum(qualityposting.PassedQty) as prevMonthpassquantity  From qualityposting where  ItemCode='$Stock_Code' AND date between '$startmonth' and '$Endmonth'";
         $PrevResult = DB_query($SQL_query,$db);
		 $prev_row = DB_fetch_array($PrevResult);
		 $Current_Quantity = $row['passquantity'];
		 $Amount = $row['itemprice'] * $row['Rejectquantity'];
		 $Total_Amount = $Total_Amount + $Amount;
	  ?>
	  <tr>
		<td><?php echo $j;  ?></td>
		<td><?php echo $row['description']; ?></td>
		<td><?php echo $row['Unit']; ?></td>
		<td><?php echo $row['Rejectquantity']; ?></td>,
		<td><?php echo $row['itemprice']; ?></td>
		<td><?php echo $row['itemprice'] * $row['Rejectquantity']; ?></td>
		<td><?php echo $row['Remarks']; ?></td>
	  </tr>
	  <?php  } $j++; }  }else{ ?>
	  <tr>
		<td colspan="7">&nbsp;</td>
		
	  </tr>
	  <?php } ?>
	  <?php
	
	 
	 
	 echo '<tr>
		<td>&nbsp;</td>
		<td>'."Total".'</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>'.$Total_Amount.'</td>
		<td>&nbsp;</td>
	  </tr>
</table>';
echo '<table width="100%" border="0">
   <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
  </tr>		
  <tr>
    <td>'."STORE KEEPER".'</td>
    <td>'."ACCOUNTANT".'</td>
    <td>'."PROJECT INCHARGE".'</td>
  </tr>
</table>';

include('includes/footer.inc');
?>
