diff --git a/include/Webservices/CreateWebClaim.php b/include/Webservices/CreateWebClaim.php new file mode 100644 index 00000000..20874795 --- /dev/null +++ b/include/Webservices/CreateWebClaim.php @@ -0,0 +1,152 @@ + 'Задержка рейса', + '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' => '12x'.$contact_id, + 'cf_2066' => '33x'.$project_id, // Связь с проектом + '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); + + // Возвращаем массив (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; +} diff --git a/webservice.php b/webservice.php index 75c8b4a1..530dc48d 100644 --- a/webservice.php +++ b/webservice.php @@ -90,7 +90,8 @@ file_put_contents('logs/webservice.log', $logstring, FILE_APPEND); // ✅ Очищаем буфер от BOM, который мог появиться при загрузке include файлов - ob_clean(); + $buffer = ob_get_clean(); + ob_start(); // Перезапускаем буферизацию $operation = vtws_getParameter($_REQUEST, "operation"); $operation = strtolower($operation);