<?php
session_start();

if (isset($_GET['sno'])) {
    $psno = $_GET['sno'];
} 

include 'actions/dbconnection.php';

// $sql = "SELECT * FROM leads where source = '$pname'  ORDER BY time DESC  limit 10";
// $result = $conn->query($sql);

// Get the current date
$currentDate = date("Y-m-d");

$sql = "SELECT leads.* 
        FROM leads
        LEFT JOIN prospecting_leads ON leads.sno = prospecting_leads.id AND prospecting_leads.next_followup_date = '$currentDate'
        LEFT JOIN contacted_leads ON leads.sno = contacted_leads.id AND contacted_leads.next_followup_date = '$currentDate'
        LEFT JOIN demodone_leads ON leads.sno = demodone_leads.id AND demodone_leads.next_followup_date = '$currentDate'
        LEFT JOIN commercials_leads ON leads.sno = commercials_leads.id AND commercials_leads.next_followup_date = '$currentDate'
        LEFT JOIN closedwon_leads ON leads.sno = closedwon_leads.id AND closedwon_leads.next_followup_date = '$currentDate'
        WHERE leads.uid = '$psno' AND (
            prospecting_leads.next_followup_date IS NOT NULL
            OR contacted_leads.next_followup_date IS NOT NULL
            OR demodone_leads.next_followup_date IS NOT NULL
            OR commercials_leads.next_followup_date IS NOT NULL
            OR closedwon_leads.next_followup_date IS NOT NULL
        )";

$result = $conn->query($sql);


$sql10 = "SELECT * FROM leads where  uid = $psno ";
$result10 = $conn->query($sql10);
$trows10 = mysqli_num_rows($result10);

$sql4 = "SELECT * FROM leads where (lead_status = 'Contacted' OR lead_status =2)  AND  uid = $psno";
$result4 = $conn->query($sql4);
$conleads = mysqli_num_rows($result4);

$sql14 = "SELECT * FROM leads where (lead_status = 'Demo Done' OR lead_status =3) AND  uid = $psno";
$result14 = $conn->query($sql14);
$demoleads = mysqli_num_rows($result14);



$sql5 = "SELECT * FROM leads where (lead_status = 'Commercials Shared' OR lead_status =4) AND  uid = $psno";
$result5 = $conn->query($sql5);
$commleads = mysqli_num_rows($result5);

$sql111 = "SELECT * FROM leads where  (lead_status = 'Closed Won' OR lead_status =5) AND  uid = $psno";
$result111 = $conn->query($sql111);
$wonleads = mysqli_num_rows($result111);


$sql1 = "SELECT * FROM leads where lead_status = 6 AND  uid = $psno";
$result1 = $conn->query($sql1);
$cloleads = mysqli_num_rows($result1);

$sql2 = "SELECT * FROM leads where (lead_status = 'Closed Lost' OR lead_status =7) AND  uid = $psno";
$result2 = $conn->query($sql2);
$lostleads = mysqli_num_rows($result2);






?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
	<title>Wisibles</title>
    <link rel="icon" href="images/fav-icon.svg" type="image/svg" sizes="16x16"> 
    
    <link rel="stylesheet" href="css/main.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/color.css">
    <link rel="stylesheet" href="css/responsive.css">
	<link href="plugins/apex/apexcharts.css" rel="stylesheet" type="text/css">

</head>
<body>
<div class="page-loader" id="page-loader">
	 <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
	 <span>Loading...</span>
