<?php
defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- bootstrap-css -->
<link rel="stylesheet" href="<?php echo base_url();?>/assets/css/bootstrap.min.css" />
<!-- //bootstrap-css -->
<!-- Custom CSS -->
<link href="<?php echo base_url();?>/assets/css/style.css" rel='stylesheet' type='text/css' />
<link href="<?php echo base_url();?>/assets/css/style-responsive.css" rel="stylesheet"/>
<!-- font CSS -->
<link href='//fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<!-- font-awesome icons -->
<link rel="stylesheet" href="<?php echo base_url();?>/assets/css/font.css" type="text/css"/>
<link href="<?php echo base_url();?>/assets/css/font-awesome.css" rel="stylesheet"/> 
<link href="<?php echo base_url();?>/assets/css/datetimepicker.min.css" rel="stylesheet"/>
<!-- //font-awesome icons -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
	<script src="https://www.reviewadda.co.in/assets/crm/js/jquery-ui.js"></script>
</head>
<body>
<section id="container">
<!--header start-->
<header class="header fixed-top clearfix">
<!--logo start-->
<div class="brand">
    <a href="<?php echo base_url();?>home/dashboard" class="logo">
        <img src="" style="  display: block;  margin-left: auto;  margin-right: auto;  width: 80%;margin-top: -22px;"/>
    </a>
    <div class="sidebar-toggle-box">
        <div class="fa fa-bars"></div>
    </div>
</div>
<!--logo end-->
<?php include_once 'common/notification_bar.php';?>
<?php include_once 'common/aside.php';?>

<section id="main-content">
	<section class="wrapper">
		<div class="table-agile-info">
  <div class="panel panel-default">
  <div id="studentInfo" style="border:0px solid;z-index:999999"></div>
    <div class="panel-heading">
  Lead Distribution
    </div>
    <div class="row w3-res-tb">
	<?php if(!empty($_POST)){$cal= getCallers($_POST['caller_id']);echo "Callername = " . $cal[0]['username'];?>
	<?php $sou= getSource($_POST['source_id']);echo "Source = " .  $sou[0]->source;?>
	<?php echo "From Date = " . $_POST['from_date'];?>
	<?php echo "To Date = " .  $_POST['to_date'];}?>
	<form method="post" action="<?php echo base_url();?>home/leadreport">
      <div class="col-sm-12 m-b-xs">
 
		<?php if($user_data[0]['user_type']!=3){?>
		<select name="caller_id" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
         <option value="">Select Caller</option>
											<?php $userid=$this->session->userdata('user_login');
											foreach(getCaller($userid[0]['id'],$userid[0]['user_type']) as $get){?>
											<option <?php if($filter_data['caller_id']==$get->id){echo "selected";}?> value="<?php echo $get->id;if($get->user_type==2){echo "-tl";}?>"><?php echo $get->username;if($get->user_type==2){echo "(TL)";}?></option>
											<?php } ?>
											</select>
											<?php } ?>
        <select name="source_id" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
          <option value="">Select Source</option>
											<?php foreach(getSource() as $get){?>
											<option <?php if($filter_data['source_id']==$get->id){echo "selected";}?> value="<?php echo $get->id;?>"><?php echo $get->source;?></option>
											<?php } ?>
											</select>
		 <input type="date" name="from_date" style="margin:5px;" placeholder="by created date" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['from_date']!=''){echo $filter_data['from_date'];}?>"/>
		 
		  <input type="date" name="to_date" style="margin:5px;" placeholder="by created date" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['to_date']!=''){echo $filter_data['to_date'];}?>"/>
		<div class="clearfix"></div>
        <button class="btn btn-sm btn-primary" name="submit" >Apply</button>                
        <a href="<?php echo base_url();?>home/reset" class="btn btn-sm btn-default">Reset</a>                
      </div>
      </form>
    </div>
	<div class="row w3-res-tb">
	<?php //print_r($leads);?>
