<?php
/**
 * Description of LoginForm
 * @author carlos augusto vazquez lara
 */
class ReportForm extends Form {
    public function __construct() {
        $this->setActionForm('Reportes.php');
        $this->setActionController('create');
        $this->setName('reportes');
        $this->setMethod('post');
        $this->setClass('reports');
        parent::__construct();
        $this->init();
        
    }

    public function init() {
        $this->addElement(array(
            'type' => 'hidden',
            'name' => 'reporte',
            'required'=>true
        ));     
        
        $this->addElement(array(
            'type' => 'hidden',
            'name' => 'optionsFromGet',
            'required'=>true
        ));   
        
        $this->addElement(array(
            'type' => 'select multiple',
            'name' => 'vendor_id',
            'label'=>'Proveedor',
            'multiOptions'=>$this->getListaProveedores(),
            'required'=>false
        ));
        
        $append = "<span class = 'btn input-group-addon'><i class='fa fa-calendar'></i></span>";
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'fechaInicio',
            'label'=>'Fecha inicio',
            'required'=>false,
            'append'=>$append,
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'fechaFin',
            'label'=>'Fecha fin',
            'required'=>false,
            'append'=>$append,
        ));
        
        $this->addElement(array(
            'type' => 'select',
            'name' => 'output',
            'label'=>'Bajar reporte',
            //'multiOptions'=>array('excel'=>'Excel','pdf'=>'PDF'),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type'=>'submit',
            'name'=>'enviar',
            'value'=>$this->_getTranslation('Enviar'),
            'class'=>'btn btn-primary'
        ));
        
        /* PARA ENVIAR REPORTES POR CORREO */
        $this->addElement(array(
            'type' => 'text',
            'name' => 'to',
            'label'=>'Para',
            'optionals'=>array('style'=>'width:350px;')
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'cc',
            'label'=>'Copia',
            'optionals'=>array('style'=>'width:350px;')
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'subject',
            'label'=>'Titulo',
            'optionals'=>array('style'=>'width:350px;')
        ));
        
        $this->addElement(array(
            'type' => 'textarea',
            'name' => 'message',
            'label'=>'Mensaje',
            'optionals'=>array('style'=>'width:350px;height:100px')
        ));
        
        
        $this->addElement(array(
            'type'=>'button',
            'name'=>'sendMail',
            'label'=>'',
            'value'=>$this->_getTranslation('Enviar mail'),
            'class'=>'btn btn-primary',
            'optionals'=>array('onclick'=>'sendReportToMail()')
        ));
        
        $this->addElement(array(
            'type' => 'button',
            'name' => 'cerrar',
            'value'=> $this->_getTranslation('Cerrar'),
            'class'=>'btn btn-default',
            'optionals'=>array(
                'data-dismiss'=>'modal',
                'aria-hidden'=>'true',
                ),
            'col-size-element'=>'12',
        ));
    }     
    
    public function getListaProveedores(){            
        $repository = new VendorRepository();
        $result = $repository->getListSelectVendors();
        
         $array = array(''=>'Seleccionar una opcion...');
        if ($result) {            
            foreach ($result as $key => $value) {
                $array[$key] = $value;
            }
        }
        return $array;
    }
    
    public function getStringFiltersForm($report){
        $formString = '';
        switch($report){   
            case 'cuentas_por_pagar':
                $this->setPropiedad('output', array('multiOptions'=>array('screen'=>'Pantalla','excel'=>'Excel')));
                
                $formString .= $this->getElementString('vendor_id');
                $formString .= $this->getElementString('fechaInicio');
                $formString .= $this->getElementString('fechaFin');
                $formString .= $this->getElementString('output');             
                
                break;
            
            case 'cuentas_por_pagar_detalles':
                $this->setPropiedad('output', array('multiOptions'=>array('screen'=>'Pantalla','excel'=>'Excel')));
                
                $formString .= $this->getElementString('vendor_id');
                $formString .= $this->getElementString('fechaInicio');
                $formString .= $this->getElementString('fechaFin');
                $formString .= $this->getElementString('output');             
                
                break;
        }
        
        return $formString;
    }
}