<?php 
$PageSecurity = 4;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/header.inc'); 
$title = _('RAW MATERIAL RECONCILATION');
 $date = date($_SESSION['DefaultDateFormat']);
//echo "<pre>"; print_r($_SESSION);
$SQL = "Select * from  locations Where loccode='".$_SESSION[UserStockLocation]."' ";
$Result = DB_query($SQL,$db,$Err);
$row = DB_fetch_array($Result);
$location_name = $row['locationname'];


		

?>
<!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><?php echo $title;  ?></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/Datecss/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php 
include('includes/header.inc'); 
?>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="13"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12%" height="14">&nbsp;</td>
        <td width="62%">&nbsp;</td>
        <td width="14%">&nbsp;</td>
        <td width="12%">&nbsp;</td>
      </tr>
      <tr>
        <td height="14" colspan="4" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="20%">&nbsp;</td>
            <td width="60%" height="30" ><div align="center"><b>ARMTECH INDIA LIMITED</b><br/>ENGONEERS & CONTRACTORS</div></td>
            <td width="20%">&nbsp;</td>
          </tr>
       </table></td>
       </tr>
       <tr>
        <td height="14" colspan="4" align="center">&nbsp;</td>
      </tr>
      <tr>
       <td height="14" colspan="4" align="center"><div align="center"><b><?php echo $title; ?></b></div></td>
       </tr>
      <tr>
        <td height="14">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="14"><b>Site Name:- </b></td>
        <td><?php  echo $location_name; ?></td>
        <td><b>Date:-</b></td>
        <td><?php echo $date; ?></td>
      </tr>
	  <tr>
        <td height="14">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr bgcolor="#CCCCCC">
    <td align="center">S.No.</td>
    <td align="center">Particular </td>
    <td align="center">Unit</td>
    <td align="center">Up to Previous Month Recive</td>
    <td align="center">This Month Received Qty. </td>
    <td align="center">Totle Recived Qty.</td>
    <td align="center">Client Consumption as per ....RA Bill</td>
    <td align="center">Wastage is ...3% </td>
    <td align="center">Physical Qty. </td>
    <td align="center">Rate </td>
    <td align="center">Amount</td>
    <td align="center">Remarks</td>
    <td align="center">Average</td>
  </tr>
  <tr>
    <td width="5%" align="center">1 Example : </td>
    <td width="4%" align="center">2</td>
    <td width="8%" align="center">3</td>
    <td width="4%" align="center">4</td>
    <td width="6%" align="center">5</td>
    <td width="6%" align="center">6=(4+5)</td>
    <td width="6%" align="center">7</td>
    <td width="6%" align="center">8</td>
    <td width="6%" align="center">9</td>
    <td width="6%" align="center">10</td>
    <td width="6%" align="center">11=(6-7-8-9)</td>
    <td width="6%" align="center">12=(10*1))</td>
    <td width="7%" align="center">13=(8/10)</td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
<?php   
    $ts = strtotime('-1 month');
	$startmonth 		=  date('Y-m-01', $ts);
	$Endmonth 			=  date('Y-m-31', $ts);
	$current_date 		= date('Y-m-01');
	$EndCurrent_date 	= date('Y-m-d');
	$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,
		Sum(qualityposting. Usable) as  Usablequantity,
		Sum(qualityposting. Usable) as  Usablequantity,
		Sum(addmrnqty.itemprice) as Price,
		stockmaster.stockid
		from qualityposting Inner Join stockmaster on(qualityposting.ItemCode =stockmaster.stockid) Inner Join addmrnqty on(addmrnqty.itemcode=stockmaster.stockid)  where  stockid='$Stock_Code' AND date between '$current_date' and '$EndCurrent_date' 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'];
		 $Current_Total_quantity = $Current_Total_quantity + $Current_Quantity; 
		 $Complete_passQty =$prev_row['prevMonthpassquantity'] + $row['passquantity'];
		 $Total_quantity = $Total_quantity + $Complete_passQty;
		 $Average = number_format(($row['Rejectquantity']/$row['Price']),3);
		 $Amount = $Complete_passQty - $row['Rejectquantity'] - $row['Usablequantity'];
		 $Total_Amount = $Amount + $Total_Amount;
		 $Price =($row['Price']*1);
		 $Price_Total = $Price_Total + $Price;
		 $Total =$Total + $Average; 
?>
   
  <tr>
    <td><?php echo $j;?></td>
    <td><?php echo $row['ItemCode'];?></td>
    <td><?php echo $row['Unit'];?></td>
    <td><?php echo $prev_row['prevMonthpassquantity'];?></td>
    <td><?php echo $row['passquantity'];?></td>
    <td><?php echo $prev_row['prevMonthpassquantity'] + $row['passquantity'];?></td>
    <td><?php  ?></td>
    <td><?php echo  $row['Rejectquantity']; ?></td>
    <td><?php echo $row['Usablequantity'];?></td>
    <td><?php echo $row['Price']; ?></td>
    <td><?php echo $Complete_passQty - $row['Rejectquantity'] - $row['Usablequantity'];?></td>
    <td><?php echo $row['Price']*1; ?></td>
    <td><?php echo $Average; ?> </td>
	
  </tr>
 
  <?php  } $j++;} 
  
    
  
  } else{  ?>
 
  <tr>
    <td colspan="13"><div align="center"><font color="#FF0000"> Record Not Found </font></div></td>
  </tr>
  <?php  } ?>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4" align="center"><div align="center"><b>Totle</b></div></td>
    <td><?php  echo  $Current_Total_quantity; ?></td>
    <td><?php echo $Total_quantity; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><?php echo $Total_Amount; ?></td>
    <td><?php  echo $Price_Total; ?></td>
    <td><?php echo $Total; ?></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20%" height="14"><b>STORE KEEPER</b> </td>
    <td width="20%">&nbsp;</td>
    <td width="20%"><b>SITE ACCOUNTANT</b> </td>
    <td width="20%">&nbsp;</td>
	<td width="20%"><b>PROJECT MANAGER</b> </td>
  </tr>
</table>

<?php 
include('includes/footer.inc');
?>
</body>
</html>
