<?php
$PageSecurity = 2;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
?>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
  <tr>
    <td  class="tabledata" colspan="2"><center>Urgent Order Pending</center></td>
    <td  class="tabledata" colspan="2"><center>Normal Order Pending</center></td>
    <td  class="tabledata">&nbsp;</td>
  </tr>
  <tr>
  	<td class="tabledata">Months</td>
    <td class="tabledata">Total Order</td>
     <td class="tabledata">Months</td>
    <td class="tabledata">Total Order</td>
     <td class="tabledata">&nbsp;</td>
  </tr> 
  <?php  
   $month_names = array("January","February","March","April","May","June","July","August","September","October","November","December","January","February","March");
   $FinY=DB_query("SELECT *,YEAR(BookPeriodStart) AS SYear,YEAR(BookPeriodEnd) AS EYEAR FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
   $FinYRow=DB_fetch_array($FinY);  
   	$diffdata=($FinYRow['EYEAR']-$FinYRow['SYear'])+1;
	
	for($i=0;$i<15;$i++)
	{
		
	if($i<12)
	{
	$j=$i+1;
	$year=$FinYRow['SYear'];	
	}
	else
	{
	$j=($i-12)+1;
	$year=$FinYRow['EYEAR'];	
	}  
	$total=0;
	 $row2=DB_query("select MONTH(orderDate) AS month from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where  ApprovalStatus='1' and  cate='Urgent' and  month(orderDate)='".$j."' and year(orderdate)='".$year."' group by salesorder.id ",$db);
     $row123=DB_fetch_array($row2);
     $dat=$row123['month'];
	 $total=0; 
	 
   $row1=DB_query("select orderNo as amt   from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where  ApprovalStatus='1' and  cate='Urgent' and  month(orderDate)='".$j."' and year(orderdate)='".$year."' group by salesorder.id ",$db);
    $UPending=DB_num_rows($row1);
   //while($row12=DB_fetch_array($row1))
//   {
//    $total=$row12['amt']+$total;	
//   }
   $total1=0; 
   $row3=DB_query("select orderNo as amt   from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where  ApprovalStatus='1' and  cate='Normal' and  month(orderDate)='".$j."' and year(orderdate)='".$year."' group by salesorder.id ",$db);
   $NPending=DB_num_rows($row3);
 //  while($row13=DB_fetch_array($row3))
//   {
//    $total1=$row13['amt']+$total1;	
//   }
    $timestamp = mktime(0, 0, 0, $dat, 1, $year);
    $monthdata= date("M", $timestamp);
    ?> 
    <?php if($i>2) { ?>
	<tr>
    <td class="tabledata_fist"><?php if($UPending!=0) { ?><a class="linkcolor" href="index.php?route=CRM/sale_order_approval_new&modid=12&frmid=339"><?php echo $month_names[$i]; ?>-<?php echo $year; ?></a> <?php } else {?><?php echo $month_names[$i]; ?>-<?php echo $year; ?><?php }?></td>
    <td class="tabledata1"><?php   echo $UPending;  ?></td>
    <td class="tabledata1"><?php if($NPending!=0) { ?><a class="linkcolor" href="index.php?route=CRM/sale_order_approval_new&modid=12&frmid=339"><?php echo $month_names[$i]; ?>-<?php echo $year; ?></a> <?php } else {?><?php echo $month_names[$i]; ?>-<?php echo $year; ?><?php }?></td>
    <td class="tabledata1"><?php echo $NPending; ?></td>
    <td class="tabledata1">&nbsp;</td>
  </tr>
  <?php } }?>  
</table>

