<?php

/**
 * This is the model class for table "aportes_funerario".
 *
 * The followings are the available columns in table 'aportes_funerario':
 * @property integer $id
 * @property integer $idtrabajador
 * @property integer $idunidad
 * @property double $aporte
 * @property boolean $blnborrado
 * @property string $fecharegistro
 * @property integer $usuario_registro
 * @property integer $id_dato_txt_funerario
 */
class AportesFunerario extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'aportes_funerario';
	}
     public $banco; 
     public $referencia; 
     public $observacion;
	/**
	 * @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('idtrabajador, idunidad, usuario_registro, id_dato_txt_funerario', 'numerical', 'integerOnly'=>true),
			array('aporte', 'numerical'),
			array('blnborrado, fecharegistro', 'safe'),
                               array('banco,referencia', 'required', 'on' => 'pagar_form'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('txt,banco,referencia,aprob_migrad,observacion','safe'),
                        array('txt', 'file', 'types' => 'csv,txt', 'maxSize'=>5242880, 'allowEmpty' => true, 'wrongType'=>'Solo se permiten archivos csv.', 'tooLarge'=>'El archivo es demasiado grande! 5MB es el limite'),
			array('id, idtrabajador, idunidad, aporte, blnborrado, fecharegistro, usuario_registro, id_dato_txt_funerario', '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, 'DatosTxt', 'id_dato_txt'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idtrabajador' => 'Idtrabajador',
			'idunidad' => 'Idunidad',
			'aporte' => 'Aporte',
			'blnborrado' => 'Blnborrado',
			'fecharegistro' => 'Fecharegistro',
			'usuario_registro' => 'Usuario Registro',
			'id_dato_txt_funerario' => 'Id Dato Txt Funerario',
		);
	}

	/**
	 * 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('aporte',$this->aporte);
		$criteria->compare('blnborrado',$this->blnborrado);
		$criteria->compare('fecharegistro',$this->fecharegistro,true);
		$criteria->compare('usuario_registro',$this->usuario_registro);
		$criteria->compare('id_dato_txt_funerario',$this->id_dato_txt_funerario);

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

      public function behaviors()
	{
	    return array(
		    // Classname => path to Class
		    'ActiveRecordLogableBehavior'=>
		    	'application.behaviors.ActiveRecordLogableBehavior',
	    );
	}
}
