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 function beforeSave($insert) { $this->num = $this->newNum(); if ($this->reg_date == null) { $this->reg_date = date("Y-m-d H:i:s"); } $cur = \app\helpers\Linet3Helper::getSetting('company.cur'); $acc = Accounts::findOne($this->account_id); if ($acc === null) { $acccur = $this->currency_id; } else { $acccur = $acc->currency_id; } if ($this->currency_id == '') { $this->currency_id = $cur; $this->sum = $this->leadsum; } //leadsum if ($cur == $this->currency_id) { $this->leadsum = $this->sum; } else { $rate = Currates::GetRate($this->currency_id, $this->valuedate); $this->leadsum = $this->sum * $rate; } //set sum accourding to acc if (!isset($this->sum)) { //adam need to dubl chk if ($this->currency_id != $acccur) { $this->currency_id = $acccur; $rate = Currates::GetRate($acccur, $this->valuedate); if ($rate == 0) { throw new \Exception(Yii::t('app', 'The rate for') . $this->currency_id . Yii::t('app', 'is invalid')); } $this->sum = $this->leadsum / $rate; } } //secsum $seccur = \app\helpers\Linet3Helper::getSetting('company.seccur'); //$seccur = Yii::$app->user->settings['company.seccur']; if ($seccur != '') { if ($seccur == $this->currency_id) { $this->secsum = $this->sum; } else { $rate = Currates::GetRate($this->currency_id, $this->valuedate); if ($rate == 0) { throw new \Exception(Yii::t('app', 'The sec rate for') . $seccur . $this->currency_id . Yii::t('app', 'is invalid')); } $this->secsum = $this->leadsum / $rate; } } return true; }
public function actionGetrate($id) { \app\helpers\Response::send(200, Currates::GetRate($id)); }