<?php

/**
 * This is the model class for table "prestamos.datos_descuento_credito".
 *
 * The followings are the available columns in table 'prestamos.datos_descuento_credito':
 * @property integer $id
 * @property integer $idtrabajador
 * @property integer $idunidad
 * @property double $aportepatrono
 * @property string $fechaaporte
 * @property boolean $blnborrado
 * @property string $fecharegistro
 * @property integer $usuario_registro
 * @property integer $id_dato_txt
 * @property string $tipo_credito
 */
class CreditoDescuentoTxt extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
    
	public function tableName()
	{
		return 'prestamos.datos_descuento_credito';
	}

	/**
	 * @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('idtrabajador, idunidad, usuario_registro, id_dato_txt', 'numerical', 'integerOnly'=>true),
			array('aportepatrono', 'numerical'),
			array('tipo_credito', 'length', 'max'=>1),
			array('fechaaporte, blnborrado,tipo_cuota,nro_cuota,idcredito, fecharegistro', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, idtrabajador, idunidad, aportepatrono, fechaaporte, blnborrado, fecharegistro, usuario_registro, id_dato_txt, tipo_credito', '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(
		//'porcentajes' => array(self::BELONGS_TO, 'Porcentaje', 'id_porcentaje'),
		'trabajador' => array(self::BELONGS_TO, 'Asociado', 'idtrabajador'),
		'unidad' => array(self::BELONGS_TO, 'Unidad', 'idunidad'),
		'datos_txt'=> array(self::BELONGS_TO, 'CreditoTxt', 'id_dato_txt'),
		'tipo_cre' => array(self::BELONGS_TO, 'TipoCredito', 'tipo_credito'),
		
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idtrabajador' => 'Idtrabajador',
			'idunidad' => 'Idunidad',
			'aportepatrono' => 'Aportepatrono',
			'fechaaporte' => 'Fechaaporte',
			'blnborrado' => 'Blnborrado',
			'fecharegistro' => 'Fecharegistro',
			'usuario_registro' => 'Usuario Registro',
			'id_dato_txt' => 'Id Dato Txt',
			'tipo_credito' => 'Tipo Credito',
		);
	}

	/**
	 * 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('idtrabajador',$this->idtrabajador);
		$criteria->compare('idunidad',$this->idunidad);
		$criteria->compare('aportepatrono',$this->aportepatrono);
		$criteria->compare('fechaaporte',$this->fechaaporte,true);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('fecharegistro',$this->fecharegistro,true);
		$criteria->compare('usuario_registro',$this->usuario_registro);
		$criteria->compare('id_dato_txt',$this->id_dato_txt);
		$criteria->compare('tipo_credito',$this->tipo_credito,true);

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