<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/repfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}

$output=''; 

if(isset($_POST['catid'])){
    $catid=intval($_POST['catid']);
    if($catid>0){
    $sql = "SELECT *,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND catid='$catid' AND status='1' AND (avqty-sloc)>0 GROUP BY unqid, pid , sizid ORDER BY name ASC Limit 200";    
    }else{
    $sql = "SELECT *,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND status='1' AND (avqty-sloc)>0 GROUP BY unqid, pid , sizid ORDER BY name ASC Limit 200";    
    }        
    }elseif(isset($_POST['subcatid'])){
    $scatid=intval($_POST['subcatid']);
    $sql = "SELECT * ,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND scatid='$scatid' AND status='1' AND (avqty-sloc)>0 GROUP BY unqid,  pid , sizid ORDER BY name ASC Limit 200";     
    }elseif(isset($_POST['brandid'])){    
    $brnid=intval($_POST['brandid']);
    if($brnid>0){
    $sql = "SELECT *,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND brnid='$brnid' AND status='1' AND (avqty-sloc)>0 GROUP BY unqid,  pid , sizid ORDER BY name ASC Limit 200";     
    }else{
    $sql = "SELECT *,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND status='1' AND (avqty-sloc)>0 GROUP BY  unqid, pid , sizid ORDER BY name ASC Limit 200";    
    }    
    }else{
    $sql = "SELECT *,SUM(avqty) AS avqty,SUM(sloc) AS sloc FROM tbl_brstock WHERE brid='$brid' AND status='1' AND (avqty-sloc)>0 GROUP BY unqid, pid , sizid ORDER BY name ASC Limit 200";
    }
$result = mysqli_query($con,$sql);
while ($row=mysqli_fetch_array($result)){
$unqid=$row['unqid'];
$output.='<div class="product-content product-select selitem" id="AX_'.$row['unqid'].'" title="'.$row['name'].'"><img src="../img/product/';
if(empty($row['image'])){$output.='no_image.png';}else{$output.=$row['image'];} 
$output.='" class="product-image"><div class="info"><h3>'.get_prostinfo($row['unqid'],'price').'</h3><p>Qty: '.($row['avqty']-$row['sloc']);
if(get_fild_data('tbl_setting','11','sval')==0){
    if($row['colid']!=0){
        $output.='<br>Color: '.get_fild_data('tbl_color',$row['colid'],'name'); 
    }
    if($row['sizid']!=0){
        $output.='<br>Size: '.get_fild_data('tbl_size',$row['sizid'],'name'); 
    }
       
} 
if(get_fild_data('tbl_setting','5','sval')==0){
$output.='<br>Cost: '.numtolocal(get_fild_data('tbl_stock','','cost',"unqid='$unqid'"),'');    
}   
$output.='</p></div><div class="product-detail"><b class="name">'.$row['name'].'</b></div><div class="product-code"><b class="sku">'.$row['code'].'</b><b class="indexg" style="display:none;">'.strtoupper(substr($row['name'],0,1)).'</b></div></div>';	
}   
echo $output;
exit;