<?php

/**
 * This is the model class for table "retenciones.nomina_mp".
 *
 * The followings are the available columns in table 'retenciones.nomina_mp':
 * @property integer $id
 * @property string $id_asociado
 * @property string $id_txt
 * @property string $monto
 * @property string $fecha_registro
 * @property boolean $blnborrado
 *
 * The followings are the available model relations:
 * @property Asociado $idAsociado
 * @property DatosTxtIntegrado $idTxt
 */
class NominaMp extends CActiveRecord
{
    public $acedula,$anombre,$aapellido;
    public $fecha_registro_range=array();
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'retenciones.nomina_mp';
	}

	/**
	 * @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('fecha_registro', 'required'),
			array('monto', 'length', 'max'=>20),
			array('id_asociado, id_txt, blnborrado', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_asociado, id_txt, monto, fecha_registro, 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(
			'idAsociado' => array(self::BELONGS_TO, 'Asociado', 'id_asociado'),
			'idTxt' => array(self::BELONGS_TO, 'DatosTxtIntegrado', 'id_txt'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_asociado' => 'Id Asociado',
			'id_txt' => 'Id Txt',
			'monto' => 'Monto',
			'fecha_registro' => 'Fecha Registro',
			'blnborrado' => 'Blnborrado',
			'acedula' => 'Cedula',
			'anombre' => 'Nombre',
			'aapellido' => 'Apellido',
			'blnborrado' => 'Blnborrado',
		);
	}

	/**
	 * 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_asociado',$this->id_asociado,true);
		$criteria->compare('id_txt',$this->id_txt,true);
		$criteria->compare('monto',$this->monto,true);
		$criteria->compare('fecha_registro',$this->fecha_registro,true);
		$criteria->compare('blnborrado',$this->blnborrado);

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

		$criteria=new CDbCriteria;
                $criteria->with='idAsociado';
		$criteria->compare('"idAsociado".cedula',$this->acedula);
		$criteria->compare('"idAsociado".nombre',$this->anombre);
		$criteria->compare('"idAsociado".apellidos',$this->aapellido);
		$criteria->compare('id_asociado',$this->id_asociado,true);
		$criteria->compare('id_txt',$this->id_txt,true);
		$criteria->compare('monto::TEXT',$this->monto,true);
		$criteria->compare('fecha_registro',$this->fecha_registro,true);
		$criteria->compare('blnborrado',$this->blnborrado);

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