<?php

/**
 * This is the model base class for the table "clientes_documentos_fiscais".
 * DO NOT MODIFY THIS FILE! It is automatically generated by giix.
 * If any changes are necessary, you must set or override the required
 * property or method in class "ClientesDocumentosFiscais".
 *
 * Columns in table "clientes_documentos_fiscais" available as properties of the model,
 * followed by relations of table "clientes_documentos_fiscais" available as properties of the model.
 *
 * @property integer $CDF_CODIGO
 * @property integer $CDF_IDCLIENTE
 * @property integer $CDF_IDDOCUMENTO
 *
 * @property DocumentosFiscais $DocumentoFiscal
 * @property Clientes $Cliente
 */
class ClientesDocumentosFiscais extends GxActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'clientes_documentos_fiscais';
    }

    public static function label($n = 1) {
        return Yii::t('app', 'Cliente X Documento Fiscal|Clientes X Documentos Fiscais', $n);
    }

    public static function representingColumn() {
        return 'CDF_CODIGO';
    }

    public function behaviors() {
        return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior'));
    }

    public function rules() {
        return array(
            array('CDF_IDCLIENTE, CDF_IDDOCUMENTO', 'required'),
            array('CDF_IDCLIENTE, CDF_IDDOCUMENTO', 'numerical', 'integerOnly' => true),
            array('CDF_CODIGO, CDF_IDCLIENTE, CDF_IDDOCUMENTO', 'safe', 'on' => 'search'),
        );
    }

    public function relations() {
        return array(
            'DocumentoFiscal'   => array(self::BELONGS_TO, 'DocumentosFiscais', 'CDF_IDDOCUMENTO'),
            'Cliente'           => array(self::BELONGS_TO, 'Clientes', 'CDF_IDCLIENTE'),
        );
    }

    public function pivotModels() {
        return array(
        );
    }

    public function attributeLabels() {
        return array(
            'CDF_CODIGO'        => 'Código',
            'CDF_IDCLIENTE'     => 'Cliente',
            'CDF_IDDOCUMENTO'   => 'Documento Fiscal',
            'Cliente'           => 'Cliente',
            'DocumentoFiscal'   => 'Documento Fiscal',
        );
    }

    public function search() {
        $criteria = new CDbCriteria;

        $criteria->compare('CDF_CODIGO', $this->CDF_CODIGO);
        $criteria->compare('CDF_IDCLIENTE', $this->CDF_IDCLIENTE);
        $criteria->compare('CDF_IDDOCUMENTO', $this->CDF_IDDOCUMENTO);

        return new CActiveDataProvider($this, array(
                'criteria' => $criteria,
                'sort' => array(
                    'defaultOrder' => 'CDF_CODIGO ASC',
                ),
                'pagination' => array(
                    'pageSize' => 20,
                )
            )
        );
    }

    public function getPrettyName() {
        return $this->CDF_IDDOCUMENTO . ' - ' . $this->DocumentoFiscal;
    }

}
