<?php require_once('../auth/auth.php');
if (isset($_GET["term"])) {
$term    = trim($_GET["term"]);
$item_id =  $_GET["item_id"];
$pro_r= mysqli_query($conn,"SELECT imei_id,imei_code,imei_color,

(SUM(COALESCE(CASE WHEN plus = '+' THEN 1 END,0)) - SUM(COALESCE(CASE WHEN plus = '-' THEN 1 END,0))) c_qty

FROM imei_tracker
WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND pro_id='$item_id' AND active=1  AND (imei_code LIKE '%$term%' || imei_color LIKE '%$term%' )   GROUP BY imei_code HAVING c_qty > 0  LIMIT 10") or die (mysqli_error($conn));
$items = [];
while ($rowp= mysqli_fetch_assoc($pro_r)) {
$items[]= ['value'=>$rowp['imei_id'] , 'label'=>$rowp['imei_code']."  ".$rowp['imei_color']." ,Pcs"];
}
echo json_encode( $items );
}
?>