diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index e0e82453..eb141076 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -55,10 +55,12 @@ $routes->group('tarifas', ['namespace' => 'App\Controllers\Tarifas'], function ( $routes->get('acabado/select', 'TarifaMaquinas::get_select_maquina_acabado'); $routes->get('manipulado/select', 'TarifaMaquinas::get_select_maquina_manipulado'); $routes->get('impresion/select', 'TarifaMaquinas::get_select_maquina_impresion'); + $routes->get('encuadernacion/select', 'TarifaMaquinas::get_select_maquina_manipulado'); $routes->get('tareas/select', 'TarifaMaquinas::get_select_maquina_tareas'); + $routes->get('acabado/datatable/(:num)', 'TarifaMaquinas::get_datatable_tarifa_acabado_maquina/$1'); $routes->get('manipulado/datatable/(:num)', 'TarifaMaquinas::get_datatable_tarifa_manipulado_maquina/$1'); $routes->get('preimpresion/datatable/(:num)', 'TarifaMaquinas::get_datatable_tarifa_preimpresion_maquina/$1'); diff --git a/ci4/app/Models/Chat/ChatModel.php b/ci4/app/Models/Chat/ChatModel.php index 78628011..0b14e266 100644 --- a/ci4/app/Models/Chat/ChatModel.php +++ b/ci4/app/Models/Chat/ChatModel.php @@ -239,7 +239,7 @@ class ChatModel extends Model $count++; } } - $row->uri = "/pedidos/edit/" . $row->pedidoId; + $row->uri = "/chat/pedido/" . $row->chatId; $row->unreadMessages = $count; } return $results; @@ -273,7 +273,7 @@ class ChatModel extends Model $count++; } } - $row->uri = "/facturas/edit/" . $row->facturaId; + $row->uri = "/chat/factura/" . $row->chatId; $row->unreadMessages = $count; } return $results; @@ -307,7 +307,7 @@ class ChatModel extends Model $count++; } } - $row->uri = "/presupuestos/presupuestocliente/edit/" . $row->presupuestoId; + $row->uri = "/chat/presupuesto/" . $row->chatId; $row->unreadMessages = $count; } @@ -321,66 +321,7 @@ class ChatModel extends Model $facturaModel = model(FacturaModel::class); $pedidoModel = model(PedidoModel::class); - $q = $this->db->table("chats") - ->select([ - "chats.id as chatId", - "chats.pedido_id as pedidoId", - "chats.presupuesto_id as presupuestoId", - "chats.factura_id as facturaId", - "chats.chat_department_id as chatDepartmentId", - "chat_departments.display as chatDisplay", - ]) - ->join("chat_departments", "chat_departments.id = chats.chat_department_id", "left") - ->join("chat_department_users", "chat_department_users.chat_department_id = chats.chat_department_id", "left") - ->where("chat_department_users.user_id", auth()->user()->id); - $rows = $q->get()->getResultObject(); - - $auth_user = auth()->user(); - foreach ($rows as $row) { - $messages = $chatMessageModel->get_chat_messages($row->chatId); - $count = 0; - $chatDeparmentUsers = $chatDeparmentModel->getChatDepartmentUsers($row->chatDepartmentId); - $chatDeparmentUsersId = array_map(fn($x) => $x->id, $chatDeparmentUsers); - foreach ($messages as $m) { - if ($m->viewed == false && $m->sender_id != auth()->user()->id && in_array($m->sender_id, $chatDeparmentUsersId) == false) - $count++; - } - if ($row->presupuestoId) { - $row->model = $presupuestoModel->find($row->presupuestoId); - if($auth_user->cliente_id){ - $row->uri = "/presupuestocliente/edit/" . $row->presupuestoId; - }else{ - $row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId; - - } - $row->title = $row->presupuestoId; - $row->avatar = "PRE"; - $row->unreadMessages = $count; - } elseif ($row->pedidoId) { - $row->model = $pedidoModel->find($row->pedidoId); - $row->uri = "/pedidos/edit/" . $row->pedidoId; - $row->title = $row->pedidoId; - $row->avatar = "P"; - $row->unreadMessages = $count; - } elseif ($row->facturaId) { - $row->model = $facturaModel->find($row->facturaId); - $row->uri = "/facturas/edit/" . $row->facturaId; - $row->avatar = "F"; - $row->title = $row->facturaId; - $row->unreadMessages = $count; - } - } - return $rows; - } - public function getChatInternalNotifications() - { - $chatMessageModel = model(ChatMessageModel::class); - $presupuestoModel = model(PresupuestoModel::class); - $facturaModel = model(FacturaModel::class); - $pedidoModel = model(PedidoModel::class); - $chatNotificationModel = model(ChatNotification::class); - - $q = $this->db->table("chats") + $q = $this->builder() ->select([ "chats.id as chatId", "chats.chat_department_id as chatDepartmentId", @@ -392,18 +333,20 @@ class ChatModel extends Model ->join("chat_messages", "chat_messages.chat_id = chats.id", "left") ->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left") ->where("chat_notifications.user_id", auth()->user()->id) - ->where("chat_notifications.viewed", false); - $auth_user = auth()->user(); + ->where("chat_notifications.viewed", false) + ->where("chats.chat_department_id is NOT NULL",NULL,FALSE); + $rows = $q->get()->getResultObject(); + $auth_user = auth()->user(); $rows_new = []; foreach ($rows as $row) { $row->unreadMessages = 0; if ($row->presupuestoId) { $row->model = $presupuestoModel->find($row->presupuestoId); if($auth_user->cliente_id){ - $row->uri = "/presupuestocliente/edit/" . $row->presupuestoId; + $row->uri = "/chat/presupuesto/" . $row->chatId; }else{ - $row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId; + $row->uri = "/chat/presupuesto/" . $row->chatId; } $row->title = $row->presupuestoId; if($row->chatDepartmentId){ @@ -416,7 +359,7 @@ class ChatModel extends Model $rows_new[] = $row; } elseif ($row->pedidoId) { $row->model = $pedidoModel->find($row->pedidoId); - $row->uri = "/pedidos/edit/" . $row->pedidoId; + $row->uri = "/chat/pedido/" . $row->chatId; $row->title = $row->pedidoId; if($row->chatDepartmentId){ $row->chatDisplay .= "[INTERNAL]"; @@ -426,7 +369,72 @@ class ChatModel extends Model $rows_new[] = $row; } elseif ($row->facturaId) { $row->model = $facturaModel->find($row->facturaId); - $row->uri = "/facturas/edit/" . $row->facturaId; + $row->uri = "/chat/factura/" . $row->chatId; + $row->avatar = "F"; + if($row->chatDepartmentId){ + $row->chatDisplay .= "[INTERNAL]"; + } + $row->title = $row->facturaId; + $row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId); + $rows_new[] = $row; + } + } + return $rows_new; + } + public function getChatInternalNotifications() + { + $presupuestoModel = model(PresupuestoModel::class); + $facturaModel = model(FacturaModel::class); + $pedidoModel = model(PedidoModel::class); + + $q = $this->builder() + ->select([ + "chats.id as chatId", + "chats.chat_department_id as chatDepartmentId", + "chats.pedido_id as pedidoId", + "chats.presupuesto_id as presupuestoId", + "chats.factura_id as facturaId", + "chats.title as chatDisplay", + ]) + ->join("chat_messages", "chat_messages.chat_id = chats.id", "left") + ->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left") + ->where("chat_notifications.user_id", auth()->user()->id) + ->where("chat_notifications.viewed", false) + ->where("chats.chat_department_id",null); + $auth_user = auth()->user(); + $rows = $q->get()->getResultObject(); + $rows_new = []; + foreach ($rows as $row) { + $row->unreadMessages = 0; + if ($row->presupuestoId) { + $row->model = $presupuestoModel->find($row->presupuestoId); + if($auth_user->cliente_id){ + $row->uri = "/chat/presupuesto/" . $row->chatId; + }else{ + $row->uri = "/chat/presupuesto/" . $row->chatId; + } + $row->title = $row->presupuestoId; + if($row->chatDepartmentId){ + $row->chatDisplay = $row->model->titulo; + }else{ + $row->chatDisplay .="[INTERNAL]"; + } + $row->avatar = "PRE"; + $row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId); + $rows_new[] = $row; + } elseif ($row->pedidoId) { + $row->model = $pedidoModel->find($row->pedidoId); + $row->uri = "/chat/pedido/" . $row->chatId; + $row->title = $row->pedidoId; + if($row->chatDepartmentId){ + $row->chatDisplay .= "[INTERNAL]"; + } + $row->avatar = "P"; + $row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId); + $rows_new[] = $row; + } elseif ($row->facturaId) { + $row->model = $facturaModel->find($row->facturaId); + $row->uri = "/chat/factura/" . $row->chatId; $row->avatar = "F"; if($row->chatDepartmentId){ $row->chatDisplay .= "[INTERNAL]"; diff --git a/ci4/app/Views/themes/vuexy/components/chat_internal_factura.php b/ci4/app/Views/themes/vuexy/components/chat_internal_factura.php index 8b6ec719..bfd881f0 100644 --- a/ci4/app/Views/themes/vuexy/components/chat_internal_factura.php +++ b/ci4/app/Views/themes/vuexy/components/chat_internal_factura.php @@ -13,20 +13,20 @@