12345678910111213141516171819202122232425262728293031323334353637 |
- <?php /** Created by Anton on 28.01.2020. */
- require '../yiiInit.php';
- use app\models\entity\Log;
- use app\models\entity\Tmc;
- use app\models\entity\TmcStatus;
- use app\models\entity\UserDevice;
- use yii\helpers\Url;
- $userId = (int) Yii::$app->request->post('user');
- $inventoryNum = Yii::$app->request->post('inventoryNum');
- $tmc = Tmc::findOne(['inventory_num' => $inventoryNum]);
- if ($userId && $tmc) {
- $userDevice = UserDevice::findOne(['employee' => $userId]) ?: new UserDevice();
- $fieldName = $userDevice->getFieldNameById($tmc->tmc_type);
- if (!$userDevice->$fieldName) {
- //Пишем в логи факт выдачи утстройства
- $log = new Log();
- $log->employee = $userId;
- $log->tmc = $tmc->id;
- $log->issue_date = (new DateTime())->format('y-m-d H:i:s');
- $result = $log->save();
- $userDevice->$fieldName = $log->id;
- $userDevice->employee = $userId;
- $userDevice->save();
- $tmc->status = TmcStatus::TMC_STATUS_ISSUED;
- $tmc->employee = $userId;
- $tmc->save();
- }
- }
- Yii::$app->response->redirect(Url::to($_SERVER['HTTP_REFERER']))->send();
|