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

@ -11,6 +11,7 @@ use App\Models\ChatNotification;
use App\Models\ChatUser;
use App\Models\Clientes\ClienteModel;
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;
@ -132,6 +133,25 @@ class ChatController extends BaseController
$data["chat"] = $chat;
return $this->response->setJSON($data);
}
public function get_chat_orden_trabajo(int $chat_department_id, int $orden_trabajo_id)
{
$data = [
"department" => $this->chatDeparmentModel->find($chat_department_id),
"chat" => null,
"messages" => null,
"count" => 0,
];
$chat = $this->chatModel->getChatOrdenTrabajo($chat_department_id, $orden_trabajo_id);
if ($chat) {
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
$data["count"] = count($data["messages"]);
}
$data["chat"] = $chat;
return $this->response->setJSON($data);
}
public function get_chat_direct_view($chat_id)
{
$chat = $this->chatModel->find($chat_id);
@ -295,6 +315,11 @@ class ChatController extends BaseController
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($factura_id, 'factura');
return $this->response->setJSON($data);
}
public function get_chat_department_orden_trabajo_users(int $chat_department_id, $orden_trabajo_id)
{
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($orden_trabajo_id, 'ot');
return $this->response->setJSON($data);
}
public function get_chat_users_internal()
{
$query = $this->userModel->builder()->select(
@ -357,6 +382,15 @@ class ChatController extends BaseController
$clienteContactos = $cm->querySelectClienteContacto($f->cliente_id,$this->request->getGet('q'));
return $this->response->setJSON($clienteContactos);
}
public function get_orden_trabajo_client_users(int $orden_trabajo_id)
{
$otm = model(OrdenTrabajoModel::class);
$ot = $otm->find($orden_trabajo_id);
$cm = model(ClienteModel::class);
$cliente = $ot->pedido()->cliente();
$clienteContactos = $cm->querySelectClienteContacto($cliente->id,$this->request->getGet('q'));
return $this->response->setJSON($clienteContactos);
}
public function store_hebra(string $model)
{
$auth_user = auth()->user();

View File

@ -1,4 +1,6 @@
<?php namespace App\Controllers\Configuracion;
<?php
namespace App\Controllers\Configuracion;
use App\Controllers\BaseResourceController;
@ -56,7 +58,7 @@ class Imposiciones extends \App\Controllers\BaseResourceController
{
if ($this->request->getPost()) :
@ -130,7 +132,7 @@ class Imposiciones extends \App\Controllers\BaseResourceController
return $this->redirect2listView('sweet-error', $message);
endif;
if ($this->request->getPost()) :
@ -279,6 +281,9 @@ class Imposiciones extends \App\Controllers\BaseResourceController
];
return $orientacionOptions;
}
public function selectImposicion()
{
$data = $this->model->querySelect($this->request->getGet('q'));
return $this->response->setJSON($data);
}
}

View File

@ -1595,7 +1595,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$presupuestoServiciosExtraModel = model('App\Models\Presupuestos\PresupuestoServiciosExtraModel');
foreach ($presupuestoServiciosExtraModel->where('presupuesto_id', $presupuesto->id)->findAll() as $servicioExtra) {
$servicioExtra->presupuesto_id = $new_id;
$presupuestoServiciosExtraModel->insert($preimpresion);
$presupuestoServiciosExtraModel->insert($servicioExtra);
}
$presupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');

View File

