<?php
class AdvancedSearchForm extends Form {

    public function __construct($controller) {      
        $this->setName('advanced_search');
        $this->setActionForm($controller.".php");
        switch($controller){
            case 'Pago':
                $actionController = 'list';
                break;
            default:
                $actionController = '';
                break;
        }
        $this->setActionController($actionController);
        $this->setMethod('post');
        parent::__construct();
        $this->init();
    }

    public function init() {         
        $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' => 'submit',
            'name' => 'search',
            'value'=> $this->_getTranslation('Buscar'),
            'class'=>'btn btn-primary'
        ));
    }
    
     public function getStringFiltersForm($controller){
        $formString = '';
        switch($controller){   
            case 'Compra':
                $compraForm = new PurchaseForm();            
                
                $compraForm->addElement(array('type'=>'select multiple','name'=>'vendor_id','label'=>'Proveedor'));
                $repository = new VendorRepository();
                $result = $repository->getListSelectVendors();

                $array = array('' => 'Seleccionar una opcion...');
                if ($result) {foreach ($result as $key => $value) {$array[$key] = $value;}   }
                $compraForm->setPropiedad('vendor_id', array('multiOptions'=>$array));  
                
                $compraForm->addElement(array('type'=>'select','name'=>'status','label'=>'Status'));                
                $purchaseRepo = new PurchaseRepository();
                $purchaseStatus = $purchaseRepo->getListStatus();         
                $array = array(''=>'Seleccionar una opcion...');
                if($purchaseStatus){foreach($purchaseStatus as $key => $value){$array[$key] = $value;}}          
                $compraForm->setPropiedad('status', array('multiOptions'=>$array));
                
                $formString .= $compraForm->getElementString('vendor_id');                  
                $formString .= $compraForm->getElementString('purchase_number');
                $formString .= $this->getElementString('fechaInicio');
                $formString .= $this->getElementString('fechaFin');
                $formString .= $compraForm->getElementString('status');                        
                
                break;
                
            case 'Pago':
                $pagoForm = new PagoForm();            
                
                $pagoForm->addElement(array('type'=>'select multiple','name'=>'vendor_id','label'=>'Proveedor'));
                $repository = new VendorRepository();
                $result = $repository->getListSelectVendors();

                $array = array('' => 'Seleccionar una opcion...');
                if ($result) {foreach ($result as $key => $value) {$array[$key] = $value;}   }
                $pagoForm->setPropiedad('vendor_id', array('multiOptions'=>$array));  
                
                $pagoForm->addElement(array('type'=>'select','name'=>'status','label'=>'Status'));                
                $pagoRepo = new PagoRepository();
                $purchaseStatus = $pagoRepo->getListStatus();         
                $array = array(''=>'Seleccionar una opcion...');
                if($purchaseStatus){foreach($purchaseStatus as $key => $value){$array[$key] = $value;}}          
                $pagoForm->setPropiedad('status', array('multiOptions'=>$array));
                
                $pagoForm->addElement(array('type'=>'text','name'=>'purchase_number','label'=>'Compra #'));
                
                $formString .= $pagoForm->getElementString('vendor_id');  
                $formString .= $pagoForm->getElementString('purchase_number');                
                $formString .= $pagoForm->getElementString('forma_de_pago');
                $formString .= $pagoForm->getElementString('num_operacion');
                $formString .= $this->getElementString('fechaInicio');
                $formString .= $this->getElementString('fechaFin');
                $formString .= $pagoForm->getElementString('status');                        
                
                break;
        }
        
        return $formString;
    }

}
