From 5138681718b2b2463b663fea7e76c903d80ace6b Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 2 May 2025 07:56:28 +0200 Subject: [PATCH 1/4] feat/ot-datatable-news --- ci4/app/Config/OrdenTrabajo.php | 19 ++- ci4/app/Config/Routes.php | 4 + .../Controllers/Produccion/Ordentrabajo.php | 67 +++++++++- .../Produccion/OrdenTrabajoTareaEntity.php | 6 + .../Tarifas/Acabados/TarifaAcabadoEntity.php | 10 +- ci4/app/Language/es/Produccion.php | 43 ++++-- ci4/app/Services/ProductionService.php | 64 ++++++--- .../viewMaquinistaMaquinaTareas.php | 2 + .../vuexy/form/produccion/ot/otProgress.php | 8 +- .../form/produccion/viewOrdenTrabajoList.php | 28 +++- .../components/datatables/otDatatable.js | 122 +++++++++++++++++- .../maquinista/maquinistaTareaView.js | 24 +++- .../js/safekat/pages/produccion/index.js | 6 +- .../assets/js/safekat/pages/produccion/ot.js | 8 +- 14 files changed, 346 insertions(+), 65 deletions(-) diff --git a/ci4/app/Config/OrdenTrabajo.php b/ci4/app/Config/OrdenTrabajo.php index 4f8be2d4..0e63dd5a 100755 --- a/ci4/app/Config/OrdenTrabajo.php +++ b/ci4/app/Config/OrdenTrabajo.php @@ -12,14 +12,14 @@ class OrdenTrabajo extends BaseConfig "interior_bn_at" => "interior_bn_user_id", "interior_color_at" => "interior_color_user_id", "cubierta_at" => "cubierta_user_id", - "sobrecubierta_at" => "sobrecubierta_user_id", //TODO - "guarda_at" => "guarda_user_id", //TODO + "sobrecubierta_at" => "sobrecubierta_user_id", + "guarda_at" => "guarda_user_id", //ACABADO "plastificado_at" => "plastificado_user_id", - "plakene_at" => "plakene_user_id", //TODO + "plakene_at" => "plakene_user_id", "retractilado_at" => "retractilado_user_id", - "estampado_at" => "estampado_user_id", //TODO - "uvi_at" => "uvi_user_id", //TODO + "estampado_at" => "estampado_user_id", + "uvi_at" => "uvi_user_id", "encuadernacion_at" => "encuadernacion_user_id", "corte_at" => "corte_user_id", "preparacion_interiores_at" => "preparacion_interior_user_id", @@ -121,7 +121,14 @@ class OrdenTrabajo extends BaseConfig "default" => ["bg" => "white", "color" => "black"], ]; - + public array $OT_TAREA_STATUS_COLOR = [ + "P" => '#FFD63A', + "F" => '#67AE6E', + "S" => '#EB5B00', + "I" => '#3A59D1', + "E" => '#FF0B55', + "D" => '#FFA725', + ]; public function __construct() { diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 352a871e..fc2e1373 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -751,6 +751,10 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->get('datatable_pendientes', 'Ordentrabajo::datatable_pendientes'); $routes->get('datatable_ferro_pendiente', 'Ordentrabajo::datatable_ferro_pendiente'); $routes->get('datatable_ferro_ok', 'Ordentrabajo::datatable_ferro_ok'); + $routes->get('datatable_news', 'Ordentrabajo::datatable_news'); + $routes->get('datatable_prod', 'Ordentrabajo::datatable_prod'); + $routes->get('datatable_waiting', 'Ordentrabajo::datatable_waiting'); + $routes->get('datatable_revision_com', 'Ordentrabajo::datatable_revision_com'); $routes->get('tareas/datatable/(:num)', 'Ordentrabajo::tareas_datatable/$1', ['as' => 'datatableTareasOrdenTrabajo']); $routes->get("tarea/progress/(:num)", "Ordentrabajo::get_orden_trabajo_progress_date/$1"); $routes->get('tarea/(:num)', 'Ordentrabajo::find_tarea/$1'); diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 413bb991..9d244726 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -283,6 +283,62 @@ class Ordentrabajo extends BaseController ->add("action", fn($q) => $q->id) ->toJson(true); } + public function datatable_news() + { + $logo = config(LogoImpresion::class); + + $q = $this->otModel->getDatatableQuery(); + return DataTable::of($q) + ->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 H:i:s", $q->fecha_encuadernado_at)->format("d/m/Y") : "" + ) + ->add("action", fn($q) => $q->id) + ->toJson(true); + } + public function datatable_prod() + { + $logo = config(LogoImpresion::class); + + $q = $this->otModel->getDatatableQuery()->where('presupuestos.ferro',1)->where("ferro_ok_at is NOT NULL", NULL, FALSE); + return DataTable::of($q) + ->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 H:i:s", $q->fecha_encuadernado_at)->format("d/m/Y") : "" + ) + ->add("action", fn($q) => $q->id) + ->toJson(true); + } + public function datatable_waiting() + { + $logo = config(LogoImpresion::class); + + $q = $this->otModel->getDatatableQuery()->where('ordenes_trabajo.is_pedido_espera',1); + return DataTable::of($q) + ->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 H:i:s", $q->fecha_encuadernado_at)->format("d/m/Y") : "" + ) + ->add("action", fn($q) => $q->id) + ->toJson(true); + } + public function datatable_revision_com() + { + $logo = config(LogoImpresion::class); + + $q = $this->otModel->getDatatableQuery()->where('presupuestos.ferro',1)->where("ferro_ok_at is NOT NULL", NULL, FALSE); + return DataTable::of($q) + ->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 H:i:s", $q->fecha_encuadernado_at)->format("d/m/Y") : "" + ) + ->add("action", fn($q) => $q->id) + ->toJson(true); + } public function papel_gramaje_datatable() { @@ -585,8 +641,15 @@ class Ordentrabajo extends BaseController $validated = $this->validation->run($bodyData, "orden_trabajo_tarea_progress_date"); // return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "data" => $this->validation->getValidated(),"errors" => $this->validation->getErrors()]); if ($validated) { - $r = $this->produccionService->storeOrdenTrabajoTareaProgressDate($this->validation->getValidated()); - return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $bodyData]); + $validatedData = $this->validation->getValidated(); + $r = $this->produccionService->storeOrdenTrabajoTareaProgressDate($validatedData); + $otTareaEntity = $this->otTarea->find($validatedData['ot_tarea_id']); + $data = [ + "tiempo_trabajado" => float_seconds_to_hhmm_string($otTareaEntity->tiempo_trabajado()), + "tarea" => $otTareaEntity, + "estado" => $validatedData['estado'], + ]; + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $data]); } else { return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); } diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php index 1d32be82..3dcf518e 100755 --- a/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php @@ -178,6 +178,12 @@ class OrdenTrabajoTareaEntity extends Entity $m = model(OrdenTrabajoTareaProgressDate::class); return $m->where('ot_tarea_id', $this->attributes["id"])->findAll() ?? []; } + public function lastState() : ?OrdenTrabajoTareaProgressDateEntity + { + $m = model(OrdenTrabajoTareaProgressDate::class); + $progressDates = $m->where('ot_tarea_id', $this->attributes["id"])->orderBy('action_at', 'DESC')->first(); + return $progressDates; + } public function tiempo_trabajado() { $dates = $this->progress_dates(); diff --git a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php index 30d846b5..1af0fde3 100755 --- a/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php +++ b/ci4/app/Entities/Tarifas/Acabados/TarifaAcabadoEntity.php @@ -24,11 +24,11 @@ class TarifaAcabadoEntity extends \CodeIgniter\Entity\Entity "deleted_at" => null, "created_at" => null, "updated_at" => null, - 'plastificado' => false, - 'plakene' => false, - 'rectractilado' => false, - 'estampado' => false, - 'uvi' => false, + 'plastificado' => null, + 'plakene' => null, + 'rectractilado' => null, + 'estampado' => null, + 'uvi' => null, 'plastificado_tipo' => null, 'plakene_tipo' => null, 'rectractilado_tipo' => null, diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index ee18d7b6..6d97b6fe 100755 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -1,15 +1,25 @@ [ + 'finalizadas' => 'Finalizadas', + 'pendientes' => 'Pendientes', + 'pendientes_ferro' => 'Ferro pendiente', + 'ferro_ok' => 'Ferro/Prototipo OK', + 'news' => 'Nuevas', + 'waiting' => 'En espera', + 'revision_com' => 'Revisión comercial', + 'prod' => 'Producción' + ], "datatable" => [ - "pedido_id"=> "Pedido ID", - "fecha_encuadernacion"=> "Fecha encuadernación", - "fecha_impresion"=> "Fecha impresión", - "cliente"=> "Cliente", - "titulo"=> "Título", - "ubicacion"=> "Ubicación", - "tirada"=> "Tirada", - "impresion"=> "Impresión", + "pedido_id" => "Pedido ID", + "fecha_encuadernacion" => "Fecha encuadernación", + "fecha_impresion" => "Fecha impresión", + "cliente" => "Cliente", + "titulo" => "Título", + "ubicacion" => "Ubicación", + "tirada" => "Tirada", + "impresion" => "Impresión", "fecha_entrega_at" => "Fecha entrega prevista", "maquina" => "Máquina", "ancho" => "Ancho", @@ -31,8 +41,6 @@ return [ "pliegos" => "Pliegos", "pliegos_libro" => "Pliegos", "fecha" => "fecha" - - ], "task" => [ "order" => "Orden", @@ -116,7 +124,7 @@ return [ "pre_solapa" => "Revisión solapa", "pre_codbarras" => "Revisión código barras", "pre_imposicion" => "Revisión imposición", - + "iniciada" => "Iniciada", "finalizada" => "Finalizada", "error" => "Error", @@ -128,7 +136,7 @@ return [ "attr_not_exist" => "El atributo {0,string} no pertenece al modelo Pedido" ], - + "progress_ferro" => "Ferro", "progress_preimpresion" => "Preimpresión", "progress_logistica" => "Logística", @@ -139,6 +147,7 @@ return [ "maquinas" => "Máquinas", "tareas_hoy" => "Tareas para HOY", "tareas_all" => "Todas", + "tareas_delay" => "Aplazadas", "play_tarea" => "Continuar", "play_pause" => "Pausar", "play_stop" => "Aplazar", @@ -146,6 +155,14 @@ return [ "cancel" => "Cancelar", ], + 'tarea_estados' => [ + 'P' => 'Pendiente', + 'I' => 'Iniciada', + 'F' => 'Finalizada', + 'S' => 'Pausada', + 'D' => 'Aplazada', + 'E' => 'Error' + ], 'duplicate_estado_tarea_progress' => "Último estado de la tarea repetido", 'task_already_finished' => "La tarea se ha marcado como finalizada.", 'print_label' => "Imprimir etiqueta", @@ -158,4 +175,4 @@ return [ "comentariosEncuadernacion" => "Comentarios encuadernación", "comentariosLogistica" => "Comentarios logística", "info_solapa_guillotina" => "Datos solapa y preparación guillotina", -]; \ No newline at end of file +]; diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index de5c7dfa..4add157d 100755 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -110,6 +110,12 @@ class ProductionService extends BaseService * @var boolean */ public bool $isPlastificado = false; //* CHECK DONE + /** + * Indica si la orden de trabajo contiene retractilado + * Se usa para mostrar la fecha correspondiente en la vista + * @var boolean + */ + public bool $isRetractilado = false; //* CHECK DONE /** * Indica si la orden de trabajo contiene gofrado * Se usa para mostrar la fecha correspondiente en la vista @@ -273,6 +279,10 @@ class ProductionService extends BaseService $this->storeOrdenTrabajoUsers(); $this->storeOrdenTrabajoDates(); $this->storeAllTareas(); + try { + $this->updatePodDates(); + } catch (\Throwable $th) { + } $this->updatePedidoEspera(); return $this->ot; } @@ -844,6 +854,7 @@ class ProductionService extends BaseService "tareas_preimpresion" => $this->tareas_preimpresion(), "tareas_impresion" => $this->tareas_impresion(), "tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(), + "tiempo_total" => $this->getTiempoTotalTareas(), "statusColor" => $this->getOtColorStatus(), "tareaCosido" => $this->getTareaCosido(), ]; @@ -989,8 +1000,8 @@ class ProductionService extends BaseService throw new Exception(lang('Produccion.task_already_finished')); } } - if(isset($data['estado'])){ - if($data['estado'] == 'F'){ + if (isset($data['estado'])) { + if ($data['estado'] == 'F') { $tareaEntity = $this->otTarea->find($data['ot_tarea_id']); $this->init($tareaEntity->orden_trabajo_id); $dateName = $this->getOrdenTrabajoTareaDate($tareaEntity); @@ -1015,11 +1026,11 @@ class ProductionService extends BaseService $data["action_at"] = Time::now()->format('Y-m-d H:i:s'); $data["action_user_id"] = auth()->user()->id; $status = $this->otTareaProgressDate->where('ot_tarea_id', $orden_trabajo_tarea_id)->delete(); - if($status){ - $tareaEntity = $this->otTarea->find($orden_trabajo_tarea_id); - $this->init($tareaEntity->orden_trabajo_id); - $dateName = $this->getOrdenTrabajoTareaDate($tareaEntity); - $this->emptyOrdenTrabajoDate($this->ot->id,$dateName); + if ($status) { + $tareaEntity = $this->otTarea->find($orden_trabajo_tarea_id); + $this->init($tareaEntity->orden_trabajo_id); + $dateName = $this->getOrdenTrabajoTareaDate($tareaEntity); + $this->emptyOrdenTrabajoDate($this->ot->id, $dateName); } if ($status) { $response = $this->storeOrdenTrabajoTareaProgressDate($data); @@ -1409,14 +1420,33 @@ class ProductionService extends BaseService } public function getTiempoTareasImpresionHHMM(): string { - $tareas_impresion = $this->ot->tareas_impresion(); - $tiempo_seconds = 0; - foreach ($tareas_impresion as $key => $tarea) { - if ($tarea->is_corte == false) { - $tiempo_seconds += $tarea->tiempo_estimado; + try { + $tareas_impresion = $this->ot->tareas_impresion(); + $tiempo_seconds = 0; + foreach ($tareas_impresion as $key => $tarea) { + if ($tarea->is_corte == false) { + $tiempo_seconds += $tarea->tiempo_estimado; + } } + return float_seconds_to_hhmm_string($tiempo_seconds); + } catch (\Throwable $th) { + return '00:00'; + } + } + public function getTiempoTotalTareas(): string + { + try { + $tareas = $this->ot->tareas(); + $tiempo_seconds = 0; + foreach ($tareas as $key => $tarea) { + if ($tarea->tiempo_real) { + $tiempo_seconds += $tarea->tiempo_real; + } + } + return float_seconds_to_hhmm_string($tiempo_seconds); + } catch (\Throwable $th) { + return '00:00'; } - return float_seconds_to_hhmm_string($tiempo_seconds); } public function getUVI(): ?TarifaAcabadoEntity { @@ -1735,13 +1765,13 @@ class ProductionService extends BaseService $acabados = $this->presupuesto->acabados(); foreach ($acabados as $key => $acabado) { $tarifa_acabado = $acabado->tarifa(); - if ($tarifa_acabado->retractilado) { + if ($tarifa_acabado->rectractilado) { $flag = true; break; } } - $this->isPlakene = $flag; - return $this->isPlakene; + $this->isRetractilado = $flag; + return $this->isRetractilado; } public function plakene_tipo(): ?string { @@ -1891,7 +1921,7 @@ class ProductionService extends BaseService ) ->join("pedidos", "pedidos.id = ordenes_trabajo.pedido_id", "right") ->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left") - ->where('orden_trabajo_tareas.maquina_id', $maquina_id) + ->where('orden_trabajo_tareas.maquina_id', $maquina_id) // ->where('pedidos.fecha_impresion IS NOT NULL', null, false) ->where("orden_trabajo_tareas.deleted_at", null) ->where("tarea_progress.estado", 'P') diff --git a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaTareas.php b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaTareas.php index 5645741a..6667d9da 100644 --- a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaTareas.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaTareas.php @@ -18,6 +18,8 @@ use CodeIgniter\I18n\Time;
+ +
diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php index 87812602..2045ebdc 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php @@ -268,7 +268,7 @@
-
"> +
">
> @@ -320,10 +320,12 @@
-

