<?php

/**
 * This is the model class for table "calculator_finance".
 *
 * The followings are the available columns in table 'calculator_finance':
 * @property integer $id
 * @property string $finance_type 
 * @property string $finance_type_en
 * @property double $minimum_first_payment
 * @property double $profit_ratio
 * @property string $maximum_duration_of_finance 
 * @property string $maximum_duration_of_finance_en
  * @property integer $max_duration_months
 */
class CalculatorFinance extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'calculator_finance';
	}

	/**
	 * @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('finance_type, finance_type_en, minimum_first_payment, profit_ratio, maximum_duration_of_finance', 'required'),
			array('minimum_first_payment, profit_ratio', 'numerical'),
            array('max_duration_months', 'numerical', 'integerOnly'=>true),
			array('finance_type, maximum_duration_of_finance, maximum_duration_of_finance_en', 'length', 'max'=>200),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, finance_type, finance_type_en, minimum_first_payment, profit_ratio, maximum_duration_of_finance, maximum_duration_of_finance_en, max_duration_months', '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'),
                			'finance_type' => Yii::t('admin','Finance Type'),
							'finance_type_en' => Yii::t('admin','Finance Type En'),
                			'minimum_first_payment' => Yii::t('admin','Minimum First Payment'),
                			'profit_ratio' => Yii::t('admin','Profit Ratio'),
                			'maximum_duration_of_finance' => Yii::t('admin','Maximum Duration Of Finance'),
							'maximum_duration_of_finance_en' => Yii::t('admin','Maximum Duration Of Finance En'),
		);
	}

	/**
	 * 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('finance_type',$this->finance_type,true);
		$criteria->compare('finance_type_en',$this->finance_type_en,true);
		$criteria->compare('minimum_first_payment',$this->minimum_first_payment);
		$criteria->compare('profit_ratio',$this->profit_ratio);
		$criteria->compare('maximum_duration_of_finance',$this->maximum_duration_of_finance,true);
		$criteria->compare('maximum_duration_of_finance_en',$this->maximum_duration_of_finance_en,true);
        $criteria->compare('max_duration_months',$this->max_duration_months); 
		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 CalculatorFinance the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
