<?php  

  session_start();
    //error_reporting(0);
		include("../db.php");
		include("../all_query.php");
		
		$pg=$page=$_GET['page'];
        $keyword=$_GET['keyword'];
        $key_for=$_GET['key_for'];
        $outstanding_slab=$_GET['outstanding_slab'].'|';
		
		$cur_page=$pg + 1;

		$page=$page*10;
 
  
		
 if(isset($_SESSION['loan_crm_username']) && isset($_SESSION['loan_crm_password']))
{
	
		
		 $_SESSION['timestamp'] = time(); 
	 
		
		 $today_date = date('Y-m-d');
		 
		
		
 
								 $where_str="";
		
		?>
			
                               <div class="card-datatable table-responsive text-nowrap" style="zoom:80%;">
   
									<?php if($key_for!='')
									{ ?>
									<a href="../excel_export_query.php?type=customer&name=<?php echo str_replace(' ','_',$key_for); ?>" target="_BLANK" style="margin:10px;color:green;cursor:pointer;" ><i class="fa fa-download"></i>Export</a>
									<?php } ?>
									<table id="add-row" class=" table border-top" cellspacing="0" width="100%" role="grid" aria-describedby="example23_info" style="width: 100%;">
                                        <thead  >
                                            
									     <th style="width:100px;cursor:pointer;"><a onclick="selectAll();">Select</a></th>
											
											
                                           <th>Account Holder ID</th>
                                           <th>Name</th>
                                           <th>Mobile</th>
                                           <?php if($_SESSION['login_as'] == 'admin') { ?><th>Advisor</th><?php } ?>
                                           <?php if($_SESSION['login_as'] == 'admin') { ?><th>Type</th><?php } ?>
                                           <th style="text-align:left !important;">Last Update</th>
										   </tr>
                                          </thead>
                                         <tbody>
											
											<?php
											
											
											if($key_for!='')
											{
												
												
												
												
												$advisor = $_REQUEST['advisor'];
												$customer_type = $_REQUEST['customer_type'];
												
												
												if($advisor!='Total')
												{
												
												
												
												
												
												if($key_for == 'Unique Cust')
												{
												
												$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
												
												
												}
												
												if($key_for == 'Allocation Count')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
												}
												
												
												
												if($key_for == 'Attempted')
												{
												//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and total_updates > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
													
													
												}
												
												
												if($key_for == 'Unattempted')
												{
												//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id not in (select account_holder_id from updates  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
												
												$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and total_updates = 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
												
												
													
												}
												
												if($key_for == 'Contact')
												{
														//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
															
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and total_contact = 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
														
															
															
												}
												
												if($key_for == 'Contact P')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P'   )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
															
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and total_contact_p > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
													
													
												}
												
												if($key_for == 'Contact N')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and total_contact_n > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
													
												}
												
												if($key_for == 'No Contact')
												{
												//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'No Contact'  )   and account_holder_id not in (select account_holder_id from updates   where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
												
												
												
												$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  total_contact = 0 and total_non_contact > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
												
												
												
												
												
												
												
												
												}
												
												if($key_for == 'Retained')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) 
													 and ( advisor = '$advisor' and  customer_type = '$customer_type' and retained = 'yes' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
												}
												
												
												if($key_for == 'PTP')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
												}
												
												if($key_for == 'Today PTP')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) and next_update_date = '$today_date'  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
												}
												
												
												if($key_for == 'Followup')
												{
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )  and    account_holder_id in (select account_holder_id from updates  where disposition='CB'    )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
												}
												
												
													if($key_for == 'Today Followup')
												{
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )  and    account_holder_id in (select account_holder_id from updates  where disposition='CB'  and next_update_date = '$today_date'    )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
												}
												
												
												
												
												}
												
												else
												{
													
													
													
													
													
													
													
												
												if($key_for == 'Unique Cust')
												{
												
												$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
												
												
												}
												
												
												if($key_for == 'Retained')
												{
												
												$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' and retained = 'yes' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
												
												
												}
												
												
												if($key_for == 'Allocation Count')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
												}
												
												
												
												if($key_for == 'Attempted')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates  )     and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and   total_updates > 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													
													
												}
												
												
												if($key_for == 'Unattempted')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id not in (select account_holder_id from updates  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and   total_updates = 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													
												}
												
												if($key_for == 'Contact')
												{
														//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
														
														$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and   total_contact > 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
														
														
												}
												
												if($key_for == 'Contact P')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P'   )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and   total_contact_p > 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													
												}
												
												if($key_for == 'Contact N')
												{
												//	$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
												
												
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and   total_contact_n > 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													
													
												}
												
												if($key_for == 'No Contact')
												{
													//$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'No Contact'  )   and account_holder_id not in (select account_holder_id from updates   where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
													
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_contact = 0 and total_non_contact > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
												
												
												
													
													
												}
												
												 
												
												if($key_for == 'PTP')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc limit $page,10");
													
												}
												
												if($key_for == 'Today PTP')
												{
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) and next_update_date = '$today_date'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc limit $page,10");
													
												}
												
												
												if($key_for == 'Followup')
												{
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )  and    account_holder_id in (select account_holder_id from updates  where disposition='CB'    )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
													
												}
												
												
													if($key_for == 'Today Followup')
												{
													
													$eQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )  and    account_holder_id in (select account_holder_id from updates  where disposition='CB'  and next_update_date = '$today_date'    )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
													
												}
													
													
													
													
												}
												
												
												
												
												
											}
											
											
											
											else
											{
											
											if($_SESSION['login_as'] == 'admin')
											{
											  
												 	 $eQ=mysqli_query($conn,"select *from customer  where  (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%'  )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%') 

													 order by id desc limit $page,10");
													 
													 
												   
											}
											else
											 {
												 
												 $advisor = $_SESSION['login_name'];
												
												 $eQ=mysqli_query($conn,"select *from customer  where ( account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor'   )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc limit $page,10");
											 }
												 
										  
											}
										
											 
											$i=$page;

											while($row=mysqli_fetch_assoc($eQ))
											 {  
										 
										    $account_holder_id = $row['account_holder_id'];
										    
											
											
											
											if($key_for == 'PTP' || $key_for == 'Today PTP')
											{
												
										 
										// 	$updatesQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id'   and (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) order by id desc limit 1 ");
											
											}
											else
											{
											//	$updatesQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id'  and next_update_date <> '' order by id desc limit 1 ");
											}
											
											//$updatesData = mysqli_fetch_assoc($updatesQ);
											
											$updatesData = array();
											
											if($row['last_update']!='')
											{
												 //echo $row['last_update'];
												$updatesData = json_decode($row['last_update'],TRUE);
												
												 
											}
											
											 
										 
											 
											 $i++; ?>
   											
											<tr class="text-nowrap">
													
								      <td> <input type="checkbox" name="delete_checkbox" value="<?php echo $row['id']; ?>" /> </td>
										
							
							           <td><a href="#" onclick="getAccountHolderView('<?php echo $row['account_holder_id']; ?>')" data-bs-toggle="modal" data-bs-target="#accountHolderView" style="text-decoration:underline" ><?php echo $row['account_holder_id']; ?></a></td>
							           <td><?php echo $row['name']; ?></td>
 							           <td><?php echo $row['mobile']; ?></td>
							           
							         <?php if($_SESSION['login_as'] == 'admin') { ?>  <td><?php echo $row['advisor']; ?></td> <?php } ?>
							          <?php if($_SESSION['login_as'] == 'admin') { ?> <td><?php echo $row['customer_type']; ?></td> <?php } ?>
							           <td><?php 
									   
									    if(isset($updatesData['remark'])) { echo "Date:".date('d-M-Y h:i A ',strtotime($updatesData['next_update_date'].' '.$updatesData['next_update_time'])); echo $updatesData['remark']; }
									   
									   	  if($key_for == 'PTP' || $key_for == 'Today PTP')
											{
												echo " <b>Amount:</b> ".$updatesData['amount'];
											}
											

									   ?></td>
							              </tr>
																		<?php }  ?>

												</tbody>
									
									
									</table>
									
									</div>
									
										<?php if($_SESSION['login_as'] == 'admin') {  ?>
									<?php if($key_for == 'Retained')
												{ } else { ?>
									<a style="color:red; cursor:pointer"  onclick="deleteSelected('customer');" style="    margin: 10px;"  >Delete</a>
												<?php } ?>
									
									<?php } ?>
									
									
									
									
									
									 <button style="    position: absolute;left: 20%;" onclick="sendMessageView('Bulk Message','0');" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send Message</button>
									
									
									
									
									
									
								
                                
                            </div>
				  
				  
                </div>
               
			   
			   
			   
			   
			   							
									
									
					
	<?php    
	
	
										 
												 
												 
											
											
											if($key_for!='')
											{
												
												
												
												$advisor = $_REQUEST['advisor'];
												
												if($advisor!='Total')
													
													{
												
												if($key_for == 'Unique Cust')
												{
												
												$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc  ");
												
												
												}
												
												if($key_for == 'Retained')
												{
												
												$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' and retained = 'yes' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc  ");
												
												
												}
												
												
												
												if($key_for == 'Allocation Count')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
													
												}
												
												
												
												if($key_for == 'Attempted')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and   total_updates > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													
													
													
												}
												
												if($key_for == 'Unattempted')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id not in (select account_holder_id from updates  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc   ");
													
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and   total_updates = 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													
												}
												
												if($key_for == 'Contact')
												{
														//	$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
														
														
														$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and   total_contact > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
														
														
														
												}
												
												if($key_for == 'Contact P')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P'   )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and   total_contact_p > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
												}
												
												if($key_for == 'Contact N')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
														$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and   total_contact_n > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
														
														
													
												}
												
												if($key_for == 'No Contact')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'No Contact'  )  and account_holder_id not in (select account_holder_id from updates   where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc   ");
													
												 $eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' )  and total_contact = 0 and total_non_contact > 0   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc   ");
												}
												if($key_for == 'PTP')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
													
												}
												
												if($key_for == 'Today PTP')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' )   and next_update_date = '$today_date'    )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
													
												}
												
												
												if($key_for == 'Followup')
												{
													
													$eNoQ=mysqli_query($conn,"select *from customer  where ( (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates      where disposition='CB'   )     )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc    ");
													
												}
												
												
												if($key_for == 'Today Followup')
												{
													
													$eNoQ=mysqli_query($conn,"select *from customer  where ( (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor' and  customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates      where  disposition='CB'   and next_update_date = '$today_date'   )     )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc    ");
													
													
												 
												}
												
												
													}
													
													else
													{
														 
														
												 if($key_for == 'Unique Cust')
												{
												
												$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
												
												
												}
												
												 if($key_for == 'Retained')
												{
												
												$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type'  and retained = 'yes' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
												
												
												}
												
												
												
												if($key_for == 'Allocation Count')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')  order by id desc  ");
													
												}
												
												
												
												if($key_for == 'Attempted')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates  )    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_updates > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													
													
												}
												
												if($key_for == 'Unattempted')
												{
												//	$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id not in (select account_holder_id from updates  )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')     order by id desc   ");
												
												$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_updates = 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													
													
												}
												
												if($key_for == 'Contact')
												{
														//	$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
														
														
														$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_contact > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
													
												}
												
												if($key_for == 'Contact P')
												{
												//	$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where attempt_status = 'Contact P'   )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
												
												
												
														$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_contact_p > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
														
														
													
												}
												
												if($key_for == 'Contact N')
												{
													// $eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
													
															$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_contact_n > 0  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
															
															
															
													
												}
												
												if($key_for == 'No Contact')
												{
													//$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   attempt_status = 'No Contact'  )  and account_holder_id not in (select account_holder_id from updates   where attempt_status = 'Contact P' or attempt_status = 'Contact N'  )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc   ");
													
													
														
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  total_contact = 0 and total_non_contact > 0    and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc  ");
												
												
												
													
													
													
													
													
													
												}
												if($key_for == 'PTP')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
												}
												
												if($key_for == 'Today PTP')
												{
													$eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' )   and next_update_date = '$today_date'    )   and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc  ");
													
												}
												
												
												if($key_for == 'Followup')
												{
													
													$eNoQ=mysqli_query($conn,"select *from customer  where ( (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates      where disposition='CB'   )     )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc    ");
													
												}
												
												
												if($key_for == 'Today Followup')
												{
													
													$eNoQ=mysqli_query($conn,"select *from customer  where ( (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and (   customer_type = '$customer_type' ) and  account_holder_id in (select account_holder_id from updates      where  disposition='CB'   and next_update_date = '$today_date'   )     )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')    order by id desc    ");
													
													
												 
												}
												
														
														
														
														
														
														
														
														
														
														
														
													}
												
												
												
											}
											
											
											
											else
											{
											
											if($_SESSION['login_as'] == 'admin')
											{
											  
												 	 $eNoQ=mysqli_query($conn,"select *from customer  where (account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc ");
													 
													 
												   
											}
											else
											 {
												 
												 $advisor = $_SESSION['login_name'];
												
												 $eNoQ=mysqli_query($conn,"select *from customer  where ( account_holder_id like '%$keyword%' or name like '%$keyword%' or father_name like '%$keyword%' or father_name like '%$keyword%' or mobile like '%$keyword%' or phone_cibil like '%$keyword%' or phone_db like '%$keyword%' or extra_phone_json like '%$keyword%' or email like '%$keyword%' ) and ( advisor = '$advisor'   )  and  (CONCAT(outstanding_slab,'|') like '%$outstanding_slab%')   order by id desc ");
											 }
												 
										  
											} 										 
												 
											 
											 
			 
		 $total_party = mysqli_num_rows($eNoQ);
		 
		 
		 $all_row_ids = array();
		 while($all_data = mysqli_fetch_assoc($eNoQ))
		 {
			 $all_row_ids[] = $all_data['account_holder_id'];
		 }
		 
		 $_SESSION['all_row_ids'] = $all_row_ids;
		 
		 
		 
		?>
		
		
		
