<?php
/**
 * Description of LoginForm
 * @author carlos augusto vazquez lara
 */
class RewardsReportsForm extends Form {
    public function __construct() {
        $this->setActionForm('RewardsReports.php');
        $this->setActionController('create');
        $this->setName('reportes');
        $this->setMethod('post');
        $this->setDefaultFormLabelsColSize(4);
        $this->setDefaultFormElementsColSize(8);
        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
        ));   
        
        $attributes_wrapper_append_date = array('class'=>'date','id'=>'fechaDatePicker');
        $append = "<span class = 'btn input-group-addon'><i class='fa fa-calendar'></i></span>";
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'startDate',
            'label'=>'Fecha inicio',
            'required'=>false,
            'append'=>$append,
            'wrapper_attributes'=>$attributes_wrapper_append_date
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'name' => 'endDate',
            'label'=>'Fecha fin',
            'required'=>false,
            'append'=>$append,
            'wrapper_attributes'=>$attributes_wrapper_append_date
        ));
        
         $this->addElement(array(
            'type' => 'select',
            'name' => 'store_id',
            'label'=>'Sucursal',
            'required'=>false,
            'append'=>$append,
            'wrapper_attributes'=>$attributes_wrapper_append_date
        ));
        
        $this->addElement(array(
            'type' => 'select',
            'name' => 'output',
            'label'=>'Bajar reporte',
            'required'=> true
        ));
        
         $this->addElement(array(
            'type'=>'submit',
            'name'=>'enviar',
            'value'=>'Enviar',
            'class'=>'btn btn-lg btn-primary'
        ));
         
          
        $this->addElement(array(
            'type' => 'button',
            'name' => 'cerrar',
            'value'=> $this->_getTranslation('Cerrar'),
            'class'=>'btn btn-default btn-lg',
            'optionals'=>array(
                'data-dismiss'=>'modal',
                'aria-hidden'=>'true',
                ),
            'col-size-element'=>'12',
        ));
        
    }
    
     public function getListSucursales(){
        $login = new Login();
        $repository = new SucursalRepository();
        $list = $repository->getListSelectSucursales();
         
        $array = array();
        if($login->getRole() == 2){
            foreach($list as $key => $value){
                if($login->getSucursal() == $key){$array[$key] = $value;}                
            }
        }else{
            foreach($list as $key => $value){
                $array[$key] = $value;
            }
        }
        
        return $array;            
    }
    
     public function getStringFiltersForm($report){
        $formString = '';
        switch($report){                      
            case 'sales_by_customer_grouped_by_product':
                $this->setPropiedad('output', array('multiOptions'=>array('excel'=>'Excel')));
                                
               // $formString .= $this->getElementString('store_id');                
                $formString .= $this->getElementString('startDate');
                $formString .= $this->getElementString('endDate');
                $formString .= $this->getElementString('output');             
                
                break;            
        }
        
        return $formString;
    }
}