: (HH:MM)

+ (HH:MM) +
-

:

+ (HH:MM) +
diff --git a/ci4/app/Views/themes/vuexy/form/produccion/viewOrdenTrabajoList.php b/ci4/app/Views/themes/vuexy/form/produccion/viewOrdenTrabajoList.php index 620c8805..d401c3d5 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/viewOrdenTrabajoList.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/viewOrdenTrabajoList.php @@ -11,17 +11,30 @@ +endSection() ?> + +section('css') ?> + + + + + + +endSection() ?> + +section("additionalExternalJs") ?> + + + + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDetails.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDetails.php index dc0f28ab..c9f59ff2 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDetails.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDetails.php @@ -22,7 +22,11 @@
-
papel_formato()->ancho?>xpapel_formato()->alto?>
+ papel_formato_personalizado): ?> +
papel_formato_ancho ?>xpapel_formato_alto ?>
+ +
papel_formato()->ancho ?>xpapel_formato()->alto ?>
+
@@ -33,30 +37,32 @@
-
paginas?>
+
paginas ?>
-
-
-
- -
-
-
solapas > 0 ? $presupuesto->solapas : 0?>
+ solapas): ?> +
+
+
+ +
+
+
solapas_ancho, 2, ',', '.') ?> mm
- + +
-
+
-
tirada?>
+
tirada ?>
@@ -68,7 +74,7 @@
-
merma?>
+
merma ?>
diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php index 40b4185a..e44420b3 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otFiles.php @@ -1,5 +1,5 @@
- 'dropzone-ot-files','modelId' => $modelId]) ?> + 'dropzone-ot-files','modelId' => $presupuesto->id]) ?>
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/main/menus/maquinista_menu.php b/ci4/app/Views/themes/vuexy/main/menus/maquinista_menu.php index da1405f9..b6e00ab1 100755 --- a/ci4/app/Views/themes/vuexy/main/menus/maquinista_menu.php +++ b/ci4/app/Views/themes/vuexy/main/menus/maquinista_menu.php @@ -22,11 +22,6 @@ if (auth()->user()->inGroup('maquina','admin')) {
- \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/pdfs/ferro.php b/ci4/app/Views/themes/vuexy/pdfs/ferro.php index 2b22a376..c59bdf65 100755 --- a/ci4/app/Views/themes/vuexy/pdfs/ferro.php +++ b/ci4/app/Views/themes/vuexy/pdfs/ferro.php @@ -286,9 +286,7 @@ $settings = $session->get('settings');
-
- © 2024 SAFEKAT. Todos los derechos reservados. -
+ diff --git a/ci4/app/Views/themes/vuexy/pdfs/orden_trabajo.php b/ci4/app/Views/themes/vuexy/pdfs/orden_trabajo.php index 315a5bf6..62271989 100755 --- a/ci4/app/Views/themes/vuexy/pdfs/orden_trabajo.php +++ b/ci4/app/Views/themes/vuexy/pdfs/orden_trabajo.php @@ -393,11 +393,6 @@ $settings = $session->get('settings'); -
- © 2024 SAFEKAT. Todos los derechos reservados. -
- - diff --git a/ci4/app/Views/themes/vuexy/pdfs/prototipo.php b/ci4/app/Views/themes/vuexy/pdfs/prototipo.php index 53f2a8fe..29dd77b7 100755 --- a/ci4/app/Views/themes/vuexy/pdfs/prototipo.php +++ b/ci4/app/Views/themes/vuexy/pdfs/prototipo.php @@ -391,9 +391,7 @@ $settings = $session->get('settings'); -
- © 2024 SAFEKAT. Todos los derechos reservados. -
+ diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js new file mode 100644 index 00000000..b504e142 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js @@ -0,0 +1,175 @@ + +import Ajax from '../../../components/ajax.js' +import { alertConfirmAction, alertError, alertSuccess } from '../../../components/alerts/sweetAlert.js' + +class MaquinistaFichajeAuto { + constructor(domItem) { + this.item = domItem + /** ELEMENT DOM VARIABLES */ + this.otInputId = this.item.find('#ot-id') + this.wrapperCard = this.item.find('#ot-fa-card') + this.btnCancelTarea = this.item.find('#btn-cancel-tarea') + this.btnFinishTarea = this.item.find('#btn-finish-tarea') + this.inputClickInit = this.item.find("#input-click-init") + this.inputClickEnd = this.item.find("#input-click-end") + + this.otId = null + this.lastOtId = null + this.maquinaId = this.item.data("id") + this.tareas = [] + + } + init() { + Notiflix.Block.circle('.section-block'); + this.otInputId.trigger('focus') + this.otInputId.on('change', this._handleGetOt.bind(this)) + this.btnFinishTarea.on('click', this._handleFinishTareasConfirm.bind(this)) + } + + hideCard() { + this.wrapperCard.addClass('d-none') + } + showCard() { + this.wrapperCard.removeClass('d-none') + } + actionLoader(status = true) { + if (status) { + Notiflix.Block.circle('.section-block'); + } else { + Notiflix.Block.remove('.section-block'); + } + } + + getFormData() { + return { + maquina_id: this.maquinaId, + tareas: this.tareas, + click_init: this.inputClickInit.val() ?? 0, + click_end: this.inputClickEnd.val() ?? 0 + } + } + fillData(data) { + this.lastOtId = data.ot.id + this.item.find('#ot-id-header').text(data.ot.id) + this.item.find('#presupuesto-id').text(data.presupuesto.id) + this.item.find('#ot-title').text(data.presupuesto.titulo) + if (data.tareas) { + this.tareas = data.tareas.map(tarea => tarea.id) + } + + } + + + _handleGetOt() { + this.otId = this.otInputId.val(); + this.otInputId.removeClass('is-valid') + this.otInputId.removeClass('is-invalid') + this.actionLoader(false) + let ajax = new Ajax( + `/produccion/ordentrabajo/tareas/maquina/${this.otId}/${this.maquinaId}`, + null, + null, + this._handleGetOtSuccess.bind(this), + this._handleGetOtError.bind(this) + ) + if (this.otId) { + ajax.get(); + } + } + _handleGetOtSuccess(response) { + this.showCard(); + if (this.lastOtId) { + console.log("Siguiente OT insertada") + console.log("Iniciar ", this.otId) + if (this.lastOtId != this.otId) { + console.log("Finalizar", this.lastOtId) + this._handleFinishTareas(this.lastOtId) + } + } else { + console.log("Primera OT insertada") + } + this.otInputId.addClass('is-valid') + popSuccessAlert(response.message) + this.actionLoader(false) + if (response.data) { + this.fillData(response.data) + response.data.tareas.forEach(tarea => { + this._handleInitTareas(tarea.id, 'I') + }); + } + } + _handleGetOtError(error) { + this.hideCard() + this.otInputId.addClass('is-invalid') + popErrorAlert(error.responseJSON.message) + } + _handleInitTareas(tareaId, estado = 'I') { + let ajax = new Ajax('/produccion/ordentrabajo/update/tarea/progress', + { + ot_tarea_id: tareaId, + estado: estado + }, null, + this._handleInitTareasSuccess.bind(this), + this._handleInitTareasError.bind(this) + ); + if (tareaId) { + ajax.post(); + } + } + _handleInitTareasSuccess() { } + _handleInitTareasError() { } + + _handleFinishTareas(otId) { + let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish', + { + orden_trabajo_id: otId, + ...this.getFormData() + }, null, + this._handleFinishTareasSucess.bind(this), + this._handleFinishTareasError.bind(this) + ); + ajax.post() + + } + _handleFinishTareasConfirm(event) { + let otId = this.otInputId.val() + console.log("Finalizar", otId); + let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish', + { + orden_trabajo_id: otId, + ...this.getFormData() + }, null, + this._handleFinishTareasConfirmSucess.bind(this), + this._handleFinishTareasConfirmError.bind(this) + ); + if (otId) { + alertConfirmAction('Se va finalizar la tarea actual y se cancelará el modo auto.') + .then((result) => { + if (result.isConfirmed) { + ajax.post(); + } + }) + } + + } + _handleFinishTareasConfirmSucess(response) { + this.hideCard() + this.otInputId.val(null) + this.otId = null + this.lastOtId = null + this.tareas = [] + popSuccessAlert(response.message) + } + _handleFinishTareasConfirmError() { } + _handleFinishTareasSucess() { } + _handleFinishTareasError() { } + + + + + + + +} + +export default MaquinistaFichajeAuto; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js new file mode 100644 index 00000000..4aa88cdd --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js @@ -0,0 +1,109 @@ + +import Ajax from '../../../components/ajax.js' +import { alertConfirmAction, alertError, alertSuccess } from '../../../components/alerts/sweetAlert.js' + +class MaquinistaScan { + constructor(domItem) { + this.item = domItem + /** ELEMENT DOM VARIABLES */ + this.otInputId = this.item.find('#ot-id') + this.wrapperCard = this.item.find('#ot-fa-card') + this.otId = null + this.maquinaId = this.item.data("id") + this.ots = [] + this.datatableItem = this.item.find('#table-scanned-ots') + this.datatableColumns = [ + { data: 'id', searchable: false, sortable: false }, + { data: 'title', searchable: false, sortable: false }, + ] + this.datatableData = []; + } + init() { + this.otInputId.trigger('focus') + this.otInputId.on('change', this.addOt.bind(this)) + this.datatable = this.datatableItem.DataTable({ + processing: true, + serverSide: false, + ordering: false, + dom: "", + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: this.datatableColumns, + data: this.datatableData + }); + } + + hideCard() { + this.wrapperCard.addClass('d-none') + } + showCard() { + this.wrapperCard.removeClass('d-none') + } + actionLoader(status = true) { + if (status) { + Notiflix.Block.circle('.section-block'); + } else { + Notiflix.Block.remove('.section-block'); + } + } + reloadFocus(){ + this.otInputId.val("") + this.otInputId.trigger('focus') + } + async addOt() { + try { + if (this.ots.includes(this.otInputId.val())) { + throw new Error("Esta OT ya ha sido introducida"); + } + if (this.otInputId.val()) { + let response = await this.getOt(this.otInputId.val()) + console.log(response) + const data = response.data + this.ots.push(data.ot.id) + this.datatable.rows.add([{ + id: data.ot.id, + title: data.presupuesto.titulo + }]) + this.datatable.draw() + this.reloadFocus() + } + + } catch (error) { + console.log(error) + this.reloadFocus() + if (error?.responseJSON) { + popErrorAlert(error.responseJSON.message) + } else { + popErrorAlert(error) + } + } + } + getOt(otId) { + return new Promise((resolve, reject) => { + let ajax = new Ajax( + `/produccion/ordentrabajo/tareas/maquina/${otId}/${this.maquinaId}`, + null, + null, + (response) => { + resolve(response) + }, + (error) => { + reject(error) + } + ) + ajax.get(); + }) + + } + + + + + + + + +} + +export default MaquinistaScan; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaList.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaList.js index 6e7dc076..397706cb 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaList.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaList.js @@ -4,13 +4,15 @@ class MaquinistaTareaList { this.item = domItem this.maquinaId = this.item.data("id") this.datatableItem = $("#maquinista-tarea-table") + this.datatableTareaAplazadaItem = this.item.find('#maquinista-tarea-aplazada-table') + this.wrapperDatatableTareaAplazada = this.item.find('#tareas-aplazadas') this.btnTareasHoy = $("#btn-tareas-hoy") this.todayDate = $('#today-date') this.btnAllTareas = $("#btn-all-tareas") this.datatableColumns = [ { data: 'otId', searchable: false, sortable: false }, { data: 'tareaName', searchable: false, sortable: false }, - { data: 'tareaEstado', searchable: false, sortable: false,render : this.renderStado.bind(this)}, + { data: 'tareaEstado', searchable: false, sortable: false, render: this.renderStado.bind(this) }, // { data: 'presupuesto_titulo', searchable: false, sortable: false }, // { data: 'papel_impresion', searchable: false, sortable: false }, // { data: 'papel_gramaje', searchable: false, sortable: false }, @@ -18,27 +20,28 @@ class MaquinistaTareaList { { data: 'action', searchable: false, sortable: false, width: "20rem" }, ] this.urlAll = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/all/' + this.maquinaId + this.urlAplazada = '/produccion/ordentrabajo/maquinista/maquinas/tareas/aplazadas/datatable/' + this.maquinaId this.urlToday = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/today/' + this.maquinaId this.initTable() this.estadoClass = { - I : 'primary', - P : 'warning', - S : 'warning', - D : 'danger', - F : 'success' + I: 'primary', + P: 'warning', + S: 'warning', + D: 'danger', + F: 'success' } this.estadoNames = { - I : 'Iniciada', - P : 'Pendiente', - S : 'Pausada', - D : 'Aplazada', - F : 'Finalizada' + I: 'Iniciada', + P: 'Pendiente', + S: 'Pausada', + D: 'Aplazada', + F: 'Finalizada' } } - init(){ - this.btnTareasHoy.on('click',this.loadToday.bind(this)) - this.btnAllTareas.on('click',this.loadAll.bind(this)) + init() { + this.btnTareasHoy.on('click', this.loadToday.bind(this)) + this.btnAllTareas.on('click', this.loadAll.bind(this)) } initTable() { @@ -51,13 +54,28 @@ class MaquinistaTareaList { bottomEnd: 'paging' }, serverSide: true, - pageLength: 25, + pageLength: 100, language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" }, columns: this.datatableColumns, ajax: this.urlToday }); + this.datatableAplazada = this.datatableTareaAplazadaItem.DataTable({ + processing: true, + layout: { + bottomStart: 'info', + bottomEnd: 'paging' + }, + serverSide: true, + pageLength: 100, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: this.datatableColumns, + ajax: this.urlAplazada + }); + this.datatableAplazada.on('draw.dt', this.handleShowTareasAplazadas.bind(this)) } loadToday() { this.btnTareasHoy.removeClass('active') @@ -66,25 +84,34 @@ class MaquinistaTareaList { this.btnAllTareas.removeAttr('aria-pressed') this.todayDate.removeClass('d-none') this.btnTareasHoy.addClass('active') - this.btnTareasHoy.attr('aria-pressed',true) + this.btnTareasHoy.attr('aria-pressed', true) this.datatable.ajax.url(this.urlToday) this.datatable.ajax.reload() } - loadAll(){ + loadAll() { this.btnTareasHoy.removeClass('active') this.btnTareasHoy.removeAttr('aria-pressed') this.todayDate.addClass('d-none') this.btnAllTareas.addClass('active') - this.btnAllTareas.attr('aria-pressed',true) + this.btnAllTareas.attr('aria-pressed', true) this.datatable.ajax.url(this.urlAll) this.datatable.ajax.reload() } - renderStado(d){ + renderStado(d) { - return `${this.estadoNames[d]}` + return `${d.title}` + } + handleShowTareasAplazadas() { + let totalTareasAplazadas = this.datatableAplazada.page.info().recordsTotal + console.log(totalTareasAplazadas) + if (totalTareasAplazadas > 0) { + this.wrapperDatatableTareaAplazada.removeClass('d-none') + } else { + this.wrapperDatatableTareaAplazada.addClass('d-none') + } } } diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js index 95b529d6..cf112100 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js @@ -123,10 +123,12 @@ class MaquinistaTareaView { } } handleGetTareaProgressSuccess(response) { - if (response.progress_dates) { + if (response.progress_dates.length > 0) { let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado console.log("Last status :", lastStatus) this.showBasedOnStatus(lastStatus) + }else{ + this.showBasedOnStatus('P') } this.item.find('#tiempo-real-info').html(response.tiempo_trabajado ?? "00:00") this.actionLoader(false) diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewFichajeAuto.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewFichajeAuto.js new file mode 100644 index 00000000..e746d8ad --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewFichajeAuto.js @@ -0,0 +1,7 @@ +import MaquinistaFichajeAuto from "./maquinistaFichajeAuto.js"; + +$(() => { + console.info("MAQUINISTA FA") + let maquinistaFA = new MaquinistaFichajeAuto($("#viewMaquinistaFichajeAuto")) + maquinistaFA.init(); +}) \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewMaquinistaScan.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewMaquinistaScan.js new file mode 100644 index 00000000..ba8f6b13 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewMaquinistaScan.js @@ -0,0 +1,7 @@ +import MaquinistaScan from "./maquinistaScan.js"; + +$(() => { + console.info("MAQUINISTA SCAN") + let maquinistaScan = new MaquinistaScan($("#viewMaquinistaTareaScan")) + maquinistaScan.init(); +}) \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/produccion/ot.js b/httpdocs/assets/js/safekat/pages/produccion/ot.js index 75fa3b81..34f05244 100644 --- a/httpdocs/assets/js/safekat/pages/produccion/ot.js +++ b/httpdocs/assets/js/safekat/pages/produccion/ot.js @@ -33,6 +33,7 @@ class OrdenTrabajo { this.datatableColumns = [ { data: 'orden', searchable: true, sortable: true, render: this._renderOrdenTarea.bind(this) }, { data: 'nombre', searchable: true, sortable: true }, + { data: 'tarea_estado', searchable: false, sortable: false, render: this._renderTareaEstado.bind(this) }, { data: 'maquina_presupuesto_linea', searchable: true, sortable: true, render: (d) => { if (d) { @@ -68,10 +69,9 @@ class OrdenTrabajo { */ this.configUploadDropzone = { domElement: '#dropzone-ot-files', - nameId: "orden_trabajo_id", - getUri: '/produccion/ordentrabajo/get_files', - postUri: '/produccion/ordentrabajo/upload_files', - resourcePath: 'orden_trabajo/' + this.modelId + nameId: "presupuesto_id", + getUri: '/presupuestos/presupuestocliente/get_files', + postUri: '/presupuestos/presupuestocliente/upload_files' } if ($(this.configUploadDropzone.domElement).length > 0) { this.fileUploadDropzone = new FileUploadDropzone(this.configUploadDropzone) @@ -266,6 +266,22 @@ class OrdenTrabajo { ` return cell; } + _renderTareaEstado(d, t) { + let html = ` +
+ + +
+ ` + if(d.userName == ""){ + html = `${d.title}` + } + return html + } _renderOrdenTarea(d, t) { return ` @@ -431,6 +447,13 @@ class OrdenTrabajo { this.fillPreimpresionReview() this.fillPliegos() this.isOtFinalizada = this.summaryData.ot.estado == "F"; + if (this.isOtFinalizada) { + this.btnEraseDate.addClass('d-none').attr('disabled', 'disabled') + this.btnErasePedidoDate.addClass('d-none').attr('disabled', 'disabled') + } else { + this.btnEraseDate.removeClass('d-none').removeAttr('disabled') + this.btnErasePedidoDate.removeClass('d-none').removeAttr('disabled') + } this.datatableTareas.ajax.reload() } catch (error) { console.error(error) From 305eea00e60c3de66682740774137928f6b19660 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 5 May 2025 00:47:00 +0200 Subject: [PATCH 4/4] fichaje automatico y escaneo --- ci4/app/Config/Routes.php | 9 + ci4/app/Config/Validation.php | 11 + .../Controllers/Produccion/Ordentrabajo.php | 148 +++++++++++- ...2025-05-04-172900_MaquinaOtTareasTable.php | 58 +++++ .../OrdenTrabajoTareaProgressDateEntity.php | 2 +- .../Tarifas/Maquinas/MaquinaOtTareaEntity.php | 45 ++++ ci4/app/Helpers/time_helper.php | 12 +- ci4/app/Language/es/Produccion.php | 7 +- ci4/app/Models/Configuracion/MaquinaModel.php | 12 +- .../Configuracion/MaquinaOtTareaModel.php | 66 ++++++ ci4/app/Services/ProductionService.php | 5 + .../cards/tarea_multiple_card_actions.php | 55 +++++ .../maquinista/viewMaquinistaMaquinaList.php | 6 +- .../maquinista/viewMaquinistaTareaScan.php | 24 +- .../viewProduccionMaquinistaOtTareasView.php | 81 +++++++ .../maquinista/maquinistaMultipleTarea.js | 223 ++++++++++++++++++ .../maquinista/maquinistaScan.js | 69 +++++- .../maquinista/viewTareaMultipleView.js | 7 + httpdocs/themes/vuexy/css/maquinista.css | 6 + 19 files changed, 821 insertions(+), 25 deletions(-) create mode 100755 ci4/app/Database/Migrations/2025-05-04-172900_MaquinaOtTareasTable.php create mode 100755 ci4/app/Entities/Tarifas/Maquinas/MaquinaOtTareaEntity.php create mode 100755 ci4/app/Models/Configuracion/MaquinaOtTareaModel.php create mode 100644 ci4/app/Views/themes/vuexy/components/cards/tarea_multiple_card_actions.php create mode 100644 ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewProduccionMaquinistaOtTareasView.php create mode 100644 httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaMultipleTarea.js create mode 100644 httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewTareaMultipleView.js diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index b733f254..cc21364d 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -762,6 +762,8 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->get('datatable_waiting', 'Ordentrabajo::datatable_waiting'); $routes->get('datatable_revision_com', 'Ordentrabajo::datatable_revision_com'); $routes->get('tareas/datatable/(:num)', 'Ordentrabajo::tareas_datatable/$1', ['as' => 'datatableTareasOrdenTrabajo']); + $routes->get('maquinas/ots/datatable/(:num)','Ordentrabajo::datatable_maquina_ordenes_trabajo/$1'); + $routes->get('maquinas/ots/(:num)','Ordentrabajo::get_maquina_ots/$1'); /**====================== * UPDATES *========================**/ @@ -780,12 +782,17 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->post("update/tarea/pliegos", "Ordentrabajo::update_orden_trabajo_pliegos"); $routes->post("update/tarea/proveedor", "Ordentrabajo::update_presupuesto_tarea_proveedor"); $routes->post("fa/tareas/finish", 'Ordentrabajo::update_orden_trabajo_fa_tareas'); + $routes->post('maquinas/ots','Ordentrabajo::store_maquina_ordenes_trabajo'); + $routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado'); + /**DELETES */ $routes->delete("portada/(:num)", 'Ordentrabajo::delete_orden_trabajo_portada/$1'); $routes->delete("tarea/progress/(:num)", "Ordentrabajo::delete_orden_trabajo_progress_date/$1"); $routes->delete('reset/tareas/(:num)', 'Ordentrabajo::reset_tareas/$1'); $routes->delete('tareas/(:num)', 'Ordentrabajo::delete_tarea/$1'); + $routes->delete('maquinas/ots/(:num)', 'Ordentrabajo::delete_maquina_orden_trabajo_tarea/$1'); + $routes->delete('maquinas/ots/all/(:num)', 'Ordentrabajo::delete_maquina_orden_trabajo_all/$1'); /**====================== * FILES *========================**/ @@ -823,6 +830,8 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->get('maquinas/view/auto/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_fichaje_automatico/$1', ['as' => 'viewMaquinistaFichajeAutomatico']); $routes->get('maquinas/view/scan/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_scan/$1', ['as' => 'viewMaquinistaTareaScan']); $routes->get('maquinas/view/tarea/(:num)', 'Ordentrabajo::maquinista_maquina_tarea_view/$1', ['as' => 'viewProduccionMaquinistaTareaView']); + $routes->get('maquinas/view/maquina/ot/tareas/(:num)', 'Ordentrabajo::maquinista_maquina_ot_tareas_view/$1', ['as' => 'viewProduccionMaquinistaOtTareasView']); + $routes->get('colas/view', 'Ordentrabajo::maquinista_colas_view', ['as' => 'viewProduccionMaquinistaColas']); /** DATATABLE */ diff --git a/ci4/app/Config/Validation.php b/ci4/app/Config/Validation.php index a1acbd7a..02265475 100755 --- a/ci4/app/Config/Validation.php +++ b/ci4/app/Config/Validation.php @@ -195,6 +195,17 @@ class Validation extends BaseConfig "label" => "Click end" ], + ]; + public array $maquina_ordenes_trabajo = [ + "ordenes_trabajo" => [ + "rules" => "required", + "label" => "Orden trabajo" + ], + "maquina_id" => [ + "rules" => "required|integer", + "label" => "Máquina" + ], + ]; public array $chat_department = [ diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 0beac9d9..0cf73fce 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -5,6 +5,7 @@ namespace App\Controllers\Produccion; use App\Controllers\BaseController; use App\Models\Compras\ProveedorModel; use App\Models\Configuracion\MaquinaModel; +use App\Models\Configuracion\MaquinaOtTareaModel; use App\Models\OrdenTrabajo\OrdenTrabajoModel; use App\Models\OrdenTrabajo\OrdenTrabajoTarea; use App\Models\OrdenTrabajo\OrdenTrabajoUser; @@ -31,6 +32,7 @@ class Ordentrabajo extends BaseController protected OrdenTrabajoTarea $otTarea; protected ProveedorModel $proveedorModel; protected MaquinaModel $maquinaModel; + protected MaquinaOtTareaModel $maquinaOtTareaModel; protected UserModel $userModel; protected Validation $validation; protected static $viewPath = 'themes/vuexy/form/produccion/'; @@ -47,6 +49,7 @@ class Ordentrabajo extends BaseController $this->produccionService = new ProductionService(); $this->otTarea = model(OrdenTrabajoTarea::class); $this->maquinaModel = model(MaquinaModel::class); + $this->maquinaOtTareaModel = model(MaquinaOtTareaModel::class); $this->proveedorModel = model(ProveedorModel::class); $this->validation = service("validation"); helper("time"); @@ -375,8 +378,8 @@ class Ordentrabajo extends BaseController ->add("action", fn($q) => $q) ->edit("orden", fn($q) => ["id" => $q->id, "orden" => $q->orden]) ->add("tarea_estado", fn($q) => $this->produccionService->getTitleTareaEstado($q->id)) - ->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("tiempo_estimado", fn($q) => float_seconds_to_hhmmss_string($q->tiempo_estimado)) + ->edit("tiempo_real", fn($q) => float_seconds_to_hhmmss_string($q->tiempo_real)) ->add("proveedor", fn($q) => $this->produccionService->getProveedorTarea($q->id)) ->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]) @@ -601,7 +604,12 @@ class Ordentrabajo extends BaseController ['title' => $maquina->nombre, 'route' => route_to("viewProduccionMaquinistaMaquina", $maquina_id), 'active' => true], ]; $this->viewData["maquinaEntity"] = $maquina; - return view(static::$viewPath . '/maquinista/viewMaquinistaMaquinaTareas', $this->viewData); + $tareasRunning = $this->maquinaOtTareaModel->queryDatatableJoinOrdenTrabajo($maquina->id)->countAllResults(); + if ($tareasRunning) { + return view(static::$viewPath . '/maquinista/viewProduccionMaquinistaOtTareasView', $this->viewData); + } else { + return view(static::$viewPath . '/maquinista/viewMaquinistaMaquinaTareas', $this->viewData); + } } public function maquinista_maquina_tareas_fichaje_automatico(int $maquina_id) { @@ -628,9 +636,19 @@ class Ordentrabajo extends BaseController ['title' => $otTareaEntity->nombre, 'route' => route_to("viewProduccionMaquinistaTareaView", $otTareaEntity->id), 'active' => true] ]; - return view(static::$viewPath . '/maquinista/viewMaquinistaMaquinaTarea', $this->viewData); } + public function maquinista_maquina_ot_tareas_view(int $maquina_id) + { + $maquinaEntity = $this->maquinaModel->find($maquina_id); + $this->viewData['maquinaEntity'] = $maquinaEntity; + $tareasRunning = $this->maquinaOtTareaModel->queryDatatableJoinOrdenTrabajo($maquina_id)->countAllResults(); + if ($tareasRunning) { + return view(static::$viewPath . '/maquinista/viewProduccionMaquinistaOtTareasView', $this->viewData); + } else { + return view(static::$viewPath . '/maquinista/viewMaquinistaMaquinaTareas', $this->viewData); + } + } public function maquinista_colas_view() { return view(static::$viewPath . '/maquinista/viewMaquinistaPlanningList', $this->viewData); @@ -722,14 +740,14 @@ class Ordentrabajo extends BaseController return $this->response->setJSON(["message" => lang("App.global_alert_fetch_success"), "data" => $data]); } else { $tareasWithMaquina = $this->produccionService->init($orden_trabajo_id)->getTareasWithMaquina($maquina_id, ['F']); - if($tareasWithMaquina){ + if ($tareasWithMaquina) { return $this->response->setJSON(["message" => lang("Produccion.errors.tareas_finalizadas"), "data" => $tareasWithMaquina])->setStatusCode(400); - }else{ + } else { return $this->response->setJSON(["message" => lang("Produccion.errors.maquina_not_in_ot"), "data" => null])->setStatusCode(400); } } } - + public function update_orden_trabajo_fa_tareas() { $bodyData = $this->request->getPost(); @@ -757,4 +775,120 @@ class Ordentrabajo extends BaseController return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); } } + public function store_maquina_ordenes_trabajo() + { + $bodyData = $this->request->getPost(); + $validated = $this->validation->run($bodyData, "maquina_ordenes_trabajo"); + if ($validated) { + $validatedData = $this->validation->getValidated(); + + foreach ($validatedData['ordenes_trabajo'] as $key => $orden_trabajo_id) { + $maquinaOtTarea = $this->maquinaOtTareaModel->where('orden_trabajo_id', $orden_trabajo_id)->where('maquina_id', $validatedData['maquina_id'])->where('deleted_at',null)->countAllResults(); + if ($maquinaOtTarea) { + continue; + } + $this->maquinaOtTareaModel->insert(['maquina_id' => $validatedData['maquina_id'], 'orden_trabajo_id' => $orden_trabajo_id]); + } + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => true, "data" => $validatedData]); + } else { + return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); + } + } + public function update_maquina_ordenes_trabajo_estado() + { + $bodyData = $this->request->getPost(); + $maquina_id = $bodyData['maquina_id']; + $estado = $bodyData['estado']; + $maquina_ots = $this->maquinaOtTareaModel->where('maquina_id', $maquina_id)->findAll(); + $totalTareas = []; + + foreach ($maquina_ots as $key => $maquina_ot) { + $tareas = $this->produccionService->init($maquina_ot->orden_trabajo_id) + ->getTareasWithMaquina($maquina_id, ['P', 'I', 'S', 'D']); + foreach ($tareas as $key => $tarea) { + $this->produccionService->storeOrdenTrabajoTareaProgressDate( + [ + 'estado' => $estado, + 'ot_tarea_id' => $tarea->id + ] + ); + $tarea->click_init = $bodyData['click_init']; + $tarea->click_end = $bodyData['click_end']; + $totalTareas[] = $tarea; + + } + + } + foreach ($totalTareas as $key => $tarea) { + $tiempo_trabajado = $tarea->tiempo_trabajado(); + $tarea->tiempo_real = $tiempo_trabajado / count($totalTareas); + $tarea->click_init = $tarea->click_init / count($totalTareas); + $tarea->click_end = $tarea->click_end / count($totalTareas); + + $this->otTarea->save($tarea); + } + if ($estado == "F") { + $this->maquinaOtTareaModel->where('maquina_id', $maquina_id)->delete(); + } + + return $this->response->setJSON(["message" => lang("Produccion.responses.update_maquina_ordenes_trabajo_estado")]); + } + public function delete_maquina_orden_trabajo_tarea($maquina_orden_trabajo_tarea_id) + { + + $status = $this->maquinaOtTareaModel->delete($maquina_orden_trabajo_tarea_id); + return $this->response->setJSON(["message" => lang("App.user_alert_delete"), "status" => $status]); + } + public function delete_maquina_orden_trabajo_all($maquina_id) + { + $maquina_ots = $this->maquinaOtTareaModel->where('maquina_id', $maquina_id)->findAll(); + foreach ($maquina_ots as $key => $maquina_ot) { + $tareas = $this->produccionService->init($maquina_ot->orden_trabajo_id) + ->getTareasWithMaquina($maquina_id, ['P', 'I', 'S', 'D']); + foreach ($tareas as $key => $tarea) { + $this->produccionService->deleteOrdenTrabajoTareaProgressDates($tarea->id); + } + } + $status = $this->maquinaOtTareaModel->where('maquina_id',$maquina_id)->delete(); + return $this->response->setJSON(["message" => lang("App.user_alert_delete"), "status" => $status]); + } + + public function datatable_maquina_ordenes_trabajo($maquina_id) + { + $query = $this->maquinaOtTareaModel->queryDatatableJoinOrdenTrabajo($maquina_id); + return DataTable::of($query) + ->add('action', fn($q) => $q->otId) + ->add('titulo', fn($q) => $this->otModel->find($q->otId)->presupuesto()->titulo) + ->add('barcode', fn($q) => $this->otModel->find($q->otId)->getBarCode()) + ->toJson(true); + } + public function get_maquina_ots($maquina_id) + { + $responseData = [ + "tiempo_total_estimado" => 0, + "tiempo_total_real" => 0, + "clicks_total" => 0, + "tirada_total" => 0, + "estado" => "P", + ]; + $maquina_ots = $this->maquinaOtTareaModel->where('maquina_id', $maquina_id)->findAll(); + foreach ($maquina_ots as $key => $maquina_ot) { + $tareas = $this->produccionService->init($maquina_ot->orden_trabajo_id) + ->getTareasWithMaquina($maquina_id, ['P', 'I', 'S', 'D']); + foreach ($tareas as $key => $tarea) { + $responseData['tiempo_total_estimado']+= $tarea->tiempo_estimado; + $responseData['tiempo_total_real']+= $tarea->tiempo_real; + $responseData["estado"] = $tarea->lastState()->estado; + if($tarea->presupuesto_linea_id){ + $responseData["clicks_total"] += $tarea->presupuesto_linea()->rotativa_clicks_total; + $responseData["tirada_total"] += $tarea->orden_trabajo()->presupuesto()->tirada; + + } + } + } + $responseData['tiempo_total_estimado'] = float_seconds_to_hhmmss_string($responseData['tiempo_total_estimado']); + $responseData['tiempo_total_real'] = float_seconds_to_hhmmss_string($responseData['tiempo_total_real']); + return $this->response->setJSON($responseData); + + } } diff --git a/ci4/app/Database/Migrations/2025-05-04-172900_MaquinaOtTareasTable.php b/ci4/app/Database/Migrations/2025-05-04-172900_MaquinaOtTareasTable.php new file mode 100755 index 00000000..47a6fc4f --- /dev/null +++ b/ci4/app/Database/Migrations/2025-05-04-172900_MaquinaOtTareasTable.php @@ -0,0 +1,58 @@ + [ + 'type' => 'INT', + 'unsigned' => true, + 'auto_increment' => true, + ], + 'maquina_id' => [ + 'type' => 'INT', + 'unsigned' => true, + 'constraint' => 11 + ], + 'orden_trabajo_id' => [ + 'type' => 'INT', + 'unsigned' => true, + ], + + ]; + + public function up() + { + $this->forge->addField($this->COLUMNS); + $currenttime = new RawSql('CURRENT_TIMESTAMP'); + $this->forge->addField([ + 'created_at' => [ + 'type' => 'TIMESTAMP', + 'default' => $currenttime, + ], + 'updated_at' => [ + 'type' => 'TIMESTAMP', + 'null' => true, + ], + 'deleted_at' => [ + 'type' => 'TIMESTAMP', + 'null' => true, + + ], + ]); + $this->forge->addPrimaryKey('id'); + $this->forge->addForeignKey('maquina_id','lg_maquinas','id','CASCADE','CASCADE','maquina_ot_tareas_maquina_id_fk'); + $this->forge->addForeignKey('orden_trabajo_id','ordenes_trabajo','id','CASCADE','CASCADE','maquina_ot_tareas_ot_id_fk'); + $this->forge->createTable("maquina_ot_tareas"); + } + + public function down() + { + $this->forge->dropTable("maquina_ot_tareas"); + } +} diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoTareaProgressDateEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoTareaProgressDateEntity.php index 60276d7e..f0a60843 100755 --- a/ci4/app/Entities/Produccion/OrdenTrabajoTareaProgressDateEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoTareaProgressDateEntity.php @@ -21,7 +21,7 @@ class OrdenTrabajoTareaProgressDateEntity extends Entity /** * Orden de trabajo de la tarea * - * @return OrdenTrabajoEntity + * @return OrdenTrabajoTareaEntity */ public function orden_trabajo_tarea() : OrdenTrabajoTareaEntity { diff --git a/ci4/app/Entities/Tarifas/Maquinas/MaquinaOtTareaEntity.php b/ci4/app/Entities/Tarifas/Maquinas/MaquinaOtTareaEntity.php new file mode 100755 index 00000000..86cdc5ed --- /dev/null +++ b/ci4/app/Entities/Tarifas/Maquinas/MaquinaOtTareaEntity.php @@ -0,0 +1,45 @@ + null, + "maquina_id" => null, + "orden_trabajo_id" => null, + ]; + protected $casts = [ + "id" => "integer", + "maquina_id" => "integer", + "orden_trabajo_id" => "integer", + ]; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; + /** + * Orden de trabajo + * + * @return OrdenTrabajoEntity + */ + public function orden_trabajo_tarea(): OrdenTrabajoEntity + { + $m = model(OrdenTrabajoModel::class); + return $m->find($this->attributes["orden_trabajo_id"]); + } + /** + * Maquina + * + * @return Maquina + */ + public function maquina(): Maquina + { + $m = model(MaquinaModel::class); + return $m->find($this->attributes["maquina_id"]); + } +} diff --git a/ci4/app/Helpers/time_helper.php b/ci4/app/Helpers/time_helper.php index 6e1381ce..fb4bcffe 100755 --- a/ci4/app/Helpers/time_helper.php +++ b/ci4/app/Helpers/time_helper.php @@ -10,7 +10,17 @@ function float_seconds_to_hhmm_string(?float $time):?string } return $time_str; } - +function float_seconds_to_hhmmss_string(?float $time): ?string +{ + $time_str = null; + if ($time !== null) { + $hours = floor($time / 3600); + $minutes = floor(($time % 3600) / 60); + $seconds = floor($time % 60); + $time_str = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); + } + return $time_str; +} function week_day_humanize(int $week_day,bool $upper = false) : string { $week_days = ["Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"]; diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index 266deb21..c9c7ddce 100755 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -164,7 +164,8 @@ return [ "placeholder_ot_id" => "Introduce el ID de la OT", "fa_ot_input_form_text" => "Introduce una OT para terminar la actual e iniciar la siguiente.", "scan_ot_input_form_text" => "Introduce una OT para añadirla al proceso", - "next_scan_ot" => "Comenzar" + "next_scan_ot" => "Comenzar", + "reset" => "Resetear" ], @@ -188,7 +189,11 @@ return [ "comentariosEncuadernacion" => "Comentarios encuadernación", "comentariosLogistica" => "Comentarios logística", "info_solapa_guillotina" => "Datos solapa y preparación guillotina", + "responses" => [ + "finish_maquina_ordenes_trabajo" => "Tareas finalizadas correctamente", + "update_maquina_ordenes_trabajo_estado" => "Tareas actualizadas correctamente", + ], "errors" => [ "maquina_not_in_ot" => "Esta OT no tiene ninguna tarea con esta máquina", "tareas_finalizadas" => "Las tareas de esta OT y máquina están marcadas como finalizadas", diff --git a/ci4/app/Models/Configuracion/MaquinaModel.php b/ci4/app/Models/Configuracion/MaquinaModel.php index d462cc08..cbe249f8 100755 --- a/ci4/app/Models/Configuracion/MaquinaModel.php +++ b/ci4/app/Models/Configuracion/MaquinaModel.php @@ -404,7 +404,9 @@ class MaquinaModel extends \App\Models\BaseModel ->select([ 'lg_maquinas.id as maquinaId', 'lg_maquinas.nombre', - 'COUNT(tarea_progress.ot_tarea_id) as countTareas' + 'COUNT(tarea_progress.ot_tarea_id) as countTareas', + 'COUNT(maquina_ot_tareas.orden_trabajo_id) as countMaquinaTareas' + ]) ->join('orden_trabajo_tareas', 'orden_trabajo_tareas.maquina_id = lg_maquinas.id', 'left') ->join( @@ -420,6 +422,14 @@ class MaquinaModel extends \App\Models\BaseModel 'tarea_progress.ot_tarea_id = orden_trabajo_tareas.id', 'left' ) + ->join( + "(SELECT orden_trabajo_id,deleted_at,maquina_id + FROM maquina_ot_tareas + WHERE deleted_at is NULL + ) as maquina_ot_tareas", + 'maquina_ot_tareas.maquina_id = lg_maquinas.id', + 'left' + ) ->join('ordenes_trabajo', 'ordenes_trabajo.id = orden_trabajo_tareas.orden_trabajo_id', 'left') ->join('pedidos', 'pedidos.id = ordenes_trabajo.pedido_id', 'left') ->where('lg_maquinas.tipo', $maquina_tipo) diff --git a/ci4/app/Models/Configuracion/MaquinaOtTareaModel.php b/ci4/app/Models/Configuracion/MaquinaOtTareaModel.php new file mode 100755 index 00000000..dce7d17e --- /dev/null +++ b/ci4/app/Models/Configuracion/MaquinaOtTareaModel.php @@ -0,0 +1,66 @@ +builder() + ->select([ + 'maquina_ot_tareas.id as maquinaOtTareaId', + 'ordenes_trabajo.id as otId' + ]) + ->join('ordenes_trabajo','ordenes_trabajo.id = maquina_ot_tareas.orden_trabajo_id','left') + ->where('maquina_ot_tareas.maquina_id',$maquina_id) + ->where('maquina_ot_tareas.deleted_at',null); + + } + + +} diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index 8f984094..1a5349d1 100755 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -1051,6 +1051,10 @@ class ProductionService extends BaseService $this->init($tareaEntity->orden_trabajo_id); $dateName = $this->getOrdenTrabajoTareaDate($tareaEntity); $this->emptyOrdenTrabajoDate($this->ot->id, $dateName); + $tareaEntity->tiempo_real = 0; + $tareaEntity->click_init = 0; + $tareaEntity->click_end = 0; + $this->otTarea->save($tareaEntity); } if ($status) { $response = $this->storeOrdenTrabajoTareaProgressDate($data); @@ -1482,6 +1486,7 @@ class ProductionService extends BaseService } return $uvi; } + //TODO ACTUALIZAR public function updateProgress(): bool { $userDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING; diff --git a/ci4/app/Views/themes/vuexy/components/cards/tarea_multiple_card_actions.php b/ci4/app/Views/themes/vuexy/components/cards/tarea_multiple_card_actions.php new file mode 100644 index 00000000..58e362c9 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/components/cards/tarea_multiple_card_actions.php @@ -0,0 +1,55 @@ +
+
+
+
+
+ +
+ +
+

Tirada

+
+
+
" > +

Clicks

+
+
+
+ +
+
+

Tiempo estimado

+
+
+
+

Tiempo real

+
+
+
+
tipo != "impresion" ? "disabled" : "" ?>> +
+ + +
+
+ + +
+
+
+ +
+
+
+ + + + + + +
+
+
+ +
+
\ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaList.php b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaList.php index aadb2a0a..2fa945e9 100644 --- a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaList.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaMaquinaList.php @@ -18,7 +18,7 @@
$maquina): ?>
- " type="button" class="maquina-btn btn btn-outline-primary w-100"> + " type="button" class="maquina-btn btn btn-outline- 0 ? "danger" : "primary" ?> w-100"> 0): ?> @@ -39,7 +39,7 @@
$maquina): ?>
- " type="button" class="maquina-btn btn btn-outline-primary w-100"> + " type="button" class="maquina-btn btn btn-outline- 0 ? "danger" : "primary" ?> w-100"> 0): ?> @@ -60,7 +60,7 @@
$maquina): ?>
- " type="button" class="maquina-btn btn btn-outline-primary w-100"> + " type="button" class="maquina-btn btn btn-outline- 0 ? "danger" : "primary" ?> w-100"> 0): ?> diff --git a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaTareaScan.php b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaTareaScan.php index 7d37ba72..526426d7 100644 --- a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaTareaScan.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaTareaScan.php @@ -10,12 +10,21 @@ -
+

