<?php
/**
 * Description of NivelForm
 *
 * @author carlos
 */

class CustomerRewardsForm extends Form {

    public function __construct() {
        $this->setActionForm('CustomerRewards.php');
        $this->setName('customerrewards');
        $this->setClass('customerrewards');
        $this->setMethod('post');
        $this->setDefaultFormElementsColSize(7);
        $this->setDefaultFormLabelsColSize(5);
        parent::__construct();
        $this->init();
    }

    public function init() {       
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Telefono',
            'name' => 'phone',
            'class'=>'_maskPhone',
            'optionals'=>array('maxlength'=>'14'),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Nombre',
            'name' => 'name',
            'required'=> true
        ));
         
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Apellido',
            'name' => 'last_name',
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Email',
            'name' => 'email',
            'required'=> true
        ));
        
         $this->addElement(array(
            'type' => 'select',
            'name' => 'contact_type',
            'label'=>'Medio de contacto',
            'multiOptions'=>array('1'=>'sms','2'=>'email','3'=>'sms / email'),
            'required'=> true
        ));        
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Fecha de nacimiento',
            'name' => 'date_of_birth',
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Fecha de registro',
            'name' => 'creado_fecha',
            'optionals'=>array('readonly'=>true),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'select',
            'name' => 'register_store',
            'label'=>'Sucursal de registro',
            'multiOptions'=>$this->getListStores(),
            'required'=> true
        ));        
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Total puntos',
            'name' => 'rewards_total',
            'optionals'=>array('readonly'=>true),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'text',
            'label'=>'Puntos disponibles',
            'name' => 'rewards',
            'optionals'=>array('readonly'=>true),
            'required'=> true
        ));
        
         $this->addElement(array(
            'type' => 'text',
            'label'=>'Monto disponible',
            'name' => 'acumulated_amount',
            'optionals'=>array('readonly'=>true),
            'required'=> true
        )); 
                      
        $this->addElement(array(
            'type' => 'select',
            'name' => 'status',
            'label'=>'Status',
            'class'=>'select_status_rules',
            'multiOptions' => $this->getListStatus(),
            'required'=> true
        ));
        
        $this->addElement(array(
            'type' => 'button',
            'name' => 'send',
            'value'=> $this->_getTranslation('Terminar'),
            'optionals'=>array(
                'onclick'=>"submit()"),
            'class'=>'btn btn-primary m-t-1 m-b-1'
        ));
        
        $this->addElement(array(
            'type' => 'button',
            'name' => 'cancelar',
            'value'=> $this->_getTranslation('Cancelar'),
            'optionals'=>array(
            'onclick'=>"document.location = '".ROOT_HOST."/Rewards/Controller/CustomerRewards.php'"),
            'class'=>'btn btn-danger m-t-1 m-b-1'
        ));
    }
    
    public function getListStatus(){
        $repository = new CustomerRewardsRepository();
        $list = $repository->getListStatus();
         
        $array = array();
        foreach($list as $key => $value){
            $array[$key] = $value;
        }
        return $array;        
    }
    
   public function getListStores(){
        $repository = new StoreRepository();
        $list = $repository->getListSelectStores();
         
        $array = array();
        foreach($list as $key => $value){
            $array[$key] = $value;
        }
        return $array;            
    }
    
    public function populate($data){
        $tools = new Tools();               
        $data['date_of_birth'] = $tools->setFormatDateToForm($data['date_of_birth']);
        $data['creado_fecha'] = $tools->setFormatDateToForm($data['creado_fecha']);

        parent::populate($data);
    }
}