<?php
class CuotasEspeciales extends CFormModel
{
    public $cuota, $fecha;


	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('fecha', 'required'),
			array('cuota', 'numerical', 'integerOnly'=>true),			
			array('cuota,fecha', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('cuota,fecha', 'safe', 'on'=>'search'),
		);
	}

	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'cuota' => 'Cuota',
			'fecha' => 'Fecha descuento',
		);
	}

        public static function getCuotasEspeciales($id){
            $model =  TipoCredito::model()->findByPk($id);
            $cuotas = array();
            if($model){
                $model->configuracion = json_decode($model->configuracion, true );
                if(is_array($model->configuracion)){  
                  
                    if(array_key_exists('CuotasEspeciales',$model->configuracion)){
                        foreach($model->configuracion['CuotasEspeciales'] as $key=>$value) {
                                 $cuotas[($key-1)] = new CuotasEspeciales();
                                 $cuotas[($key-1)]->fecha = $value;
                        }
                    }                    
                }               
            }
            return $cuotas;
        }
}
