<?php require_once('../auth/auth.php'); ?>
<?php
  if(!isset($_POST['search'])){ 
    $data = [];
  } else {
   $search = $_POST['search'];
   $g_type = $_POST['g_type'];

   $accat= mysqli_query($conn,"SELECT acid,ac_name,ac_alise,ac_number,balance,outlet_id FROM accounts LEFT JOIN ac_sub_g_category ON(accounts.gcatid=ac_sub_g_category.ac_g_catid) WHERE accounts.coid='$coid' AND bid='$bid' AND brid='$brid' AND (ac_name LIKE '%$search%' ||  outlet_id LIKE '%$search%' ||   ac_alise LIKE '%$search%' || ac_number LIKE '%$search%') AND active=1 AND g_type IN($g_type)  LIMIT 10") or die(mysqli_error($conn));
   $data = [];
   while($acat= mysqli_fetch_assoc($accat)){
  $data[] = ['id'=>$acat['acid'].",".$acat['balance'],'text'=>$acat['ac_name']."-".$acat['ac_number']." "."(".$acat['outlet_id'].")"];
 }

echo json_encode($data);
}
?>