<?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"];
$id = $_REQUEST["id"];
$id1=base64_decode($_GET['id']);
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
$q=mysqli_query($con,"select * from tbl_manager where manager_id='$dis_id'");
$res=mysqli_fetch_assoc($q);
$imei_no=$res['imei_no'];
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	

	if($_REQUEST['id']=='policy7')
 {
	 $name="Policy Renewal Within & days";
 }	
elseif($_REQUEST['id']=='policy10')
{
	$name="policy Renewal B/W 7-10 Days";
} 
elseif($_REQUEST['id']=='policy15')
{
	$name="policy Renewal B/W 10-15 Days";
} 
elseif($_REQUEST['id']=='graced')
{
	$name="Graced Policy Renewal";
} 
elseif($_REQUEST['id']=='missed')
{
	$name="Missed Policy";
} 

       
?>
<!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 rel="stylesheet" type="text/css" href="assets/extra-libs/multicheck/multicheck.css">
    <link href="assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.css" rel="stylesheet">
    <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">
		<div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title"><?php echo $name; ?></h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<li class="breadcrumb-item active" aria-current="page"><?php echo $name; ?></li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
           
            <div class="container-fluid" style="float:left; width:100%; overflow-Y: auto; height: 550px;">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table id="zero_config" class="table table-striped table-bordered">
                                        <thead>
                                            <tr>
											  <th><b>#</b></th>
											  <th><b>Customer Name</b></th>
											  <th><b>Phone No</b></th>
											  <th><b>Renewal Date</b></th>
											  <th><b>Policy Number</b></th>
											  <th><b>Premium Amount</b></th>
											  <th><b>Action</b></th>
											</tr>
                                        </thead>
                                        <tbody>
										<?php 
										   $c=1;
										   if($_REQUEST['id']=='policy7')
										   {
									if($user_type=='Manager') 		   
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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 ) ");
									else
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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 ) ");
										   }
										   elseif($_REQUEST['id']=='policy10')
										   {
									if($user_type=='Manager') 		 
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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 ) ");
									else
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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_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($_REQUEST['id']=='policy15')
										   {
									if($user_type=='Manager') 		 
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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 ) ");
									else
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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_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($_REQUEST['id']=='graced')
										   {
									if($user_type=='Manager') 		 
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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 ) ");
									else
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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_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($_REQUEST['id']=='missed')
										   {
									if($user_type=='Manager') 		 
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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_customer.status in ('Active','Deactive') and (tbl_policy_master.renewal_date < CURRENT_DATE - INTERVAL 30 DAY ) ");
									else
										$select_policies = mysqli_query($con,"select * , tbl_policy_master.status as sta 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_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 ) ");
										   }
											if(mysqli_num_rows($select_policies)>0)
											{
												while($recset=mysqli_fetch_array($select_policies))
												{
										?>
                                        <tr>
											  <td><?php echo $c++; ?></td>
											  <td><?php echo $recset['customer_name']; ?></td>
											  <td><?php echo $recset['phone_no']; ?></td>
											  <td><?php echo $recset['renewal_date']; ?></td>
											  <td><?php echo $recset['policy_no']; ?></td>
											  <td>
											  <?php echo $recset['premium_amt'];  ?></td>
											  <td width='14%'>
											 <?php 
											  /* $select_policies1 = mysqli_query($con,"Select * from tbl_customer_premium where manager_id='".$recset['manager_id']."' and customer_id='".$recset['customer_id']."' and policy_no='".$recset['policy_no']."' and status='Pending' order by transaction_id desc limit 1");
											   if(mysqli_num_rows($select_policies1)>0)
											   {
											  $recset1=mysqli_fetch_array($select_policies1);*/
											 // $msg='Already assigned to agent';
											if($recset['status']=='Active')
											{
											  ?>
											   <?php if($imei_no=='0' || $imei_no=='') { ?>
											  <a href="assign-agent-work.php?id=<?php echo base64_encode($recset['customer_id'])?>&id2=<?php echo base64_encode($recset['policy_no'])?>&id3=<?php echo base64_encode($recset['premium_amt'])?>&id4=<?php echo base64_encode($id)?>&id5=<?php echo base64_encode($recset['manager_id'])?>&id6=<?php echo $id;?>" style="font-size:12px;padding:1px 5px;" onClick="return confirm('Are you sure to assign to agent')" class="btn btn-success">Assign</a>
												<?php } else { ?> 
												<a href="#" style="font-size:12px;padding:1px 5px;"  onClick="alert('You Are Already Login in App...First Logout Fom App then Assign Agent From Here')" disabled class="btn btn-danger">Assign</a>
													<?php } ?>												
											  <?php } 
											  elseif($recset['status']=='Renewal Pending')
											  {
												?>
												<a href="#" style="font-size:12px;padding:1px 5px;"  onClick="return confirm('Already assigned to agent')" disabled class="btn btn-danger">Assigned</a>
												<?php } ?>
											  </td>
											 
											</tr>
											<?php }} else { ?>
											 <tr>
											  <td colspan='6'>No Data Available</td>
											</tr>
											<?php } ?>
                                        </tbody>
                                       
                                    </table>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
             
            </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>
    <!-- slimscrollbar scrollbar JavaScript -->
    <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 js -->
    <script src="assets/extra-libs/multicheck/datatable-checkbox-init.js"></script>
    <script src="assets/extra-libs/multicheck/jquery.multicheck.js"></script>
    <script src="assets/extra-libs/DataTables/datatables.min.js"></script>
    <script>
        /****************************************
         *       Basic Table                   *
         ****************************************/
        $('#zero_config').DataTable();
    </script>

</body>

</html>