<?php

require('header.php');

$team_manager_session=$_SESSION['team_manager'];
if(isset($_POST["submit"])){
    $fromdate=$_POST['fromdate'];
        $to=$_POST['todate'];
        $where1=" and  lead_given_date BETWEEN  '$fromdate' and '$to'";

  unset($_SESSION['sms']);
    unset($_SESSION['where1']);
    $_SESSION['sms']=true;
    $_SESSION['where1']=$where1;
    
    
}else{
    $date1 = new DateTime('now');
$date = $date1->format('Y-m-d');
$date2 = $date1->format('Y-m-01');
$where1=" and lead_given_date BETWEEN '$date2' and '$date'";

  unset($_SESSION['sms']);
    unset($_SESSION['where1']);
}


?>
<style>
         .table-bordered {
    border: 2px solid #000 !important;
}

 .table-bordered > tbody > tr > td, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > td, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > thead > tr > th {
  border: 1px solid #07481d !important;
    border-bottom-width: 1px;
}



table {
    
  width: 100% ! important;
  /*margin-top: 100px;*/
  font-size: 15px;
  border-collapse: collapse;
   
}

td,
th {
  padding: 8px;
 text-align: center;
 width: auto;
 vertical-align:middle !important;
}

thead tr {
  /*background-color:  #609966;*/
 color: #191825;
  height: 54px;
  
}

thead th {
  width: auto;

   text-align:center;
   font-weight:bold;
}
tbody th {
  width: auto;
   /*text-align:center;*/
}
tbody td {
  width: auto;
   /*text-align:center;*/
}

tbody tr:nth-child(odd) {
  
  height: 40px;
}

tbody tr:nth-child(even) {
  /*background-color: #e9ecef !important;*/
  height: 40px;
}
 center{
     overflow: scroll;
 }
</style>


<br>
<br>
    
      
            <div class="admin-dashone-data-table-area mg-b-15">
                <div class="container-fluid">
                    
                    
           
                    
                    
                    
                     <div class="row">
                        <div class="col-lg-12">
                            <div class="sparkline8-list shadow-reset">
                                
                                <div class="sparkline8-graph">
                                    
                                      
                    <div class="row" >
                         
                       
           <form action="" method="post" style="
    margin-left: -5%;
">
    <div class="row" style="margin-left: 176px;margin-top: 29px;">
        <h3 style="font-size: 20px;font-weight: 751;" >Lead Given Date Search</h3>
        </div>
                                        <div class="row">
                                            <div class="col-lg-2">
                                            <label class="login2 pull-right pull-right-pro" style="
    margin-top: 31px;
">From</label></div>
                                            <div class="col-lg-3">
                                            <input type="date" name="fromdate" class="form-control" style="margin-top: 29px;">
                                            </div>
                                            
                                            <div class="col-lg-1" style="margin-top: 26px;">
                                            <label class="login2 pull-right pull-right-pro" style="
    margin-top: 5px;
">To</label></div>
                                            <div class="col-lg-3" style="margin-top: 26px;">
                                            <input type="date" name="todate" class="form-control">
                                            </div>
                                            <div class="col-lg-2" style="margin-top: 27px;" >
                                                                            
                                                                             
                                       <button class="btn btn-sm btn-primary login-submit-cs" name="submit" value="submit" type="submit" id="basicSuccessNoIcon" >Get Records</button>
                                        </div>
                                    </div>
                            </form>
    </div>
                
                    </div>
                    
                 </div>
                            </div>
                        </div>
                    </div>
             
             
             
             <?php
               
          if($_SESSION["fullname"]=="SWATHIKA" || $_SESSION["fullname"]=="GOBIKA")
{
    $where5=" and lead_generated_by='".$_SESSION["fullname"]."'";
}
               
               $where8="";
               $fromdate=date("Y-m-01");
              $today1=date("Y-m-d");
             $yesterday="   and assigned_date!='$today1' ";
             $today=" and assigned_date='$today1' ";
            
             if($_SESSION["fullname"]=="ROSHNI G" || $_SESSION["fullname"]=="MARY PRISILLA" || $_SESSION["fullname"]=="MOHANAPRIYA S" || $_SESSION["fullname"]=="RAJESWARI S" )
{
    $where8=" and assigned_to='".$_SESSION["fullname"]."'";
}
             
   $own_lead="and lead_generated_by!='GOBIKA' and lead_generated_by!='SWATHIKA' and lead_generated_by!=''";      
