/** * Creates a new Exchange model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Exchange(); if ($model->load(Yii::$app->request->post())) { if ($model->beforeValidate()) { if ($model->selectorIncomeExpenses == 'income') { $model->expenses = 0; $model->income = $model->inputIncomeExpenses; } else { $model->income = 0; $model->expenses = $model->inputIncomeExpenses; } if ($model->create_time) { false; } else { $model->create_time = date('Y-m-d'); } } $users = Users::findOne(Yii::$app->user->id); $location = $users->location_id; $model_report = $model->updateReport($location, $model->create_time, $model->currency, $model->income, $model->expenses, $model->transaction, $model->bo); $model->location_id = $location; $model->save(); $model_report->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }