public function actionCreate() { $model = new Trip(['scenario' => 'edit']); $model->rentNumberDate = Yii::$app->formatter->asDate(time(), 'php:d.m.Y'); $view = 'create'; if ($model->load(Yii::$app->request->post()) && $model->save()) { $view = 'view'; Yii::$app->session->setFlash('tripSaved', 'Данные о командировке успешно сохранены'); } if (Yii::$app->request->isAjax) { return $this->renderAjax($view, ['model' => $model]); } else { throw new NotFoundHttpException('Запрашиваемая страница не найдена.'); } }
public function actionTrip() { $this->stdout("Загружаю командировки\n", Console::FG_BLUE, Console::BOLD); $query = (new Query())->from($this->tripTableName); $this->stdout("Источник: таблица '{$this->tripTableName}' " . $query->count() . " записей.\nЦелевая коллекция: '" . Trip::collectionName() . "'\n"); $this->cleanCollection(Trip::collectionName()); $successCounter = 0; foreach ($query->all() as $item) { $trip = new Trip(); $number = (new Query())->select(['number'])->from($this->numberTableName)->where(['id' => $item['mobile_id']])->one(); $trip['numberId'] = Number::findOne(['number' => $number['number']])->getPrimaryKey(); $trip['employeeId'] = (int) $item['employee_id']; $trip['duration'] = ['from' => new MongoDate(strtotime("+1 day", (int) $item['rent_date'])), 'to' => new MongoDate((int) $item['return_date'])]; $trip['numberPossession'] = ['from' => new MongoDate((int) $item['rent_date']), 'to' => new MongoDate(strtotime($item['actual_return_date']))]; if ($trip['numberPossession']['to'] !== null) { $trip['complete'] = true; } $trip['destination'] = $item['destination']; if ($trip->save(false)) { $successCounter++; } } $this->stdout("Успешно загружено {$successCounter} записей\n", Console::BOLD, Console::FG_GREEN); $this->stdout("\n"); return Controller::EXIT_CODE_NORMAL; }