<?php  if($key_for == '') {  ?>
		
		
		
		
		
		
		
		
		
	Total Records: <?php  echo $total_party; ?>
		<nav style="float: right" aria-label="...">
  <ul class="pagination pagination-sm">
  
  <li class="page-link"> <span <?php if($cur_page>1) { ?> onclick="fetchAllParty('<?php echo $pg - 1; ?>','<?php echo $keyword; ?>','')"   <?php } ?> class="paginate_button">Prev</span><li>
  <?php		

        
			
        for($i=$pg;$i<$total_party/10;$i++)
		{
 
	// $limit = $cur_page + 3;
	if($i <  ($pg + 10) )
	{	
	?>
	
	
   <li class="page-item"><a onclick="fetchAllParty('<?php echo $i; ?>','<?php echo $keyword; ?>','')" class="page-link" href="#"  <?php if($i == $pg) { ?> style="background:#2962ff  !important; border-color:#2962ff  !important; color: #fff; text-decoration: none; border: none !important; padding: .56rem .95rem;" <?php } ?> style="padding: .5rem .75rem; "><?php echo $i+1; ?></a></li>
   
   <?php }   } ?>
		 <li class="page-link"> <span  <?php if($total_party/5  > $cur_page ) { ?> onclick="fetchAllParty('<?php echo $pg + 1; ?>','<?php echo $keyword; ?>','')"  <?php }  ?>  class="paginate_button">Next</span><li>
		 </ul>
</nav>
        
	
	</div>
	
	<?php } 	else {  ?>
	
	
 





	
		
		
	Total Records: <?php  echo $total_party; ?>
		<nav style="float: right" aria-label="...">
  <ul class="pagination pagination-sm">
  
  <li class="page-link"> <span <?php if($cur_page>1) { ?> onclick="fetchAllParty('<?php echo $pg - 1; ?>','<?php echo $keyword; ?>','<?php echo $key_for; ?>','<?php echo $advisor; ?>','<?php echo $customer_type; ?>')"   <?php } ?> class="paginate_button">Prev</span><li>
  <?php		

        
			
        for($i=$pg;$i<$total_party/10;$i++)
		{
 
	// $limit = $cur_page + 3;
	if($i <  ($pg + 10) )
	{	
	?>
	
	
   <li class="page-item"><a onclick="fetchAllParty('<?php echo $i; ?>','<?php echo $keyword; ?>','<?php echo $key_for; ?>','<?php echo $advisor; ?>','<?php echo $customer_type; ?>')" class="page-link" href="#"  <?php if($i == $pg) { ?> style="background:#2962ff  !important; border-color:#2962ff  !important; color: #fff; text-decoration: none; border: none !important; padding: .56rem .95rem;" <?php } ?> style="padding: .5rem .75rem; "><?php echo $i+1; ?></a></li>
   
   <?php }   } ?>
		 <li class="page-link"> <span  <?php if($total_party/5  > $cur_page ) { ?> onclick="fetchAllParty('<?php echo $pg + 1; ?>','<?php echo $keyword; ?>','<?php echo $key_for; ?>','<?php echo $advisor; ?>','<?php echo $customer_type; ?>')"  <?php }  ?>  class="paginate_button">Next</span><li>
		 </ul>
</nav>
        
	
	</div>
	
	
	
<?php } ?>
	
	
<?php } ?>