<?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;
}

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>
             
             
             
             <?php
             if($_SESSION["fullname"]=="SWATHIKA" || $_SESSION["fullname"]=="GOBIKA")
{
    $where5=" and lead_generated_by='".$_SESSION["fullname"]."'";
}
             
             $fromdate=date("Y-m-01");
             $today1=date("Y-m-d");
             $yesterday=" and lead_given_date!='$today1' ";
             $today="  and lead_given_date='$today1' ";
             $where8="";
             if($_SESSION["fullname"]=="ROSHNI G" || $_SESSION["fullname"]=="MARY PRISILLA" || $_SESSION["fullname"]=="RAJESWARI S")
{
    $where8=" and assigned_to='".$_SESSION["fullname"]."'";
}
             
             $where1=" and lead_given_date between '$fromdate' and '$today1' ".$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_given_date between '$lead_given_date_from' and '$lead_given_date_to'".$where8.$where5;
                }
             }
             
$url="lead_dashboard";

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





             ?>
                    

                    
                    
                    <!--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 Generated Dashboard</h4>      




                    <div class="row" style="overflow-x: auto;">
                        
  <?php
    
    
    ?>
<center>
  
<table id="search"  class="table-bordered table sortable" style="width:80%;">
 <thead>
          <tr>
            <th colspan="31">LEAD MANAGEMENT</th>
          </tr>
          <tr>
            <th style="width:5%;">S.No</th>
            <th >LEAD TYPE</th>
            <th>TILL YESTERDAY</th>
           
            <th>TODAY</th>
            <th>TOTAL</th>
            
             <th>ASSIGNED</th>
            <th style="
    background: #fdf8a6;
">NOT ASSIGNED</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;
$total=0;

  $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 >= '$fromdate' ";
        
        $where1_today=" and lead_given_date='$date' ";
        
        $where1=" and lead_given_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 >= '$fromdate' and lead_given_date <= '$to' ";
        
        $where1_today=" and lead_given_date='$date' ";
        
        $where1=" and lead_given_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";

$data="select distinct lead_source from final_leads_education where id!='' $where1 ";
$result=$con->query($data);
while($row = $result->fetch_array()){ 
     $lead=$row['lead_source'];
     
                      
$sql="select count(*) from final_leads_education where lead_source='$lead'  $where1_yesterday "  ;


$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
     $count1=$row3['count(*)'];
 }
 
$_SESSION[$url.$lead.'l_one']=str_replace("count(*)"," * ",$sql)." ";
$tl_one=$tl_one."[]".str_replace("count(*)"," * ",$sql)." ";

 
$sql="select count(*) from final_leads_education where lead_source='$lead'   $where1_today " ;   
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count2=$row3['count(*)'];
}
$_SESSION[$url.$lead.'l_two']=str_replace("count(*)"," * ",$sql)." ";
$tl_two=$tl_two."[]".str_replace("count(*)"," * ",$sql)." ";


$sql="select count(*) from final_leads_education where lead_source='$lead'    $where1 " ; 

$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count3=$row3['count(*)'];
 }
$_SESSION[$url.$lead.'l_three']=str_replace("count(*)"," * ",$sql)." ";
$tl_three=$tl_three."[]".str_replace("count(*)"," * ",$sql)." ";

              
$sql="select count(*) from final_leads_education where lead_source='$lead' and assigned_to!=''   $where1"  ;
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count4=$row3['count(*)'];
}

$_SESSION[$url.$lead.'l_four']=str_replace("count(*)"," * ",$sql)." ";
$tl_four=$tl_four."[]".str_replace("count(*)"," * ",$sql)." ";

                      
$sql="select count(*) from final_leads_education where lead_source='$lead'  and assigned_to=''     $where1 "  ;
$res=$con->query($sql);
while($row3 = mysqli_fetch_array($res)){ 
    $count5=$row3['count(*)'];
}

$_SESSION[$url.$lead.'l_five']=str_replace("count(*)"," * ",$sql)." ";
$tl_five=$tl_five."[]".str_replace("count(*)"," * ",$sql)." ";



?>
                      
<tr>  

    <th><?php echo $i++ ?></th>
    
    <th style="text-align:left;color:blue;text-transform: uppercase;font-size: 21px;"><?php echo $lead ?></th>
    
<?php            

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

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

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

          

   
    $total1=$total1+$count1;
    $total2=$total2+$count2;
    $total3=$total3+$count3;
    $total4=$total4+$count4;
    $total5=$total5+$count5;
  
  
           
} 
$_SESSION['tl_one']=$tl_one;
$_SESSION['tl_two']=$tl_two;
$_SESSION['tl_three']=$tl_three;
$_SESSION['tl_four']=$tl_four;
$_SESSION['tl_five']=$tl_five;  




 ?>
 
</tbody>
<tfoot>
    
<tr style="background-color: #f0dc8f;color:black;">
    
    <th colspan="2" style="text-align: center;" >TOTAL</th>
  <?php      
    echo "<td><a href='lead_list_view.php?session=tl_one&assign' style='font-weight: 700;font-size:14px;color:black;'>$total1</a></td>
    
    <td><a href='lead_list_view.php?session=tl_two&assign' style='font-weight: 700;font-size:14px;color:black;'>$total2</a></td>
    
     <td><a href='lead_list_view.php?session=tl_three&assign' style='font-weight: 700;font-size:14px;color:black;'>$total3</a></td>
     
    <td><a href='lead_list_view.php?session=tl_four&assign'  style='font-weight: 700;font-size:14px;color:black;'>$total4</a></td>
    
     <td><a href='lead_list_view.php?session=tl_five&assign' style='font-weight: 700;font-size:14px;color:black;'>$total5</a></td>
     
   
    
            
</tr>";
?>


</tfoot>
</table>
</center>


<br>
<br>

<?php

?>

                         <input type="text" name="willpay" id="savewillpayvalue"    style='display:none'>
                                <button type="submit" name="save" id="savewillpay"  style='display:none'>submit</button>
                                
                                </form>
                         
                    </div>
                    
                    
<?php


$count1_sq="";
$count2_sq="";
$count2_con_sq="";
$count1_1_sq="";
$count2_1_sq="";
$count3_sq="";
$count4_sq="";
$count5_sq="";
$count6_sq="";
$count7_sq="";

$total_num4="0";
$total_num5="0";
$total_num3="0";
$total_num1="0";
$total_num2="0";
$total_num2_con="0";
$total_num1_1="0";
$total_num2_1="0";
$total_num6="0";
$total_num7="0";

?>

<br>
<br>


                            </div>
                        </div>
                    </div>
                
                
                <!--assigned to-->
                
                
                  
                  
                
                  
             
                </div>
            </div>
            
            
       
<?php
require('footer.php');
?>