<?php

/**
 * This is the model class for table "prestamos.v_descuentos_credito".
 *
 * The followings are the available columns in table 'prestamos.v_descuentos_credito':
 * @property integer $id
 * @property integer $idtrabajador
 * @property integer $idunidad
 * @property double $monto_cuota
 * @property integer $tipo_credito
 * @property boolean $blnborrado
 * @property string $fecharegistro
 * @property integer $usuario_registro
 * @property integer $id_dato_txt
 * @property string $tipo_nomina
 * @property integer $idcredito
 * @property integer $nro_cuota
 * @property double $amortizacion
 * @property double $monto_interes
 * @property double $cuota
 */
class VDescuentosCredito extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'prestamos.v_descuentos_credito';
	}
        
        public function primaryKey()
	{
		return 'id';
	}

	/**
	 * @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, idtrabajador, idunidad, tipo_credito, usuario_registro, id_dato_txt, idcredito, nro_cuota', 'numerical', 'integerOnly'=>true),
			array('monto_cuota, amortizacion, monto_interes, cuota', 'numerical'),
			array('tipo_nomina', 'length', 'max'=>1),
			array('blnborrado, fecharegistro', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, idtrabajador, idunidad, monto_cuota, tipo_credito, blnborrado, fecharegistro, usuario_registro, id_dato_txt, tipo_nomina, idcredito, nro_cuota, amortizacion, monto_interes, cuota', '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(
            	'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',
			'monto_cuota' => 'Monto Cuota',
			'tipo_credito' => 'Tipo Credito',
			'blnborrado' => 'Blnborrado',
			'fecharegistro' => 'Fecharegistro',
			'usuario_registro' => 'Usuario Registro',
			'id_dato_txt' => 'Id Dato Txt',
			'tipo_nomina' => 'Tipo Nomina',
			'idcredito' => 'Idcredito',
			'nro_cuota' => 'Nro Cuota',
			'amortizacion' => 'Amortizacion',
			'monto_interes' => 'Monto Interes',
			'cuota' => 'Cuota',
		);
	}

	/**
	 * 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('monto_cuota',$this->monto_cuota);
		$criteria->compare('tipo_credito',$this->tipo_credito);
		$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_nomina',$this->tipo_nomina,true);
		$criteria->compare('idcredito',$this->idcredito);
		$criteria->compare('nro_cuota',$this->nro_cuota);
		$criteria->compare('amortizacion',$this->amortizacion);
		$criteria->compare('monto_interes',$this->monto_interes);
		$criteria->compare('cuota',$this->cuota);

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