<?php

class Seguro_Form_VistoriaPreviaConsulta extends Agro_Form {

	public function setIdEmpresa($id_empresa) {
		$this->id_empresa_vistoriador = $id_empresa;
	}

	public function init() {

		$this->addElement('select', 'pesquisar_por', array(
			'MultiOptions' => array(
				''=>'',
				'p.nr_apolice' => 'Apólice',
				'prop.cpf_cnpj' => 'CPF/CNPJ',
				'prop.ds_nome_proponente' => 'Nome do Segurado',
				'p.id' => 'Proposta'
			),
			'decorators' => $this->elementDecorator,
			'label' => 'Pesquisar por'
		));

		$this->addElement('text', 'vl_pesquisar_por', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Valor',
			'class' => 'upper',
			'size' => 30
		));

		$this->addElement('select', 'id_status_empresa', array(
			'MultiOptions' => array(
				'' => '',
				Sistema_Model_Status::VP_AGUARDANDO_VISTORIA => 'Aguardando Vistoria',
				Sistema_Model_Status::VP_ENC => 'Encaminhada',
				Sistema_Model_Status::VP_TRANSMITIDA => 'Transmitida',
				Sistema_Model_Status::VP_TRANSMITIDA_SEM_FOTOS => 'Transmitida Sem Fotos'
			),
			'decorators' => $this->elementDecorator,
			'label' => 'Status Prévia',
	        'multiple' => true,
	        'class' => 'multiple'
		));

		$this->addElement('select', 'id_status_analise_search', array(
			'decorators' => $this->elementDecorator,
			'MultiOptions' => $this->getComboStatusAnalise(),
			'label' => 'Status de Análise',
		    'multiple' => true,
		    'class' => 'multiple',
			'required' => ''
		));

		$Auth = Zend_Auth::getInstance()->getIdentity();
		if ($Auth->tp_usuario == 'C') {
			$Prepostos = new Sistema_Model_Prepostos();
			$prepostos = $Prepostos->getComboUsuario($Auth->id);
			$this->addElement('select', 'id_preposto', array(
				'decorators' => $this->elementDecorator,
				'MultiOptions' => $prepostos,
				'label' => 'Sublogin'
			));
		}

		$Safras = new Seguro_Model_Safras();
		$Safra = new Produto_Model_Safras();
		$this->addElement('select', 'id_safra', array(
			'decorators' => $this->elementDecorator,
			'MultiOptions' => $Safras->getCombo(0,false,false),
			'value' => $Safras->safraCurrent,
			'label' => 'Safra'
		));
		
		$this->addElement('select', 'id_produto', array(
			'decorators' => $this->elementDecorator,
			'MultiOptions' => array_merge(
				['' => '--- Selecione um produto ---'],
				$Safra->getComboProdutoSafraRequest($Safra->safraCurrent, 0)
			),
			'label' => 'Produto'
		));
	}

	private function getComboStatusAnalise()
	{
		$Status = new Sistema_Model_Status();
		$comboStatusAnalise = array();

		foreach ($Status->getComboSimples('VP_ANALISE', 'ds_status') as $key => $value) {
			if (in_array($key, array(170, 171, 177, 234))) {
				continue;
			}

			$comboStatusAnalise[$key] = $value;

			if ($key == 169) {
				$comboStatusAnalise['170,171,177'] = "Em análise";
			}
		}

		asort($comboStatusAnalise);

		return $comboStatusAnalise;
	}

	public function populate(array $values) {
		parent::populate($values);
	}
}