<?php
/**********************************************************************
***********************************************************************/
//-------------------------------------------------------------------------------------------------------------

function get_item_list_sql($stock_id, $category_id, $description, $long_description, $mb_flag, $pos, $resturant, $laundry, 
        $item_category, $country_of_origin, $country_of_manufacture, $supplier_id, $local_agent, $brand, $type)
{
//   $filter = ""; 
   
//    if ($category_id == -1){
//        $filter .= "LEFT JOIN ".TB_PREF."stock_category ON 
//                    sc.category_id = sm.category_id  "; 
//    }
//    
//    if ($category_id != -1) 
//	{
//         $filter .=" ,".TB_PREF."stock_category sc ";
//	} 

    $sql = "SELECT sm.stock_id, sm.description, sm.long_description
                    
            FROM ".TB_PREF."stock_master sm
                      
            WHERE 1  ";

	if ($stock_id != null) 
	{
		$sql .= " AND sm.stock_id = ".db_escape($stock_id);
	} 
    
    if ($description != null) 
	{
		$sql .= " AND sm.description = ".db_escape($description);
	} 
    
    if ($long_description != null) 
	{
		$sql .= " AND sm.long_description = ".db_escape($long_description);
	} 
    
    if ($mb_flag != null) 
	{
		$sql .= " AND sm.mb_flag = ".db_escape($mb_flag);
	} 
    
    if ($item_category != -1) 
	{
		$sql .= " AND sm.item_category = ".db_escape($item_category);
	}
    
    if ($country_of_origin != -1) 
	{
		$sql .= " AND sm.country_of_origin = ".db_escape($country_of_origin);
	}
    
    if ($country_of_manufacture != -1) 
	{
		$sql .= " AND sm.country_of_manufacture = ".db_escape($country_of_manufacture);
	}
    
    if ($supplier_id != -1) 
	{
		$sql .= " AND sm.supplier_id = ".db_escape($supplier_id);
	}
    
    if ($local_agent != -1) 
	{
		$sql .= " AND sm.local_agent = ".db_escape($local_agent);
	}
    
    if ($brand != -1) 
	{
		$sql .= " AND sm.brand = ".db_escape($brand);
	}
    
    if ($type != -1) 
	{
		$sql .= " AND sm.type = ".db_escape($type);
	}
    
    if ($category_id != -1) 
	{
		$sql .= " AND sc.category_id = ".db_escape($category_id);
        $sql .= " AND sc.category_id = sm.category_id ";
	} 

    
    $sql .= " AND sm.is_pos = ".db_escape($pos);
    $sql .= " AND sm.is_restaurant = ".db_escape($resturant);
    $sql .= " AND sm.is_laundry = ".db_escape($laundry);
	
        $sql .= " ORDER BY sm.stock_id";
        
   	return $sql;
}
?>