<?php

/**
 * This is the model class for table "retenciones.pagos_adicionales".
 *
 * The followings are the available columns in table 'retenciones.pagos_adicionales':
 * @property integer $id
 * @property string $id_txt
 * @property integer $tipo_aporte
 * @property string $monto_adicional
 * @property string $fecha_transaccion
 * @property string $fecha_registro
 * @property boolean $blnborrado
 * @property integer $usuario
 *
 * The followings are the available model relations:
 * @property DatosTxtIntegrado $idTxt
 * @property TipoAporteDiferido $tipoAporte
 */
class PagosAdicionales extends CActiveRecord
{
	public $desc;

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'retenciones.pagos_adicionales';
	}

	/**
	 * @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('id_txt, monto_adicional, usuario', 'required'),
			array('tipo_aporte, usuario', 'numerical', 'integerOnly'=>true),
			array('monto_adicional', 'length', 'max'=>20),
			array('fecha_transaccion, fecha_registro, blnborrado', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_txt, tipo_aporte, monto_adicional, fecha_transaccion, fecha_registro, blnborrado, usuario', '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(
			'idTxt' => array(self::BELONGS_TO, 'DatosTxtIntegrado', 'id_txt'),
			'tipoAporte' => array(self::BELONGS_TO, 'TipoAporteDiferido', 'tipo_aporte'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_txt' => 'Id Txt',
			'tipo_aporte' => 'Tipo Aporte',
			'monto_adicional' => 'Monto Adicional',
			'fecha_transaccion' => 'Fecha Transaccion',
			'fecha_registro' => 'Fecha Registro',
			'blnborrado' => 'Blnborrado',
			'usuario' => 'Usuario',
			'desc' => 'Descripción',
		);
	}

	/**
	 * 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->compare('id',$this->id);
		$criteria->compare('id_txt',$this->id_txt);
		$criteria->compare('tipo_aporte',$this->tipo_aporte);
		$criteria->compare('monto_adicional',$this->monto_adicional);
		$criteria->compare('fecha_transaccion',$this->fecha_transaccion);
		$criteria->compare('fecha_registro',$this->fecha_registro);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('usuario',$this->usuario);

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

	public function searchExcedente($idtxt)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_txt',$idtxt);
		$criteria->compare('tipo_aporte',$this->tipo_aporte);
		$criteria->compare('monto_adicional',$this->monto_adicional);
		$criteria->compare('fecha_transaccion',$this->fecha_transaccion);
		$criteria->compare('fecha_registro',$this->fecha_registro);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('usuario',$this->usuario);

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