<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$user_type = $_SESSION["user_type"];
$user_session = $_SESSION["user_session"];
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>BTCOVER : Admin Dashboard</title>
    <!-- Custom CSS -->
    <link href="assets/libs/flot/css/float-chart.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="dist/css/style.min.css" rel="stylesheet">
</head>

<body>
 
  
    
    <div id="main-wrapper">
     
       <?php include("header.php"); ?>
    
        <?php include("menu.php"); ?>
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
             <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Dashboard</h4>
                        
                    </div>
                </div>
            </div>
            <div class="container-fluid">
              <?php 
		if($user_type=='Manager')
		{			
			$selrenew=mysqli_query($con,"select * from tbl_customer where manager_id='$dis_id' and status!='Deleted'");
		}
		elseif($user_type=='Admin')
		{
			$selrenew=mysqli_query($con,"select * from tbl_customer where status!='Deleted' and manager_id in (select manager_id from tbl_manager where admin_id='$ver')");
		}
		 $count_row=mysqli_num_rows($selrenew);
		if($user_type=='Admin') 
		{
		$selrenew1=mysqli_query($con,"select * from tbl_insurance_company where admin_id='$ver'  and status!='Deleted'");
		$count_row1=mysqli_num_rows($selrenew1);
		}
		if($user_type=='Manager') 
		{
			$selrenew2=mysqli_query($con,"select * from tbl_agent where manager_id='$dis_id'  and status!='Deleted'");
		}
		elseif($user_type=='Admin')
		{
			$selrenew2=mysqli_query($con,"select * from tbl_agent where status!='Deleted' and manager_id in (select manager_id from tbl_manager where admin_id='$ver')");
		}
		$count_row2=mysqli_num_rows($selrenew2);
		if($user_type=='Admin') 
		{
		$selrenew3=mysqli_query($con,"select * from tbl_manager where admin_id='$ver'  and status!='Deleted' and manage_type='Manager'");
		$count_row3=mysqli_num_rows($selrenew3);
		}
		if($user_type=='Admin') 
		{
		$selrenew4=mysqli_query($con,"select * from tbl_admin_panel where admin_id='$ver'");
		while($recset=mysqli_fetch_array($selrenew4))
		{
			$renewdate=explode(" ",$recset['next_renew_date']);
		}
		$r_date=strtotime($renewdate[0]);
		$r2_date= strtotime("-7 day", $r_date);
		$d2_date=trim(date('Y-m-d', $r2_date));
		}
		
		if($user_type=='Manager') 
		{
	 			$select_policies1 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id='$dis_id' and  tbl_customer.status in ('Active','Deactive') and tbl_policy_master.status in ('Active','Renewal Pending') and (tbl_policy_master.renewal_date >= CURRENT_DATE && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 7 DAY ) ");
		}
			elseif($user_type=='Admin')
				{
	 			$select_policies1 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id in (select manager_id from tbl_manager where admin_id='$ver') and tbl_policy_master.status in ('Active','Renewal Pending') and  tbl_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date >= CURRENT_DATE && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 7 DAY ) ");
				}
			$policy7=mysqli_num_rows($select_policies1);
			if($user_type=='Manager')
				{				
	 			$select_policies2 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id='$dis_id' and  tbl_customer.status in ('Active','Deactive') and tbl_policy_master.status in ('Active','Renewal Pending') and (tbl_policy_master.renewal_date >= CURRENT_DATE + INTERVAL 7 DAY && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 10 DAY ) ");
				}
			elseif($user_type=='Admin')
				{
	 			$select_policies2 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id in (select manager_id from tbl_manager where admin_id='$ver') and tbl_policy_master.status in ('Active','Renewal Pending') and  tbl_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date >= CURRENT_DATE + INTERVAL 7 DAY && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 10 DAY )");
				}
			$policy10=mysqli_num_rows($select_policies2);
			if($user_type=='Manager') 
				{
	 			$select_policies3 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id='$dis_id' and  tbl_customer.status in ('Active','Deactive') and tbl_policy_master.status in ('Active','Renewal Pending') and (tbl_policy_master.renewal_date >= CURRENT_DATE + INTERVAL 10 DAY && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 15 DAY )");
				}
			elseif($user_type=='Admin')
				{
	 			$select_policies3 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id in (select manager_id from tbl_manager where admin_id='$ver') and tbl_policy_master.status in ('Active','Renewal Pending') and  tbl_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date >= CURRENT_DATE + INTERVAL 10 DAY && tbl_policy_master.renewal_date < CURRENT_DATE + INTERVAL 15 DAY )");
				}
			$policy15=mysqli_num_rows($select_policies3);
			if($user_type=='Manager') 
	 		{	
			$select_policies4 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id='$dis_id' and  tbl_customer.status in ('Active','Deactive') and tbl_policy_master.status in ('Active','Renewal Pending') and (tbl_policy_master.renewal_date > CURRENT_DATE - INTERVAL 30 DAY && tbl_policy_master.renewal_date <= CURRENT_DATE )");
	 		}
			elseif($user_type=='Admin')
	 		{
			$select_policies4 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id in (select manager_id from tbl_manager where admin_id='$ver') and tbl_policy_master.status in ('Active','Renewal Pending') and  tbl_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date > CURRENT_DATE - INTERVAL 30 DAY && tbl_policy_master.renewal_date <= CURRENT_DATE )");
			}
			$policy30=mysqli_num_rows($select_policies4);
			
			if($user_type=='Manager') 
	 		{
			$select_policies5 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id='$dis_id' and  tbl_customer.status in ('Active','Deactive') and tbl_policy_master.status in ('Active','Renewal Pending') and (tbl_policy_master.renewal_date < CURRENT_DATE - INTERVAL 30 DAY )");
			}
	 		elseif($user_type=='Admin')
				{
	 			$select_policies5 = mysqli_query($con,"select *from tbl_customer,tbl_insurance_company,tbl_policy_master where tbl_customer.customer_id=tbl_policy_master.customer_id and tbl_insurance_company.company_id=tbl_policy_master.company_id and tbl_customer.manager_id in (select manager_id from tbl_manager where admin_id='$ver') and tbl_policy_master.status in ('Active','Renewal Pending') and  tbl_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date < CURRENT_DATE - INTERVAL 30 DAY )");
				}
				$policyb30=mysqli_num_rows($select_policies5);
				
		
		?>
                <div class="row">
                    <!-- Column -->
					<div class="col-md-6 col-lg-3 col-xlg-3">
                        <a href="customer.php"><div class="card card-hover">
                            <div class="box bg-cyan text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-account-circle"></i></h1>
                                <h6 class="text-white">Customer&nbsp;&nbsp;
								
								<span style="color:#af170c;"><b>(<?php echo $count_row; ?>)</b>
							
								</span></h6>
                            </div>
                        </div></a>
                    </div>
                   
                    <!-- Column -->
				<?php 	if($user_type=='Admin') 
					{
						?>
                    <div class="col-md-6 col-lg-3 col-xlg-3">
                        <a href="#"><div class="card card-hover">
                            <div class="box bg-success text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-chart-areaspline"></i></h1>
                                <h6 class="text-white">Renew Date&nbsp;&nbsp;
								<?php if($cdate<$d2_date) { ?>
								<span style="color:#141619;">(<?php echo date("d-M-Y", strtotime($renewdate[0])); ?>)
								<?php } else { ?>
								<span style="color:#af170c;"><b>(<?php echo date("d-M-Y", strtotime($renewdate[0])); ?>)</b>
								<?php } ?>
								</span></h6>
                            </div>
                        </div></a>
                    </div>
				
                     <!-- Column -->
                    <div class="col-md-6 col-lg-3 col-xlg-3">
                        <a href="insurance_company.php"><div class="card card-hover">
                            <div class="box bg-warning text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-collage"></i></h1>
                                <h6 class="text-white">Insurance Company&nbsp;&nbsp;<span style="color:#141619;">(<?php echo $count_row1; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
					 <div class="col-md-6 col-lg-3 col-xlg-3">
                       <a href="manager.php"> <div class="card card-hover">
                            <div class="box bg-info text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-account-circle"></i></h1>
                                <h6 class="text-white">Manager&nbsp;&nbsp;<span style="color:#141619;">(<?php echo $count_row3; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
						<?php } ?>
                    <!-- Column -->
					
                    <div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="agent.php"> <div class="card card-hover">
                            <div class="box bg-danger text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-account-circle"></i></h1>
								<br>
                                <h6 class="text-white">Agent&nbsp;&nbsp;<span style="color:#141619;">(<?php echo $count_row2; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
					
						
						<!-- <div class="col-md-6 col-lg-2 col-xlg-3">
                        <a href="customer-policy7.php?id=policy7"><div class="card card-hover">
                            <div class="box bg-warning text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-border-outside"></i></h1>
                                <h6 class="text-white">Policy Renewal Within 7 days &nbsp;&nbsp;<br><span style="color:#141619;">(<?php// echo $policy7; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>-->
					<div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="customer-policy7.php?id=policy7"> <div class="card card-hover">
                            <div class="box bg-warning text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-arrow-all"></i></h1>
                                <h6 class="text-white">Policy Renewal Within 7 days &nbsp;&nbsp;<span style="color:#141619;">(<?php echo $policy7; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
						 <div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="customer-policy7.php?id=policy10"> <div class="card card-hover">
                            <div class="box bg-info text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-arrow-all"></i></h1>
                                <h6 class="text-white">Policy Renewal B/W 7-10 days &nbsp;&nbsp;<span style="color:#141619;">(<?php echo $policy10; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
						<div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="customer-policy7.php?id=policy15"> <div class="card card-hover">
                            <div class="box bg-danger text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-border-outside"></i></h1>
                                <h6 class="text-white">Policy Renewal B/W 10-15 days &nbsp;&nbsp;<span style="color:#141619;">(<?php echo $policy15; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
					<div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="customer-policy7.php?id=graced"> <div class="card card-hover">
                            <div class="box bg-success text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-border-outside"></i></h1>
                                <h6 class="text-white"> Graced Policy Renewal  &nbsp;&nbsp;<span style="color:#141619;">(<?php echo $policy30; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div><div class="col-md-6 col-lg-2 col-xlg-3">
                       <a href="customer-policy7.php?id=missed"> <div class="card card-hover">
                            <div class="box  bg-cyan text-center">
                                <h1 class="font-light text-white"><i class="mdi mdi-border-outside"></i></h1>
                                <h6 class="text-white">Missed Policy Renewal  &nbsp;&nbsp;<span style="color:#141619;">(<?php echo $policyb30; ?>)</span></h6>
                            </div>
                        </div></a>
                    </div>
					
					
                    <!-- Column -->
                   
                    <!-- Column -->
                    <!-- Column -->
                   
                </div>
                <!-- ============================================================== -->
                <!-- Sales chart -->
                <!-- ============================================================== -->
               
              
            </div>
          
            <footer class="footer text-center">
               2019 &copy; All Rights Reserved by BTCOVER. Designed and Developed by <a href="http://www.belltechnology.in/">Bell Technology</a>.
            </footer>
          
        </div>
      
    </div>
  
    <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!--This page JavaScript -->
    <!-- <script src="dist/js/pages/dashboards/dashboard1.js"></script> -->
    <!-- Charts js Files -->
    <script src="assets/libs/flot/excanvas.js"></script>
    <script src="assets/libs/flot/jquery.flot.js"></script>
    <script src="assets/libs/flot/jquery.flot.pie.js"></script>
    <script src="assets/libs/flot/jquery.flot.time.js"></script>
    <script src="assets/libs/flot/jquery.flot.stack.js"></script>
    <script src="assets/libs/flot/jquery.flot.crosshair.js"></script>
    <script src="assets/libs/flot.tooltip/js/jquery.flot.tooltip.min.js"></script>
    <script src="dist/js/pages/chart/chart-page-init.js"></script>

</body>

</html>