add_tmc.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php /** Created by Anton on 26.01.2020. */
  2. use app\models\entity\Storage;
  3. use app\models\entity\Tmc;
  4. use app\models\entity\TmcStatus;
  5. use app\models\entity\TmcType;
  6. use yii\helpers\Url;
  7. require '../yiiInit.php';
  8. $tmcTypeId = (int) Yii::$app->request->post('tmcType');
  9. $tmcType = TmcType::findOne($tmcTypeId);
  10. $inventoryNum = Yii::$app->request->post('inventoryNum');
  11. $ip = Yii::$app->request->post('ip');
  12. $mac = Yii::$app->request->post('mac');
  13. if ($ip && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
  14. die('Неверный IP');
  15. }
  16. $tmc = new Tmc();
  17. $tmc->title = $tmcType->title . ' ' . $inventoryNum;
  18. $tmc->tmc_type = $tmcTypeId;
  19. $tmc->inventory_num = $inventoryNum;
  20. $tmc->ip = $ip;
  21. $tmc->mac = $mac;
  22. $tmc->storage = (int) Yii::$app->request->post('storage');
  23. $tmc->desc = Yii::$app->request->post('desc');
  24. $tmc->status = TmcStatus::TMC_STATUS_IN_STORAGE;
  25. $tmc->company = (int) Yii::$app->request->post('company');
  26. $tmc->receipt_date = (new DateTime())->format('Y-m-d H:i:s');
  27. $tmc->save();
  28. $storage = Storage::findOne($tmc->storage);
  29. $storage->tmc = $tmc->id;
  30. $storage->save();
  31. Yii::$app->response->redirect('/index.php?act=tmc/detail/added&id=' . $tmc->id)->send();