ESCANEAR: nombre ?>

-
- + +
+
+ +
+
+
+
@@ -38,16 +47,23 @@
-
+ + endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewProduccionMaquinistaOtTareasView.php b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewProduccionMaquinistaOtTareasView.php new file mode 100644 index 00000000..7ef0af1c --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewProduccionMaquinistaOtTareasView.php @@ -0,0 +1,81 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> +section('content'); ?> + +
+
+ + + + + + + + + + + +
+
+
+
+ +
+
+
+
+ +
+
+
+ +endSection() ?> + +section('css') ?> + + + + + + + +endSection() ?> + +section("additionalExternalJs") ?> + + + + + + + +endSection() ?> \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaMultipleTarea.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaMultipleTarea.js new file mode 100644 index 00000000..9211b8f7 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaMultipleTarea.js @@ -0,0 +1,223 @@ + + +import Ajax from '../../../components/ajax.js' +import { alertConfirmAction, alertError, alertSuccess } from '../../../components/alerts/sweetAlert.js' +class MaquinistaMultipleTarea { + constructor(domItem) { + this.item = domItem + this.maquinaId = this.item.data("id"); + this.btnPlay = this.item.find("#btn-start-tarea") + this.btnPause = this.item.find("#btn-pause-tarea") + this.btnDelay = this.item.find("#btn-stop-tarea") + this.btnFinish = this.item.find("#btn-finish-tarea") + this.btnDeleteProgress = this.item.find("#btn-delete-tarea") + this.actionButtons = this.item.find('.action-btn') + this.tareaCardClass = '.tarea-card-action-block' + this.inputClick = $('.ot-tarea-click') + this.datatableItem = this.item.find('#table-scanned-ots') + this.datatableColumns = [ + { data: 'otId', searchable: false, sortable: false }, + { data: 'titulo', searchable: false, sortable: false }, + { + data: 'barcode', searchable: false, sortable: false, render: (d, t) => { + return `barcode` + } + }, + { + data: 'action', searchable: false, sortable: false, render: (d, t) => { + return `` + } + }, + ] + } + init() { + this.actionButtons.on('click', this.eventActionButton.bind(this)) + this.btnDelay.on('click', this.delayEventActionButton.bind(this)) + this.btnDeleteProgress.on('click', this.deleteAll.bind(this)) + this.actionLoader(true) + this.datatableItem.DataTable({ + processing: true, + dom: "", + serverSide: true, + ordering: false, + pageLength: 25, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columns: this.datatableColumns, + ajax: '/produccion/ordentrabajo/maquinas/ots/datatable/' + this.maquinaId, + + }); + this.initData() + } + async initData() { + try { + let responseData = await this.getMaquinaMultipleTarea(); + this.fillCardData(responseData) + } catch (error) { + console.error(error) + } finally { + this.actionLoader(false) + } + } + fillCardData(responseData) { + this.item.find('#tirada-info').text(responseData?.tirada_total ?? 0) + this.item.find('#clicks-info').text(responseData?.clicks_total ?? 0) + this.item.find('#tiempo-estimado-info').text(responseData.tiempo_total_estimado ?? "00:00:00") + this.item.find('#tiempo-real-info').text(responseData.tiempo_total_real ?? "00:00:00") + this.showBasedOnStatus(responseData.estado) + } + async deleteAll() { + try { + let result = await alertConfirmAction('Se resetearán las tareas y se borrará el progreso') + if(result.isConfirmed){ + let response = await this.deleteMaquinaOrdenesTrabajo() + popSuccessAlert(response.message); + window.location.reload(); + } + } catch (error) { + console.error(error) + } + + } + async eventActionButton(event) { + try { + this.actionLoader(true) + let statusClick = $(event.currentTarget).data('estado'); + this.showBasedOnStatus(statusClick); + console.info(`Estado ${statusClick}`) + this.showBasedOnStatus(statusClick); + if (statusClick == "F") { + let result = await alertConfirmAction('Se marcarán como finalizadas todas las tareas') + if (result.isConfirmed == false) { + this.enableButtons() + throw new Error('Cancelado') + } + } + let response = await this.updateEstadoOts(statusClick) + popSuccessAlert(response.message) + let responseData = await this.getMaquinaMultipleTarea() + this.fillCardData(responseData) + if(statusClick == "F"){ + window.location.reload(); + } + } catch (error) { + console.error(error) + } finally { + this.actionLoader(false) + } + } + + async delayEventActionButton(event) { + try { + this.actionLoader(true) + let statusClick = $(event.currentTarget).data('estado'); + this.showBasedOnStatus(statusClick); + let response = await this.updateEstadoOts(statusClick) + popSuccessAlert(response.message) + let responseData = await this.getMaquinaMultipleTarea() + this.fillCardData(responseData) + } catch (error) { + console.error(error) + } finally { + this.actionLoader(false) + } + } + actionLoader(status = true) { + if (status) { + Notiflix.Block.circle(this.tareaCardClass); + } else { + Notiflix.Block.remove(this.tareaCardClass); + } + } + showPlay() { + this.btnPause.addClass('d-none') + this.btnPlay.removeClass('d-none') + this.btnFinish.removeClass('d-none') + this.btnDelay.removeClass('d-none') + + } + showPause() { + this.btnPlay.addClass('d-none') + this.btnFinish.addClass('d-none') + this.btnPause.removeClass('d-none') + + } + disableButtons() { + this.actionButtons.attr('disabled', 'disabled') + this.btnDelay.attr('disabled', 'disabled') + this.btnDeleteProgress.attr('disabled', 'disabled') + } + enableButtons() { + this.actionButtons.removeAttr('disabled') + this.btnDelay.removeAttr('disabled', 'disabled') + this.btnDeleteProgress.removeAttr('disabled', 'disabled') + } + + showBasedOnStatus(status) { + if (['P', 'S'].includes(status)) { + this.enableButtons() + this.showPlay() + } + if (['F', 'E'].includes(status)) { + this.disableButtons() + this.showPlay() + } + if (status == 'I') { + this.enableButtons() + this.showPause() + } + if (status == "D") { + this.showPlay() + } + + } + getClicks() { + return { + click_init: this.item.find('#input-click-init').val() ?? 0, + click_end: this.item.find('#input-click-end').val() ?? 0, + } + } + /** maquinas/ots/estado */ + updateEstadoOts(estado) { + return new Promise((resolve, reject) => { + new Ajax('/produccion/ordentrabajo/maquinas/ots/estado', + { + maquina_id: this.maquinaId, + estado: estado, + ...this.getClicks() + }, + null, + resolve, + reject + ).post() + }) + } + getMaquinaMultipleTarea() { + return new Promise((resolve, reject) => { + new Ajax('/produccion/ordentrabajo/maquinas/ots/' + this.maquinaId, + null, + null, + resolve, + reject + ).get() + }) + } + + deleteMaquinaOrdenesTrabajo() { + return new Promise((resolve, reject) => { + new Ajax('/produccion/ordentrabajo/maquinas/ots/all/' + this.maquinaId, + null, + null, + resolve, + reject + ).delete() + }) + } + + + + +} + +export default MaquinistaMultipleTarea; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js index 4aa88cdd..863ebf97 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaScan.js @@ -7,20 +7,26 @@ class MaquinistaScan { this.item = domItem /** ELEMENT DOM VARIABLES */ this.otInputId = this.item.find('#ot-id') - this.wrapperCard = this.item.find('#ot-fa-card') this.otId = null this.maquinaId = this.item.data("id") this.ots = [] this.datatableItem = this.item.find('#table-scanned-ots') + this.btnSave = this.item.find('#btn-save-maquina-ots'); + this.btnReset = this.item.find('#btn-reset-ots') this.datatableColumns = [ { data: 'id', searchable: false, sortable: false }, { data: 'title', searchable: false, sortable: false }, ] this.datatableData = []; + this.linkAfterSave = this.item.find('#ot-maquina-tareas-link') + this.scanWrapper = this.item.find('.ot-scan-wrapper') + } init() { this.otInputId.trigger('focus') this.otInputId.on('change', this.addOt.bind(this)) + this.btnReset.on('click',this.reset.bind(this)) + this.btnSave.on('click',this.saveMultipleOTs.bind(this)) this.datatable = this.datatableItem.DataTable({ processing: true, serverSide: false, @@ -32,13 +38,20 @@ class MaquinistaScan { columns: this.datatableColumns, data: this.datatableData }); - } - hideCard() { - this.wrapperCard.addClass('d-none') } - showCard() { - this.wrapperCard.removeClass('d-none') + reset(){ + this.ots = [] + this.datatable.clear() + this.datatable.draw() + this.reloadFocus(); + this.btnSave.attr('disabled','disabled'); + } + hideWrapper() { + this.scanWrapper.addClass('d-none') + } + showWrapper() { + this.scanWrapper.removeClass('d-none') } actionLoader(status = true) { if (status) { @@ -47,10 +60,31 @@ class MaquinistaScan { Notiflix.Block.remove('.section-block'); } } - reloadFocus(){ + reloadFocus() { this.otInputId.val("") this.otInputId.trigger('focus') } + async saveMultipleOTs() { + try { + let result = await alertConfirmAction() + if(result.isConfirmed){ + this.actionLoader(true) + let response = await this.postMaquinaOrdenesTrabajo() + this.actionLoader(false) + popSuccessAlert(response.message) + this.hideWrapper() + this.linkAfterSave.removeClass('d-none') + } + + } catch (error) { + this.actionLoader(false) + if (error?.responseJSON) { + popErrorAlert(error.responseJSON.message) + } else { + popErrorAlert(error) + } + } + } async addOt() { try { if (this.ots.includes(this.otInputId.val())) { @@ -67,6 +101,7 @@ class MaquinistaScan { }]) this.datatable.draw() this.reloadFocus() + this.btnSave.removeAttr('disabled') } } catch (error) { @@ -97,6 +132,26 @@ class MaquinistaScan { } + postMaquinaOrdenesTrabajo() { + return new Promise((resolve, reject) => { + let ajax = new Ajax( + `/produccion/ordentrabajo/maquinas/ots`, + { + maquina_id: this.maquinaId, + ordenes_trabajo: this.ots + }, + null, + (response) => { + resolve(response) + }, + (error) => { + reject(error) + } + ) + ajax.post(); + }) + } + diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewTareaMultipleView.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewTareaMultipleView.js new file mode 100644 index 00000000..2080234e --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/viewTareaMultipleView.js @@ -0,0 +1,7 @@ +import MaquinistaMultipleTarea from "./maquinistaMultipleTarea.js" + +$(() => { + console.info("MAQUINISTA MAQUINA OT TAREAS") + let tareaMultiple = new MaquinistaMultipleTarea($("#viewProduccionMaquinistaOtTareasView")) + tareaMultiple.init() +}) \ No newline at end of file diff --git a/httpdocs/themes/vuexy/css/maquinista.css b/httpdocs/themes/vuexy/css/maquinista.css index 61ac1780..d37c8901 100644 --- a/httpdocs/themes/vuexy/css/maquinista.css +++ b/httpdocs/themes/vuexy/css/maquinista.css @@ -4,6 +4,12 @@ width : 100%; font-size : 20px; } +.maquina-btn-v +{ + height : 5rem; + width : 1rem; + font-size : 20px; +} .table-maquinista td{ height : 7rem; } \ No newline at end of file