Merge branch 'main' into 'feat/catalogo'

Main

See merge request jjimenez/safekat!707
This commit is contained in:
Ignacio Martinez Navajas
2025-04-15 19:07:51 +00:00
60 changed files with 1872 additions and 779 deletions

View File

@ -136,6 +136,7 @@ class ChatDeparmentModel extends Model
->where('chat_department_users.presupuesto_id',null)
->where('chat_department_users.pedido_id',null)
->where('chat_department_users.factura_id',null)
->where('chat_department_users.orden_trabajo_id',null)
->get();
return $result->getResultObject() ?: [];
@ -161,6 +162,13 @@ class ChatDeparmentModel extends Model
->get()->getResultObject();
return $result;
}
public function getChatDeparmentOrdenTrabajoUsers(int $chat_deparment_id, int $orden_trabajo_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.orden_trabajo_id', $orden_trabajo_id)
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id): string
{
return $this->find($chat_deparment_id)->display;

View File

@ -19,7 +19,9 @@ class ChatDeparmentUserModel extends Model
"user_id",
"pedido_id",
"factura_id",
"presupuesto_id"
"presupuesto_id",
"orden_trabajo_id",
];
protected bool $allowEmptyInserts = false;

View File

@ -6,11 +6,13 @@ use App\Entities\Chat\ChatEntity;
use App\Models\ChatNotification;
use App\Models\ChatUser;
use App\Models\Facturas\FacturaModel;
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
use App\Models\Pedidos\PedidoModel;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Model;
use CodeIgniter\Database\BaseBuilder;
use Config\OrdenTrabajo;
class ChatModel extends Model
{
@ -25,6 +27,7 @@ class ChatModel extends Model
"chat_department_id",
"presupuesto_id",
"factura_id",
"orden_trabajo_id",
"title"
];
@ -86,6 +89,10 @@ class ChatModel extends Model
{
return $this->builder()->where("factura_id", $factura_id)->where("chat_department_id", $chat_department_id)->get()->getFirstRow();
}
public function getChatOrdenTrabajo(int $chat_department_id, int $orden_trabajo_id)
{
return $this->builder()->where("orden_trabajo_id", $orden_trabajo_id)->where("chat_department_id", $chat_department_id)->get()->getFirstRow();
}
public function createChatPresupuesto(int $chat_department_id, int $presupuesto_id): int
{
@ -123,6 +130,17 @@ class ChatModel extends Model
"chat_department_id" => $chat_department_id
]);
}
public function createChatOrdenTrabajo(int $chat_department_id, int $orden_trabajo_id): int
{
$model = model(OrdenTrabajoModel::class);
$chatDeparmentModel = model(ChatDeparmentModel::class);
$ot = $model->find($orden_trabajo_id);
return $this->insert([
"title" => "[OT]".$ot->id . "[" . $chatDeparmentModel->getDisplay($chat_department_id) . "]",
"orden_trabajo_id" => $orden_trabajo_id,
"chat_department_id" => $chat_department_id
]);
}
public function createChatSingle(): int
{
return $this->insert(["chat_department_id" => null]);
@ -323,6 +341,7 @@ class ChatModel extends Model
"chats.pedido_id as pedidoId",
"chats.presupuesto_id as presupuestoId",
"chats.factura_id as facturaId",
"chats.orden_trabajo_id as ordenTrabajoId",
"chats.title as chatDisplay",
"COUNT(chat_notifications.id) as unreadMessages"
])
@ -363,6 +382,13 @@ class ChatModel extends Model
$row->title = $row->facturaId;
$rows_new[] = $row;
}
elseif ($row->ordenTrabajoId) {
// $row->model = $facturaModel->find($row->facturaId);
$row->uri = "/chat/ot/" . $row->ordenTrabajoId . "#accordionChatOrdenTrabajo";
$row->avatar = "OT";
$row->title = $row->ordenTrabajoId;
$rows_new[] = $row;
}
}
return $rows_new;
}
@ -374,6 +400,7 @@ class ChatModel extends Model
"chats.chat_department_id as chatDepartmentId",
"chats.pedido_id as pedidoId",
"chats.presupuesto_id as presupuestoId",
"chats.orden_trabajo_id as ordenTrabajoId",
"chats.factura_id as facturaId",
"chats.title as chatDisplay",
"COUNT(chat_messages.id) as unreadMessages"
@ -413,6 +440,13 @@ class ChatModel extends Model
$row->title = $row->facturaId;
$rows_new[] = $row;
}
elseif ($row->ordenTrabajoId) {
$row->uri = "/produccion/ordentrabajo/edit/" . $row->ordenTrabajoId . "#accordionChatOrdenTrabajo";
$row->avatar = "OT";
$row->chatDisplay .= "[INTERNAL]";
$row->title = $row->ordenTrabajoId;
$rows_new[] = $row;
}
}
return $rows_new;
}
@ -433,6 +467,7 @@ class ChatModel extends Model
->where("chats.chat_department_id", null)
->where("chats.pedido_id", null)
->where("chats.factura_id", null)
->where("chats.orden_trabajo_id", null)
->where("chat_notifications.viewed", false)
->where("chat_notifications.user_id", auth()->user()->id);
$rows = $q->get()->getResultObject();
@ -513,6 +548,27 @@ class ChatModel extends Model
$data["users"] = $this->getChatUsers($chat_id);
return $data;
}
public function getChatInternalHebraOrdenTrabajo($chat_id, $orden_trabajo_id)
{
$data = [];
$query = $this->builder()->select([
"chats.id as chatId",
"chat_messages.message",
"users.username as senderUserName",
"chat_messages.created_at",
"CONCAT(users.first_name,' ',users.last_name) as senderFullName",
])
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
->join("users", "users.id = chat_messages.sender_id", "left")
->where("chats.id", $chat_id)
->where("chats.orden_trabajo_id", $orden_trabajo_id);
$data["chatId"] = $chat_id;
$data["messages"] = $query->get()->getResultObject();
$data["chatTitle"] = "OT" . "[" . $orden_trabajo_id . "] - ";
$data["chatTitle"] .= $this->find($chat_id)->title;
$data["users"] = $this->getChatUsers($chat_id);
return $data;
}
public function getChatUsers(int $chat_id)
{
$query = $this->builder()->select([
@ -557,6 +613,17 @@ class ChatModel extends Model
}
return $data;
}
public function getOrdenTrabajoHebras($orden_trabajo_id): array
{
$data = [];
$chats = $this->builder()->select("chats.id as chatId")
->where("chats.chat_department_id", null)
->where("chats.orden_trabajo_id", $orden_trabajo_id)->get()->getResultObject();
foreach ($chats as $chat) {
$data[$chat->chatId] = $this->getChatInternalHebraOrdenTrabajo($chat->chatId, $orden_trabajo_id);
}
return $data;
}
public function countUnreadMessagePresupuesto(int $presupuesto_id): int|string
{
return $this->builder()->select()
@ -586,6 +653,15 @@ class ChatModel extends Model
->where("chat_notifications.viewed", false)
->where("chat_notifications.user_id", auth()->user()->id)->countAllResults();
}
public function countUnreadMessageOrdenTrabajo($orden_trabajo_id): int|string
{
return $this->builder()->select()
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
->where("chats.orden_trabajo_id", $orden_trabajo_id)
->where("chat_notifications.viewed", false)
->where("chat_notifications.user_id", auth()->user()->id)->countAllResults();
}
public function countUnreadMessageDirectos(int $chat_id): int|string
{
return $this->builder()->select()
@ -606,6 +682,7 @@ class ChatModel extends Model
->where("chats.presupuesto_id", null)
->where("chats.pedido_id", null)
->where("chats.factura_id", null)
->where("chats.orden_trabajo_id", null)
->where("chats.id", $chat_id)
->where("chat_messages.receiver_id", auth()->user()->id)->get()->getFirstRow();
$userModel = model(UserModel::class);
@ -837,6 +914,36 @@ class ChatModel extends Model
}
return $query->groupBy('chatMessageId');
}
public function getQueryDatatableMessageOrdenTrabajo(int $user_id): BaseBuilder
{
$query = $this->builder()
->select([
"chats.id",
"cm.id as chatMessageId",
"u.id as userId",
"cm.message",
"chats.created_at",
"
(
SELECT cm2.updated_at
FROM chat_messages cm2
WHERE cm2.chat_id = chats.id
ORDER BY cm2.updated_at DESC LIMIT 1
) as updated_at",
"CONCAT(u.first_name,' ',u.last_name) as creator",
"chats.title",
])
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
->join("users u", "u.id = cm.sender_id", 'left')
->join("ordenes_trabajo", "ordenes_trabajo.id = chats.orden_trabajo_id", "left")
->where("chats.orden_trabajo_id is NOT NULL", NULL, FALSE);
if (auth()->user()->inGroup("cliente-administrador","cliente")) {
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
}
return $query->groupBy('chatMessageId');
}
public function createNewDirectChat(string $title, string $message, array $users)
{
$chatMessageModel = model(ChatMessageModel::class);

View File

@ -151,7 +151,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.deleted_at', 0);
$builder->where('t1.deleted_at', null);
$builder->where('t1.plantilla_id', $plantilla_id);
if (empty($search))

View File

@ -388,7 +388,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.deleted_at', 0);
$builder->where('t1.deleted_at', null);
$builder->where('t1.cliente_id', $cliente_id);
if (empty($search))

View File

@ -1,4 +1,5 @@
<?php
namespace App\Models\Configuracion;
class ImposicionModel extends \App\Models\BaseModel
@ -95,21 +96,37 @@ class ImposicionModel extends \App\Models\BaseModel
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orlike("t1.ancho", $search)
->orLike("t1.alto", $search)
->orLike("t1.unidades", $search)
->orLike("t1.orientacion", $search)
->orLike("t1.maquina", $search)
->orLike("t1.etiqueta", $search)
->orlike("t1.id", $search)
->orLike("t1.ancho", $search)
->orLike("t1.alto", $search)
->orLike("t1.unidades", $search)
->orLike("t1.orientacion", $search)
->orLike("t1.maquina", $search)
->orLike("t1.etiqueta", $search)
->groupEnd();
->groupStart()
->like("t1.id", $search)
->orlike("t1.ancho", $search)
->orLike("t1.alto", $search)
->orLike("t1.unidades", $search)
->orLike("t1.orientacion", $search)
->orLike("t1.maquina", $search)
->orLike("t1.etiqueta", $search)
->orlike("t1.id", $search)
->orLike("t1.ancho", $search)
->orLike("t1.alto", $search)
->orLike("t1.unidades", $search)
->orLike("t1.orientacion", $search)
->orLike("t1.maquina", $search)
->orLike("t1.etiqueta", $search)
->groupEnd();
}
public function querySelect(?string $q)
{
$query = $this->builder()->select([
"id",
"CONCAT(lg_imposiciones.ancho,'x',lg_imposiciones.alto,'_',COALESCE(lg_imposiciones.unidades,'NULL'),'_',COALESCE(lg_imposiciones.orientacion,'NULL')) as name",
"COALESCE(lg_imposiciones.etiqueta,'" . lang("Produccion.imposicion_no_label") . "') as description"
]);
if ($q) {
$query->orLike("CONCAT(lg_imposiciones.ancho,'x',lg_imposiciones.alto)", $q);
$query->orLike("lg_imposiciones.etiqueta", $q);
}
return $query
->orderBy('id', 'ASC')
->get()->getResultArray();
}
}

