<?php

class IngSetup {

	/*************************************************
	/ This function add new Ing Setup
	*************************************************/
	
	public static function AddIngSetup($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_INGSETUP, $data);
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			return $id;
		}else{
			return false;
		}
	
	} // AddIng

	/*************************************************
	/ This function update Ing
	*************************************************/
	
	public static function UpdateIngSetup($pid,$data) {
		global $db;
				
		$id = $db->query_update(TABLE_INGSETUP,$data,"id='$pid'");
		
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			
			return $id;
		}else{
			return $id;
		}
	
	} // UpdateIng


	public static function GetIngSetupById($id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_INGSETUP." WHERE id ='$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Ing

	public static function GetIngSetupByIngCode($pcode) {
	
		global $db;
		$query = "SELECT * from ".TABLE_INGSETUP." WHERE code LIKE '$pcode%'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Ing


	public static function CheckIng($name, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_INGSETUP." WHERE name ='$name' && id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Ing
	
	/**********************************************************
	/ This function will return IngSetup
	**********************************************************/
		
	public static function GetIngSetupListPacking($filter="",$pageno="null",$pagesize="null") {

                    global $db;

              $query = "SELECT * FROM " . TABLE_INGSETUP . " WHERE category_id = 1 AND status = 'active' ORDER BY name";

              // Display the query in a JavaScript alert for debugging
           //   echo "<script>alert('SQL Query: " . addslashes($query) . "');</script>";

              // Execute the query and fetch the results
              $rows = $db->fetch_all_array($query, $pageno, $pagesize);

              if ($db->affected_rows > 0) {
                  return $rows;
              } else {
                  return false;
              }
              }//GetIngSetupListPacking

  public static function GetIngSetupListIngredient($filter="",$pageno="null",$pagesize="null") {
              global $db;

          $query = "SELECT * FROM " . TABLE_INGSETUP . " WHERE category_id != 1 AND status = 'active' ORDER BY name";

          // Display the query in a JavaScript alert for debugging
       //   echo "<script>alert('SQL Query: " . addslashes($query) . "');</script>";

          // Execute the query and fetch the results
          $rows = $db->fetch_all_array($query, $pageno, $pagesize);

          if ($db->affected_rows > 0) {
              return $rows;
          } else {
              return false;
          }
      }//GetIngSetupListPacking
  public static function GetIngSetupList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_INGSETUP." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//IngSetup
   public static function GetIngredientById($ingredient_id) {
        global $db;
        $query = "SELECT * FROM " . TABLE_INGREDIENT . " WHERE id = '$ingredient_id'";
        return $db->query_first($query);
    }

	public static function GetNumRows() { global $db; return $db->GetNumRows(); }
	public static function GetNumberOfPages() { global $db; return $db->GetNumberOfPages(); }
		
	
}

?>
