<?php  

  session_start();
   error_reporting(0);
   include("../db.php");
  include("../all_query.php");
		

   if(isset($_SESSION['loan_crm_username']) && isset($_SESSION['loan_crm_password']))
  {
	  
	  
	  $advisor = $_SESSION['login_name'];
	  
	  $today_date = date('Y-m-d');
	  
	  
	  // get first if advisor is busy or free
	  
	   $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
	   $advisorData = mysqli_fetch_assoc($advisorQ);
	   
	   $advisor_id = $advisorData['id'];
	   
	   $customerTypeQ = mysqli_query($conn,"select *from `customer_type` where id in (select customer_type_id from advisors where name = '$advisor' )   ");
	   $typeData = mysqli_fetch_assoc($customerTypeQ);
	   $customer_type = $typeData['name'];
	   
	   
	   $login_statusQ = mysqli_query($conn,"select *from `advisor_login_status` where advisor_id = $advisor_id order by id desc limit 1 ");
	   $loginStatusData = mysqli_fetch_assoc($login_statusQ);
	   
	   $auto_dial_type  = $loginStatusData['auto_dial_type'];
	   

       if($loginStatusData['login_status'] == 'logged_in' && $loginStatusData['login_status_type'] == 'auto')
	   {
	   
	  
	   if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
	   {
		   
		   if($auto_dial_type == '')  {  $auto_dial_type = 'non_contact';  }
		   
		   
		   
		  
		   
		   /******************************  Smart Logic **********************************/
		   
		   
		   
		   if($auto_dial_type == 'smart_logic')
		   {
			   
			   
			   // first system will check if any current  next update ptp user  for current user_error
			   
			  
			   
			   //$remQ = mysqli_query($conn,"select * from updates where  update_by = '$advisor' and next_update_date = '$today_date' and time(next_update_time) <= now()  and (status = '' or status is NULL)      ");
			   
			   $current_date_time = date('Y-m-d H:i');
			   $try_next_date_time = date('Y-m-d H:i',strtotime(' +3 hours'));
				 
			   $repeat_followup = false;
			   
			  // $remQ = mysqli_query($conn,"select * from updates where  update_by = '$advisor' and next_update_date = '$today_date' and  str_to_date(CONCAT(next_update_date,' ',next_update_time),'%Y-%m-%d %H:%i') <= str_to_date('$current_date_time','%Y-%m-%d %H:%i')  and (status = '' or status is NULL)    and account_holder_id in (SELECT account_holder_id from customer)  and account_holder_id not in (select account_holder_id from payments )      ");
			   
		//	  $remQ = mysqli_query($conn,"select * from updates where  update_by = '$advisor' and next_update_date = '$today_date' and  str_to_date(CONCAT(next_update_date,' ',next_update_time),'%Y-%m-%d %H:%i') <= str_to_date('$current_date_time','%Y-%m-%d %H:%i')  and (status = '' or status is NULL)   ");
			   
			   
			   
			   
			   
			   //  get such customer if system take followup but non contacted at that time , then repeat after 3 hour
			   if(false)
			 //     if(mysqli_num_rows($remQ) == 0)
			   {
				   
				 $repeat_followup  = true;
				   
				   
			 // $remQ = mysqli_query($conn,"select *  from updates curr where  update_by = '$advisor'  and ( try_next_date_time <> '' and try_next_date_time is not NULL ) and  str_to_date(try_next_date_time,'%Y-%m-%d %H:%i') <= str_to_date('$current_date_time','%Y-%m-%d %H:%i')   and ( (SELECT `attempt_status` from updates where account_holder_id = curr.account_holder_id order by id desc limit 1) = 'No Contact' )  and account_holder_id in (SELECT account_holder_id from customer)   and account_holder_id not in (select account_holder_id from payments )   order by id desc   limit 1 ");
				  
				 
				   
				   
			   }
			   
			 
			   if(mysqli_num_rows($remQ) > 0)
			   {
				   
				   
				   // first system will check if any current  next update ptp user  for current user_error
			   
			 while($remData = mysqli_fetch_assoc($remQ))
			{ 
				 
				
				
				  $update_id = $remData['id'];
				  $account_holder_id = $remData['account_holder_id'];
				  $phone_no = $remData['mobile'];
		 	    
				  
			
			             $m_count  = 0;
					    
							   
							 $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
						     $advisorData = mysqli_fetch_assoc($advisorQ);
								 
								 if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
								 {
									 
									 $m_count++;
							   
							   
								// call here for auto call
							
							 $is_need_call = true;
							   
							   
							   if($is_need_call)
							   {
								   $uniqueid = uniqid(); 
								   
								   
								   $resultArray = array();
								   $resultArray['account_holder_id'] = $account_holder_id;
								   $resultArray['mobile'] = $phone_no;
								   $resultArray['uniqueid'] = $uniqueid;
								   $resultArray['customer_name'] = $customerData['name'];
								   $resultArray['call_type_label'] = "PTP/Followup";
								   
								   
								   echo json_encode($resultArray);
								   
								   
								   // init call here
								  
								  
								  
								  	$mobile = $phone_no;	
									  
		
	 
									$advisor_id = $advisorData['id'];
		  
									//$uniqueid = uniqid();

									$DATA = array();
									
									$DATA['customer_mobile'] = $mobile;
									$DATA['customer_name'] = $customerData['name'];
									$DATA['emp_code'] = $advisorData['username'];
									$DATA['apisipid'] = $advisorData['apisipid'];
									$DATA['uniqueid'] = $uniqueid;
									$DATA['advisor_mobile'] = $advisorData['mobile'];
									$DATA['advisor_name'] = $advisorData['name'];
									$DATA['account_holder_id'] = $account_holder_id;
									$DATA['is_hit'] = '0';
									$DATA['init_type'] = 'auto';
									$DATA['customer_type'] = $customer_type;
				 
			 
			 
			
								    insertTable($conn,'call_init',$DATA,'add_submit');
									
									
									
									mysqli_query($conn,"update `advisors` set is_busy_on_call = 'on' where id=$advisor_id ");
									
									
									mysqli_query($conn,"update `updates` set status = 'done', `try_next_date_time` = '$try_next_date_time' where id=$update_id ");
									
									
									  mysqli_query($conn,"update temp_filter_customer set advisor = '$advisor',  attempt='1' where account_holder_id = '$account_holder_id'  and attempt='0'  and  (advisor='' or advisor is NULL)   ");
											
									  mysqli_query($conn,"update `customer` set advisor='$advisor' where account_holder_id = '$account_holder_id'  and  (advisor='' or advisor is NULL)  ");
										
									
								  
									 
									  
								  /******************************************************************************************/
								  
								  
								  
							   }
								   
								    
								   
							   }
							
							
							
							
					 
		   
		   
		 
				
				
				
			}
			
			
			   
			   
			   
			   
			   
				   /************************************* eND Reminder call **************************************/
				   
			   }
			   
			   
			   
			   
			   
			   
			   
			    else
				 
				 {
			   
			    
			   
			   
			     $check_for_next = true;
		   
		         $current_id = 0;
		         $current_score = 100000000;
		    
		   
		    while($check_for_next)
		   {
			   
		     
			 //  $customerQ  = mysqli_query($conn,"select *from `temp_filter_customer` where advisor='$advisor' and customer_type = '$customer_type' and attempt = '0'  and account_holder_id not in (select account_holder_id from payments )  order by   imp_score desc  limit 1   ");
			   
			    $customerQ  = mysqli_query($conn,"select *from `temp_filter_customer` where advisor='$advisor' and customer_type = '$customer_type' and attempt = '0'  order by   imp_score desc  limit 1   ");
			   
			   
			   if(mysqli_num_rows($customerQ) == 0)
			   {
				   
				 //$customerQ  = mysqli_query($conn,"select *from `temp_filter_customer` where  ( advisor is NULL or advisor = '')  and ( old_advisor is NULL or old_advisor = '' or old_advisor = '$advisor' )   and customer_type = '$customer_type'   and  call_count = 0  and attempt = '0'  and account_holder_id not in (select account_holder_id from payments )   order by  imp_score desc  limit 1   ");
				 
				 $customerQ  = mysqli_query($conn,"select *from `temp_filter_customer` where  ( advisor is NULL or advisor = '')  and ( old_advisor is NULL or old_advisor = '' or old_advisor = '$advisor' )   and customer_type = '$customer_type'   and  call_count = 0  and attempt = '0'    order by  imp_score desc  limit 1   ");
				 
				
			   }
			   
			   
			   if(mysqli_num_rows($customerQ) == 0)
			   {
				    $check_for_next = false;
			   }
			   
			   
		      
			while($customerData = mysqli_fetch_assoc($customerQ))
			{
				
				$current_id = $customerData['id'];
				$current_score = $customerData['imp_score'];
				$account_holder_id = $customerData['account_holder_id'];
				
				
				mysqli_query($conn,"update `temp_filter_customer` set advisor = '$advisor' where account_holder_id = '$account_holder_id' ");
				
				
				 
				 
				  $extra_phone_json = $customerData['extra_phone_json'];
		   
				   $extra_phone_jsonArray = array();
				   if($extra_phone_json!='')
				   {
					   $extra_phone_jsonArray = json_decode($extra_phone_json,TRUE);
				   }
				   
				   $phone_cibil = $customerData['phone_cibil'];
				   $phone_db = $customerData['mobile'];
				   $phoneArrayDb = explode(' || ',$phone_db);
				   $phoneArray = explode(' || ',$phone_cibil);
				   
				   $phoneArray1 = array();
				   
				   
				    foreach($phoneArrayDb as $phone_no)
				   {
					  
					   $phone = substr($phone_no, -10);
					   
					   if(!in_array($phone,$phoneArray1))
					   {
						$phoneArray1[] = $phone;
					   }
				   }
				   
		   
					$phoneArrayDb = $phoneArray1;
					
					
					foreach($phoneArray as $phone_no)
		              {
			  
					   $phone = substr($phone_no, -10);
					   
						 if(strlen($phone) == 10)
					   {
					   if(is_numeric($phone))
					   {
					   if(!in_array($phone,$phoneArray1))
					   {
						$phoneArray1[] = $phone;
					   }
					   }
					   
					   }
							   
					   
					 }
			
			
			
			
			             $m_count  = 0;
					     foreach($phoneArray1 as $phone_no)
						  {
							   
							 $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
						     $advisorData = mysqli_fetch_assoc($advisorQ);
								 
								 if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
								 {
									 
									 $m_count++;
							   
							
								// call here for auto call
							
							
							  // check if scrap no
							   $is_need_call = true;
							   
							   
							     //$scrapCheckQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id' and mobile = '$phone_no' and disposition in (select name from `disposition` where is_scrap_phone='on' ) ");
			   
								  // if(mysqli_num_rows($scrapCheckQ) > 0)
									  
								  if(in_array($phone_no,explode(',',$customerData['scrap_phone'])))
								   {
									   $is_need_call = false;
									   
									   if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
										mysqli_query($conn,"update temp_filter_customer set advisor = '$advisor',  attempt='1' where account_holder_id = '$account_holder_id'  ");
										
										mysqli_query($conn,"update `customer` set advisor='$advisor' where account_holder_id = '$account_holder_id'  ");
										
									}
									
								   }
								   
								   
								   
								   
								   
								   
								   
								   
								   
								   
								   
							    
							    
							   
							   $needCheckQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id' and mobile = '$phone_no' and  (disposition = 'WTR' or disposition = 'RNR' or disposition = 'NC')  and update_date = '$today_date' ");
							   
							   if(mysqli_num_rows($needCheckQ) > 0)
							   {
								   $is_need_call = false;
								   
								   
								   if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
										mysqli_query($conn,"update temp_filter_customer set advisor = '$advisor',  attempt='1' where account_holder_id = '$account_holder_id'  ");
										
										mysqli_query($conn,"update `customer` set advisor='$advisor' where account_holder_id = '$account_holder_id'  ");
										
									}
								   
								   
							   }
							   
							   
							   
							   // check if contacted then no allowed next number
							    
							    $isCallDone  = mysqli_query($conn,"select * from updates where (attempt_status = 'Contact P' or attempt_status = 'Contact N')  and update_date = '$today_date' and account_holder_id = '$account_holder_id'  ");
								
								if(mysqli_num_rows($isCallDone) > 0)
								{
									 $is_need_call = false;
									 
									  if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
										mysqli_query($conn,"update temp_filter_customer set advisor = '$advisor',  attempt='1' where account_holder_id = '$account_holder_id'  ");
										
										mysqli_query($conn,"update `customer` set advisor='$advisor' where account_holder_id = '$account_holder_id'  ");
										
									}
								   
								}
								
			
						 
			
							   
							   
							   
							   
							   
							   if($is_need_call)
							   {
								   
								 $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
						         $advisorData = mysqli_fetch_assoc($advisorQ);
								 
								 if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
								 {
									 
									 
									 
								   $uniqueid = uniqid(); 
								   
								   
								   $resultArray = array();
								   $resultArray['account_holder_id'] = $account_holder_id;
								   $resultArray['mobile'] = $phone_no;
								   $resultArray['uniqueid'] = $uniqueid;
								   $resultArray['customer_name'] = $customerData['name'];
								   $resultArray['call_type_label'] = "Auto Allocation";
								   
								   
								   echo json_encode($resultArray);
								   
								   
								   // init call here
								  
								  
								  
								  	$mobile = $phone_no;	
									  
		
	 
									$advisor_id = $advisorData['id'];
		  
									//$uniqueid = uniqid();

									$DATA = array();
									
									$DATA['customer_mobile'] = $mobile;
									$DATA['customer_name'] = $customerData['name'];
									$DATA['emp_code'] = $advisorData['username'];
									$DATA['apisipid'] = $advisorData['apisipid'];
									$DATA['uniqueid'] = $uniqueid;
									$DATA['advisor_mobile'] = $advisorData['mobile'];
									$DATA['advisor_name'] = $advisorData['name'];
									$DATA['account_holder_id'] = $account_holder_id;
									$DATA['is_hit'] = '0';
									$DATA['init_type'] = 'auto';
									 $DATA['customer_type'] = $customer_type;

				 
			 
			 
			
								   insertTable($conn,'call_init',$DATA,'add_submit');
									
									
									
									mysqli_query($conn,"update `advisors` set is_busy_on_call = 'on' where id=$advisor_id ");
									
									
									mysqli_query($conn,"update temp_filter_customer set advisor = '$advisor', call_count = call_count + 1   where account_holder_id = '$account_holder_id'  ");
									
									mysqli_query($conn,"update `customer` set advisor='$advisor' where account_holder_id = '$account_holder_id'  ");
									
									 
									 
								 }
									 
									 $check_for_next = false;
								  
								  
								  /******************************************************************************************/
								  
								  
								  
							   }
								   
								    
								   
							   }
							
							
							
							
							
							
							  
							  
							  
						   }
		   
		   
		   
		   
		   
		   
		   
				
				
				
			}
			
			
			   
			   
			   
			   
		   }
			   
			   
			   
			   
		   }
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			    
			   
			   
			   
		   }
		   
		    
			
			  
		   /******************************  End Smart Logic **********************************/
		  
		  
		  
		    
		   else
			   
		  {
				   
				   
				   
		     /****************************** Auto Selection Logic **********************************/
		  
		   
		   
		   
		   $check_for_next = true;
		   
		   $current_id = 100000000;
		    
		   while($check_for_next)
		   {
		    
		    
			
			
			
		      
			if($auto_dial_type == 'non_contact') {
		   
		 //   $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor') 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 account_holder_id not in (select account_holder_id from payments )    and  ( id < $current_id )  order by id desc   limit 1  ");
			
			
			 $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor') and  total_contact = 0 and total_non_contact > 0   and  ( id < $current_id )  order by id desc   limit 1  ");
			
			}
			
			
		   if($auto_dial_type == 'ptp') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor') and  account_holder_id in (select account_holder_id from updates where   (disposition = 'PTP' or disposition = 'BRPTP' or  disposition = 'FPTP' ) )   and account_holder_id not in (select account_holder_id from payments )   and  ( id < $current_id )   order by id desc   limit 1  ");
			
			}
			
			
			
		   if($auto_dial_type == 'td_ptp') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor')  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 account_holder_id not in (select account_holder_id from payments )   and  ( id < $current_id )   order by id desc   limit 1  ");
			
			}
			
			
				
		   if($auto_dial_type == 'followup') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor')  and   account_holder_id in (select account_holder_id from updates  where disposition='CB' )  and account_holder_id not in (select account_holder_id from payments )   and  ( id < $current_id )   order by id desc   limit 1 ");
			
			}
			
			
			
			 if($auto_dial_type == 'td_followup') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor')  and    account_holder_id in (select account_holder_id from updates  where disposition='CB'  and next_update_date = '$today_date' ) and account_holder_id not in (select account_holder_id from payments )   and  ( id < $current_id )   order by id desc   limit 1  ");
			
			}
			
			
			 if($auto_dial_type == '1_emi_missed') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where ( advisor = '$advisor')  and    account_holder_id in (select account_holder_id from leads where JSON_EXTRACT(`lead_data`, '$.noofemismissed') = '1' )   order by id desc   limit 1  ");
			
			}
			
			 if($auto_dial_type == '2_emi_missed') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor')  and    account_holder_id in (select account_holder_id from leads where JSON_EXTRACT(`lead_data`, '$.noofemismissed') = '2' )   order by id desc   limit 1  ");
			
			}
			
			 if($auto_dial_type == '3_emi_missed') {
		   
		    $customerQ  = mysqli_query($conn,"select *from `customer` where  ( advisor = '$advisor')  and    account_holder_id in (select account_holder_id from leads where JSON_EXTRACT(`lead_data`, '$.noofemismissed') = '3' )   order by id desc   limit 1  ");
			
			}
			
			
			
			
			
			
			$total_customer = mysqli_num_rows($customerQ);
			
			
	
			while($customerData = mysqli_fetch_assoc($customerQ))
			{
				
				$current_id = $customerData['id'];
				
				$account_holder_id = $customerData['account_holder_id'];
				 
				 
				$extra_phone_json = $customerData['extra_phone_json'];
		   
				   $extra_phone_jsonArray = array();
				   if($extra_phone_json!='')
				   {
					   $extra_phone_jsonArray = json_decode($extra_phone_json,TRUE);
				   }
				   
				   $phone_cibil = $customerData['phone_cibil'];
				   $phone_db = $customerData['mobile'];
				   $phoneArrayDb = explode(' || ',$phone_db);
				   $phoneArray = explode(' || ',$phone_cibil);
				   
				   $phoneArray1 = array();
				   
				   
				    foreach($phoneArrayDb as $phone_no)
				   {
					  
					   $phone = substr($phone_no, -10);
					   
					   if(!in_array($phone,$phoneArray1))
					   {
						$phoneArray1[] = $phone;
					   }
				   }
				   
		   
					$phoneArrayDb = $phoneArray1;
					
					
			     foreach($phoneArray as $phone_no)
		              {
			  
					   $phone = substr($phone_no, -10);
										   
								 if(strlen($phone) == 10)
								   {
								   if(is_numeric($phone))
								   {
								   if(!in_array($phone,$phoneArray1))
								   {
									$phoneArray1[] = $phone;
								   }
								   }
								   
								   }
						   
					 }
			
			
			
			
			             $m_count  = 0;
					     foreach($phoneArray1 as $phone_no)
						   {
							   
							 $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
						     $advisorData = mysqli_fetch_assoc($advisorQ);
								 
								 if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
								 {
									 
									 $m_count++;
							   
							   
							// call here for auto call
							
							
							  // check if scrap no
							    $is_need_call = true;
							   
							   
							  /*  $scrapCheckQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id' and mobile = '$phone_no' and disposition in (select name from `disposition` where is_scrap_phone='on' ) ");
			   
								   if(mysqli_num_rows($scrapCheckQ) > 0)
								   {
									   $is_need_call = false;
									   
									    if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
									}
								   
									   
									   
									
								   }
							    
								*/
								
								  if(in_array($phone_no,explode(',',$customerData['scrap_phone'])))
							   {
									 $is_need_call = false;
									  if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
									}
							   }
								
								
								
								
								
							   
							   $needCheckQ = mysqli_query($conn,"select *from `updates` where account_holder_id = '$account_holder_id' and mobile = '$phone_no' and  (disposition = 'WTR' or disposition = 'RNR' or disposition = 'NC')  and update_date = '$today_date' ");
							   
							   if(mysqli_num_rows($needCheckQ) > 0)
							   {
								   $is_need_call = false;
								   
								   
								   if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
									}
								   
								   
							   }
							   
							   
							   
							   // check if contacted then no allowed next number
							   
							   
							   
							   
							    $isCallDone  = mysqli_query($conn,"select * from updates where (attempt_status = 'Contact P' or attempt_status = 'Contact N')  and update_date = '$today_date' and account_holder_id = '$account_holder_id'  ");
								
								if(mysqli_num_rows($isCallDone) > 0)
								{
									 $is_need_call = false;
									 
									  if($m_count == count($phoneArray1))
									{  
										$check_for_next = true;
										
									}
								   
								}
								
			
						 
			
							   
							   
							   
							   
							   
							   if($is_need_call)
							   {
								   
								   
								 $advisorQ  = mysqli_query($conn,"select *from `advisors` where name='$advisor'  ");
						         $advisorData = mysqli_fetch_assoc($advisorQ);
								 
								 if($advisorData['is_busy_on_call'] == '' && $advisorData['is_paused'] == '')
								 {
									 
									 
								   $uniqueid = uniqid(); 
								   
								   
								   $resultArray = array();
								   $resultArray['account_holder_id'] = $account_holder_id;
								   $resultArray['mobile'] = $phone_no;
								   $resultArray['uniqueid'] = $uniqueid;
								   $resultArray['customer_name'] = $customerData['name'];
								   $resultArray['call_type_label'] = $auto_dial_type;
								   
								   
								   echo json_encode($resultArray);
								   
								   
								   // init call here
								  
								  
								  
								  	$mobile = $phone_no;	
									  
		
	 
									$advisor_id = $advisorData['id'];
		  
									//$uniqueid = uniqid();

									$DATA = array();
									
									$DATA['customer_mobile'] = $mobile;
									$DATA['customer_name'] = $customerData['name'];
									$DATA['emp_code'] = $advisorData['username'];
									$DATA['apisipid'] = $advisorData['apisipid'];
									$DATA['uniqueid'] = $uniqueid;
									$DATA['advisor_mobile'] = $advisorData['mobile'];
									$DATA['advisor_name'] = $advisorData['name'];
									$DATA['account_holder_id'] = $account_holder_id;
									$DATA['is_hit'] = '0';
									$DATA['init_type'] = 'auto';
								   $DATA['customer_type'] = $customer_type;

				 
			 
			 
			
								   insertTable($conn,'call_init',$DATA,'add_submit');
									
									
									
								   mysqli_query($conn,"update `advisors` set is_busy_on_call = 'on' where id=$advisor_id ");
									
									 
									
								  
								 }
								  
								  
								   
									 $check_for_next = false;
								  
								  
								  
								  /******************************************************************************************/
								  
								  
								  
							   }
							   
							   
							   
							   
							   
								   
								    
								   
							   }
							
							
							
							
							
							
							  
							  
							  
						   }
		   
		   
		   
		   
		   
		   
		   
				
				
				
			}
			
			
			
			
			
			
			
			
			
	   }
				  
				  
		   
		   
		   
		   
		   
		   
	   }
	   
	   
	   
	   
	   
	   }
	   
	   
	   	   
	   /**************************************  End Auto Selection Logic **************************************/
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   }
		   
	  
  }
  
  
  
  ?>