<?php

/**
 * This is the model class for table "prestamos.tipo_nomina_periodo".
 *
 * The followings are the available columns in table 'prestamos.tipo_nomina_periodo':
 * @property integer $id
 * @property string $id_tipo_nomina
 * @property string $fecha_desde
 * @property string $fecha_hasta
 * @property integer $numero_periodo
 * @property boolean $periodo_activo
 */
class TipoNominaPeriodo extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'prestamos.tipo_nomina_periodo';
	}

	/**
	 * @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('numero_periodo', 'numerical', 'integerOnly'=>true),
			array('id_tipo_nomina, fecha_desde, fecha_hasta, periodo_activo', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_tipo_nomina, fecha_desde, fecha_hasta, numero_periodo, periodo_activo', '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(
                    'datosPreNominaCreditos' => array(self::HAS_MANY, 'DatosPreNominaCredito', 'id_tipo_momina_periodo'),
                    'idTipoNomina' => array(self::BELONGS_TO, 'TipoNomina', 'id_tipo_nomina'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_tipo_nomina' => 'Id Tipo Nomina',
			'fecha_desde' => 'Fecha Desde',
			'fecha_hasta' => 'Fecha Hasta',
			'numero_periodo' => 'Numero Periodo',
			'periodo_activo' => 'Periodo Vencido',
		);
	}

	/**
	 * 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_tipo_nomina',$this->id_tipo_nomina,true);
		$criteria->compare('fecha_desde',$this->fecha_desde,true);
		$criteria->compare('fecha_hasta',$this->fecha_hasta,true);
		$criteria->compare('numero_periodo',$this->numero_periodo);
		$criteria->compare('periodo_activo',$this->periodo_activo);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
         public function beforeSave(){            
            if($this->fecha_hasta =='')
                $this->fecha_hasta = NULL;
            
            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 TipoNominaPeriodo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
