<?php
session_start();
require_once 'dbconfig.php';
require_once 'db_connection.php'; 

$branch_id = $_SESSION['branch_id'];

if(isset($_POST['product'])){
   $product =  $_POST['product'];

   $productlist = mysqli_query($conn, "SELECT * FROM mobileproducts WHERE itemcode LIKE '$product%' OR proname LIKE '%$product%'");
    $list = "";
   if ($productlist->num_rows > 0) {
    $list .= "<div>";
      while($row = $productlist->fetch_assoc()) {  
        $prid = $row['prid'];
            $user_qury_03 = mysqli_query($conn, "SELECT * FROM tbl_stock WHERE prid = '$prid' AND branch_id='$branch_id'");
		    $user_res1 = mysqli_fetch_assoc($user_qury_03);
		    $sqty = $user_res1['qty']; 

          if($user_res1['qty'] < 1){
               $list .= "<div style='background-color:red !important; color:#fff;' tabindex='0'>".$row['itemcode']." / " .$row['proname']." / OUT OF STOCK</div>";    
          }else{
               $list .= "<div onkeydown='if(event.keyCode==13){ addNewProductById(".$row['prid']."); event.preventDefault(); }' onclick='addNewProductById(".$row['prid'].");' tabindex='0'>".$row['itemcode']." / " .$row['proname']." / QTY - " .$sqty."</div>";    
          }
            
            
           
        } 
        $list .= "</div>";
        echo $list;
   }else{
        echo $list;
   }



}




?>