From 47fa27402f9459166eb6fff5524028099ba90135 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sun, 16 Feb 2025 08:10:07 +0000 Subject: [PATCH] message Service added --- ci4/app/Config/Routes.php | 2 +- ci4/app/Controllers/Chat/ChatController.php | 7 +++++++ ci4/app/Controllers/Presupuestos/Presupuestocliente.php | 4 +++- ci4/app/Services/MessageService.php | 5 ++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 3b03dfa2..8ae7e295 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -886,8 +886,8 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route $routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']); $routes->get('department/(:num)/users', 'ChatController::get_chat_department_users/$1', ['as' => 'getChatDepartmentUsers']); - $routes->get('(:num)', 'ChatController::get_chat/$1', ['as' => 'getChat']); + $routes->post('message/error/presupuesto', 'ChatController::store_chat_error_message', ['as' => 'storeChatErrorMessage']); $routes->post('message/presupuesto', 'ChatController::store_chat_message_presupuesto', ['as' => 'storeChatMessagePresupuesto']); $routes->post('message/pedido', 'ChatController::store_chat_message_pedido', ['as' => 'storeChatMessagePedido']); $routes->post('message/factura', 'ChatController::store_chat_message_factura', ['as' => 'storeChatMessageFactura']); diff --git a/ci4/app/Controllers/Chat/ChatController.php b/ci4/app/Controllers/Chat/ChatController.php index 854f562b..0be4e8ed 100644 --- a/ci4/app/Controllers/Chat/ChatController.php +++ b/ci4/app/Controllers/Chat/ChatController.php @@ -766,4 +766,11 @@ class ChatController extends BaseController $this->chatModel->setAsUnviewedChatUserNotifications($chat_id, auth()->user()->id); return $this->response->setJSON(["message" => "ok", "status" => true]); } + public function store_chat_error_message() + { + $bodyData = $this->request->getPost(); + $messageService = service('messages'); + $r = $messageService->createErrorMessagePresupuesto("Error",$bodyData['presupuesto_id']); + return $this->response->setJSON(["message" => "ok","data" => $r]); + } } diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index e6f14ce1..1902d77d 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -18,6 +18,7 @@ use App\Models\Presupuestos\PresupuestoModel; use App\Models\Presupuestos\PresupuestoPreimpresionesModel; use App\Models\Presupuestos\PresupuestoServiciosExtraModel; use App\Models\Presupuestos\ErrorPresupuesto; +use App\Services\MessageService; use App\Services\PresupuestoClienteService; use App\Services\PresupuestoService; use Exception; @@ -42,7 +43,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController protected $indexRoute = 'listaPresupuestos'; - + protected MessageService $messageService; public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { @@ -61,6 +62,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController ['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false], ['title' => "Listado", 'route' => site_url('presupuestocliente/list'), 'active' => true] ]; + $this->messageService = service('messages'); parent::initController($request, $response, $logger); $this->model = new PresupuestoModel(); diff --git a/ci4/app/Services/MessageService.php b/ci4/app/Services/MessageService.php index 54bd9b4f..3ad4effa 100644 --- a/ci4/app/Services/MessageService.php +++ b/ci4/app/Services/MessageService.php @@ -36,7 +36,8 @@ class MessageService extends BaseService } public function createErrorMessagePresupuesto(string $error, int $presupuesto_id) { - $chat_department_name = $this->configVariables->getVariable('send_error_to_chat_department_name'); + $dataResponse = null; + $chat_department_name = $this->configVariables->getVariable('send_error_to_chat_department_name')?->value; $chat_department_id = $this->chatDepartmentModel->where('name', $chat_department_name)->first()?->id; if ($chat_department_id) { $existChat = $this->chatModel->existChatPresupuesto($chat_department_id, $presupuesto_id); @@ -55,5 +56,7 @@ class MessageService extends BaseService } } } + return $dataResponse; + } }