<?php

class Regulacao_Form_Lf032ItemSegurado extends Sinistro2_Form_LaudoFinalItemSegurado {
    public function init($idLaudoFinal = null) {
        
        $dados = $this->getDados();
        
        $ModelLaudosFinais = new Sinistro2_Model_LaudosFinais();
        $arItensSegurados  = $ModelLaudosFinais->getItensSeguradosLaudoFinal($dados['id_proposta'], $dados['id_cobertura'], $dados['id_vistoria'], $dados['id_laudo_final']);
        
        parent::init($idLaudoFinal);
        
        $this->addElement('hidden', 'id_cultura', array(
            'decorators' => $this->hiddendecorator,
            'order' => 69
        ));
        
        $this->addElement('hidden', 'id_item_segurado', array(
            'decorators' => $this->elementDecorator,
            'order' => 4
        ));
        
        $this->addElement('text', 'ds_coordenadas_geograficas', array(
            'decorators' => $this->elementLabellessDecorator,
            'class' => 'coordenadas',
            'label' => 'Coordenadas Geográficas',
            'size' => 26,
            'required' => false,
            'ignore' => $this->getReadOnly(),
            'readonly' => $this->getReadOnly()
        ));
        
        $this->addElement('text', 'vl_percent_colhido', array(
            'decorators' => $this->elementLabellessDecorator,
            'class' => 'decimal',
            'label' => 'Percentual Colhido',
            'required' => false,
            'ignore' => $this->getReadOnly(),
            'readonly' => $this->getReadOnly()
        ));
        
        foreach ($arItensSegurados as $item_segurado) {
            $id_item = $item_segurado['id_item_segurado'];
            $nr_item = $item_segurado['nr_item_segurado'];
            $vl_area = $item_segurado['vl_area'];
            
            $this->addElement('radio', 'fl_floracao_'.$id_item, array(
                'MultiOptions' => array('pre'=>' Pré-Floração','pos'=>' Pós-Floração'),
                'decorators' => $this->elementDecorator,
                'disableLoadDefaultDecorators' => true,
                'separator'=>'',
                //'label' => 'Fase de floração',
                'required' => false,
                //'ignore' => $this->getReadOnly(),
                //'readonly' => $this->getReadOnly(),
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $this->addElement('radio', 'fl_indenizacao_fitossanitaria_'.$id_item, array(
                'MultiOptions' => array(1=>' Sim',0=>' Não'),
                'decorators' => $this->elementDecorator,
                'disableLoadDefaultDecorators' => true,
                'separator'=>'',
                //'label' => 'Concessão à cobertura de Proteção Fitossanitária Pós Granizo',
                'required' => false,
                'ignore' => $this->getReadOnly(),
                'readonly' => $this->getReadOnly(),
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $this->addElement('text', 'vl_percent_colhido_'.$id_item, array(
                'decorators' => $this->elementLabellessDecorator,
                'class' => 'decimal',
                'label' => 'Percentual Colhido',
                'required' => false,
                'ignore' => $this->getReadOnly(),
                'readonly' => $this->getReadOnly(),
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $this->addElement('text', 'ds_coordenadas_geograficas_'.$id_item, array(
                'decorators' => $this->elementLabellessDecorator,
                'class' => 'coordenadas',
                'label' => 'Coordenadas Geográficas',
                'size' => 26,
                'required' => false,
                'ignore' => $this->getReadOnly(),
                'readonly' => $this->getReadOnly(),
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $Estadio = new Sinistro2_Model_EstadiosFenologicos();
            $this->addElement('select', 'id_estadio_fenologico_'.$id_item, array(
                'MultiOptions' => $Estadio->fetchPairs('id', 'ds_nome_estadio_fenologico', false, false, 1, 'id_grupo_estadio_fenologico = 1', true, 'ASC'),
                'decorators' => $this->elementDecorator,
                //'label' => 'Estádio Fenológico',
                'required' => true,
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $this->addElement('text', 'nr_amostras_'.$id_item, array(
                'decorators' => $this->elementDecorator,
                'disableLoadDefaultDecorators' => true,
                'maxlength'=>4,
                'class'=>'integer',
                'size'=>5,
                'required' => true,
                'ignore' => $this->getReadOnly(),
                'readonly' => $this->getReadOnly()
            ));
            
            $this->addElement('hidden', 'vl_area_sinistrada_'.$id_item, array(
                'decorators' => $this->hiddendecorator,
                'belongsTo' => 'ItemSegurado['.$id_item.']',
                'value' => $vl_area
            ));
            
            $this->addElement('hidden', 'nr_item_segurado_'.$id_item, array(
                'decorators' => $this->hiddendecorator,
                'belongsTo' => 'ItemSegurado['.$id_item.']',
                'value' => $nr_item
            ));
            
            $this->addElement('checkbox', 'fl_nao_vistoriada_'.$id_item, array(
                'decorators' => $this->elementNaoVistoriadaDecorator,
                //'label'      => 'Item não vistoriado',
                'order' => 10,
                'class' => 'ctrl-nao-vistoriada',
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $Model_MotivosQuadraNaoVistoriada = new Sinistro2_Model_MotivosQuadraNaoVistoriada();
            $this->addElement('select', 'id_motivo_quadra_nao_vistoriada_'.$id_item, array(
                'MultiOptions' => $Model_MotivosQuadraNaoVistoriada->getOptions(),
                'decorators' => $this->elementDecorator,
                'label' => 'Motivo:',
                'class' => 'ctrl-nao-vistoriada',
                'belongsTo' => 'ItemSegurado['.$id_item.']'
            ));
            
            $count = 0;
            while ($count <= 100) {
                $this->addElement('text', 'nr_cachos_percent_perda_'.$count.'_'.$id_item, array(
                    'decorators' => $this->elementDecorator,
                    'disableLoadDefaultDecorators' => true,
                    'maxlength'=>4,
                    'class'=>'integer',
                    'size'=>5,
                    'ignore' => $this->getReadOnly(),
                    'readonly' => $this->getReadOnly(),
                    'belongsTo' => 'ItemSegurado['.$id_item.']'
                ));
                
                if ($count < 10) {
                    $count += 5;
                } else {
                    $count += 10;
                }
            }
            
        }
    }
}