//              if($_SESSION["fullname"]=="MARY PRISILLA")
// {
//     $where8="";
//     $where5=" and (lead_generated_by='".$_SESSION["fullname"]."' or assigned_to='".$_SESSION["fullname"]."')";
// }
             
             
             $where1=" and lead_given_date between '$fromdate' and '$today1' and (lead_type='ORGANIC LEADS' or lead_type='CAMPAIGN LEADS')".$where8.$where5;
             
             if(isset($_POST['submit']))
             {
                $lead_given_date_from=$_POST['lead_given_date_from'];
                
                $lead_given_date_to=$_POST['lead_given_date_to'];
                
                if($lead_given_date_from!='')
                {
                    $where1=" and (lead_type='ORGANIC LEADS' or lead_type='CAMPAIGN LEADS') and lead_given_date between '$lead_given_date_from' and '$lead_given_date_to'".$where8.$where5;
                }
             }
             
             if(isset($_POST['submit1']))
             {
                $lead_given_date_from=$_POST['lead_given_date_from'];
                
                $lead_given_date_to=$_POST['lead_given_date_to'];
                
                if($lead_given_date_from!='')
                {
                    $where1=" and (lead_type='ORGANIC LEADS' or lead_type='CAMPAIGN LEADS') and assigned_date between '$lead_given_date_from' and '$lead_given_date_to'".$where8.$where5;
                }
             }
             
             $url="lead_dashboard";

include "dbconfig.php";
$link = opencon();

if($team_manager_session!="Admin")
    {
        $tm_condition=" and assigned_to='$team_manager_session'";
    }
       

             ?>
                    

                    
                    <br>
                    <br>
                    
                    <!--team_manager-->
                      <div class="row">
                        
                        <div class="col-lg-12">
                            <div class="sparkline8-list shadow-reset">
                                
                                <div class="sparkline8-graph" >
                                    
                              <h4 style="
    text-align: center;font-weight:bold;
">Lead Assigned Dashboard</h4>      

                    <div class="row" style="overflow-x: auto;">
                         
                    

<table id="print1"  class="table-bordered table sortable" style="width:80%;">
 <thead>
          <tr>
            <th colspan="31">LEAD MANAGEMENT</th>
          </tr>
          <tr>
            <th rowspan="3" style="width:5%;">S.No</th>
            <th  rowspan="3">LEAD ASSGINED TO</th>
            <th rowspan="3"></th>
           
            <th rowspan="3">TOTAL LEADS ASSIGNED </th>
            <th rowspan="3">TOTAL LEADS UPDATED</th>
            <th rowspan="3">TOTAL CONNECTED</th>
            <th colspan="8">CONNECTED</th>
            
             <th rowspan="3" style="
    background: #fdf8a6 !important;
">NOT CONNECTED</th>
             
             
          </tr>
       
          <tr>
              <th colspan="4" style="
    background: #7edf75;
">INTERESTED</th>
             <th colspan="4" style="background:#f0aaaa;">NOT INTERESTED</th>
          </tr>
          
          
          <tr>
            <th style="
    background: #7fd277;
">ELIGIBILITY COMPLETED</th>
            
            <th style="
    background: #7fd277;
">ADMISSION COMPLETED</th>
            <th style="
    background: #7fd277;
">SURE PIPELINE</th>
            <th style="
    background: #7fd277;
">UNDER PROJECTION</th>
            
            <th style="background:#f0aaaa;">HIGH FEES</th>
            <th style="background:#f0aaaa;">COURSE NOT AVAILABLE</th>
            <th style="background:#f0aaaa;">UNIVERSITY NOT AVAILABLE</th>
             <th style="background:#f0aaaa;">STUDENT NOT ELIGIBLE</th>
          </tr>
</thead>
<tbody id="table">
<?php

$i=1;