View File

@ -5,6 +5,7 @@ namespace App\Models\OrdenTrabajo;
use App\Entities\Produccion\OrdenTrabajoDateEntity;
use CodeIgniter\Database\MySQLi\Builder;
use CodeIgniter\Model;
use Config\OrdenTrabajo;
class OrdenTrabajoDate extends Model
{
@ -17,25 +18,36 @@ class OrdenTrabajoDate extends Model
protected $allowedFields = [
"orden_trabajo_id",
"fecha_entrada_at",
"fecha_entrega_at",
"fecha_entrega_real_at",
"fecha_entrega_change_at",
"fecha_impresion_at",
"fecha_encuadernado_at",
"fecha_externo_at",
"pendiente_ferro_at",
"ferro_en_cliente_at",
"ferro_ok_at",
//IMPRESION
"interior_bn_at",
"interior_color_at",
"preparacion_interiores_at",
"cubierta_at",
//ACABADO
"plastificado_at",
"encuadernacion_at",
"corte_at",
"preparacion_interiores_at",
"entrada_manipulado_at",
"cosido_at",
"solapa_at",
"grapado_at",
"retractilado_at",
"retractilado5_at",
"prototipo_at",
"marcapaginas_at",
//FERRO
"pendiente_ferro_at",
"ferro_en_cliente_at",
"ferro_ok_at",
//ENVIO
"embalaje_at",
"envio_at",
"entrada_manipulado_at"
//PREIMPRESION
"pre_formato_at",
"pre_lomo_at",
"pre_solapa_at",
"pre_codbarras_at",
"pre_imposicion_at"
];
protected bool $allowEmptyInserts = false;
@ -103,22 +115,8 @@ class OrdenTrabajoDate extends Model
return $data;
}
public function updateUserDateMap($orden_trabajo_id,$data){
$mapping = [
"fecha_encuadernado_at" => "encuadernacion_user_id",
// "fecha_externo_at" => "null",
"fecha_impresion_at" => null,
"pendiente_ferro_at" => "pendiente_ferro_user_id",
"ferro_en_cliente_at" => "ferro_en_cliente_user_id",
"ferro_ok_at" => "ferro_ok_user_id",
"interior_bn_at" => "interior_bn_user_id",
"interior_color_at" => "interior_color_user_id",
"preparacion_interiores_at" => "preparacion_interior_user_id",
"cubierta_at" => "cubierta_user_id",
"plastificado_at" => "plastificado_user_id",
"corte_at" => "corte_user_id",
"embalaje_at" => "embalaje_user_id",
"entrada_manipulado_at" => "entrada_manipulado_user_id"
];
$ordenTrabajoConfig = new OrdenTrabajo();
$mapping = $ordenTrabajoConfig->DATE_USER_MAPPING;
$otUser = model(OrdenTrabajoUser::class);
$auth_user_id = auth()->user()->id;
foreach ($data as $key => $value) {

View File

@ -82,7 +82,9 @@ class OrdenTrabajoModel extends Model
"tipos_presupuestos.codigo as tipo_presupuesto_impresion",
"ordenes_trabajo.progreso",
"presupuesto_linea.tipo as presupuesto_linea_tipo",
"orden_trabajo_dates.ferro_ok_at"
"orden_trabajo_dates.ferro_ok_at",
"CONCAT(lg_imposiciones.ancho,'x',lg_imposiciones.alto,'_',COALESCE(lg_imposiciones.unidades,'NULL'),'_',COALESCE(lg_imposiciones.orientacion,'NULL')) as imposicion_name"
])
->join("orden_trabajo_dates","orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id","left")
->join("pedidos","pedidos.id = ordenes_trabajo.pedido_id","left")
@ -92,6 +94,9 @@ class OrdenTrabajoModel extends Model
->join("clientes","clientes.id = presupuestos.cliente_id","left")
->join("tipos_presupuestos","presupuestos.tipo_impresion_id = tipos_presupuestos.id","left")
->join("ubicaciones","ubicaciones.id = pedidos_linea.ubicacion_id","left")
->join("orden_trabajo_tareas","orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id","left")
->join("lg_imposiciones","lg_imposiciones.id = orden_trabajo_tareas.imposicion_id","left")
->whereIn("presupuesto_linea.tipo",["lp_bn","lp_bnhq","lp_rot_bn","lp_color","lp_colorhq","lp_rot_color"])
->where("ordenes_trabajo.deleted_at",null)
->groupBy("ordenes_trabajo.id");

