<?php
class Safra14_Model_Lf007Auxiliar extends Agro_Db_Table_Abstract {
	protected $_schema 	= 'safra14';
	protected $_name 	= 'lf007_auxiliar';
	protected $_primary = 'id';
	public 	  $_order 	= 'id_estadio_fenologico';
	
	public function get($id_estadio_fenologico, $percentual_informado, $desfolhamento=true){
		try {
			$ModelEstadioFenologico = new Sinistro_Model_EstadiosFenologicos();
			$EstadioFenologico = $ModelEstadioFenologico->find($id_estadio_fenologico)->current();

			$Select = $this->select()->setIntegrityCheck(false);
			$Select->from(array("aux"=>"{$this->_schema}.{$this->_name}"), array("valor"));
			$Select->where("aux.id_estadio_fenologico=$id_estadio_fenologico");
			$Select->where("$percentual_informado between aux.min and aux.max");
			$Select->where("aux.fl_desfolhamento=".($desfolhamento ? "true" : "false"));

			return number_format($this->getDefaultAdapter()->fetchOne($Select), 2);
			
		} catch (Exception $e) {
			die($e->getMessage());
		}
			
	}
} 
	