<?php

/**
 * This is the model class for table "prestamos.cobro_diferencial_cuota".
 *
 * The followings are the available columns in table 'prestamos.cobro_diferencial_cuota':
 * @property integer $id
 * @property string $id_proceso
 * @property integer $id_nombre_proceso
 * @property string $total_cobro
 * @property string $capital_pagado
 * @property string $interes_pagado
 * @property string $capital_cobro
 * @property string $interes_cobro
 * @property boolean $blnborrado
 */
class CobroDiferencialCuota extends CActiveRecord
{
	public $id_estatus,$nombre_estatus, $fecha_estatus;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'prestamos.cobro_diferencial_cuota';
	}

	/**
	 * @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_nombre_proceso', 'numerical', 'integerOnly'=>true),
			array('total_cobro, capital_pagado, interes_pagado, capital_cobro, interes_cobro', 'numerical'),
			array('id_proceso, blnborrado', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_estatus, id_proceso, id_nombre_proceso, total_cobro, capital_pagado, interes_pagado, capital_cobro, interes_cobro, 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(
			'idCobroSeguimientoActual' => array(self::HAS_MANY, 'CobroDiferencialCuotaSeguimiento', 'id_cobro_diferencial_cuota', 'condition'=>'actual=true'), 
			'idTipoProceso' => array(self::BELONGS_TO, 'CobroDiferencialTipoProceso', 'id_nombre_proceso'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_proceso' => 'Id Proceso',
			'id_nombre_proceso' => 'Tipo de proceso',
			'total_cobro' => 'Total Cobro',
			'capital_pagado' => 'Capital Pagado',
			'interes_pagado' => 'Interes Pagado',
			'capital_cobro' => 'Capital Cobro',
			'interes_cobro' => 'Interes Cobro',
			'blnborrado' => 'Blnborrado',
			'id_estatus' => 'Estatus',
		);
	}

	/**
	 * 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_proceso',$this->id_proceso,true);
		$criteria->compare('id_nombre_proceso',$this->id_nombre_proceso);
		$criteria->compare('total_cobro',$this->total_cobro,true);
		$criteria->compare('capital_pagado',$this->capital_pagado,true);
		$criteria->compare('interes_pagado',$this->interes_pagado,true);
		$criteria->compare('capital_cobro',$this->capital_cobro,true);
		$criteria->compare('interes_cobro',$this->interes_cobro,true);
		$criteria->compare('blnborrado',$this->blnborrado);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function afterFind(){
            $model = $this->idCobroSeguimientoActual();
            if($model){
                $this->nombre_estatus = $model[0]->idEstatusCobro->descripcion;
                $this->id_estatus = $model[0]->id_estatus_cobro_cuota;
                $this->fecha_estatus = $model[0]->fecha_registro;
            }
            /*$model = CreditoSeguimiento::model()->find('id_credito=:id AND (id_estatus_credito =1 OR id_estatus_credito =6 OR id_estatus_credito =8)',array(':id'=>  $this->id));
            if($model){
                $this->fecha_solicitud = $model->fecha_registro;
                //echo "<pre>";print_r($this->id);exit;
            }*/

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