/** * Lists all Exchange models. * @return mixed */ public function actionIndex() { $searchModel = new ExchangeSearch(); $searchModel->create_time = date('Y-m-d'); $users = Users::findOne(Yii::$app->user->id); $location = $users->location_id; $dataProviderCashUSD = $searchModel->search(Yii::$app->request->queryParams, 'USD', 'cash', $location); $dataProviderHedgeUSD = $searchModel->search(Yii::$app->request->queryParams, 'USD', 'hedge', $location); $dataProviderCashEUR = $searchModel->search(Yii::$app->request->queryParams, 'EUR', 'cash', $location); $dataProviderHedgeEUR = $searchModel->search(Yii::$app->request->queryParams, 'EUR', 'hedge', $location); $sumCashUSD = $searchModel->getSum($dataProviderCashUSD); $sumHedgeUSD = $searchModel->getSum($dataProviderHedgeUSD); $sumCashEUR = $searchModel->getSum($dataProviderCashEUR); $sumHedgeEUR = $searchModel->getSum($dataProviderHedgeEUR); $model_report = Report::findOne(['date' => $searchModel->create_time, 'location_id' => $location]); $cbr = new CBRAgent(); if ($cbr->load()) { $cbrUSD = $cbr->get('USD'); $cbrEUR = $cbr->get('EUR'); } else { $cbrUSD = 0; $cbrEUR = 0; } return $this->render('index', ['searchModel' => $searchModel, 'dataProviderCashUSD' => $dataProviderCashUSD, 'dataProviderHedgeUSD' => $dataProviderHedgeUSD, 'dataProviderCashEUR' => $dataProviderCashEUR, 'dataProviderHedgeEUR' => $dataProviderHedgeEUR, 'model_report' => $model_report, 'sumCashUSD' => $sumCashUSD, 'sumHedgeUSD' => $sumHedgeUSD, 'sumCashEUR' => $sumCashEUR, 'sumHedgeEUR' => $sumHedgeEUR, 'cbrUSD' => $cbrUSD, 'cbrEUR' => $cbrEUR]); }
/** * Finds the Report model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $date * @param integer $location_id * @return Report the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($date, $location_id) { if (($model = Report::findOne(['date' => $date, 'location_id' => $location_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Report model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Report the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Report::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }