<?php

/**
 * This is the model class for table "sidcai_rechazar_pago".
 *
 * The followings are the available columns in table 'sidcai_rechazar_pago':
 * @property integer $rech_codigo_pk
 * @property string $rech_descripcion
 * @property boolean $rech_habilitado
 */
class SidcaiRechazarPago extends CActiveRecord{
	/**
	 * @return string the associated database table name
	 */
	public function tableName(){
		return 'sidcai_rechazar_pago';
	}

	/**
	 * @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('rech_descripcion', 'required'),
			array('rech_descripcion', 'length', 'max'=>255),
			array('rech_habilitado', '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(
			'rech_codigo_pk' => 'Código',
			'rech_descripcion' => 'Descripción',
			'rech_habilitado' => 'Habilitado',
		);
	}


	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return SidcaiRechazarPago the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * Obtiene todas las Errores de los Recaudos que pueden ser rechazados.
	 */
	public static function getRechazos(){
		Yii::import('application.controllers.FuncionesController');

		if(FuncionesController::permitirPerfil([3, 4])){
			$concatenar = " AND rech_codigo_pk = 1 OR rech_codigo_pk = 2 OR rech_codigo_pk = 5";
		}elseif(FuncionesController::permitirPerfil([5, 6])){
			$concatenar = " AND rech_codigo_pk = 1 OR rech_codigo_pk = 2 OR rech_codigo_pk = 4 OR rech_codigo_pk = 5";
		}else{
			$concatenar = "";
		}

		$sql = "SELECT * FROM sidcai_rechazar_pago WHERE rech_habilitado = TRUE $concatenar";
		$errores = Yii::app()->db->createCommand($sql)->queryAll();

		return CHtml::listData($errores, 'rech_codigo_pk', 'rech_descripcion');


		// $errores = SidcaiRechazarPago::model()->findAll(
		// 	array(
		// 		'condition' => 'rech_habilitado = :rech_habilitado',
		// 		'params' => array(':rech_habilitado' => true),
		// 		'order' => 'rech_descripcion',
		// 	)
		// );

		// return CHtml::listData($errores, 'rech_codigo_pk', 'rech_descripcion');

	}
}
