<?php

class Nobre_Form_PesquisaProcesso extends Agro_Form {

	public function init($id_empresa_vistoriadora = null) {

		$this->addElement('select', 'tipo_pesquisa', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Tipo de Pesquisa',
			'MultiOptions' => array(
				'id_proposta' => 'Proposta',
				'nr_apolice' => 'Número da Apólice',
				'ds_nome_proponente' => 'Nome do Segurado',
				'id'=>'Número de Processo',
				'id_aviso'=>'Número de Aviso',
				'id_processo_seguradora' => 'Processo Seguradora' 
			)
		));
		
		$this->addElement('text', 'valor_pesquisa', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Valor da Pesquisa'
		));		
		
		if ($id_empresa_vistoriadora) {
			$this->addElement('hidden', 'id_empresa', array(
				'decorators' => $this->buttonDecorator,
				'id' => 'id_empresa',
				'value' => $id_empresa_vistoriadora
			));

		} else {
	        $Categoria = new Sistema_Model_Categorias();
	        $RowCategoria = $Categoria->fetchRow("ds_chave = 'VISTORIADORA'");

	        $Empresa = new Sistema_Model_Empresas();
	        $this->addElement('select', 'id_empresa', array(
				'MultiOptions' => $Empresa->fetchPairs('id', 'ds_nome_fantasia', false, false, 1, "id_categoria = {$RowCategoria->id}", true, 'ASC'),
				'decorators' => $this->elementDecorator,
				'label' => 'Empresa Vistoriadora'
			));
		}

		$Status = new Sistema_Model_Status();
		$listStatus = $Status->getListStatus('SP');

		$options = array();
		$options[''] = '';

		foreach($listStatus as $item){
			$options[$item['id']] = $item['ds_status'];
		}

		$this->addElement('select', 'id_status', array(
			'MultiOptions' => $options,
			'decorators' => $this->elementDecorator,
			'label' => 'Status do Processo'
		));

        
		
        //solicitado pela Rubia/Laura para não mostrar pra Nobre processos de outras safras além da 15
        $perfil = Zend_Auth::getInstance()->getIdentity()->ds_chave;
        switch ($perfil){
        	case "SEGURADORA":
        		$where = 'id = 15';
        		break;
        	case "SEGURADORA_ESSOR":
        		$where = 'id >= 16';
        		break;
        	default:
        		$where = false;
        		break;
        }

        $Safras = new Produto_Model_Safras();
        $this->addElement('select', 'id_safra', array(
        		'MultiOptions' => $Safras->fetchPairs('id', 'ds_nome_safra', false, false, 1, $where, true, 'DESC'),
        		'decorators' => $this->elementDecorator,
        		'label' => 'Safra'
        ));
        

        $Cultura = new Produto_Model_Culturas();
		$this->addElement('select', 'id_cultura', array(
			'MultiOptions' => $Cultura->fetchPairs('id', 'ds_nome_cultura', false, false, 1, false, true, 'ASC'),
			'decorators' => $this->elementDecorator,
			'label' => 'Cultura'
		));

	}
}