@ -118,7 +118,26 @@ class Ordentrabajo extends BaseController
return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400);
}
}
public function update_orden_trabajo_pedido_date()
{
try {
$bodyData = $this->request->getPost();
$r = $this->produccionService->init($bodyData["orden_trabajo_id"])->updateOrdenTrabajoPedidoDate($bodyData);
return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r["status"], "user" => $r["user"], "data" => $bodyData]);
} catch (\Throwable $th) {
return $this->response->setJSON(["errors" => $th->getMessage(), "status" => false])->setStatusCode(500);
}
}
public function update_orden_trabajo_pedido()
{
try {
$bodyData = $this->request->getPost();
$r = $this->produccionService->init($bodyData["orden_trabajo_id"])->updateOrdenTrabajoPedido($bodyData);
return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $bodyData]);
} catch (\Throwable $th) {
return $this->response->setJSON(["errors" => $th->getMessage(), "status" => false])->setStatusCode(500);
}
}
public function edit($orden_trabajo_id)
{
// Breadcrumbs
@ -128,9 +147,14 @@ class Ordentrabajo extends BaseController
];
$this->viewData["modelId"] = $orden_trabajo_id;
$this->produccionService->init($orden_trabajo_id);
$this->produccionService->reInsertOrdenTrabajoDates();
$this->produccionService->reInsertOrdenTrabajoUsers();
$this->viewData["presupuesto"] = $this->produccionService->getPresupuesto();
$this->viewData["cliente"] = $this->produccionService->getCliente();
$this->viewData["ot"] = $this->produccionService->getOrdenTrabajo();
$this->viewData["user_dates"] = $this->produccionService->userDates();
$this->viewData["pedido_user_dates"] = $this->produccionService->pedidoUserDates();
return view(static::$viewPath . $this->editRoute, $this->viewData);
}
@ -141,7 +165,7 @@ class Ordentrabajo extends BaseController
$q = $this->otModel->getDatatableQuery()->where("ordenes_trabajo.estado", "F");
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("logo", fn($q) => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)))
->add("logo", fn($q) => ["logo" => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)), "imposicion" => $q->imposicion_name,"color" => $this->produccionService->init($q->id)->getOtColorStatus()])
->edit(
"fecha_encuadernado_at",
fn($q) => $q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : ""
@ -156,7 +180,7 @@ class Ordentrabajo extends BaseController
$q = $this->otModel->getDatatableQuery()->whereIn("ordenes_trabajo.estado", ["I", "PM"]);
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("logo", fn($q) => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)))
->add("logo", fn($q) => ["logo" => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)), "imposicion" => $q->imposicion_name,"color" => $this->produccionService->init($q->id)->getOtColorStatus()])
->edit(
"fecha_encuadernado_at",
fn($q) => $q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : ""
@ -171,7 +195,7 @@ class Ordentrabajo extends BaseController
$q = $this->otModel->getDatatableQuery()->where("ferro_ok_at", null);
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("logo", fn($q) => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)))
->add("logo", fn($q) => ["logo" => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)), "imposicion" => $q->imposicion_name,"color" => $this->produccionService->init($q->id)->getOtColorStatus()])
->edit(
"fecha_encuadernado_at",
fn($q) => $q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : ""
@ -186,7 +210,7 @@ class Ordentrabajo extends BaseController
$q = $this->otModel->getDatatableQuery()->where("ferro_ok_at is NOT NULL", NULL, FALSE);
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("logo", fn($q) => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)))
->add("logo", fn($q) => ["logo" => site_url($logo->get_logo_path($q->presupuesto_linea_tipo)), "imposicion" => $q->imposicion_name,"color" => $this->produccionService->init($q->id)->getOtColorStatus()])
->edit(
"fecha_encuadernado_at",
fn($q) => $q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : ""
@ -232,6 +256,7 @@ class Ordentrabajo extends BaseController
->edit("tiempo_estimado", fn($q) => float_seconds_to_hhmm_string($q->tiempo_estimado))
->edit("tiempo_real", fn($q) => float_seconds_to_hhmm_string($q->tiempo_real))
->edit("maquina_tarea", fn($q) => ["id" => $q->id, "maquina_id" => $q->maquina_tarea, "maquina_name" => $q->maquina_nombre])
->add("imposicion", fn($q) => ["id" => $q->id, "imposicion_id" => $q->imposicion_id, "name" => $q->imposicion_name, "is_presupuesto_linea" => $q->presupuesto_linea_id ? true : false])
->toJson(true);
}
public function get_pdf($orden_trabajo_id)
@ -241,7 +266,6 @@ class Ordentrabajo extends BaseController
public function upload_orden_trabajo_portada()
{
try {
//code...
$file = $this->request->getFile("portada_file");
$bodyData = $this->request->getPost();
$id = $bodyData["orden_trabajo_id"];
@ -249,6 +273,12 @@ class Ordentrabajo extends BaseController
$fullpath = null;
if ($file->isValid() && !$file->hasMoved()) {
$fullpath = $file->store('ordenes_trabajo_portadas');
$otEntity = $this->otModel->find($id);
if ($otEntity->portada_path) {
if (file_exists($otEntity->full_path)) {
unlink($otEntity->full_path);
}
}
$r = $this->otModel->update($id, ["portada_path" => $fullpath]);
}
return $this->response->setJSON(["message" => "Portada subida", "data" => $r]);
@ -256,7 +286,7 @@ class Ordentrabajo extends BaseController
if ($fullpath) {
delete_files($fullpath);
}
return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode($th->getCode());
return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode(500);
}
}
public function delete_orden_trabajo_portada($orden_trabajo_id)
@ -280,7 +310,7 @@ class Ordentrabajo extends BaseController
try {
$ot = $this->otModel->find($orden_trabajo_id);
if ($ot->portada_path) {
$filePath = WRITEPATH . 'uploads/' . $ot->portada_path;
$filePath = $ot->full_path;
if (file_exists($filePath)) {
$mimeType = mime_content_type($filePath);
@ -296,31 +326,30 @@ class Ordentrabajo extends BaseController
}
} catch (\Throwable $th) {
return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode(500);
}
}
public function planning_rotativa_datatable()
{
$q = $this->produccionService->planningRotativaQueryDatatable();
return DataTable::of($q)
$query = $this->produccionService->planningRotativaQueryDatatable();
return DataTable::of($query)
->edit("fecha_entrega_real_at", fn($q) => $q->fecha_entrega_real_at ? Time::createFromFormat("Y-m-d", $q->fecha_entrega_real_at)->format("d/m/Y") : "")
->add("metros_check", fn($q) => $q->otId)
->add("corte", fn($q) => ["otId" => $q->otId, "tipo_corte" => $this->produccionService->ordenTrabajoTareaCorte($q->otId)])
->add("action", fn($q) => $q)
->add("action", fn($q) => ["data" => $q])
->toJson(true);
}
public function planning_plana_datatable()
{
$q = $this->produccionService->planningPlanaQueryDatatable();
$query = $this->produccionService->planningPlanaQueryDatatable();
$padreId = $this->request->getGet('padre_id');
if ($padreId) {
$q->where('lg_maquinas.padre_id', $padreId);
$query->where('lg_maquinas.padre_id', $padreId);
}
return DataTable::of($q)
return DataTable::of($query)
->edit("tiempo_real_sum", fn($q) => $q->tiempo_real_sum)
->edit("fecha_entrega_real_at", fn($q) => $q->fecha_entrega_real_at ? Time::createFromFormat("Y-m-d", $q->fecha_entrega_real_at)->format("d/m/Y") : "")
->add("pliegos_check", fn($q) => $q->otId)
->add("action", fn($q) => $q)
->add("action", fn($q) => ["data" => $q ])
->toJson(true);
}
public function select_maquina_planning_rot()
@ -404,4 +433,9 @@ class Ordentrabajo extends BaseController
);
}
}
public function get_orden_trabajo_color_status(int $orden_trabajo_id)
{
$color = $this->produccionService->init($orden_trabajo_id)->getOtColorStatus();
return $this->response->setJSON(["color" => $color]);
}
}