<?php

/**
 * This is the model class for table "pagos.orden_pago_seguimiento".
 *
 * The followings are the available columns in table 'pagos.orden_pago_seguimiento':
 * @property integer $id
 * @property string $id_estatus_orden_pago
 * @property string $id_orden_pago
 * @property string $fecha_registro
 * @property boolean $actual
 * @property string $id_usuario
 * @property string $observacion
 *
 * The followings are the available model relations:
 * @property EstatusOrdenPago $idEstatusOrdenPago
 * @property OrdenPago $idOrdenPago
 */
class OrdenPagoSeguimiento extends CActiveRecord
{
	public $num_comprobante, $idBanco;
	 public $datosUsuario, $nombre_estatus;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pagos.orden_pago_seguimiento';
	}

	/**
	 * @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('num_comprobante, idBanco,fecha_registro', 'required','on'=>'pagar'),
			array('fecha_registro', 'required','on'=>'aprobar'),
			array('observacion', 'required','on'=>'denegar'),
			array('fecha_registro, actual, id_usuario, observacion', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_estatus_orden_pago, id_orden_pago, fecha_registro, actual, id_usuario, observacion', '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(
			'idEstatusOrdenPago' => array(self::BELONGS_TO, 'EstatusOrdenPago', 'id_estatus_orden_pago'),
			'idOrdenPago' => array(self::BELONGS_TO, 'OrdenPago', 'id_orden_pago'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_estatus_orden_pago' => 'Id Estatus Orden Pago',
			'id_orden_pago' => 'Id Orden Pago',
			'fecha_registro' => 'Fecha Registro',
			'actual' => 'Actual',
			'id_usuario' => 'Id Usuario',
			'observacion' => 'Observacion',
			'idBanco' => 'Banco',
		);
	}

	/**
	 * 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($id)
	{
		// @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_estatus_orden_pago',$this->id_estatus_orden_pago,true);
		$criteria->compare('id_orden_pago',$id);
		$criteria->compare('fecha_registro',$this->fecha_registro,true);
		$criteria->compare('actual',$this->actual);
		$criteria->compare('id_usuario',$this->id_usuario,true);
		$criteria->compare('observacion',$this->observacion,true);
		$criteria->order='id desc';
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function afterFind(){
            
            if($this->idEstatusOrdenPago){
                $this->nombre_estatus = $this->idEstatusOrdenPago->descripcion;
                 if($this->id_estatus_orden_pago==1)$color='#0040FF';
                 else if($this->id_estatus_orden_pago==2)$color='#DF7401';
                 else if($this->id_estatus_orden_pago==3)$color='#088A85';
                 else if($this->id_estatus_orden_pago==4)$color='#8A0808';
                 else if($this->id_estatus_orden_pago==5)$color='#088A08';
                 else $color='#000000';
                 $this->nombre_estatus =  '<span style="color:'.$color.'">'. $this->idEstatusOrdenPago->descripcion.'</span>';
                 
            }
            if($this->id_usuario!=''){
                $model = CrugeUserI::model()->findByPk($this->id_usuario);
                if($model){
                    $this->datosUsuario= $model->cedula.' '.$model->nombres.' '.$model->apellidos;
                }
            }
            
            
            return parent::afterFind();
        }

	public function beforeSave() {
			if($this->fecha_registro=='')
                $this->fecha_registro= date('d-m-Y H:m:s');
            $this->id_usuario = Yii::app()->user->id;
            return parent::beforeSave();            
        }
	/**
	 * 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 OrdenPagoSeguimiento the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
