<?php  

  session_start();
  set_time_limit(0);
  ini_set('max_execution_time', 0);
  // error_reporting(0);
   include("../db.php");
   include("../all_query.php");
		
 
	 
	  
	  
	$customerQ = mysqli_query($conn,"select *from `customer`  where  total_outstanding = 0   limit 1000 ");
	
	    
     while($customerData = mysqli_fetch_assoc($customerQ))
	 {
		  $account_holder_id = $customerData['account_holder_id'];
		  
		  
		  $lQ = mysqli_query($conn,"SELECT SUM(CAST(tos as UNSIGNED)) as `total_outstanding`  from leads WHERE account_holder_id = $account_holder_id ");
		  
		  
		  $lData = mysqli_fetch_assoc($lQ);
		  
		  $total_outstanding = $lData['total_outstanding'];
		  
		  
		  $outstanding_slab = '';
		  
		  if($total_outstanding >= 100000)
		  {
			  
			  $outstanding_slab = 'HIGHEST';
			  
		  }
		  
		  else if($total_outstanding < 100000  &&  $total_outstanding  >=50000 )
		  {
			  $outstanding_slab = 'HIGH';
		  }
		  
		   else if($total_outstanding < 50000  &&  $total_outstanding  >=20000 )
		  {
			  $outstanding_slab = 'MEDIUM';
		  }
		  else
		  {
			   $outstanding_slab = 'LOW';
		  }
		  
		  
		   
		   
		   
		   mysqli_query($conn,"update `customer` set total_outstanding = $total_outstanding , outstanding_slab = '$outstanding_slab' where account_holder_id = $account_holder_id ");
		   
		   
		  
		  echo "<br/>******* $account_holder_id  :  Total: $total_outstanding **************************<br/>";
		  
		  
		   
		  
		  
		  
	  }
	  
	  
	  
	  
	  
	  
	    
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	   
 

 
  ?>