$total1=0;
$total2=0;
$total3=0;
$total4=0;
$total5=0;
$total6=0;
$total7=0;
$total8=0;
$total9=0;
$total=0;
$tl_one="";
$tl_two="";
$tl_three="";
$tl_four="";
$tl_five="";


  $fromdate=date("Y-m-01");
  $to=date("Y-m-t");
  $date=date("Y-m-d");
  
  
   $where1_yesterday=" and lead_given_date!='$date' and lead_given_date between '$fromdate' and   '$to' ";
        
        $where1_today=" and lead_given_date='$date' ";
        
        $where1=" and lead_given_date between '$fromdate' and '$to' ";
        
          $where1_yesterday_status=" and status_date!='$date' and status_date between '$fromdate' and   '$to' ";
        
        $where1_today_status=" and status_date='$date' ";
        
        $where1_status=" and status_date between '$fromdate' and '$to' ";

if(isset($_POST["submit"])){
    
         $fromdate=$_POST['fromdate'];
        $to=$_POST['todate'];
       
        $date=date("Y-m-d");    
        
        $where1_yesterday=" and lead_given_date!='$date' and lead_given_date between  '$fromdate' and  '$to' ";
        
        $where1_today=" and lead_given_date='$date' ";
        
        $where1=" and lead_given_date between '$fromdate' and '$to' ";
        
         $where1_yesterday_status=" and status_date!='$date' and status_date between '$fromdate' and   '$to' ";
        
        $where1_today_status=" and status_date='$date' ";
        
        $where1_status=" and status_date between '$fromdate' and '$to' ";
    

}


$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'hrdant7r_market';
$DATABASE_PASS = 'gAw=6Y79}FDN';
$DATABASE_NAME = 'hrdant7r_market';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);

$url="lead_assign_dash";
$arrays=array("TILL YESTERDAY","TODAY","TOTAL");
$data="select distinct assigned_to from final_leads_education  where assigned_to!='' and id!='' $tm_condition $where1 ";

$result=$con->query($data);
while($row = $result->fetch_array()){ 
     $lead=$row['assigned_to'];
     
 $k=0;         
while($k<3)
{
     $date=date("Y-m-d");
    if($k==2)
    {
        $where1_date=$where1;
         $where1_date1=$where1_status;
    }
    else if($k==0)
    {
        $where1_date=$where1_yesterday;
         $where1_date1=$where1_yesterday_status;
         
    }
    else if($k==1)
    {
       
        $where1_date=$where1_today;
         $where1_date1=$where1_today_status;
    }
    else
    {
        
    }
    
    $name=$arrays[$k];
    $sql="select count(*) from final_leads_education where  assigned_to='$lead'  $where1_date "  ;
   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
     $count1=$row3['count(*)'];
 }
 
$_SESSION[$url.$lead.$name.'l_one']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_one=$tl_one."[]".str_replace("count(*)"," * ",$sql)." ";
}
 
$sql="select count(*) from final_leads_education where assigned_to='$lead'  and status='ELIGIBILITY COMPLETED' $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count2=$row3['count(*)'];
}
$_SESSION[$url.$lead.$name.'l_two']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_two=$tl_two."[]".str_replace("count(*)"," * ",$sql)." ";
}

$sql="select count(*) from final_leads_education where assigned_to='$lead'   and status='ADMISSION COMPLETED'  $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count3=$row3['count(*)'];
 }
$_SESSION[$url.$lead.$name.'l_three']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_three=$tl_three."[]".str_replace("count(*)"," * ",$sql)." ";
}
              
$sql="select count(*) from final_leads_education where assigned_to='$lead'  and status='SURE PIPELINE' $where1_date1 "  ;
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count4=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_four']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_four=$tl_four."[]".str_replace("count(*)"," * ",$sql)." ";
}
                      
$sql="select count(*) from final_leads_education where assigned_to='$lead'  and status='UNDER PROJECTION' $where1_date1 "  ;
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count5=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_five']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_five=$tl_five."[]".str_replace("count(*)"," * ",$sql)." ";
}
$sql="select count(*) from final_leads_education where assigned_to='$lead' and status='HIGH FEES' $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count6=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_six']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_six=$tl_six."[]".str_replace("count(*)"," * ",$sql)." ";
}

$sql="select count(*) from final_leads_education where assigned_to='$lead' and status='COURSE NOT AVAILABLE' $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count7=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_seven']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_seven=$tl_seven."[]".str_replace("count(*)"," * ",$sql)." ";
}

$sql="select count(*) from final_leads_education where assigned_to='$lead' and status='UNIVERSITY NOT AVAILABLE'  $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count8=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_eight']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_eight=$tl_eight."[]".str_replace("count(*)"," * ",$sql)." ";
}

