/** * @return \yii\db\ActiveQuery */ public function getCurrency() { return $this->hasOne(Currency::className(), ['code' => 'currency_code']); }
/** * @param $currencyTo * @return Money */ public function convertToCurrency($currencyTo) { $currencyTo = Currency::getInstance($currencyTo); if ($crossCourse = $this->getCurrency()->getCrossCourse($currencyTo)) { $newMoney = $this->multiply($crossCourse); return new static($newMoney->getAmount(), $currencyTo); } else { throw new InvalidArgumentException(\Yii::t('skeeks/money', 'Unable to get the cross rate for the currency') . ' ' . $currencyTo->getCurrencyCode()); } }
/** * Объект текущей валюты * * @return Currency */ public function getCurrencyObject() { return Currency::getInstance(\Yii::$app->money->currencyCode); }