<?php

class Produto_Form_Validacoescapacidade extends Agro_Form {

	public function init() {
        $this->addElement('text', 'id', array(
            'decorators' => $this->elementDecorator,
            'label' => 'ID',
            'required' => false,
            'maxlength' => 10,
            'size' => 10
        ));

		$this->addElement('text', 'ds_nome_grupo', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Nome do Grupo',
			'required' => true,
			'maxlength' => 100,
			'size' => 40
		));

        $this->addElement('text', 'ds_nome_subgrupo', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Nome do Subgrupo',
            'required' => false,
            'maxlength' => 100,
            'size' => 40
        ));

        $this->addElement('text', 'ds_nome_usuario', array(
            'decorators' => $this->elementDecorator,
            'label' => 'Login',
            'required' => false,
            'maxlength' => 40,
            'size' => 30
        ));

		$this->addElement('text', 'vl_limite_capacidade', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Limite Liberado',
			'required' => true,
			'class' => 'currency',
			'maxlength' => 20,
			'size' => 20
		));

    	$this->addElement('checkbox', 'fl_agrupar_municipios', array(
            'MultiOptions' => array(true=>'Sim'),
            'decorators' => $this->elementDecorator,
            'label' => 'Agrupar Municípios?',
        	'required' => true
        ));
    	
    	$this->addElement('radio', 'tipo_corretor_vinculo', array(
    		'MultiOptions' => array('a' => 'Apenas os corretores/prepostos selecionados', 
    								'e' => 'Todos corretores/prepostos, exceto os selecionados', 
    								't' => 'Todos corretores/prepostos'),
    		'decorators' => $this->elementDecorator,
    		'label' => '',
    		'required' => false
    	));

    	$this->addElement('checkbox', 'fl_limite_corretor', array(
            'MultiOptions' => array(true=>'Sim'),
            'decorators' => $this->elementDecorator,
            'label' => 'Limite por Corretor(es)?',
        	'required' => true
        ));

		$Safras = new Produto_Model_Safras();
		$this->addElement('select', 'id_safra', array(
			'MultiOptions' => $Safras->fetchPairs('id', 'ds_nome_safra', false, false, 1, false, true, 'DESC'),
			'decorators' => $this->elementDecorator,
			'label' => 'Safra'
		));

		$this->addElement('select', 'id_safra_search', array(
			'MultiOptions' => $Safras->fetchPairs('id', 'ds_nome_safra', false, false, 1, false, false, 'DESC'),
			'decorators' => $this->elementDecorator,
			'value' => $Safras->safraCurrent,
			'label' => 'Safra',
			'required' => false
		));

		$this->addElement('select', 'fl_ativo', array(
			'MultiOptions' => array(0=>'Não',1=>'Sim'),
			'decorators' => $this->elementDecorator,
			'label' => 'Ativo'
		));

		$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'
		));

        $this->addElement('text', 'vl_reserva_tecnica', array(
          'decorators' => $this->elementDecorator,
          'label' => '% de Reserva Técnica',
          'class' => 'currency',
          'size' => 20
        ));
	}

	public function populate($values) {
		$values['vl_limite_capacidade'] = Agro_Util::formatDbCurrency($values['vl_limite_capacidade']);
        $values['vl_reserva_tecnica'] = !empty($values['vl_reserva_tecnica']) ? $values['vl_reserva_tecnica'] : 0;
        $values['vl_reserva_tecnica'] = Agro_Util::formatDbCurrency($values['vl_reserva_tecnica']);

		parent::populate($values);
	}
}