<?php

class RetiroParcialPrestamo extends CFormModel
{
	public $opcionAdm, $porcentajeAdm, $opcionAs, $porcentajeAs, $descripcion;

	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('opcionAdm', 'validarSeleccion','on'=>'RegistroRetiroParcial'),
			array('porcentajeAdm, porcentajeAs', 'match',  //PARA VALIDAR CAMPOS CON FORMATO MONEDA
					'pattern' => '/^[0-9]\d{0,2}(\.[0-9]\d{2,2})*(\,\d{1,2})?$/',
 					'message' => 'El valor del campo debe tener un formato 100,00',),
			array('porcentajeAdm, porcentajeAs', 'length', 'max'=>6),
			array('opcionAdm, porcentajeAdm, opcionAs, porcentajeAs', 'safe'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idtipopago' => 'Idtipopago',
			'descripcion' => 'Tipo de pago',
			'usuario' => 'Usuario',
			'fecharegistro' => 'Fecharegistro',
			'blnborrado' => 'Blnborrado',
		);
	}

	public function validarSeleccion(){
    	if($this->opcionAdm==1){
    		if($this->porcentajeAdm== '')
    			$this->addError('porcentajeAdm','Debe indicar el porcentaje');
    		else{
    			if($this->porcentajeAdm>100)
    				$this->addError('porcentajeAdm','Monto no permitido');
    		}
    	}
    	else{
    		$this->porcentajeAdm=NULL;
    	}
    	if($this->opcionAs==1){
    		if($this->porcentajeAs== '')
    			$this->addError('porcentajeAs','Debe indicar el porcentaje');
    		else{
    			if($this->porcentajeAdm>100)
    				$this->addError('porcentajeAs','Monto no permitido');
    		}
    	}else{
    		$this->porcentajeAs=NULL;
    	}
    }
}
