<?php
/**
 * This is the model class for table "option".
 *
 * The followings are the available columns in table 'option':
 * @property string $key
 * @property string $value
 * @property string $group
 *
 * The followings are the available model relations:
 * @property OptionGroup $group0
 */
class Option extends CActiveRecord
{
    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
	return 'option';
    }
    /**
     * @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('key, value, group', 'required'),
	    array('key, group', 'length', 'max' => 45),
	    array('value', 'length', 'max' => 450),
            array('key', 'unique'),
	    // The following rule is used by search().
	    // @todo Please remove those attributes that should not be searched.
	    array('key, value, group', '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(
	    'optionGroup' => array(self::BELONGS_TO, 'OptionGroup', 'group'),
	);
    }
    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
	return array(
	    'key' => Yii::t("admin","Key"),
	    'value' => Yii::t("admin","Value"),
	    'group' => Yii::t("admin","Group"),
	);
    }
    /**
     * 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('t.key', $this->key, true);
	$criteria->compare('t.value', $this->value, true);
	$criteria->compare('t.group', $this->group, false);
	return new CActiveDataProvider($this, array(
	    'criteria' => $criteria,
            'pagination'=>array('pageSize'=>20),
	));
    }
    /**
     * 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 Option the static model class
     */
    public static function model($className = __CLASS__)
    {
	return parent::model($className);
    }

    public function updateCurrencyIssue($issue_number,$issue_date,$issue_time,$issue_AmPmtime)
    {
        $option_issue_AmPmtimeModel=option::model()->findByAttributes(array('key'=>'ISSUE_AM_PM_TIME' ));
        $option_issue_AmPmtimeModel->value=$issue_AmPmtime;
        $option_issue_AmPmtimeModel->save();

        $option_issue_timeModel=option::model()->findByAttributes(array('key'=>'ISSUE_TIME' ));
        $option_issue_timeModel->value=$issue_time;
        $option_issue_timeModel->save();


        $option_issue_dateModel=option::model()->findByAttributes(array('key'=>'ISSUE_DATE' ));
        $option_issue_dateModel->value=$issue_date;
        $option_issue_dateModel->save();


        $option_issue_numberModel=option::model()->findByAttributes(array('key'=>'ISSUE_NUMBER' ));
        $option_issue_numberModel->value=$issue_number;
        $option_issue_numberModel->save();

    }

    public function updateCommission($MINIMUM_TO_OPEN_CURRENT_ACCOUNT,$MINIMUM_PROFIT_CALCULATION,$MINIMUM_INVESTMENT_ACCOUNT_OPENING)
    {
        $MINIMUM_TO_OPEN_CURRENT_ACCOUNT_Model=option::model()->findByAttributes(array('key'=>'MINIMUM_TO_OPEN_CURRENT_ACCOUNT' ));
        $MINIMUM_TO_OPEN_CURRENT_ACCOUNT_Model->value=$MINIMUM_TO_OPEN_CURRENT_ACCOUNT;
        $MINIMUM_TO_OPEN_CURRENT_ACCOUNT_Model->save();

        $MINIMUM_PROFIT_CALCULATION_Model=option::model()->findByAttributes(array('key'=>'MINIMUM_PROFIT_CALCULATION' ));
        $MINIMUM_PROFIT_CALCULATION_Model->value=$MINIMUM_PROFIT_CALCULATION;
        $MINIMUM_PROFIT_CALCULATION_Model->save();


        $MINIMUM_INVESTMENT_ACCOUNT_OPENING_Model=option::model()->findByAttributes(array('key'=>'MINIMUM_INVESTMENT_ACCOUNT_OPENING' ));
        $MINIMUM_INVESTMENT_ACCOUNT_OPENING_Model->value=$MINIMUM_INVESTMENT_ACCOUNT_OPENING;
        $MINIMUM_INVESTMENT_ACCOUNT_OPENING_Model->save();


    }
}