<div class="table-responsive">
	<?php $i=0;foreach($_SESSION['leadsdata'] as $lead){
			//$leadstatus=getStatus($lead->lead_status);
		//$project=getProjects($lead->interested_in);
		//$tl=getTL($lead->caller_id);
		if($source_id!=''){
			$source_id1=$source_id;}
			
			else{
			$source_id1=$filter_data['source_id'];
			
		}
		?>
      <table class="table table-striped b-t b-light">
        <thead>
          <tr>
            <th style="font-weight: normal;">ID</th>
            <th style="font-weight: normal;">Name</th>
           
            <th style="font-weight: normal;">Total Leads Assigned</th>
            <th style="font-weight: normal;">Follow Up Leads</th>
            <th style="font-weight: normal;">Interested Leads</th>
            <th style="font-weight: normal;">Site Visit Leads</th>
            <th style="font-weight: normal;color:red">Reverted Leads</th>
   
          </tr>
        </thead>
        <tbody>
	
		<tr>
		<th><?php echo $i+1;?></th>
            <th style="font-weight: normal;"><?php echo $lead->username;?></th>
            <th style="font-weight: normal;"><?php $sett[$lead->cl_id]= getTotalSourcecount($lead->cl_id,'',$source_id1,$from_date,$to_date);
			//echo "<pre/>";print_r($sett);
			echo (count($sett[$lead->cl_id][0])+count($sett[$lead->cl_id][1]));
			?></th>
            <th style="font-weight: normal;"><?php $fl= getTotalSourcecount($lead->cl_id,3,$source_id1,$from_date,$to_date);
			echo (count($fl[0])+count($fl[1]));
			?></th>
            <th style="font-weight: normal;"><?php $il= getTotalSourcecount($lead->cl_id,4,$source_id1,$from_date,$to_date);echo (count($il[0])+count($il[1]));?></th>
            <th style="font-weight: normal;"><?php $svl= getTotalSourcecount($lead->cl_id,5,$source_id1,$from_date,$to_date);echo (count($svl[0])+count($svl[1]));?></th>
            <th style="font-weight: normal;background:#ff4050;color:#000"><?php $rl[$lead->cl_id]= getTotalreverted($lead->cl_id,15,$source_id1,$from_date,$to_date);
			echo (count($rl[$lead->cl_id][0])+count($rl[$lead->cl_id][1]));?></th>
        

		</tr>
	
		</tbody>
		</table>
		  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
		<div class="col-sm-6">
	
	<?php $clid= $lead->cl_id;
	$arrs='';$arrs1='';
	foreach($sett[$clid][0] as $lead){
		$arrs .=$lead->source_id.',';
	}
	foreach($sett[$clid][1] as $lead){
		$arrs .=$lead->source_id.',';
	}
    $arrs=rtrim($arrs,',');
	
	//echo "<pre/>";print_r($arrs);
	$arrs1=explode(',',$arrs);
	//echo count($arrs1);
	$aas=(array_count_values($arrs1));
	$chtt='';
	foreach($aas as $keys => $charts){
	$leads=getSource($keys);
	$chtt .="['".$leads[0]->source."-".$charts."',".$charts."],";	
	}
	$chtt = rtrim($chtt,',');
	?>
    <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'lead Source'],
          <?php echo $chtt;?>
        ]);

        var options = {
          title: 'Total Leads Report According to Source',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart_<?php echo $clid;?>dd'));
        chart.draw(data, options);
      }
    </script>
 
    <div id="piechart_<?php echo $clid;?>dd" style="min-width:400px; height:350px; margin: 0 auto"></div>
 
  </div>
		
<div class="col-sm-6">
	
	<?php  $cliid = $clid;
	$arrs11='';$arrs111='';
	foreach($rl[$cliid][0] as $leadr){
		$arrs11 .=$leadr->source_id.',';
	}
	foreach($rl[$cliid][1] as $leadr){
		$arrs11 .=$leadr->source_id.',';
	}
    $arrs11=rtrim($arrs11,',');
	
	//echo "<pre/>";print_r($arrs);
	$arrs111=explode(',',$arrs11);
	//echo count($arrs1);
	$aas1=(array_count_values($arrs111));
	$chtt1='';
	foreach($aas1 as $keys1 => $charts1){
	$leads1=getSource($keys1);
	$chtt1 .="['".$leads1[0]->source."-".$charts1."',".$charts1."],";	
	}
	$chtt1 = rtrim($chtt1,',');
	?>
    <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'lead Source'],
          <?php echo $chtt1;?>
        ]);

        var options = {
          title: 'Reverted Leads Report According to Source',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart_<?php echo $cliid;?>revertdd'));
        chart.draw(data, options);
      }
    </script>
 
    <div id="piechart_<?php echo $cliid;?>revertdd" style="min-width:400px; height:350px; margin: 0 auto"></div>
 
  </div>	
		<?php $i++;} ?>
		</div>
	
	</div>
  </div>
</div>
</section>
<style>
.footnav{display:none;}
@media(max-width:750px){
.footnav{display:block;}	
}
</style>

<div style="width:100%;padding:16px;background:#1a20c3;color:#fff;position:fixed;bottom:0px;border-top:3px solid #d01525" class="footnav">
<?php if($userid[0]['user_type']==1){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/report" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-bar-chart" > Report</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
<?php if($userid[0]['user_type']==2){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/my_team" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list" > My Team</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
<?php if($userid[0]['user_type']==3){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
</div>
 <!-- footer -->
		  <div class="footer">
			<div class="wthree-copyright">
			 	<p >Develped by <a href="https://www.tenacioushub.com/" target="_blank"><img src="<?php echo base_url;?>/assets/images/logo.png" style="height:25px;"/></a></p>
			</div>
		  </div>
  <!-- / footer -->
</section>
<style>
.btnh{border: 1px solid #ccc;
padding: 5px;
border-radius: 100%;}
</style>
<!--main content end-->
</section>

<script src="<?php echo base_url();?>/assets/js/bootstrap.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.dcjqaccordion.2.7.js"></script>
<script src="<?php echo base_url();?>/assets/js/scripts.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.slimscroll.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.nicescroll.js"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot-chart/excanvas.min.js"></script><![endif]-->
<script src="<?php echo base_url();?>/assets/js/jquery.scrollTo.js"></script>
</body>
</html>
