<?php

/**
 * This is the model class for table "commission".
 *
 * The followings are the available columns in table 'commission':
 * @property integer $id
 * @property string $declaration_ar
 * @property string $declaration_en
 * @property string $amount_ar
 * @property string $amount_en
 * @property string $note_ar
 * @property string $note_en
 */
class Commission extends CActiveRecord
{
	public $import_file;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'commission';
	}

	/**
	 * @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('declaration_ar, declaration_en, amount_ar, amount_en', 'required'),
			array('declaration_ar, declaration_en', 'length', 'max'=>800),
			array('amount_ar, amount_en', 'length', 'max'=>500),
			array('note_ar, note_en','safe'),
			array('import_file', 'file', 
					'types'=>'xls,xlsx',
					// 'maxSize'=>1024 * 1024 * 10, // 10MB
					'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',
					'allowEmpty' => false,
					'on'=>'import',
                              ),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, declaration_ar, declaration_en, amount_ar, amount_en, note_ar, note_en', '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(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
                			'id' => Yii::t('admin','ID'),
                			'declaration_ar' => Yii::t('admin','Declaration Ar'),
                			'declaration_en' => Yii::t('admin','Declaration En'),
                			'amount_ar' => Yii::t('admin','Amount Ar'),
                			'amount_en' => Yii::t('admin','Amount En'),
                			'note_ar' => Yii::t('admin','Note Ar'),
                			'note_en' => Yii::t('admin','Note En'),
							'import_file' => 'Select file',
		);
	}

	/**
	 * 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('declaration_ar',$this->declaration_ar,true);
		$criteria->compare('declaration_en',$this->declaration_en,true);
		$criteria->compare('amount_ar',$this->amount_ar,true);
		$criteria->compare('amount_en',$this->amount_en,true);
		$criteria->compare('note_ar',$this->note_ar,true);
		$criteria->compare('note_en',$this->note_en,true);

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