12345678910111213141516171819202122232425262728293031323334353637 |
- <?php /** Created by Anton on 26.01.2020. */
- use app\models\entity\Storage;
- use app\models\entity\Tmc;
- use app\models\entity\TmcStatus;
- use app\models\entity\TmcType;
- use yii\helpers\Url;
- require '../yiiInit.php';
- $tmcTypeId = (int) Yii::$app->request->post('tmcType');
- $tmcType = TmcType::findOne($tmcTypeId);
- $inventoryNum = Yii::$app->request->post('inventoryNum');
- $ip = Yii::$app->request->post('ip');
- $mac = Yii::$app->request->post('mac');
- if ($ip && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
- die('Неверный IP');
- }
- $tmc = new Tmc();
- $tmc->title = $tmcType->title . ' ' . $inventoryNum;
- $tmc->tmc_type = $tmcTypeId;
- $tmc->inventory_num = $inventoryNum;
- $tmc->ip = $ip;
- $tmc->mac = $mac;
- $tmc->storage = (int) Yii::$app->request->post('storage');
- $tmc->desc = Yii::$app->request->post('desc');
- $tmc->status = TmcStatus::TMC_STATUS_IN_STORAGE;
- $tmc->company = (int) Yii::$app->request->post('company');
- $tmc->receipt_date = (new DateTime())->format('Y-m-d H:i:s');
- $tmc->save();
- $storage = Storage::findOne($tmc->storage);
- $storage->tmc = $tmc->id;
- $storage->save();
- Yii::$app->response->redirect('/index.php?act=tmc/detail/added&id=' . $tmc->id)->send();
|