Esempio n. 1
0
 public function addOperation()
 {
     if ($this->currency_id != '1') {
         $course = new Course();
         if (!$course->checkCourse($this->currency_id)) {
             $course->currency_id = $this->currency_id;
             $currency = Currency::findOne($this->currency_id);
             $course->course = $course->getCourse($currency->iso);
             if (!$course->save()) {
                 throw new ErrorException('Курс не обновлен' . var_dump($course));
             }
         }
     }
     $operation = new Operation();
     $operation->user_id = Yii::$app->getUser()->id;
     $operation->category_id = $this->category_id === '' ? 1 : $this->category_id;
     $operation->currency_id = $this->currency_id === '' ? 1 : $this->currency_id;
     $operation->summ = $this->operation_type == 'income' ? $this->summ * 100 : $this->summ * -100;
     $operation->description = $this->description;
     return $operation->save() ? $operation : null;
 }
Esempio n. 2
0
        $country = $result->country['Name'];
    }
    return $country;
}], ['attribute' => 'ContactID', 'label' => 'Туристы', 'content' => function ($data) {
    $mainContact = $data->contact;
    $list = "<ul>";
    $list .= "<li>" . $mainContact['Name'] . " " . $mainContact['SurName'] . "</li>";
    foreach ($data->participants as $value) {
        $contact = Contact::findOne($value['ContactID']);
        $list .= "<li>" . $contact->Name . " " . $contact->SurName . "</li>";
    }
    $list .= "</ul>";
    return $list;
}], ['attribute' => 'CurrencyID', 'label' => 'Валюта', 'content' => function ($data) {
    $currency = '';
    $result = Currency::findOne($data->orderCalc['CurrencyID']);
    if (is_object($result)) {
        $currency = $result->Currency;
    }
    return $currency;
}], ['attribute' => 'Price', 'label' => 'Стоимость', 'content' => function ($data) {
    return $data->orderCalc['Price'];
}], ['attribute' => 'Charges', 'label' => 'Комиссия', 'content' => function ($data) {
    return $data->Charges;
}], ['attribute' => 'Sum', 'label' => 'Долг', 'content' => function ($data) {
    return $data->Sum - $data->Charges;
}, 'contentOptions' => function ($model, $key, $index, $column) {
    $status = '';
    $debt = $model->Sum - $model->Charges;
    if ($debt > 0) {
        $status = 'text-danger';
Esempio n. 3
0
 /**
  * Finds the Currency model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Currency the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Currency::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * @throws InvalidConfigException
  */
 public static function refreshRates()
 {
     /** @var Currency $defaultCurrency */
     $defaultCurrency = Currency::findOne(['is_default' => 1]);
     if (!$defaultCurrency) {
         throw new InvalidConfigException('Default currency is not set.');
     }
     /** @var Currency[] $currencies */
     $currencies = Currency::find()->all();
     foreach ($currencies as $currency) {
         if ($currency->code == $defaultCurrency->code) {
             $currency->rate = 1;
         } else {
             $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' . $defaultCurrency->code . $currency->code . '=X';
             $handle = @fopen($url, 'r');
             if ($handle === false) {
                 throw new Exception('Can not connect to exchange rates provider service.');
             }
             $result = fgets($handle, 4096);
             fclose($handle);
             $currencyData = explode(',', $result);
             $currency->rate = $currencyData[1];
         }
         $currency->save();
     }
 }
Esempio n. 5
0
 public function setCourse($currency_id)
 {
     $this->currency_id = $currency_id;
     $currency = Currency::findOne($currency_id);
     $this->course = $this->getCourse($currency->iso);
     return $this->save() ? $this : null;
 }