<?php

class Seguro_Form_Cotacao extends Agro_Form
{
    public function init()
    {
        $corretores = new Sistema_Model_Corretores();
        $prepostos = new Sistema_Model_Prepostos();
        $auth = Zend_Auth::getInstance()->getIdentity();

        $this->addElement('hidden', 'id_estado', array(
            'decorators' => $this->buttonDecorator
        ));

        $this->addElement('hidden', 'id_municipio', array(
            'decorators' => $this->buttonDecorator
        ));

        switch ($auth->tp_usuario) {
            case 'C':
                $this->addElement(
                    'hidden',
                    'id_corretor_search',
                    array('decorators' => $this->buttonDecorator, 'value' => $auth->id)
                );

                $this->addElement('select', 'id_preposto_search', array(
                    'decorators' => $this->elementDecorator,
                    'label' => 'Login',
                    'MultiOptions' => $prepostos->getComboUsuario($auth->id)
                ));
                break;
            case 'P':
                $this->addElement(
                    'hidden',
                    'id_preposto_search',
                    array('decorators' => $this->buttonDecorator, 'value' => $auth->id)
                );

                $preposto = $prepostos->fetchRow('id_usuario = ' . $auth->id);
                $corretor = $preposto->corretor();

                $this->addElement(
                    'hidden',
                    'id_corretor_search',
                    array('decorators' => $this->buttonDecorator, 'value' => $corretor->id_usuario)
                );
                break;
            default:
                $this->addElement('select', 'id_corretor_search', array(
                    'MultiOptions' => $corretores->getComboUsuario(),
                    'decorators' => $this->elementDecorator,
                    'label' => 'Corretor',
                    'required' => true
                ));

                $this->addElement('select', 'id_preposto_search', array(
                    'decorators' => $this->elementDecorator,
                    'label' => 'Login'
                ));
        }

        $this->addElement('select', 'id_corretor', array(
            'MultiOptions' => $corretores->getComboUsuario(),
            'decorators' => $this->elementDecorator,
            'label' => 'Corretor',
            'required' => true
        ));

        $this->addElement('select', 'id_preposto', array(
            'decorators' => $this->elementDecorator,
            'MultiOptions' => ['' => '--- Selecione um Corretor ---'],
            'label' => 'Login'
        ));

        $this->addElement('select', 'id_produto', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Produto',
            'MultiOptions' => ['' => '--- Selecione um Corretor ---'],
            'required' => true
        ));

        $this->addElement('select', 'tp_pessoa', array(
            'MultiOptions' => array('' => '', 'F' => 'FÍSICA', 'J' => 'JURÍDICA'),
            'decorators' => $this->elementDecorator,
            'label' => 'Tipo Pessoa',
            'required' => true
        ));

        $this->addElement('text', 'cpf_cnpj', array(
            'decorators' => $this->elementDecorator,
            'label' => 'CPF/CNPJ',
            'class' => 'cpf_cnpj',
            'required' => true,
            'maxlength' => 18,
            'size' => 19,
            'disabled' => 'disabled'
        ));

        $this->addElement('text', 'ds_nome_proponente', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Nome Proponente',
            'required' => true,
            'maxlength' => 100,
            'size' => 70,
            'disabled' => 'disabled'
        ));

        $this->addElement('text', 'ds_cep', array(
            'decorators' => $this->elementDecorator,
            'label' => 'CEP da Propriedade',
            'class' => 'cep',
            'maxlength' => 10,
            'size' => 10,
            'required' => true,
        ));

        $this->addElement('text', 'ds_estado', array(
            'decorators' => $this->elementDecorator,
            'label' => 'UF',
            'class' => 'upper',
            'maxlength' => 2,
            'size' => 2,
            'disabled' => 'disabled'
        ));

        $this->addElement('text', 'ds_municipio', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Município',
            'class' => '',
            'maxlength' => 255,
            'size' => 110,
            'disabled' => 'disabled'
        ));

        $this->addElement('text', 'vl_area', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Área',
            'required' => true,
            'size' => 10,
            'class' => 'currency'
        ));

        $this->addElement('text', 'vl_produtividade', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Produtividade',
            'required' => true,
            'size' => 12,
            'class' => 'decimal3casas'
        ));

        $this->addElement('text', 'vl_tonelada', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Valor Tonelada',
            'required' => true,
            'size' => 14,
            'class' => 'currency'
        ));

        $safras = new Relatorio_Model_Safras();
        $this->addElement('select', 'id_safra_search', array(
            'decorators' => $this->elementDecorator,
            'MultiOptions' => $safras->getCombo(),
            'value' => $safras->safraCurrent,
            'label' => 'Safra',
            'required' => true
        ));

        $this->addElement('select', 'id_produto_search', array(
            'decorators' => $this->elementDecorator,
            'MultiOptions' => (new Produto_Model_Safras())->getComboProdutoSafraRequest($safras->safraCurrent),
            'label' => 'Produto'
        ));

        $this->addElement('select', 'id_estado_search', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Estado',
            'MultiOptions' => (new Sistema_Model_Estados())->getCombo()
        ));

        $this->addElement('select', 'id_municipio_search', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Municípios',
        ));

        $this->addElement('text', 'numero_cotacao_search', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Número da cotação'
        ));

        $this->addElement('text', 'cpf_cnpj_search', array(
            'decorators' => $this->elementDecorator,
            'label' => 'CPF/CNPJ',
            'class' => 'cpf_cnpj',
            'maxlength' => 18,
            'size' => 19
        ));
    }
}