View File

@ -3,6 +3,7 @@
namespace App\Models\OrdenTrabajo;
use App\Entities\Produccion\OrdenTrabajoUserEntity;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Database\MySQLi\Builder;
use CodeIgniter\Model;
@ -18,28 +19,42 @@ class OrdenTrabajoUser extends Model
"orden_trabajo_id",
"user_created_id",
"user_update_id",
"inaplazable_revised_change_user_id",
"ferro_disponible_hecho_user_id",
"ferro_disponible_ok_user_id",
"ferro_entregado_user_id",
"pendiente_ferro_user_id",
"ferro_en_cliente_user_id",
"ferro_ok_user_id",
//IMPRESION
"interior_bn_user_id",
"interior_color_user_id",
"preparacion_interior_user_id",
"cubierta_user_id",
//ACABADO
"plastificado_user_id",
"encuadernacion_user_id",
"corte_user_id",
"embalaje_user_id",
"preparacion_interior_user_id",
"entrada_manipulado_user_id",
"cosido_user_id",
"solapa_user_id",
"grapado_user_id",
"retractilado_user_id",
"retractilado5_user_id",
"prototipo_user_id",
"marcapaginas_user_id",
//FERRO
"pendiente_ferro_user_id",
"ferro_en_cliente_user_id",
"ferro_ok_user_id",
//ENVIO
"embalaje_user_id",
"envio_user_id",
//PREIMPRESION
"pre_formato_user_id",
"pre_lomo_user_id",
"pre_solapa_user_id",
"pre_codbarras_user_id",
"pre_imposicion_user_id",
"pre_imprimir_user_id"
//UNUSED
"inaplazable_revised_change_user_id",//!DELETE
"ferro_disponible_hecho_user_id",//!DELETE
"ferro_entregado_user_id",//!DELETE
"pre_imprimir_user_id", //!DELETE
"ferro_disponible_ok_user_id", //!DELETE
];
protected bool $allowEmptyInserts = false;
@ -72,6 +87,5 @@ class OrdenTrabajoUser extends Model
protected $beforeDelete = [];
protected $afterDelete = [];
}