<?php

/**
 * This is the model class for table "contable.param_bancos".
 *
 * The followings are the available columns in table 'contable.param_bancos':
 * @property integer $id
 * @property integer $clvcuenta
 * @property string $num_cuenta
 * @property boolean $estatus
 * @property boolean $blnborrado
 */
class ParametrosBancos extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'configuracion.param_bancos';
	}

	/**
	 * @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('clvcuenta, num_cuenta', 'numerical', 'integerOnly'=>true),
			array('num_cuenta', 'length', 'max'=>40),
            array('num_cuenta,tipo_cuenta,id_banco', 'required'),
			array('clvcuenta', 'required', 'on'=>'Contabilidad'),
			array('banco', 'required', 'on'=>'Administrativo'),
			array('estatus,num_cuenta,clvcuenta, blnborrado,banco,descripcion,tipo_cuenta,tv_virtual, id_banco', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, clvcuenta, num_cuenta, estatus, blnborrado', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @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(
                'cuenta' => array(self::BELONGS_TO, 'CuentasConsolidada', 'clvcuenta'),
                'idBanco' => array(self::BELONGS_TO, 'Banco', 'id_banco'),
                'estructuraArchivoBancos' => array(self::HAS_MANY, 'EstructuraArchivoBanco', 'id_param_bancos'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{ 
            if ($this->scenario=='create' || $this->scenario=='update'  || $this->scenario=='Contabilidad'  || $this->scenario=='Administrativo'){
                
            return array(
			'id' => 'ID',
			'clvcuenta' => 'Cuenta contable',
			'num_cuenta' => 'N° cuenta bancaria',
			'estatus' => '¿Activar?',
			'tipo_cuenta' => 'Tipo cuenta',
			'descripcion' => 'descripcion',
			'tv_virtual' => 'Visible tienda virtual',
			'banco' => 'Banco',
            'blnborrado' => 'Blnborrado',
			'id_banco' => 'Banco',
		);
                
            }
            else{
            return array(
			'id' => 'ID',
			'clvcuenta' => 'Cuenta contable',
			'num_cuenta' => 'N° cuenta bancaria',
			'estatus' => '¿Está activa?',
			'tipo_cuenta' => 'Tipo cuenta',
			'descripcion' => 'descripcion',
			'tv_virtual' => 'Visible tienda virtual',
			'banco' => 'Banco',
			'blnborrado' => 'Blnborrado',
		);
            }
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->condition ='blnborrado=false';
		$criteria->compare('id',$this->id);
		$criteria->compare('clvcuenta',$this->clvcuenta);
		$criteria->compare('num_cuenta',$this->num_cuenta,true);
		$criteria->compare('estatus',$this->estatus);
		$criteria->compare('blnborrado',$this->blnborrado);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

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