<?php  

  session_start();
  set_time_limit(0);
  ini_set('max_execution_time', 0);
  // error_reporting(0);
  
 
 
$host="localhost";
	  $username="finmarnf";
	  $password="Finman!@123";
	  $database="finmarnf_bhawani_crm";
 	   
	 
	  
	    $conn=mysqli_connect($host,$username,$password,$database);
 	    
	     date_default_timezone_set("Asia/Kolkata"); 
	 
	 
	 
		
		
		  $tempFilterQ = mysqli_query($conn,"select *from `temp_filter_customer` where  ( advisor is NULL or advisor = '')  and customer_type = 'mumbai'    and account_holder_id not in (select account_holder_id from payments )       order by  imp_score desc  ");
		  
		  
		  if(mysqli_num_rows($tempFilterQ) == 0)
		  {
			  
			  
			  // set non contact 0 and call once again
			  
			   $noCQ = mysqli_query($conn," select * from `customer` where   (  customer_type = 'mumbai'  and   total_contact = 0 and total_non_contact > 0   )   ");
			   
			   
			   while($nonContactData = mysqli_fetch_assoc($noCQ))
               {
				   echo "<br>".  $account_holder_id = $nonContactData['account_holder_id'];
				   
				   
				   mysqli_query($conn,"update customer set advisor = ''   where account_holder_id = '$account_holder_id' ");
				   
				   
				   mysqli_query($conn,"update temp_filter_customer set advisor = '' , attempt='0', call_count = 0  where account_holder_id = '$account_holder_id' ");
				   
				   
			   }
			   
			 
		  }
		  
		  
		  
		  // Tracce
		  
		  
		  	
		  $trtempFilterQ = mysqli_query($conn,"select *from `temp_filter_customer` where  ( advisor is NULL or advisor = '')  and customer_type = 'malegaon'   and account_holder_id not in (select account_holder_id from payments )     order by  imp_score desc  ");
		  
		  
		  if(mysqli_num_rows($trtempFilterQ) == 0)
		  {
			  
			  
			  // set non contact 0 and call once again
			  
			   $noCQ = mysqli_query($conn," select * from `customer` where   (  customer_type = 'malegaon'  and    total_contact = 0 and total_non_contact > 0   )    ");
			   
			   
			   while($nonContactData = mysqli_fetch_assoc($noCQ))
               {
				   echo "<br>".  $account_holder_id = $nonContactData['account_holder_id'];
				   
				   
				   mysqli_query($conn,"update customer set advisor = ''   where account_holder_id = '$account_holder_id' ");
				   
				   
				   mysqli_query($conn,"update temp_filter_customer set advisor = '' , attempt='0', call_count = 0  where account_holder_id = '$account_holder_id' ");
				   
				   
			   }
			   
			 
		  }
		  
 

?>