$sql="select count(*) from final_leads_education where assigned_to='$lead' and status='STUDENT NOT ELIGIBLE'  $where1_date1 " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count10=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_ten']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
    {
$tl_ten=$tl_ten."[]".str_replace("count(*)"," * ",$sql)." ";
}

$sql="select count(*) from final_leads_education where assigned_to='$lead' and (status='' or status='NOT CONNECTED') $where1_date " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count9=$row3['count(*)'];
}

$_SESSION[$url.$lead.$name.'l_nine']=str_replace("count(*)"," * ",$sql)." ";
if($k==2)
{
$tl_nine=$tl_nine."[]".str_replace("count(*)"," * ",$sql)." ";
}


$count1_1=$count2+$count3+$count4+$count5+$count6+$count7+$count8+$count10;

$_SESSION[$url.$lead.$name.'l_one_1']=$_SESSION[$url.$lead.$name.'l_two']."[]".$_SESSION[$url.$lead.$name.'l_three']."[]".$_SESSION[$url.$lead.$name.'l_four']."[]".$_SESSION[$url.$lead.$name.'l_five']."[]".$_SESSION[$url.$lead.$name.'l_six']."[]".$_SESSION[$url.$lead.$name.'l_seven']."[]".$_SESSION[$url.$lead.$name.'l_eight']."[]".$_SESSION[$url.$lead.$name.'l_ten'];

$count1_2=$count1_1+$count9;

$_SESSION[$url.$lead.$name.'l_one_2']=$_SESSION[$url.$lead.$name.'l_one_1']."[]".$_SESSION[$url.$lead.$name.'l_nine'];

if($k==2)
{
    
$tl_one_1=$tl_one_1."[]".$_SESSION[$url.$lead.$name.'l_one_1'];
$tl_one_2=$tl_one_2."[]".$_SESSION[$url.$lead.$name.'l_one_2'];

}

?>
                      
<tr >  


    
    
   
    
    <?php
    if($k==0)
    {
        ?>
        <th rowspan="3"  ><?php echo $i++ ?></th>
          <th rowspan="3" style="text-align:left;color:blue;text-transform: uppercase;font-size: 21px;"><?php echo $lead ?></th>
        <?php
    }
    ?>
       
    
    
<?php            

echo"<td>$name</td>";

  echo"<td><a href='lead_list_view.php?session=".$url.$lead.$name."l_one&assign' style='font-weight: 700;font-size:14px;color:black;'>$count1</a></td>";



echo"<td style='background:#9fc7d4'><a href='lead_list_view.php?session=".$url.$lead.$name."l_one_1&assign' style='font-weight: 700;font-size:14px;color:black;'>$count1_2</a></td>";

