<?php

/**
 * This is the model class for table "retiro.detalle_pagos".
 *
 * The followings are the available columns in table 'retiro.detalle_pagos':
 * @property integer $id
 * @property string $id_liquidacion
 * @property string $id_retiro
 * @property boolean $comprobado
 * @property boolean $blnborrado
 * @property string $id_pagos
 * @property string $id_credito
 *
 * The followings are the available model relations:
 * @property Liquidacion $idLiquidacion
 * @property ConfRetiroParcial $idRetiro
 * @property PagosMasivos $idPagos
 * @property Credito $idCredito
 */
class DetallePagos extends CActiveRecord
{
    
        public $liq_cedula;
        public $liq_nombre;
        public $liq_apellido;
        public $liq_monto;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'retiro.detalle_pagos';
	}

	/**
	 * @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_liquidacion, id_retiro, comprobado, blnborrado, id_pagos', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_liquidacion, id_retiro, comprobado, blnborrado, id_pagos', '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(
			'idLiquidacion' => array(self::BELONGS_TO, 'Liquidacion', 'id_liquidacion'),
			'idRetiro' => array(self::BELONGS_TO, 'RetiroParcial', 'id_retiro'),
			'idPagos' => array(self::BELONGS_TO, 'PagosMasivos', 'id_pagos'),
                        'idCredito' => array(self::BELONGS_TO, 'Credito', 'id_credito'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_liquidacion' => 'Id Liquidacion',
			'id_retiro' => 'Id Retiro',
			'comprobado' => 'Comprobado',
			'blnborrado' => 'Blnborrado',
			'id_pagos' => 'Id Pagos',
			'liq_cedula' => 'Cédula',
			'liq_nombre' => 'Nombre',
			'liq_apellido' => 'Apellido',
			'liq_monto' => 'Monto a Pagar',
		);
	}

	/**
	 * 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($tipo_pago)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with='idPagos';
                $criteria->together=TRUE; 
		$criteria->compare('id',$this->id);
		$criteria->compare('id_liquidacion',$this->id_liquidacion,true);
		$criteria->compare('id_retiro',$this->id_retiro,true);
		$criteria->compare('comprobado',$this->comprobado);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('id_pagos',$this->id_pagos,true);
		$criteria->addCondition('"idPagos".id_tipo_pago='.$tipo_pago);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        /**
         * 
         * @return \CActiveDataProvider
         */
	public function searchLiquidaciones($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with='idPagos';
                $criteria->together=TRUE; 
		$criteria->compare('id',$this->id);
		$criteria->compare('id_liquidacion',$this->id_liquidacion,true);
		$criteria->compare('id_retiro',$this->id_retiro,true);
		$criteria->compare('comprobado',$this->comprobado);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('id_pagos',$id);
		//$criteria->addCondition('"idPagos".id_tipo_pago='.$tipo_pago);
		$criteria->addCondition('id_liquidacion IS NOT NULL');

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function searchRetiros($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with='idPagos';
                $criteria->together=TRUE; 
		$criteria->compare('id',$this->id);
		$criteria->compare('id_liquidacion',$this->id_liquidacion,true);
		$criteria->compare('id_retiro',$this->id_retiro,true);
		$criteria->compare('comprobado',$this->comprobado);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('id_pagos',$id);
		$criteria->addCondition('id_retiro IS NOT NULL');

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function searchCreditos($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with='idPagos';
                $criteria->together=TRUE; 
		$criteria->compare('id',$this->id);
		$criteria->compare('id_liquidacion',$this->id_liquidacion,true);
		$criteria->compare('id_retiro',$this->id_retiro,true);
		$criteria->compare('comprobado',$this->comprobado);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('id_pagos',$id);
		$criteria->addCondition('id_credito IS NOT NULL');

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