<?php

/**
 * This is the model class for table "sidcai_banco".
 *
 * The followings are the available columns in table 'sidcai_banco':
 * @property integer $banc_codigo_pk
 * @property string $banc_ruta
 * @property string $banc_habilitado
 * @property string $banc_nombre
 * @property string $banc_tipo_cuenta
 */
class SidcaiBanco extends CActiveRecord{
	/**
	 * @return string the associated database table name
	 */
	public function tableName(){
		return 'sidcai_banco';
	}

	/**
	 * @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('banc_nombre', 'length', 'max'=>50),
			array('banc_tipo_cuenta', 'length', 'max'=>10),
			array('banc_ruta, banc_habilitado', 'safe'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels(){
		return array(
			'banc_codigo_pk' => 'Banc Codigo Pk',
			'banc_ruta' => 'Banc Ruta',
			'banc_habilitado' => 'Banc Habilitado',
			'banc_nombre' => 'Banc Nombre',
			'banc_tipo_cuenta' => 'Banc Tipo Cuenta',
		);
	}


	/**
	 * 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 SidcaiBanco the static model class
	 */
	public static function model($className=__CLASS__){
		return parent::model($className);
	}

	// Obtiene todos los bancos que son usados para aportes
	public static function bancosAportes(){
		$bancos = SidcaiBanco::model()->findAll(
			array(
				'condition' => 'banc_tipo_cuenta = :banc_tipo_cuenta AND banc_habilitado = :banc_habilitado',
				'params' => array(':banc_tipo_cuenta' => 'APORTES', ':banc_habilitado' => true),
				'order' => 'banc_nombre'
			));
		
		return CHtml::listData($bancos, 'banc_codigo_pk', 'banc_nombre');
	}

	// Obtiene todos los bancos
	public static function bancos_todos(){
		$sql = "SELECT banc_codigo_pk, CONCAT ('(',banc_tipo_cuenta,') ', banc_nombre) AS cuenta FROM sidcai_banco WHERE banc_codigo_pk = 6 OR banc_codigo_pk = 9 OR banc_codigo_pk = 6 OR banc_codigo_pk = 19 OR banc_codigo_pk = 21 OR banc_codigo_pk = 24 OR banc_codigo_pk = 35 OR banc_codigo_pk = 36 OR banc_codigo_pk = 37 OR banc_codigo_pk = 38 OR banc_codigo_pk = 39 OR banc_codigo_pk = 12 ORDER BY banc_tipo_cuenta";
		$banco = Yii::app()->db->createCommand($sql)->queryAll();

		return CHtml::listData($banco, 'banc_codigo_pk', 'cuenta');
	}

	// Obtiene todos los bancos para los Analista
	public static function bancosAportesAnalista(){
		$bancos = SidcaiBanco::model()->findAll(
			array(
				'condition' => 'banc_tipo_cuenta = :banc_tipo_cuenta',
				'params' => array(':banc_tipo_cuenta' => 'APORTES'),
				'order' => 'banc_nombre'
			));

		return CHtml::listData($bancos, 'banc_codigo_pk', 'banc_nombre');
	}

	// Obtiene todos los bancos que son usados para multas
	public static function bancosMultas(){
		$bancos = SidcaiBanco::model()->findAll(
		array(
			'condition' => 'banc_tipo_cuenta = :banc_tipo_cuenta AND banc_habilitado = :banc_habilitado',
			'params' => array(':banc_tipo_cuenta' => 'MULTAS', ':banc_habilitado' => true),
			'order' => 'banc_nombre'
		));
		
		return CHtml::listData($bancos, 'banc_codigo_pk', 'banc_nombre');
	}
}