</div><!-- page loader -->
<div class="theme-layout">
	
	<?php include 'header.php'; ?>
	<div class="top-sub-bar">
		<div class="container-fluid">
			<div class="row">
				<div class="col-lg-6 col-md-6 col-sm-6">
					<div class="menu-btn">
						<i class="">
                        <svg id="menu-btn" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></i>
					</div>
					<div class="page-title">
						<h4>Dashboard</h4>
					</div>
				</div>
				<div class="col-lg-6 col-md-6 col-sm-6">
					<ul class="breadcrumb">
						<li><a href="#" title="">Home</a></li>
						<li><a href="#" title="">Dashboard</a></li>
					</ul>
				</div>
			</div>
		</div>	
	</div><!-- top sub bar -->
	<?php include 'left_menu.php'; ?>
	

	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">
				<div class="panel-content">
					<h4 class="main-title"></h4>
					
					<div class="row merged20 mb-4">

						<div class="col-lg-4 col-md-4 col-sm-4">
							<a href="total_leads?uid=<?php echo $psno; ?>"> <div class="d-widget soft-red">
								<div class="d-widget-title">
									<h5>Total Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6> Check Now</h6>
									<h5><?php echo $trows10; ?></h5>
									<i class="icofont-users-alt-3"></i>
								</div>
							    </div>
                            </a>	
						</div>
						

						<div class="col-lg-4 col-md-4 col-sm-4">
						    <a href="contacted_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-blue">
								<div class="d-widget-title">
									<h5>Contacted Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Contacted</h6>
									<h5><?php echo $conleads; ?></h5>
									<i class="icofont-computer"></i>
								</div>
							    </div>
                            </a>	

						</div>

						<div class="col-lg-4 col-md-4 col-sm-4">
						   <a href="demodone_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-green">
								<div class="d-widget-title">
									<h5>Demo Done Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Check Now</h6>
									<h5><?php echo $demoleads; ?></h5>
									<i class="icofont-computer"></i>
								</div>
							</div>
                            </a>
						</div>
						
					</div>

					<div class="row merged20 mb-4">
					
					    <div class="col-lg-4 col-md-4 col-sm-4">
						    <a href="commercialsshared_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-red">
								<div class="d-widget-title">
									<h5>Commercials Shared Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Check Now</h6>
									<h5><?php echo $commleads; ?></h5>
									<i class="icofont-optic"></i>
								</div>
							   </div>
                            </a>   
						</div>
						
					    <div class="col-lg-4 col-md-4 col-sm-4">
						<a href="closedwon_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-blue">
								<div class="d-widget-title">
									<h5>Won Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Check Now</h6>
									<h5><?php echo $wonleads; ?></h5>
									<i class="icofont-optic"></i>
								</div>
							</div>
                        </a>	
						</div>

						<div class="col-lg-4 col-md-4 col-sm-4">
						<a href="closed_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-green">
								<div class="d-widget-title">
									<h5>Closed Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Check Now</h6>
									<h5><?php echo $cloleads; ?></h5>
									<i class="icofont-computer"></i>
								</div>
							</div>
                        </a>	
						</div>
						
					</div>

					<div class="row merged20 mb-4">
					
					   
					  

						<div class="col-lg-4 col-md-4 col-sm-4">
						<a href="closedlost_leads?uid=<?php echo $psno; ?>"><div class="d-widget soft-red">
								<div class="d-widget-title">
									<h5>Lost Leads</h5>
								</div>
								<div class="d-widget-content">
									<span class="realtime-ico pulse"></span>
									<h6>Check Now</h6>
									<h5><?php echo $lostleads; ?></h5>
									<i class="icofont-computer"></i>
								</div>
							</div>
                        </a>	
						</div>
						
					</div>
				
					<div class="row merged20 mb-4">
						<div class="col-lg-12">
							<div class="d-widget">
                                <div class="row">
                                    <div class="mb-4 col-lg-6">
                                        <div class="d-widget-title">
                                            <h5>Today Follow-Up Leads</h5>
                                        </div>
                                    </div>    
                                    <div class="mb-4 col-lg-6"> 
                                        <input class="uk-input" type="text" placeholder="Search..." id="myInput">
                                    </div>
                                </div>    
								<table class="table table-default all-events table-striped table-responsive-lg">
									<thead>
										<tr>
											<th>S NO</th>
											<th>School Name</th>
											<th>Name</th>
											
											<th>Mobile</th>
											
											<th>Add By</th>
                                            <!-- <th>Assigned To</th> -->
                                            <th>Status</th>
											
											<th>Action</th>
										</tr>
									</thead>
									<tbody id="myTable">
											   <?php
		   
												$count=0;
													while($row = $result->fetch_assoc())
													{   
												
												?>	
										<tr>
											<td><?php echo ++$count; ?></td>
											<td><?php echo $row['school_name']?></td>
                                            <td><?php echo $row['name'] ?></td>
								
											
											<td><?php echo $row['mobile']?></td>
											
											
											
                                            <td class="text-danger"><?php echo $row['source']; ?></td>

                                            <!-- <td class="text-primary">
                                                <?php
                                                $ass = $row['assign_by'];
                                                
                                                $sql1 = "select * from team where sno='$ass'";
                                                $result1 = $conn->query($sql1);
                                            
                                                while($row1 = $result1->fetch_assoc())
                                                {
                                                    echo $row1['name'];    
                                                }
                                                ?>
                                            </td> -->
                                            <!-- <td><?php echo $row['assign_by']?></td> -->
                                            <td><?php if ($row['lead_status'] == 1 || $row['lead_status'] == 'Prospecting') {
												echo "Prospecting";
												 }else if($row['lead_status'] == 2 || $row['lead_status'] == 'Contacted') {
													echo "Contacted";
												 }else if($row['lead_status'] == 3 || $row['lead_status'] == 'Demo Done') {
													echo "Demo Done";
												 }else if($row['lead_status'] == 4 || $row['lead_status'] == 'Commercials Shared') {
													echo "Commercials Shared";
												 }else if($row['lead_status'] == 5 || $row['lead_status'] == 'Closed Won') {
													echo "Won Lead";
												 }else if($row['lead_status'] == 6) {
													echo "Closed";
												 }else if($row['lead_status'] == 7 || $row['lead_status'] == 'Closed Lost') {
													echo "Lost";
												 }
												 ?>
											</td>
											
											<td>
                                                <!-- <div class="button button-success"><a href="assign_leads?sno=<?php echo $row['sno']?>">Assign</a></div> -->
								                <div class="button soft-primary"><a href="lead_details?sno=<?php echo $row['sno']?>"><i class="icofont-eye"></i></a></div>
                                                <!-- <div class="button soft-danger"><a href="actions/delete_leads.php?sno=<?php echo $row['sno']?>"><i class="icofont-bin"></i></a></div> -->
												<!-- <div class="button soft-primary"><a href="edit_leads?sno=<?php echo $row['sno']?>"><i class="icofont-pen-alt-1"></i></a></div> -->

											</td>
										</tr>
										<?php  }	?>  
									</tbody>
								</table>	
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div><!-- main content -->
	
	<!-- side slide message & popup -->
</div>
	
	<script src="js/main.min.js"></script>
	<script src="js/vivus.min.js"></script>
	<script src="js/script.js"></script>
	
	<script src="plugins/apex/apexcharts.min.js"></script>
	<script src="js/graphs-scripts.js"></script>

	

</body>	

</html>