'Задержка рейса', 'cancel_flight' => 'Отмена рейса', 'missed_connection' => 'Пропуск стыковки', 'delay_train' => 'Задержка поезда', 'cancel_train' => 'Отмена поезда', 'delay_ferry' => 'Задержка парома', 'cancel_ferry' => 'Отмена парома' ); $ticketCategory = isset($eventTypeMap[$event_type]) ? $eventTypeMap[$event_type] : 'Цифровой адвокат ЕРВ'; // Формируем title если не указан if (empty($title)) { $title = $ticketCategory; if (!empty($transport_number)) { $title .= ' ' . $transport_number; } } // Формируем описание $fullDescription = ''; if (!empty($description)) { $fullDescription .= $description . "\n\n"; } if (!empty($event_type)) { $fullDescription .= "Тип события: " . $ticketCategory . "\n"; } if (!empty($incident_date)) { $fullDescription .= "Дата инцидента: " . $incident_date . "\n"; } if (!empty($transport_number)) { $fullDescription .= "Номер транспорта: " . $transport_number . "\n"; } $fullDescription .= "\nИсточник: ERV Platform Web Form"; try { $params = array ( 'ticket_title' => $title, 'parent_id' => '11x67458', // Заявитель - контрагент 'ticketcategories' => $ticketCategory, 'ticketstatus' => 'рассмотрение', 'contact_id' => $contactWsId, 'cf_2066' => $projectWsId, // Связь с проектом 'ticketpriorities' => 'High', 'assigned_user_id' => vtws_getWebserviceEntityId('Users', $current_user->id), 'description' => $fullDescription ); $logstring = date('Y-m-d H:i:s').' Массив для создания Заявки: '.json_encode($params).PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); $result = vtws_create('HelpDesk', $params, $current_user); $ticketId = substr($result['id'], 3); // Убираем префикс "17x" $ticketNumber = isset($result['ticket_no']) ? $result['ticket_no'] : 'N/A'; $logstring = date('Y-m-d H:i:s').' ✅ Создана Заявка id='.$ticketId.' ticket_no='.$ticketNumber.PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); // 🚧 Создаём двустороннюю связь между Проектом и Заявкой try { $relationCheck = $adb->pquery( "SELECT 1 FROM vtiger_crmentityrel WHERE (crmid = ? AND relcrmid = ?) OR (crmid = ? AND relcrmid = ?) LIMIT 1", array($projectIdNumeric, $ticketId, $ticketId, $projectIdNumeric) ); if (!$relationCheck || $adb->num_rows($relationCheck) === 0) { $adb->pquery( "INSERT INTO vtiger_crmentityrel (crmid, module, relcrmid, relmodule) VALUES (?, ?, ?, ?)", array($projectIdNumeric, 'Project', $ticketId, 'HelpDesk') ); $logstring = date('Y-m-d H:i:s').' 🔗 Добавлена связь Project('.$projectIdNumeric.') ⇄ HelpDesk('.$ticketId.')'.PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); } else { $logstring = date('Y-m-d H:i:s').' 🔗 Связь Project('.$projectIdNumeric.') ⇄ HelpDesk('.$ticketId.') уже существует'.PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); } } catch (Exception $relEx) { $logstring = date('Y-m-d H:i:s').' ⚠️ Ошибка связывания Project('.$projectIdNumeric.') ⇄ HelpDesk('.$ticketId.'): '.$relEx->getMessage().PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); } // Возвращаем массив (vTiger сам сделает json_encode) $output = array( 'ticket_id' => $ticketId, 'ticket_number' => $ticketNumber, 'title' => $title, 'category' => $ticketCategory, 'status' => 'рассмотрение' ); } catch (WebServiceException $ex) { ob_end_clean(); $logstring = date('Y-m-d H:i:s').' ❌ Ошибка создания: '.$ex->getMessage().PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); throw $ex; } $logstring = date('Y-m-d H:i:s').' Return: '.json_encode($output).PHP_EOL; file_put_contents('logs/CreateWebClaim.log', $logstring, FILE_APPEND); // ✅ Очищаем буфер (удаляем все warnings/notices) ob_end_clean(); return $output; }