Current File : /home/inlingua/public_html/sales/reports_n.php
<?php
session_start();
ob_start(); 
include "header.php";
// Include the database connection details
require('dbConnection.php');

// Include common functions
require('commonFunc.php');

// Include common functions
require('globalVars.php');

// Include the table handler class
require('dbHandler.class.php');

// Init and connect to database
$dbObject = new dbHandler();
$dbObject->connect();
if($_REQUEST['year_r']!="")
{
$year_r=$_REQUEST['year_r'];
}
else{
   $year_r=date("Y");
}

$year_r_n=$year_r+1;
 $month_array=array("".$year_r."-04",
              "".$year_r."-05",
              "".$year_r."-06",
              "".$year_r."-07",
              "".$year_r."-08",
              "".$year_r."-09",
              "".$year_r."-10",
              "".$year_r."-11",
              "".$year_r."-12",
              
              "".$year_r_n."-01",
              "$year_r_n-02",
              "$year_r_n-03"
              );
 
 $sqlQuery = "SELECT * FROM sales_enquiry_source";
 $result=mysql_query($sqlQuery);
 while($num=mysql_fetch_array($result))
 {
    $cc.="<td>".$num['enquiry_source']."</td>";
    
 }
 
 echo"<table>";
 echo"<tr><td><b>Consolidated</b> FY ".$year_r."-".$year_r_n."</td></tr>";
 echo"<tr style='background-color:yellow'><td>&nbsp;</td><td></td><td><b>Total Received</b></td>".$cc."<td><b>Closed</b></td></tr>";
 foreach($month_array as $key=>$val)
 {
    $month=date("F",strtotime("".$val."-01"));
 $sqlQuery = "SELECT * FROM sales_enquiry_source";
 $result=mysql_query($sqlQuery);
 $cc1="";
 $queryTott="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31'";
    $resultTott=mysql_query($queryTott);
    $numTott=mysql_fetch_array($resultTott);
 
 
 while($num=mysql_fetch_array($result))
 {
    $queryTot="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31' && lead_source='".$num['enquiry_source']."'";
    $resultTot=mysql_query($queryTot);
    $numTot=mysql_fetch_array($resultTot);
    $cc1.="<td>".$numTot['tot']."</td>";
 }
 
 $queryTotC="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31' && equiry_status='Closed'";
    $resultTotC=mysql_query($queryTotC);
    $numTotC=mysql_fetch_array($resultTotC);
    
    
 echo"<tr><td></td><td style='background-color:yellow'>".$month."</td><td>".$numTott['tot']."</td>".$cc1."<td>".$numTotC['tot']."</td></tr>";
    
    
 }
 echo"<tr><td>&nbsp;</td></tr>";
 
 $query1="select * from sales_login";
 $result1=mysql_query($query1);
 while($num1=mysql_fetch_array($result1))
 {
 echo"<tr><td><b>".$num1['user_name']."</b> FY ".$year_r."-".$year_r_n."</td></tr>";
    
 echo"<tr style='background-color:yellow'><td>&nbsp;</td><td></td><td><b>Total Received</b></td>".$cc."<td><b>Closed</b></td></tr>";
 foreach($month_array as $key=>$val)
 {
    $queryTott="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31' && handle_by='".$num1['recNo']."'";
    $resultTott=mysql_query($queryTott);
    $numTott=mysql_fetch_array($resultTott);
 
    $month=date("F",strtotime("".$val."-01"));
 $sqlQuery = "SELECT * FROM sales_enquiry_source";
 $result=mysql_query($sqlQuery);
 $cc1="";
 while($num=mysql_fetch_array($result))
 {
    $queryTot="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31' && lead_source='".$num['enquiry_source']."' && handle_by='".$num1['recNo']."'";
    $resultTot=mysql_query($queryTot);
    $numTot=mysql_fetch_array($resultTot);
    $cc1.="<td>".$numTot['tot']."</td>";
 }
 
 $queryTotC="select count(*) as tot from jos_corporate_contact where createDate>='".$val."-01' && createDate<='".$val."-31' && equiry_status='Closed' && handle_by='".$num1['recNo']."'";
    $resultTotC=mysql_query($queryTotC);
    $numTotC=mysql_fetch_array($resultTotC);
    
    
 echo"<tr><td></td><td style='background-color:yellow'>".$month."</td><td>".$numTott['tot']."</td>".$cc1."<td>".$numTotC['tot']."</td></tr>";
    
    
 }   
 echo"<tr><td>&nbsp;</td></tr>";
    
 }
 
 
 echo"</table>";
 
  include "footer.php";

 ?>