<?php
include("common/connection.php");
login_check();

$CurrentMonth = date('m');
$CurrentYear = date('Y');
?>
<!doctype html>
<html class="no-js" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Current Leads | Buurtzorg</title>
    <script>
	function delete_lead(per) 
	{
	  var response = confirm("Are You Sure to Delete Lead!");
	  if (response == true) 
	  {
		$.ajax({
		url:"ajax_delete_lead.php",
		type:"POST",
		data:{'per':per},
		success:function(data)
		{
 			//alert('Lead '+data+' Deleted Successfully');
		}
		});
	  } 
	  else 
	  {
		alert('Lead Not Deleted');
	  }
	}
	</script>
    <script>
	function update_callconnect(Status,Lead_Id)
	{
	 //alert(Status);
	 
	 $.ajax({
		url:"ajax_updatecall_lead.php",
		type:"POST",
		data:{'Status':Status,'Lead_Id':Lead_Id},
		success:function(data)
		{
		//alert(data)
			if(Status=='Call Connected')
			{
			
			  window.location.href='call_connected.php?Lid='+Lead_Id;
			}
			else
			{
			  window.location.href='current_leads.php';
			}
		}
		})
	}
	</script>
    <?php include("headerlink.php"); ?>
    <?php
		//---------user type check-------// 
	    $user_sql="select User_Type as type,Location from user_master where User_Name='".$_SESSION['user']."'";
		$user_query=mysqli_query($con,$user_sql);
		$user=mysqli_fetch_array($user_query);
		
		//---------all leads fetching by condition-------// 
		$all_leads_sql="select count(Lead_ID) as total_leads from lead_master";
		
		if($user['type']!='Super Admin')
		{
		//$all_leads_sql.=" where Lead_Referred_To='".$_SESSION['user']."'";
		  $all_leads_sql.=" where Control_Location='".$user['Location']."'";
		}
		
		$all_leads_query=mysqli_query($con,$all_leads_sql);
		$all_leads=mysqli_fetch_array($all_leads_query);
		
		
		//---------fresh leads fetching by condition-------// 
		$fresh_leads_sql="select count(Lead_ID) as fresh_leads from lead_master where Status ='Yet to be Called'";
		
		if($user['type']!='Super Admin')
		{
		//$fresh_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		   $fresh_leads_sql.=" and Control_Location='".$user['Location']."'";
		}
		
		$fresh_leads_query=mysqli_query($con,$fresh_leads_sql);
		$fresh_leads=mysqli_fetch_array($fresh_leads_query);
		
		//---------fresh leads fetching by condition-------// 
		$progress_leads_sql="select count(Lead_ID) as progress_leads from lead_master where (Status !='Yet to be Called' and Status !='')";
		
		if($user['type']!='Super Admin')
		{
		//$progress_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		$progress_leads_sql.=" and Control_Location='".$user['Location']."'";
		}
		
		$progress_leads_query=mysqli_query($con,$progress_leads_sql);
		$progress_leads=mysqli_fetch_array($progress_leads_query);
		
		//---------today leads fetching by condition-------// 
		$today_leads_sql="select count(Lead_ID) as today_leads from communication_master where (Status !='Yet to be Called' and Status !='') and Date_Of_Communication LIKE'".date('Y-m-d')."%'";
		
		if($user['type']!='Super Admin')
		{
		$today_leads_sql.=" and Communicator_ID='".$_SESSION['user']."'";
		}
		//echo $today_leads_sql;
		$today_leads_query=mysqli_query($con,$today_leads_sql);
		$today_leads=mysqli_fetch_array($today_leads_query);		
		?>
     	<link rel="stylesheet" href="css/data-table/bootstrap-table.css">
    	<link rel="stylesheet" href="css/data-table/bootstrap-editable.css">
        
        
        <style>
		table {overflow:inherit !important}
		table thead {overflow:inherit !important}
		table thead tr {overflow:inherit !important}
		
		table tbody {overflow:inherit !important}
		table tbody tr {overflow:inherit !important; }
		table tbody tr td {overflow:inherit !important}
		
		
	/*	.fixed-table-body {overflow:inherit !important}*/
		.action_dropdown {padding:0 !important; min-width:460px !important;  left:-258px; background-color:rgba(0,0,0,0) !important;
		 box-shadow:none !important; border:none !important; margin-top:-70px}
										
		 .action_dropdown:after {
			  content:'';
			  width: 0;
			  height: 0;
			  border-left: 7px solid transparent;
			  border-right: 7px solid transparent;
			  border-top: 12px solid #337ab7;
			  margin-top:40px;
			  position:absolute;
			  top:-10px;
			  margin-left:-190px;
		}
		
		
		 .bgcolor_1 { background-color:#f2dede; color:#a94442 !important }
		 .bgcolor_2 { xbackground-color:white !important }
		 .bgcolor_3 { background-color:#dff0d8; color:#3c763d !important }
		 
		 
		 
		 
		 .main_txt{
		 float:left;
		 width:60%;
		 height:auto;
		 text-align:left;
		 font-size:15px;
		 color:#FFFFFF;
		 font-weight:600;
		 }
		 
		 .number_div{
		 float:left;
		 width:40%;
		 text-align:right;
		 color:#FFFFFF;
		 font-size:50px;
		 font-weight:600;
		 }
		 
		 .maindiv{
		 float:left;
		 width:100%;
		 height:90px;
		 padding:15px;
		 border-radius:5px;
		 }
		
		</style>
</head>

<body>
    <!--[if lt IE 8]>
		<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
	<![endif]-->
    <!-- Start Left menu area -->
    
    
    
    <?php include("left-menu.php"); ?>
    
    
    
    <!-- End Left menu area -->
    <!-- Start Welcome area -->
    <div class="all-content-wrapper">
        
        
       <?php include("header-menu.php"); ?> 
        
        
        <!-- Static Table Start -->
        <div class="static-table-area">
        
       
        
        
        
            <div class="container-fluid">
                <div class="row">
                
                
                
                
                    
                    <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" >
                        <div class="sparkline9-list mt-b-30 res-mg-t-30 analysis-progrebar-ctn">
                        
           
                        
                        
                        
                            <div class="sparkline9-hd">
                                <div class="main-sparkline9-hd">
                                    <h1>DATE WISE LEADS STATUS </h1>
                                </div>
                            </div>
                            
                            
                            <div class="sparkline13-graph">
                                <div class="datatable-dashv1-list custom-datatable-overright">
                                    <div id="toolbar">
                                        <select class="form-control dt-tb" style="width:150px; display:none">
											<option value="">Export Basic</option>
											<option selected value="all">Export All</option>
											<option value="selected">Export Selected</option>
										</select>
                                        
                                        
                                        
                                        <div class="form-group" style="width:100%;">
                                        <form action="#" method="post" id="dt_lead_search">
                                     
                                          
                                            
                                             
                                        <input name="From_Date" id="start"  type="text" class="form-control" 
                                                      placeholder="From Date" style="margin-right:10px; width:150px; float:left;  margin-bottom:10px;" value="<?php echo $_REQUEST['From_Date'] ?>" data-rule-required="true" data-msg-required="Please select From Date" autocomplete="off">
                                                      <input name="To_Date" id="finish" type="text" class="form-control" 
                                                      placeholder="To Date" style="width:150px; float:left;  margin-bottom:10px; margin-right:10px;" value="<?php echo $_REQUEST['To_Date'] ?>" data-rule-required="true" data-msg-required="Please select To Date" autocomplete="off">
												<select name="source" class="form-control" id="source" style="width:120px; float:left; margin-right:10px;" >
                                           <option value="">Source</option>
                                           <option value="">--ALL--</option>
                                           <?php
											  $SqlLoc="select SLN, Source_Name from source_master";
                                               $RsLoc= mysqli_query($con,$SqlLoc);
                                               while($RowLoc=mysqli_fetch_array($RsLoc))
											   {
											 ?>
                                           <option value="<?php echo $RowLoc['Source_Name']; ?>" <?php if($_REQUEST['source']==$RowLoc['Source_Name']){ echo "selected"; } ?>><?php echo $RowLoc['Source_Name']; ?></option>
                                           <?php
												}
												?>
                                         </select>	  
												<select name="Lead_Location" class="form-control" id="Lead_Location" style="width:120px; float:left; margin-right:10px;">
														 <option value="">Location</option>
															 <?php
															  $SqlLoc="select SLN, Location_Name from location_master";
															   $RsLoc= mysqli_query($con,$SqlLoc);
															   while($RowLoc=mysqli_fetch_array($RsLoc))
															   {
															 ?>
															  <option value="<?php echo $RowLoc['Location_Name']; ?>" <?php if($RowLoc['Location_Name']==$_REQUEST['Lead_Location']){echo "selected";} ?>><?php echo $RowLoc['Location_Name']; ?></option>
																<?php
																}
																?>
														 </select>
										
                                           <select name="Service" class="form-control" id="Service" style="width:110px; float:left; margin-right:10px;">
														 <option value="">Service</option>
															 <?php
															   $SqlService="select * from service_master";
															   $RsService=mysqli_query($con,$SqlService);
															   $i=1;
															  while($RowService=mysqli_fetch_array($RsService))
															   {
															   ?>
															  <option value="<?php echo $RowService['Service']; ?>" <?php if($RowService['Service']==$_REQUEST['Service']){echo "selected";} ?>><?php echo $RowService['Service']; ?></option>
																<?php
																}
																?>
														 </select>	  
													  
													  
                                                      
                                                      <input type="submit" class="btn btn-custon-rounded-three
                                    				btn-primary" name="Lead_Search" value="Submit">
                                        
                                         
                                                      
                                                       
                                          </form>            
                                                   </div>
                                        
                                
                                    </div>
                                    
                                    
 <?php
 if($_REQUEST['Month']=='')
 {
   $_REQUEST['Month']=$CurrentMonth;
 }
 if($_REQUEST['Year']=='')
 {
    $Year=$CurrentYear;
 }
 else
 {
   $Year=$_REQUEST['Year'];
 }
// $_REQUEST['Month']=04;
 $DOM = cal_days_in_month(CAL_GREGORIAN, $_REQUEST['Month'], $Year) ; 
 
  //$MyDate=strtotime($Year ."-".$_REQUEST['Month']."-".$i);
 ?>								
                                
                                    <?php
									if($_REQUEST['From_Date']!='' && $_REQUEST['To_Date']!='' )
									{
									?>
                                    <table id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="false" data-key-events="true" data-show-toggle="false" data-resizable="true" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" class="textcenter table-striped">
                                        <thead>
                                        
                                            <tr align="center">
                                       
                                                <th  data-field="Lead ID" data-editable="false">Date</th>
                                                <?php
												$k=1;
                                                 $query ="select SLN, Source_Name from source_master";
                                                 $result = mysqli_query($con,$query);
												 while($RowSource=mysqli_fetch_array($result))
	                                              {
                                                  ?>
												  <th  colspan="" data-field="Total Lead <?php echo $k; ?>" data-editable="false">
												  <?php echo $RowSource["Source_Name"] ?> <br>All Lead
                                                  
                                                  </th>
												   <th  colspan="" data-field="Interested Lead<?php echo $k; ?>" data-editable="false">
												  <?php echo $RowSource["Source_Name"] ?> <br>Int. Lead
                                                  
                                                  </th>
                                                  
                                                  <?php
												  $k++;
												  }
												  ?>
                                            </tr>
                                             
                                             
                                        </thead>
                                        <tbody>
                                       
                                        <!--<tr class="">
                                             <td>&nbsp;</td>
                                            <td>Lead</td><td>Interested</td>
                                             <td>Lead</td><td>Interested</td>
                                              <td>Lead</td><td>Interested</td>
                                               <td>Lead</td><td>Interested</td>
                                                <td>Lead</td><td>Interested</td>
                                                 <td>Lead</td><td>Interested</td>
                                            </tr>-->	
                                            
                                            
                                           <!-- <tr class="">
                                             <td>dd</td>
                                             <td colspan="2">dddd</td>
                                             <td colspan="2">dddd</td>
                                             <td colspan="2">dddd</td>
                                             <td colspan="2">dddd</td>
                                             <td colspan="2">dddd</td>
                                             <td colspan="2">dddd</td>
                                            </tr>-->
                                            
                                            <!--<tr class="">
                                             <td>&nbsp;</td>
                                            <td>Lead</td><td>Interested</td>
                                            </tr>-->
                                            
                                            
                                        <tr class="">
                                     
                                           
                                                <td ><?php //echo date('d M, Y',strtotime($leads_datas['Lead_Creation_Date'])); ?></td>
                                                
                                                 <?php
												
                                                 $query ="select SLN, Source_Name from source_master";
                                                 $result = mysqli_query($con,$query);
												 $countSource=mysqli_num_rows($result);
												 
												  
												for ($x = 10000000; $x <= $countSource; $x++) {
													?>
                                                    
                                                  <td>
												 <div class="col-xs-6" style="border-right:1px solid #ccc;  text-align:center; margin-top:-8px; margin-bottom:-8px; padding:8px 0">Lead</div>
                                                 
                                                 
                                                 <div  class="col-xs-6" style="text-align:center; margin-top:-8px; margin-bottom:-8px;padding:8px 0">Int.</div>
                                                 
                                                 </td>
                                                    
                                                    <?php
												}
                                                ?>
                                                </tr>
                                                
                                                <?php
												//$date1=$_REQUEST['fdate'];
                                                //$date2=$_REQUEST['tdate'];
												
												$date1=$_REQUEST['From_Date'];
                                                $date2=$_REQUEST['To_Date'];
												$t=1;	
												
												$datediff = strtotime($date2) - strtotime($date1);
                                                $dayno=floor($datediff/(60*60*24))+1;
                                                $today=date("Y-m-d",strtotime($date1));
												
												
												
												
                                                 for($z=1;$z<=$dayno;$z++)
	                                             { 
												  //$MyDate=strtotime($Year ."-".$_REQUEST['Month']."-".$z); 
												  //$Dt= date("Y-m-d",$MyDate);
												  $MyDate=$today;
												  $Dt=$today;
												 ?>
                                                 <tr>
                                                 <td ><?php //echo  date("Y-m-d",$MyDate);?><?php echo date('d M, Y',strtotime($MyDate)); ?><?php //echo $today; ?></td>
                                                <?php
												 
												 
												 $i=1;
												 
												 $query ="select SLN, Source_Name from source_master";
                                                 $result = mysqli_query($con,$query);
												 $countSource=mysqli_num_rows($result);
												 while($RowSource=mysqli_fetch_array($result))
	                                              {
												     $sqlLead="select Lead_ID from lead_master where Lead_Creation_Date ='".$Dt."' and Source = '".$RowSource['Source_Name']."'";
													 /* if($_REQUEST['source']!='')
										{
										
										 $leads_table_sql.=" ";
										} */
													 if($_REQUEST['Lead_Location']!='')
										             {
											
											            $sqlLead.=" and City='".$_REQUEST['Lead_Location']."'";
										             }
													 if($_REQUEST['Service']!='')
										             {
											
											            $sqlLead.=" and Course_Name='".$_REQUEST['Service']."'";
										              }
													 
													 $RsLead=mysqli_query($con,$sqlLead);
													 $CountTotalLead=mysqli_num_rows($RsLead);
													 
													 $sqlLeadInt="select Lead_ID from lead_master where Source='".$RowSource['Source_Name']."' and Lead_Creation_Date ='".$Dt."' and Status ='Valid Lead'";
													 
													  if($_REQUEST['Lead_Location']!='')
										             {
											
											            $sqlLeadInt.=" and City='".$_REQUEST['Lead_Location']."'";
										             }
													 if($_REQUEST['Service']!='')
										             {
											
											             $sqlLeadInt.=" and Course_Name='".$_REQUEST['Service']."'";
										              }
													 
													 
													 $RsLeadInt=mysqli_query($con,$sqlLeadInt);
													 $CountIntLead=mysqli_num_rows($RsLeadInt);
													// $RowLead=mysqli_fetch_array($RsLead);
                                                  ?>
												      
                                                 <td>
												   <?php echo $CountTotalLead;  ?>
                                                 
                                                 
                                                 
                                                 
                                                 </td>
												 
												 <td>
												 
                                                 
                                                 
                                                <?php echo $CountIntLead;  ?>
                                                 
                                                 </td>
                                            
                                                  <?php
												  $i++;
												 
												  }
												  ?>
                                                  
                                                  
                                            </tr>
                                            
                                            
                                            
                                               <?php
											    $today=date("Y-m-d",strtotime("+".$t." days", strtotime($today)));
											   }
											   
											  
											   ?>
                                            
                                            <tr>
                                            <td><b>Total</b></td>
                                            
                                            <?php
											     $query ="select SLN, Source_Name from source_master";
                                                 $result = mysqli_query($con,$query);
												 $countSource=mysqli_num_rows($result);
												 while($RowSource=mysqli_fetch_array($result))
	                                              {
												  
												     //$sqlLead="select Lead_ID from lead_master where Source='".$RowSource['Source_Name']."' and MONTH(`Lead_Creation_Date`) ='".$_REQUEST['Month']."'";
													 $sqlLead="select Lead_ID from lead_master where Source='".$RowSource['Source_Name']."' and Lead_Creation_Date between '".date('Y-m-d',strtotime($_REQUEST['From_Date']))."' and '".date('Y-m-d',strtotime($_REQUEST['To_Date']))."'";
													  if($_REQUEST['Lead_Location']!='')
										             {
											
											            $sqlLead.=" and City='".$_REQUEST['Lead_Location']."'";
										             }
													 if($_REQUEST['Service']!='')
										             {
											
											             $sqlLead.=" and Course_Name='".$_REQUEST['Service']."'";
										              }
													 
													 
													 $RsLead=mysqli_query($con,$sqlLead);
													 $CountTotalLead=mysqli_num_rows($RsLead);
													 
													 //$sqlLeadInt="select Lead_ID from lead_master where Source='".$RowSource['Source_Name']."' and MONTH(`Lead_Creation_Date`) ='".$_REQUEST['Month']."' and Status ='Valid Lead'";
													 $sqlLeadInt="select Lead_ID from lead_master where Source='".$RowSource['Source_Name']."' and Lead_Creation_Date between '".date('Y-m-d',strtotime($_REQUEST['From_Date']))."' and '".date('Y-m-d',strtotime($_REQUEST['To_Date']))."' and Status ='Valid Lead'";
													  if($_REQUEST['Lead_Location']!='')
										             {
											
											            $sqlLeadInt.=" and City='".$_REQUEST['Lead_Location']."'";
										             }
													 if($_REQUEST['Service']!='')
										             {
											
											             $sqlLeadInt.=" and Course_Name='".$_REQUEST['Service']."'";
										              }
													 
													 
													 $RsLeadInt=mysqli_query($con,$sqlLeadInt);
													 $CountIntLead=mysqli_num_rows($RsLeadInt);
												  
											?>
                                               <td>
												<?php echo $CountTotalLead;  ?>
                                                
                                                 
                                                 </td>
												 
												 <td>
												 
                                                 <?php echo $CountIntLead;  ?>
                                                 
                                                 </td>
                                                 <?php
												 }
												 ?>
                                                
                                            </tr>
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                             
                                        </tbody>
                                    </table>
									<?php
									}
									?>
                              </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                
            </div>
        </div>
        <!-- Static Table End -->
        <div class="footer-copyright-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="footer-copy-right">
                            <p>Copyright © 2019. All rights reserved.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	
	<script type="text/javascript">
$("#dt_lead_search").validate({
          
      showErrors: function(errorMap, errorList) {
          // Clean up any tooltips for valid elements
          $.each(this.validElements(), function (index, element) {
              var $element = $(element);
              $element.data("title", "") // Clear the title - there is no error associated anymore
                  .removeClass("error")
                  .tooltip("destroy");
          });
          // Create new tooltips for invalid elements
          $.each(errorList, function (index, error) {
              var $element = $(error.element);

              $element.tooltip("destroy") // Destroy any pre-existing tooltip so we can repopulate with new tooltip content
                  .data("title", error.message)
                  .addClass("error")
                  .tooltip(); // Create a new tooltip based on the error messsage we just set in the title
          });
      },

     
	  
});
</script> 

    <!-- jquery
		============================================ -->
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <!-- bootstrap JS
		============================================ -->
    <script src="js/bootstrap.min.js"></script>
    <!-- wow JS
		============================================ -->
    <script src="js/wow.min.js"></script>
    <!-- price-slider JS
		============================================ -->
    <script src="js/jquery-price-slider.js"></script>
    <!-- meanmenu JS
		============================================ -->
    <script src="js/jquery.meanmenu.js"></script>
    <!-- owl.carousel JS
		============================================ -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- sticky JS
		============================================ -->
    <script src="js/jquery.sticky.js"></script>
    <!-- scrollUp JS
		============================================ -->
    <script src="js/jquery.scrollUp.min.js"></script>
    
    
    
    <!-- datepicker JS
		============================================ -->
    <script src="js/datepicker/jquery-ui.min.js"></script>
    <script src="js/datepicker/datepicker-active.js"></script>
    
    
    
    <!-- data table JS
		============================================ -->
    <script src="js/data-table/bootstrap-table.js"></script>
    <script src="js/data-table/tableExport.js"></script>
    <script src="js/data-table/data-table-active.js"></script>
    <script src="js/data-table/bootstrap-table-editable.js"></script>
    <script src="js/data-table/bootstrap-editable.js"></script>
    <script src="js/data-table/bootstrap-table-resizable.js"></script>
    <script src="js/data-table/colResizable-1.5.source.js"></script>
    <script src="js/data-table/bootstrap-table-export.js"></script>
    
    
    
    <!-- mCustomScrollbar JS
		============================================ -->
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>
    <!-- metisMenu JS
		============================================ -->
    <script src="js/metisMenu/metisMenu.min.js"></script>
    <script src="js/metisMenu/metisMenu-active.js"></script>
    <!-- peity JS
		============================================ -->
    <script src="js/peity/jquery.peity.min.js"></script>
    <script src="js/peity/peity-active.js"></script>
    <!-- sparkline JS
		============================================ -->
    <script src="js/sparkline/jquery.sparkline.min.js"></script>
    <script src="js/sparkline/sparkline-active.js"></script>
    <!-- tab JS
		============================================ -->
    <script src="js/tab.js"></script>
    <!-- plugins JS
		============================================ -->
    <script src="js/plugins.js"></script>
    <!-- main JS
		============================================ -->
    <script src="js/main.js"></script>
    <!-- tawk chat JS
		============================================ -->
        
         <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script>
<!------------------------Fancybox---------------------------------->
 
 <script type="text/javascript" src="lib/jquery.mousewheel.pack.js"></script>

<script type="text/javascript" src="source/jquery.fancybox.pack.js?v=2.1.5"></script>
	<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css" media="screen" />

<style type="text/css">
	.fancybox-custom .fancybox-skin {
		box-shadow: 0 0 50px #222;
	}
</style> 
<script>
$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 380,
		maxHeight	: 410,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		
		
		
		
	});
	
 
});

</script>
<!--    <script src="js/tawk-chat.js"></script>-->


</body>

</html>