private function ini() { if ($this->valuedate == null) { $this->valuedate = Record::writeDate(time()); } if (!$this->ini) { $this->_precision = Yii::$app->params['precision']; $item = Item::findByPk($this->item_id, $this->valuedate); if (is_null($item)) { $this->iVatRate = 0; } else { $this->iVatRate = $item->vat; } //for vat resons... //if ($this->rate == 0) { $this->rate = Currates::GetRate($this->currency_id, $this->valuedate); //} if ($this->doc_rate == 0) { $doc = Docs::findOne($this->doc_id); $this->doc_rate = Currates::GetRate($doc->currency_id, $this->valuedate); } $this->ini != $this->ini; } }
public static function GetRate($id, $time = null) { if ($time == null) { $time = Record::writeDate(time()); } $date = Currates::find()->andWhere(['currency_id' => $id])->andFilterWhere(['>=', 'date', $time])->orderBy(['date' => SORT_ASC])->One(); if ($date == null) { //no value then get latest $date = Currates::find()->andWhere(['currency_id' => $id])->orderBy(['date' => SORT_DESC])->One(); } if ($date == null) { //no rate return 1; } return $date->value; }