echo"<td><a href='lead_list_view.php?session=".$url.$lead.$name."l_one_1&assign' style='font-weight: 700;font-size:14px;color:black;'>$count1_1</a></td>";

    echo"<td style='background:#d2ffd2'><a href='lead_list_view.php?session=".$url.$lead.$name."l_two&assign' style='font-weight: 700;font-size:14px;color:black;'>$count2</a></td>";
 
    echo"<td style='background:#d2ffd2'><a href='lead_list_view.php?session=".$url.$lead.$name."l_three&assign'  style='font-weight: 700;font-size:14px;color:black;'>$count3</a></td>";

  

    echo"<td style='background:#d2ffd2'><a href='lead_list_view.php?session=".$url.$lead.$name."l_four'   style='font-weight: 700;font-size:14px;color:black;'>$count4</a></td>";
  
     echo"<td style='background:#d2ffd2'><a href='lead_list_view.php?session=".$url.$lead.$name."l_five'  style='font-weight: 700;font-size:14px;color:black;'>$count5</a></td>";
 
     echo"<td style='background:#ffd7d7'><a href='lead_list_view.php?session=".$url.$lead.$name."l_six'  style='font-weight: 700;font-size:14px;color:black;'>$count6</a></td>";
      
    echo"<td style='background:#ffd7d7'><a href='lead_list_view.php?session=".$url.$lead.$name."l_seven'  style='font-weight: 700;font-size:14px;color:black;'>$count7</a></td>";
    
    echo"<td style='background:#ffd7d7'><a href='lead_list_view.php?session=".$url.$lead.$name."l_eight'  style='font-weight: 700;font-size:14px;color:black;'>$count8</a></td>";   
    
     echo"<td style='background:#ffd7d7'><a href='lead_list_view.php?session=".$url.$lead.$name."l_ten'  style='font-weight: 700;font-size:14px;color:black;'>$count10</a></td>";  
     
  echo"<td><a href='lead_list_view.php?session=".$url.$lead.$name."l_nine'  style='font-weight: 700;font-size:14px;color:black;'>$count9</a></td>";   

    echo"</tr>";
            

          

   
   
      
      if($k==2)
    {
    $total1=$total1+$count1;
     $total1_1=$total1_1+$count1_1;
     $total1_2=$total1_2+$count1_2;
    $total2=$total2+$count2;
    $total3=$total3+$count3;
    $total4=$total4+$count4;
    $total5=$total5+$count5;
    $total6=$total6+$count6;
     $total7=$total7+$count7;
      $total8=$total8+$count8;
      $total9=$total9+$count9;
      $total10=$total10+$count10;
    }
  $k++;
           
} 



}
$_SESSION['tl_one']=$tl_one;
$_SESSION['tl_one_1']=$tl_one_1;
$_SESSION['tl_one_2']=$tl_one_2;
$_SESSION['tl_two']=$tl_two;
$_SESSION['tl_three']=$tl_three;
$_SESSION['tl_four']=$tl_four;
$_SESSION['tl_five']=$tl_five;  
$_SESSION['tl_six']=$tl_six;
$_SESSION['tl_seven']=$tl_seven;
$_SESSION['tl_eight']=$tl_eight;
$_SESSION['tl_nine']=$tl_nine;
$_SESSION['tl_ten']=$tl_ten;
 ?>
 
</tbody>
<tfoot>
    
<tr style="background-color: #f0dc8f;color:black;">
    
    <th colspan="3" style="text-align: center;" >TOTAL</th>
  <?php      
    echo "<td><a href='lead_list_view.php?session=tl_one' style='font-weight: 700;font-size:14px;color:black;'>$total1</a></td>
    
   
    
        <td style='background:#9fc7d4'><a href='lead_list_view.php?session=tl_one_2' style='font-weight: 700;font-size:14px;color:black;'>$total1_2</a></td>
    
     <td><a href='lead_list_view.php?session=tl_one_1' style='font-weight: 700;font-size:14px;color:black;'>$total1_1</a></td>
    
    <td style='background:#d2ffd2'><a href='lead_list_view.php?session=tl_two' style='font-weight: 700;font-size:14px;color:black;'>$total2</a></td>
    
     <td style='background:#d2ffd2'><a href='lead_list_view.php?session=tl_three' style='font-weight: 700;font-size:14px;color:black;'>$total3</a></td>
     
    <td style='background:#d2ffd2'><a href='lead_list_view.php?session=tl_four'  style='font-weight: 700;font-size:14px;color:black;'>$total4</a></td>
    
     <td style='background:#d2ffd2'><a href='lead_list_view.php?session=tl_five' style='font-weight: 700;font-size:14px;color:black;'>$total5</a></td>
     <td style='background:#ffd7d7'><a href='lead_list_view.php?session=tl_six' style='font-weight: 700;font-size:14px;color:black;'>$total6</a></td>
     <td style='background:#ffd7d7'><a href='lead_list_view.php?session=tl_seven' style='font-weight: 700;font-size:14px;color:black;'>$total7</a></td>
     <td style='background:#ffd7d7'><a href='lead_list_view.php?session=tl_eight' style='font-weight: 700;font-size:14px;color:black;'>$total8</a></td>
    <td style='background:#ffd7d7'><a href='lead_list_view.php?session=tl_ten' style='font-weight: 700;font-size:14px;color:black;'>$total10</a></td>
  <td><a href='lead_list_view.php?session=tl_nine' style='font-weight: 700;font-size:14px;color:black;'>$total9</a></td>
    
            
</tr>";
?>


</tfoot>
</table>


                         
                    </div>
                    
                    
                    
                    <br>
                    <br>
                
                 </div>
                            </div>
                        </div>
                    </div>
                    <!--team_leader-->
                    
                     <!--telecaller_leader-->
                    
                </div>
            </div>
<?php
require('footer.php');
?>