<?php 
ob_start();
session_start();
include "../config/config.php";

$cond='';
$search="";
$location_id = $_REQUEST['location_id'];
$search_text = $_REQUEST['search_text'];

if(isset($search_text)){
    $search .= $search_text;
}

if(isset($location_id) && $location_id!=0){
    $cond .= " and pr.location_id=".$location_id;
}

$cond .= " AND (tbl_products.product_name like '%" . $search . "%' OR pr.hsn_code like '%" . $search . "%')";

    $statement = $pdo->prepare("SELECT pr.*, tbl_products_name.name as orginal_product_name
    FROM tbl_product_variants pr
    LEFT JOIN tbl_products ON tbl_products.id=pr.product_id 
    LEFT JOIN tbl_products_name ON tbl_products_name.id=pr.product_name 
    WHERE 1=1 and pr.status=1 AND pr.quantity!=0
    $cond");
    

    $statement->execute();
    $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    
   /*INR Symbol₹*/
   /*Stock Qty : '.$res['quantity'].'&nbsp;&nbsp;&nbsp;</b>*/
    
    if($totalData>0){
        foreach($emp_data as $res){
            
            echo '<div onclick="product_selection('.$res['id'].')" style="font-weight: 700;">
                    Product Name : '.$res['orginal_product_name'].' <br>
                    HSN Code : '.$res['hsn_code'].' <br>
                    
                </div>';
        }
        
    }else{
        echo '<div><center> No Data Found...</center><div>';
    }
    

?>