<?php

class cStockgeneral{



function catalogo_filtro_stock($nom,$cod,$cat,$mar,$est,$atr_ids,$verven,$vercom,$unibas){

		$sql="SELECT * 

		FROM tb_producto p

		INNER JOIN tb_categoria c ON p.tb_categoria_id=c.tb_categoria_id

		INNER JOIN tb_marca m ON p.tb_marca_id=m.tb_marca_id

		INNER JOIN tb_presentacion pr ON p.tb_producto_id=pr.tb_producto_id

		INNER JOIN tb_catalogo ct ON pr.tb_presentacion_id=ct.tb_presentacion_id

		INNER JOIN tb_unidad u ON ct.tb_unidad_id_equ=u.tb_unidad_id ";

		

		if($atr_ids!="")$sql.=" INNER JOIN tb_tag t ON pr.tb_presentacion_id=t.tb_presentacion_id ";

		

		$sql.=" WHERE tb_producto_est LIKE '%$est%' ";



		if($atr_ids!="")$sql.=" AND tb_atributo_id IN ($atr_ids) ";



		if($verven==1 and $vercom==1)

		{

			$sql.=" AND (ct.tb_catalogo_verven=1 OR ct.tb_catalogo_vercom=1)";

		}

		

		if($verven==1 and $vercom==0)

		{

			$sql.=" AND ct.tb_catalogo_verven=1 ";

		}

		

		if($verven==0 and $vercom==1)

		{

			$sql.=" AND ct.tb_catalogo_vercom=1 ";

		}

		

		if($verven==0 and $vercom==0)

		{

			$sql.=" AND (ct.tb_catalogo_verven=0 AND ct.tb_catalogo_vercom=0)";

		}



		if($nom!="")$sql.=" AND tb_producto_nom LIKE '%$nom%' ";

		if($cod!="")$sql.=" AND tb_presentacion_codbar = '$cod'";

		if($cat!="")$sql.=" AND p.tb_categoria_id IN ($cat) ";

		if($mar!="")$sql.=" AND p.tb_marca_id=$mar ";

		

		if($unibas==1)$sql.=" AND ct.tb_catalogo_unibas =1 ";

		

		if($atr_ids!="")$sql.=" GROUP BY ct.tb_catalogo_id ";

		

		$sql.=" ORDER BY c.tb_categoria_nom, m.tb_marca_nom ";

		$oCado = new Cado();

		$rst=$oCado->ejecute_sql($sql);

		return $rst;

	}

	

}

?>