<?php

class ProductionSetup {

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

	/*************************************************
	/ This function add new Production Item
	 *************************************************/

	public static function AddProductionItem($data) {
		global $db;
		$id = $db->query_insert(TABLE_PRODUCTION_ITEM, $data);
		if($db->affected_rows > 0){
			return $id;
		}else{
			return false;
		}
	} // AddProductionItem

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


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

	public static function GetProductionItems($filter="",$pageno="null",$pagesize="null") {
		global $db;
		$query = "SELECT * from ".TABLE_PRODUCTION_ITEM." ". $filter;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
		if($db->affected_rows > 0){
			return $rows;
		}else{
			return false;
		}
	}//GetProductionItems

	public static function CheckProductionAccount($account_number, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_PRODUCTION." WHERE bank_account_number ='$account_number' && id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Production
	
	/**********************************************************
	/ This function will return ProductionSetup
	**********************************************************/
		
	public static function GetProductionSetupList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_PRODUCTION." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//ProductionSetup

	public static function GetProductionBatchWiseTotalList($filter="",$pageno="null",$pagesize="null") {

		global $db;
		$query = "SELECT batch_name, SUM(batch_qty) AS batches, TRUNCATE(SUM(batch_qty*per_unit_oil), 2) AS oil, SUM(batch_qty*per_unit_mung) AS mung, SUM(batch_qty*per_unit_mash) AS mash,
SUM(batch_qty*per_unit_rice) AS rice, SUM(batch_qty*per_unit_packets) AS packets, SUM(total) AS total FROM ".TABLE_PRODUCTION." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//ProductionSetup


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

?>
