瀏覽代碼

Actualización API

Jose Brito 1 年之前
父節點
當前提交
08e93d9c3d

+ 1398 - 0
sistema-mantenimiento-back/app/Http/Controllers/ControlPanelController.php

@@ -0,0 +1,1398 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Http\File;
+
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+
+class ControlPanelController extends Controller{
+    private $responseController;
+    private $encryptionController;
+    private $functionsController;
+
+    public function __construct(){
+        $this->responseController = new ResponseController();
+        $this->encryptionController = new EncryptionController();
+        $this->functionsController = new FunctionsController();
+    }
+
+    public function getPanels($idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $panels = DB::table('S002V01TPACO')->select([
+            'PACO_IDPC AS ID_PANEL',
+            'PACO_NPCO AS NOMBRE_PANEL',
+            'PACO_ORPA AS ORIENTACION',
+            'PACO_ESTA AS ESTADO',
+            'PACO_USRE AS USRREG',
+            'PACO_FERE AS FECREG',
+            'PACO_USMO AS USRMOD',
+            'PACO_FEMO AS FECMOD'
+        ])->where('PACO_NULI', '=', $line)->get()->all();
+
+        foreach($panels as $key=>$panel){
+            $relatedUsers = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_PCRE', '=', $panel->ID_PANEL]
+            ])->get()->all();
+
+            $panel->USUARIOS_RELACIONADOS = count($relatedUsers);
+            $panel->ID_PANEL = $this->encryptionController->encrypt($panel->ID_PANEL);
+
+            $usrReg = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $panel->USRREG]
+            ])->first();
+
+            $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $panel->USRREG = $usrRegName . " (" . $panel->USRREG . ")";
+
+            if(!is_null($panel->USRMOD)){
+                $usrMod = DB::table('S002V01TUSUA')->where([
+                    ['USUA_NULI', '=', $line],
+                    ['USUA_IDUS', '=', $panel->USRMOD]
+                ])->first();
+    
+                $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+                $panel->USRMOD = $usrModName . " (" . $panel->USRMOD . ")";
+            }
+
+            $panels[$key] = $panel;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó los paneles de control registrados.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $panels);
+    }
+
+    public function registerPanel(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'panel_name' => 'required|string|max:100',
+            'orientation' => 'required|string|in:H,V',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $orientations = ['V' => 'Vertical', 'H' => 'Horizontal'];
+        $orientation = $orientations[$form['orientation']];
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $panelID = DB::table('S002V01TPACO')->insertGetId([
+            'PACO_NULI' => $form['linea'],
+            'PACO_NPCO' => $form['panel_name'],
+            'PACO_INRE' => '[]',
+            'PACO_ORPA' => $orientation,
+            'PACO_USRE' => $idUser,
+            'PACO_FERE' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Registro',
+            "El usuario $name (" . $usr->USUA_IDUS . ") registró el panel de control $form[panel_name] ($panelID).",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function updatePanel(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_panel' => 'required|string',
+            'panel_name' => 'required|string|max:100',
+            'orientation' => 'required|string|in:H,V',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPanel = $this->encryptionController->decrypt($form['id_panel']);
+        if(!$idPanel){
+            return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
+        }
+
+        $panel = DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->first();
+        
+        if(is_null($panel)){
+            return $this->responseController->makeResponse(true, 'El  panel que desea actualizar no existe.', [], 404);
+        }
+
+        $orientations = ['V' => 'Vertical', 'H' => 'Horizontal'];
+        $orientation = $orientations[$form['orientation']];
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->update([
+            'PACO_NPCO' => $form['panel_name'],
+            'PACO_ORPA' => $orientation,
+            'PACO_USMO' => $idUser,
+            'PACO_FEMO' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el panel de control #$idPanel.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function getCountersList($idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $counters = DB::table('S002V01TCONA')->select([
+            'CONA_IDCO AS ID_CONTADOR',
+            'CONA_COEQ AS CODIGO_EQUIPAMIENTO',
+            'EQUI_IDEQ AS ID_EQUIPAMIENTO',
+            'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
+            'EQUI_MODE AS MODELO_EQUIPAMIENTO'
+        ])->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'CONA_COEQ')->where([
+            ['CONA_NULI', '=', $line],
+        ])->get()->all();
+
+        foreach($counters as $key=>$counter){
+            $counterLastMeasures = DB::table('S002V01TMEDI')->select([
+                'MEDI_IDME AS ID_MEDIDA',
+                'MEDI_CORE AS CONTADOR',
+                'MEDI_VALO AS VALOR',
+                'MEDI_WSRE AS ID_SERVICIO_WEB',
+                'LSWE_URLX AS URL_SERVICIO_WEB',
+                'MEDI_HORE AS HORA_REGISTRO',
+            ])->join('S002V01TLSWE', 'LSWE_IDSW', '=', 'MEDI_WSRE')->where([
+                ['MEDI_NULI', '=', $line],
+                ['MEDI_CORE', '=', $counter->ID_CONTADOR]
+            ])->orderBy('MEDI_IDME', 'desc')
+            ->offset(0)->limit(10)->get()->all();
+
+            foreach($counterLastMeasures as $key0=>$measure){
+                $measure->ID_MEDIDA = $this->encryptionController->encrypt($measure->ID_MEDIDA);
+                $measure->CONTADOR = $this->encryptionController->encrypt($measure->CONTADOR);
+                $measure->ID_SERVICIO_WEB = $this->encryptionController->encrypt($measure->ID_SERVICIO_WEB);
+
+                $counterLastMeasures[$key0] = $measure;
+            }
+
+            $counter->LAST_MEASURES = $counterLastMeasures;
+            $counter->ID_CONTADOR = $this->encryptionController->encrypt($counter->ID_CONTADOR);
+            $counter->CODIGO_EQUIPAMIENTO = $this->encryptionController->encrypt($counter->CODIGO_EQUIPAMIENTO);
+            $counter->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($counter->ID_EQUIPAMIENTO);
+
+            $counters[$key] = $counter;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó los indicadores disponibles.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $counters);
+    }
+
+    public function getPanel($idPanel, $idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $idPanel = $this->encryptionController->decrypt($idPanel);
+        if(!$idPanel){
+            return $this->responseController->makeResponse(true, 'El ID del panel solicitado no está encriptado correctamente', [], 400);
+        }
+
+        $panel = DB::table('S002V01TPACO')->select([
+            'PACO_IDPC AS ID_PANEL',
+            'PACO_NPCO AS NOMBRE_PANEL',
+            'PACO_INRE AS INDICADORES_RELACIONADOS',
+            'PACO_ORPA AS ORIENTACION',
+            'PACO_ESTA AS ESTADO',
+            'PACO_USRE AS USRREG',
+            'PACO_FERE AS FECREG',
+            'PACO_USMO AS USRMOD',
+            'PACO_FEMO AS FECMOD'
+        ])->where([
+            ['PACO_NULI', '=', $line],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->first();
+
+        $panel->ID_PANEL = $this->encryptionController->encrypt($panel->ID_PANEL);
+        $usrReg = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $panel->USRREG]
+        ])->first();
+
+        $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+        $panel->USRREG = $usrRegName . " (" . $panel->USRREG . ")";
+
+        if(!is_null($panel->USRMOD)){
+            $usrMod = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $panel->USRMOD]
+            ])->first();
+
+            $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+            $panel->USRMOD = $usrModName . " (" . $panel->USRMOD . ")";
+        }
+
+        $panelElementsArr = json_decode($panel->INDICADORES_RELACIONADOS, true);
+        foreach($panelElementsArr as $key=>$element){
+            $element['module'] = $this->encryptionController->encrypt($element['module']);
+            $element['idElement'] = $this->encryptionController->encrypt($element['idElement']);
+
+            $panelElementsArr[$key] = $element;
+        }
+
+        $panel->INDICADORES_RELACIONADOS = json_encode($panelElementsArr);
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó el panel de control #$idPanel.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $panel);
+    }
+
+    public function updatePanelElements(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_panel' => 'required|string',
+            'elements' => 'required|json',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPanel = $this->encryptionController->decrypt($form['id_panel']);
+        if(!$idPanel){
+            return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
+        }
+
+        $panel = DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->first();
+        
+        if(is_null($panel)){
+            return $this->responseController->makeResponse(true, 'El  panel que desea actualizar no existe.', [], 404);
+        }
+
+        $elementsArr = json_decode($form['elements'], true);
+        foreach($elementsArr as $key=>$element){
+            if(!isset($element['module']) || !isset($element['idElement'])){
+                return $this->responseController->makeResponse(true, "El elemento en la posición $key tiene un formato inválido.", [], 400);
+            }
+
+            $element['module'] = $this->encryptionController->decrypt($element['module']);
+            if(!$element['module']){
+                return $this->responseController->makeResponse(true, "El módulo del elemento en la posición $key no fue encriptado correctamente.", [], 400);
+            }
+
+            $element['idElement'] = $this->encryptionController->decrypt($element['idElement']);
+            if(!$element['idElement']){
+                return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key no fue encriptado correctamente.", [], 400);
+            }
+
+            $elementsArr[$key] = $element;
+        }
+
+        $elementsStr = json_encode($elementsArr);
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->update([
+            'PACO_INRE' => $elementsStr,
+            'PACO_USMO' => $idUser,
+            'PACO_FEMO' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó los elementos del panel de control #$idPanel.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function updatePanelAssociations(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_panel' => 'required|string',
+            'associated_users' => 'required|json',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPanel = $this->encryptionController->decrypt($form['id_panel']);
+        if(!$idPanel){
+            return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
+        }
+
+        $panel = DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->first();
+        
+        if(is_null($panel)){
+            return $this->responseController->makeResponse(true, 'El  panel que desea actualizar no existe.', [], 404);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $associatedUsersArr = json_decode($form['associated_users'], true);
+        $associatedUsersArrDec = [];
+        //Actualizar las asociaciones hechas en el front
+        foreach($associatedUsersArr as $key=>$idAssociatedUser){
+            $idAssociatedUserDec = $this->encryptionController->decrypt($idAssociatedUser);
+            if(!$idAssociatedUserDec){
+                return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de usuarios asociados no fue encriptado correctamente.", [], 400);
+            }
+
+            $associatedUsersArrDec[] = $idAssociatedUserDec;
+            $associatedUser = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $form['linea']],
+                ['USUA_IDUS', '=', $idAssociatedUserDec]
+            ])->first();
+        
+            if(is_null($associatedUser)){
+                return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de usuarios asociados no existe.", [], 404);
+            }
+
+            DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $form['linea']],
+                ['USUA_IDUS', '=', $idAssociatedUserDec]
+            ])->update([
+                'USUA_PCRE' => $idPanel,
+                'USUA_USMO' => $idUser,
+                'USUA_FEMO' => $nowStr,
+            ]);
+        }
+
+        //Actualizar las asociaciones de los usuarios en la tabla
+        $users = DB::table('S002V01TUSUA')->where('USUA_NULI', '=', $form['linea'])->get()->all();
+        foreach($users as $user){
+            if(!in_array($user->USUA_IDUS, $associatedUsersArrDec)){
+                if($user->USUA_PCRE == intval($idPanel)){
+                    DB::table('S002V01TUSUA')->where([
+                        ['USUA_NULI', '=', $form['linea']],
+                        ['USUA_IDUS', '=', $user->USUA_IDUS]
+                    ])->update([
+                        'USUA_PCRE' => 0,
+                        'USUA_USMO' => $idUser,
+                        'USUA_FEMO' => $nowStr,
+                    ]);
+                }
+            }
+        }
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó los usuarios asociados al panel #$idPanel.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function deletePanel(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_panel' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPanel = $this->encryptionController->decrypt($form['id_panel']);
+        if(!$idPanel){
+            return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
+        }
+
+        $panel = DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->first();
+        
+        if(is_null($panel)){
+            return $this->responseController->makeResponse(true, 'El  panel que desea actualizar no existe.', [], 404);
+        }
+
+        $relatedUsers = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_PCRE', '=', $idPanel]
+        ])->get()->all();
+
+        if(count($relatedUsers) > 0){
+            return $this->responseController->makeResponse(true, 'El panel de control no se peuede eliminar porque tiene usuarios relacionados.', [], 401);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $form['linea']],
+            ['PACO_IDPC', '=', $idPanel]
+        ])->update([
+            'PACO_ESTA' => 'Eliminado',
+            'PACO_USMO' => $idUser,
+            'PACO_FEMO' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F04MIIG',
+            'S002V01P01PCIN',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el panel de control #$idPanel.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function getInfoToExcel($indicator, $idModule, $idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $idModule = $this->encryptionController->decrypt($idModule);
+        if(!$idModule){
+            return $this->responseController->makeResponse(true, 'El ID del módulo seleccionado no está encriptado correctamente', [], 400);
+        }
+
+        $module = DB::table('S002V01TMODU')->where([
+            ['MODU_NULI', '=', $line],
+            ['MODU_IDMO', '=', $idModule]
+        ])->first();
+
+        if(is_null($module)){
+            return $this->responseController->makeResponse(true, 'El módulo relacionado no está registrado', [], 404);
+        }
+
+        $indicator = $this->encryptionController->decrypt($indicator);
+        if(!$indicator){
+            return $this->responseController->makeResponse(true, 'El ID del indicador seleccionado no está encriptado correctamente', [], 400);
+        }
+
+        $spreadsheet = null;
+        switch($idModule){
+            case "S002V01M06COAC":
+                $activator = DB::table('S002V01TACTI')->where([
+                    ['ACTI_NULI', '=', $line],
+                    ['ACTI_CORE', '=', $indicator]
+                ])->first();
+
+                $unitStr = "";
+                if($activator->ACTI_TIAC == 'Medida' || $activator == 'Valor'){
+                    $configArr = json_decode($activator->ACTI_COAC, true);
+                    $unit = DB::table('S002V01TLIME')->where([
+                        ['LIME_NULI', '=', $line],
+                        ['LIME_IDME', '=', $configArr['unit']],
+                        ['LIME_MAGN', '=', $configArr['magnitude']],
+                    ])->first();
+
+                    $unitStr = $unit->LIME_ACME;
+                }else if($activator->ACTI_TIAC == 'Sintoma'){
+                    $configArr = json_decode($activator->ACTI_COAC, true);
+                    $sign = DB::table('S002V01TLISI')->where([
+                        ['LISI_NULI', '=', $line],
+                        ['LISI_IDSI', '=', $configArr['sign']]
+                    ])->first();
+
+                    $unit = DB::table('S002V01TLIME')->where([
+                        ['LIME_NULI', '=', $line],
+                        ['LIME_IDME', '=', $sign->LISI_IDME],
+                    ])->first();
+
+                    $unitStr = $unit->LIME_ACME;
+                }
+
+                $measures = DB::table('S002V01TMEDI')->select([
+                    'MEDI_IDME AS ID_MEDIDA',
+                    'MEDI_CORE AS CONTADOR',
+                    'MEDI_VALO AS VALOR',
+                    DB::raw("CONCAT(LSWE_URLX, ' (', MEDI_WSRE, ')') AS SERVICIO_WEB"),
+                    'MEDI_HORE AS HORA_REGISTRO',
+                ])->join('S002V01TLSWE', 'LSWE_IDSW', '=', 'MEDI_WSRE')->where([
+                    ['MEDI_NULI', '=', $line],
+                    ['MEDI_CORE', '=', $indicator]
+                ])->orderBy('MEDI_IDME', 'desc')->get()->all();
+
+                foreach($measures as $key=>$measure){
+                    $measure->VALOR = trim($measure->VALOR . " $unitStr");
+                    $measure->HORA_REGISTRO = $this->functionsController->buildProjectDate($measure->HORA_REGISTRO);
+
+                    $measures[$key] = $measure;
+                }
+
+                $columns = ['ID', 'CONTADOR', 'VALOR', 'WEB SERVICE', 'REGISTRO'];
+                $spreadsheet = $this->exportExcel($measures, $columns);
+            break;
+        }
+
+        if(is_null($spreadsheet)){
+            return $this->responseController->makeResponse(true, 'La hoja de cálculo no pudo ser generada', [], 400);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        
+        $dateTimeArr = explode(" ", $nowStr);
+        $dateArr = explode("-", $dateTimeArr[0]);
+        $year = substr($dateArr[0], 2);
+        $como = 'PCSA';
+        $cldo = 'IN';
+        $fecr = $year . $dateArr[1] . $dateArr[2];
+
+        $sec = DB::table('S002V01TAFAL')->where([
+            ['AFAL_NULI', '=', $line],
+            ['AFAL_COMO', '=', $como],
+            ['AFAL_CLDO', '=', $cldo],
+        ])->orderBy('AFAL_NUSE', 'desc')->first();
+
+        $nuse = "";
+        if(is_null($sec)){
+            $nuse = '000001';
+        }else{
+            $secu = "" . intval($sec->AFAL_NUSE) + 1 . "";
+            $nuse = "";
+
+            for($i = strlen($secu); $i < 6; $i++){
+                $nuse .= "0";
+            }
+
+            $nuse = $nuse . $secu;
+        }
+
+        $timestamp = $now->timestamp;
+        $noar = "informe_panel_control_$timestamp";
+        $exte = "xlsx";
+
+        $ver = DB::table('S002V01TAFAL')->where([
+            ['AFAL_NULI', '=', $line],
+            ['AFAL_COMO', '=', $como],
+            ['AFAL_CLDO', '=', $cldo],
+            ['AFAL_NOAR', '=', $noar],
+            ['AFAL_EXTE', '=', $exte],
+        ])->orderBy('AFAL_NUVE', 'desc')->first();
+
+        $nuve = "";
+        if(is_null($ver)){
+            $nuve = "01";
+        }else{
+            $vers = intval($ver->AFAL_NUVE) + 1;
+            $nuve = $vers < 10 ? "0$vers" : "$vers";
+        }
+
+        $line = $line < 10 ? "0$line" : "$line";
+        $filePath = 'C:\inetpub\wwwroot\sam\public_files\\';
+        $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
+        
+        $tempFile = $filePath . $fileName;
+        if(file_exists($tempFile)){
+            unlink($tempFile);
+        }
+
+        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
+        $writer->save($tempFile);
+        $ubic = Storage::putFile('files', new File($tempFile));
+        $ubic = str_replace("/", "\\", $ubic);
+        $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
+        $tama = filesize($ubic);
+        $usac = json_encode([$idUser]);
+        unlink($tempFile);
+
+        DB::table('S002V01TAFAL')->insert([
+            'AFAL_NULI' => $line,
+            'AFAL_COMO' => $como,
+            'AFAL_CLDO' => $cldo,
+            'AFAL_FECR' => $fecr,
+            'AFAL_NUSE' => $nuse,
+            'AFAL_NUVE' => $nuve,
+            'AFAL_NOAR' => $noar,
+            'AFAL_EXTE' => $exte,
+            'AFAL_TAMA' => $tama,
+            'AFAL_UBIC' => $ubic,
+            'AFAL_USAC' => $usac,
+            'AFAL_USRE' => $idUser,
+            'AFAL_FERE' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F03EDJC',
+            '-',
+            'Registro',
+            "El usuario $name (" . $usr->USUA_IDUS . ") registró el archivo #$fileName.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', ['report' => $this->encryptionController->encrypt($fileName)]);
+    }
+
+    private function exportExcel($data, $columns) : Spreadsheet {
+        $spreadsheet = new Spreadsheet;
+        $spreadsheet->getProperties()->setCreator('STC');
+
+        $worksheet = $spreadsheet->getActiveSheet();
+        $startRow = 2;
+        $startColumn = 2;
+        $endRow = count($data) + $startRow;
+        $endColumn = count($columns) + $startColumn;
+
+        for($row = $startRow; $row <= $endRow; $row++){
+            $rowIndex = $row - 2;
+            $rowInfo = $rowIndex == 0 ? $columns : (array) $data[$rowIndex - 1];
+            $rowHeaders = array_keys($rowInfo);
+
+            for($col = $startColumn; $col < $endColumn; $col++){
+                $colIndex = $col - 2;
+                $colName = $rowHeaders[$colIndex];
+                $colValue = $rowInfo[$colName];
+                $colStr = Coordinate::stringFromColumnIndex($col);
+
+                if($rowIndex == 0){
+                    $worksheet->setCellValue($colStr . $row, $colValue)->getStyle($colStr . $row)->getFill()
+                        ->setFillType(Fill::FILL_SOLID)
+                        ->getStartColor()->setRGB('B7BCC4');
+                    $worksheet->getStyle($colStr . $row)->getFont()->setBold(true);
+                    $worksheet->getStyle($colStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
+                }else{
+                    $worksheet->setCellValue($colStr . $row, $colValue);
+                }
+
+                $worksheet->getColumnDimension($colStr)->setAutoSize(true);
+            }
+        }
+
+        return $spreadsheet;
+    }
+
+    public function registerBroadcastList(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'list_name' => 'required|string|max:75',
+            'related_users' => 'required|json'
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $relatedUsers = json_decode($form['related_users'], true);
+        if(count($relatedUsers) < 2){
+            return $this->responseController->makeResponse(true, 'La lista de difusión debe tener al menos 2 usuarios relacionados.', [], 400);
+        }
+
+        foreach($relatedUsers as $key=>$user){
+            $user = $this->encryptionController->decrypt($user);
+            if(!$user){
+                return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de integrantes no fue encriptado correctamente.", [], 400);
+            }
+
+            $userInfo = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $form['linea']],
+                ['USUA_IDUS', '=', $user]
+            ])->first();
+        
+            if(is_null($userInfo)){
+                return $this->responseController->makeResponse(true, "El usuario en la posición $key no existe.", [], 404);
+            }else if($userInfo->USUA_ESTA == 'Eliminado'){
+                return $this->responseController->makeResponse(true, "El usuario en la posición $key está eliminado.", [], 404);
+            }
+
+            $relatedUsers[$key] = $user;
+        }
+
+        $relatedUsersStr = json_encode($relatedUsers);
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+
+        $idList = DB::table('S002V01TLIDI')->insertGetId([
+            'LIDI_NULI' => $form['linea'],
+            'LIDI_NLDI' => $form['list_name'],
+            'LIDI_INLI' => $relatedUsersStr,
+            'LIDI_USRE' => $idUser,
+            'LIDI_FERE' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F01CLDI',
+            'S002V01P01ASPE',
+            'Registro',
+            "El usuario $name (" . $usr->USUA_IDUS . ") registró la lista de difusión #$idList.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function getBroadcastLists($idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $lists = DB::table('S002V01TLIDI')->select([
+            'LIDI_IDLD AS ID_LISTA',
+            'LIDI_NLDI AS NOMBRE_LISTA',
+            'LIDI_ESTA AS ESTADO',
+            'LIDI_USRE AS USRREG',
+            'LIDI_FERE AS FECREG',
+            'LIDI_USMO AS USRMOD',
+            'LIDI_FEMO AS FECMOD'
+        ])->where('LIDI_NULI', '=', $line)->get()->all();
+
+        foreach($lists as $key=>$list){
+            $list->ID_LISTA = $this->encryptionController->encrypt($list->ID_LISTA);
+
+            $usrReg = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $list->USRREG]
+            ])->first();
+
+            $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $list->USRREG = $usrRegName . ' (' . $list->USRREG . ')';
+
+            if(!is_null($list->USRMOD)){
+                $usrMod = DB::table('S002V01TUSUA')->where([
+                    ['USUA_NULI', '=', $line],
+                    ['USUA_IDUS', '=', $list->USRMOD]
+                ])->first();
+
+                $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+                $list->USRMOD = $usrModName . ' (' . $list->USRMOD . ')';
+            }
+
+            $lists[$key] = $list;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F01CLDI',
+            'S002V01P01ASPE',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó las listas de difusión registradas.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $lists);
+    }
+
+    public function getBroadcastList($idList, $idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
+        }
+
+        $idList = $this->encryptionController->decrypt($idList);
+        if(!$idList){
+            return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
+        }
+
+        $broadcastList = DB::table('S002V01TLIDI')->select([
+            'LIDI_IDLD AS ID_LISTA',
+            'LIDI_NLDI AS NOMBRE_LISTA',
+            'LIDI_INLI AS INTEGRANTES',
+            'LIDI_ESTA AS ESTADO',
+            'LIDI_USRE AS USRREG',
+            'LIDI_FERE AS FECREG',
+            'LIDI_USMO AS USRMOD',
+            'LIDI_FEMO AS FECMOD'
+        ])->where([
+            ['LIDI_NULI', '=', $line],
+            ['LIDI_IDLD', '=', $idList]
+        ])->first();
+
+        if(is_null($broadcastList)){
+            return $this->responseController->makeResponse(true, 'La lista solicitada no existe.', [], 404);
+        }else if($broadcastList->ESTADO == 'Eliminado'){
+            return $this->responseController->makeResponse(true, 'La lista solicitada está eliminada.', [], 404);
+        }
+
+        $broadcastList->ID_LISTA = $this->encryptionController->encrypt($broadcastList->ID_LISTA);
+        $usersList = json_decode($broadcastList->INTEGRANTES, true);
+
+        $usersListFn = [];
+        foreach($usersList as $key=>$userID){
+            $user = DB::table('S002V01TUSUA')
+            ->join('S002V01TPERF', 'PERF_IDPE', '=', 'USUA_PERF')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $userID]
+            ])->first();
+
+            $usersListFn[] = [
+                'ID_USUARIO' => $this->encryptionController->encrypt($user->USUA_IDUS),
+                'NOMBRE_USUARIO' => $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA),
+                'ID_PERFIL' => $this->encryptionController->encrypt($user->PERF_IDPE),
+                'NOMBRE_PERFIL' => $user->PERF_NOPE
+            ];
+        }
+
+        $broadcastList->INTEGRANTES = json_encode($usersListFn);
+        $usrReg = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $broadcastList->USRREG]
+        ])->first();
+
+        $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+        $broadcastList->USRREG = $usrRegName . ' (' . $broadcastList->USRREG . ')';
+
+        if(!is_null($broadcastList->USRMOD)){
+            $usrMod = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $broadcastList->USRMOD]
+            ])->first();
+
+            $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+            $broadcastList->USRMOD = $usrModName . ' (' . $broadcastList->USRMOD . ')';
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M14PCSA',
+            'S002V01F01CLDI',
+            'S002V01P01ASPE',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó la lista de difusión #$idList.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $broadcastList);
+    }
+
+    public function updateBroadcastList(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'list_name' => 'required|string|max:75',
+            'related_users' => 'required|json',
+            'id_list' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idList = $this->encryptionController->decrypt($form['id_list']);
+        if(!$idList){
+            return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
+        }
+
+        $list = DB::table('S002V01TLIDI')->where([
+            ['LIDI_NULI', '=', $form['linea']],
+            ['LIDI_IDLD', '=', $idList]
+        ])->first();
+        
+        if(is_null($list)){
+            return $this->responseController->makeResponse(true, 'La lista de difusión solicitada no existe.', [], 404);
+        }
+
+        $relatedUsers = json_decode($form['related_users'], true);
+        if(count($relatedUsers) < 2){
+            return $this->responseController->makeResponse(true, 'La lista de difusión debe tener al menos 2 usuarios relacionados.', [], 400);
+        }
+
+        foreach($relatedUsers as $key=>$user){
+            $user = $this->encryptionController->decrypt($user);
+            if(!$user){
+                return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de integrantes no fue encriptado correctamente.", [], 400);
+            }
+
+            $userInfo = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $form['linea']],
+                ['USUA_IDUS', '=', $user]
+            ])->first();
+        
+            if(is_null($userInfo)){
+                return $this->responseController->makeResponse(true, "El usuario en la posición $key no existe.", [], 404);
+            }else if($userInfo->USUA_ESTA == 'Eliminado'){
+                return $this->responseController->makeResponse(true, "El usuario en la posición $key está eliminado.", [], 404);
+            }
+
+            $relatedUsers[$key] = $user;
+        }
+
+        $relatedUsersStr = json_encode($relatedUsers);
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+
+        DB::table('S002V01TLIDI')->where([
+            ['LIDI_NULI', '=', $form['linea']],
+            ['LIDI_IDLD', '=', $idList]
+        ])->update([
+            'LIDI_NLDI' => $form['list_name'],
+            'LIDI_INLI' => $relatedUsersStr,
+            'LIDI_USMO' => $idUser,
+            'LIDI_FEMO' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F01CLDI',
+            'S002V01P01ASPE',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la lista de difusión #$idList.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function deleteBroadcastList(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_list' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idList = $this->encryptionController->decrypt($form['id_list']);
+        if(!$idList){
+            return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
+        }
+
+        $list = DB::table('S002V01TLIDI')->where([
+            ['LIDI_NULI', '=', $form['linea']],
+            ['LIDI_IDLD', '=', $idList]
+        ])->first();
+        
+        if(is_null($list)){
+            return $this->responseController->makeResponse(true, 'La lista de difusión solicitada no existe.', [], 404);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+
+        DB::table('S002V01TLIDI')->where([
+            ['LIDI_NULI', '=', $form['linea']],
+            ['LIDI_IDLD', '=', $idList]
+        ])->update([
+            'LIDI_ESTA' => 'Eliminado',
+            'LIDI_USMO' => $idUser,
+            'LIDI_FEMO' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M14PCSA',
+            'S002V01F01CLDI',
+            'S002V01P01ASPE',
+            'Eliminación',
+            "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la lista de difusión #$idList.",
+            $idUser,
+            $nowStr,
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+}

+ 1316 - 3
sistema-mantenimiento-back/app/Http/Controllers/CorrectiveMaintenanceController.php

@@ -287,7 +287,7 @@ class CorrectiveMaintenanceController extends Controller{
                     }
 
                     $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
-                    if(!$finalFile){
+                    if(!$finalFile[0]){
                         return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
                     }else{
                         $attachedArrFn[] = $finalFile[1];
@@ -637,8 +637,12 @@ class CorrectiveMaintenanceController extends Controller{
             ['USUA_NULI', '=', $line]
         ])->first();
 
-        $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
-        $order->USUREG = $nameReg . " (" . $order->USUREG . ")";
+        if(is_null($usrReg)){
+            $order->USUREG = "AUTOMÁTICO (0)";
+        }else{
+            $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $order->USUREG = $nameReg . " (" . $order->USUREG . ")";
+        }
 
         if(!is_null($order->USUMOD)){
             $usrMod = DB::table('S002V01TUSUA')->where([
@@ -3292,4 +3296,1313 @@ class CorrectiveMaintenanceController extends Controller{
         $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
         return $this->responseController->makeResponse(false, 'EXITO.', $reports);
     }
+
+    public function registerMaintnencePlan(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'equipment' => 'required|string',
+            'equipment_status' => 'required|string|in:DE,DP,EF',
+            'lru' => 'string',
+            'lru_status' => 'string|in:DE,DP,EF',
+            'description' => 'required|string|min:15',
+            'inm_time' => 'required|numeric',
+            'priority' => 'required|string',
+            'total_duration' => 'required|numeric',
+            'classification' => 'required|string|max:100',
+            'specialties' => 'required|json',
+            'specialties_conf' => 'required|json',
+            'resources' => 'required|json',
+            'attached' => 'required|json',
+            'symptom' => 'required|string',
+            'scada' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
+        if(!$equipmentCode){
+            return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
+        }
+
+        $equipment = DB::table('S002V01TEQUI')->where([
+            ['EQUI_COEQ', '=', $equipmentCode],
+            ['EQUI_NULI', '=', $form['linea']]
+        ])->first();
+        
+        if(is_null($equipment)){
+            return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
+        }
+
+        $lrui = null;
+        $eflr = null;
+        if(isset($form['lru'])){
+            $lruCode = $this->encryptionController->decrypt($form['lru']);
+            if(!$lruCode){
+                return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
+            }
+
+            $lru = DB::table('S002V01TEQUI')->where([
+                ['EQUI_COEQ', '=', $lruCode],
+                ['EQUI_NULI', '=', $form['linea']]
+            ])->first();
+            
+            if(is_null($lru)){
+                return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
+            }
+
+            if(!isset($form['lru_status'])){
+                return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
+            }
+
+            $lrui = $lruCode;
+            $eflr = $form['lru_status'];
+        }
+
+        $priorityDec = $this->encryptionController->decrypt($form['priority']);
+        $systemParamsExists = file_exists('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
+        if(!$systemParamsExists){
+            return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
+        }
+
+        $paramsStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\system-params.json');
+        $paramsArr = json_decode($paramsStr, true);
+        $orderPriorities = $paramsArr['order_priorities'];
+
+        $priorityFilt = array_filter($orderPriorities, function($v, $k) use($priorityDec) {
+            return $v['value'] == $priorityDec;
+        }, ARRAY_FILTER_USE_BOTH);
+
+        if(count($priorityFilt) < 1){
+            return $this->responseController->makeResponse(true, 'La prioridad seleccionada es inválida.', [], 400);
+        }
+
+        //PENDINTE REVISAR RECURSOS CON STOCK
+        $attachedArr = json_decode($form['attached'], true);
+        $attachedArrFn = [];
+        foreach($attachedArr as $key=>$attached){
+            $idDec = $this->encryptionController->decrypt($attached['id']);
+            if(!$idDec){
+                return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
+            }
+
+            $tempFile = DB::table('S002V01TARTE')->where([
+                ['ARTE_IDAR', '=', $idDec],
+                ['ARTE_NULI', '=', $form['linea']]
+            ])->first();
+
+            if(is_null($tempFile)){
+                return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
+            }else if($tempFile->ARTE_ESTA == 'Eliminado'){
+                return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
+            }
+
+            $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
+            if(!$finalFile[0]){
+                return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
+            }else{
+                $attachedArrFn[] = [
+                    'ID' => $finalFile[1],
+                    'TYPE' => $attached['type']
+                ];
+            }
+        }
+
+        $idSymptom = $this->encryptionController->decrypt($form['symptom']);
+        if(!$idSymptom){
+            return $this->responseController->makeResponse(true, 'El ID del síntoma no fue encriptado correctamente.', [], 400);
+        }
+
+        $symptom = DB::table('S002V01TLISI')->where([
+            ['LISI_NULI', '=', $form['linea']],
+            ['LISI_IDSI', '=', $idSymptom],
+        ])->first();
+        
+        if(is_null($symptom)){
+            return $this->responseController->makeResponse(true, 'El síntoma relacionado no existe.', [], 404);
+        }
+
+        $idSCADA = $this->encryptionController->decrypt($form['scada']);
+        if(!$idSCADA){
+            return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
+        }
+
+        $scada = DB::table('S002V01TLISC')->where([
+            ['LISC_NULI', '=', $form['linea']],
+            ['LISC_IDSC', '=', $idSCADA]
+        ])->first();
+        
+        if(is_null($scada)){
+            return $this->responseController->makeResponse(true, 'El SCADA relacionado no existe.', [], 404);
+        }
+
+        //Una vez que se aprueban los datos se registra el contador relacionado
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $idCounter = DB::table('S002V01TCONA')->insertGetId([
+            'CONA_NULI' => $form['linea'],
+            'CONA_INLE' => 5,
+            'CONA_UTIL' => 'min',
+            'CONA_TOIN' => 1,
+            'CONA_UTTI' => 'min',
+            'CONA_IDSC' => $idSCADA,
+            'CONA_COEQ' => is_null($lrui) ? $equipmentCode : $lrui,
+            'CONA_COVI' => '[]',
+            'CONA_USRE' => $idUser,
+            'CONA_FERE' => $nowStr
+        ]);
+
+        $repeatStartDate = new Carbon($now->toDateString());
+        $repeatStart = str_replace(' ', 'T', $repeatStartDate->toDateTimeString());
+
+        $repeatHourDate = new Carbon($nowStr);
+        $hour = $repeatHourDate->hour;
+        $hourStr = "";
+        $minute = $repeatHourDate->minute;
+        $minuteStr = "";
+
+        if($minute > 0 && $minute <= 15){
+            $minuteStr = "15";
+            $hourStr = $hour < 10 ? "0$hour" : "$hour";
+        }else if($minute > 15 && $minute <= 30){
+            $minuteStr = "30";
+            $hourStr = $hour < 10 ? "0$hour" : "$hour";
+        }else if($minute > 30 && $minute <= 45){
+            $minuteStr = "45";
+            $hourStr = $hour < 10 ? "0$hour" : "$hour";
+        }else{
+            $minuteStr = "00";
+            $hourAux = $hour + 1;
+            $hourStr = $hourAux < 10 ? "0$hourAux" : "$hourAux";
+        }
+
+        $repeatHourStr = "$hourStr:$minuteStr:00";
+        $symptomRepeat = [
+            'sign' => $idSymptom,
+            'color' => 'rgb(79, 195, 255)',
+            'repeat' => 'TD',
+            'startDate' => "$repeatStart.000Z",
+            'startHour' => $repeatHourStr,
+            'customRepeat' => '',
+        ];
+
+        //Se procede a crear un activador relacionado al contador nuevo
+        $symptomRepeatStr = json_encode($symptomRepeat);
+        $idActivator = DB::table('S002V01TACTI')->insertGetId([
+            'ACTI_NULI' => $form['linea'],
+            'ACTI_PRIO' => $priorityDec,
+            'ACTI_TIAC' => 'Sintoma',
+            'ACTI_COAC' => $symptomRepeatStr,
+            'ACTI_CORE' => $idCounter,
+            'ACTI_USRE' => $idUser,
+            'ACTI_FERE' => $nowStr,
+        ]);
+        
+        $specialtiesArr = json_decode($form['specialties'], true);
+        $specialtiesDec = [];
+        foreach($specialtiesArr as $specialty){
+            $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
+        }
+
+        $specialtiesStr = json_encode($specialtiesDec);
+
+        //Una vez obtenido el ID del nuevo contador relacionado se ingresa el plan de mantenimiento
+        $come = isset($form['comments']) ? $form['comments'] : null;
+        $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
+        $dore = json_encode($attachedArrFn);
+        
+        $idPlan = DB::table('S002V01TPMCO')->insertGetId([
+            'PMCO_NULI' => $form['linea'],
+            'PMCO_EQIN' => $equipmentCode,
+            'PMCO_LRUI' => $lrui,
+            'PMCO_EFEQ' => $form['equipment_status'],
+            'PMCO_EFLR' => $eflr,
+            'PMCO_DESC' => $form['description'],
+            'PMCO_TIES' => $form['inm_time'],
+            'PMCO_DTIN' => $form['total_duration'],
+            'PMCO_CLAS' => $form['classification'],
+            'PMCO_ESRE' => $specialtiesStr,
+            'PMCO_COES' => $form['specialties_conf'],
+            'PMCO_COME' => $come,
+            'PMCO_RECU' => $form['resources'],
+            'PMCO_DEAD' => $dead,
+            'PMCO_DORE' => $dore,
+            'PMCO_CORE' => $idCounter,
+            'PMCO_USRE' => $idUser,
+            'PMCO_FERE' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02PLAN',
+            'S002V01P01ASPL',
+            'Registro',
+            "El usuario $name (" . $usr->USUA_IDUS . ") registró el plan de mantenimiento correctivo #$idPlan.",
+            $idUser,
+            $nowStr,
+            'S002V01S02GEME'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.', [
+            'PLAN' => $this->encryptionController->encrypt($idPlan),
+            'ACTIVADOR' => $this->encryptionController->encrypt($idActivator),
+            'CONTADOR' => $this->encryptionController->encrypt($idCounter),
+        ]);
+    }
+
+    public function getMaintenancePlans($idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
+        }
+
+        $plansList = DB::table('S002V01TPMCO')->select([
+            'PMCO_IDPM AS ID_PLAN',
+            'PMCO_EQIN AS EQUIPAMIENTO',
+            'PMCO_LRUI AS LRU',
+            'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
+            'PMCO_DTIN AS DURACION_TOTAL',
+            'PMCO_CLAS AS CLASIFICACION',
+            'PMCO_CORE AS CONTADOR',
+            'ACTI_IDAC AS ACTIVADOR',
+            'ACTI_PRIO AS PRIORIDAD',
+            'PMCO_ESTA AS ESTADO',
+            'PMCO_USRE AS USRREG',
+            'PMCO_FERE AS FECREG',
+            'PMCO_USMO AS USRMOD',
+            'PMCO_FEMO AS FECMOD',
+        ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')->get()->all();
+
+        foreach($plansList as $key=>$plan){
+            $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
+
+            $equipment = DB::table('S002V01TEQUI')->where([
+                ['EQUI_NULI', '=', $line],
+                ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
+            ])->first();
+
+            $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
+            $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
+
+            if(!is_null($plan->LRU)){
+                $lru = DB::table('S002V01TEQUI')->where([
+                    ['EQUI_NULI', '=', $line],
+                    ['EQUI_COEQ', '=', $plan->LRU]
+                ])->first();
+
+                $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
+                $plan->LRU = $this->encryptionController->encrypt($lruLabel);
+            }
+            
+            $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
+            $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
+            $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
+
+            $usrReg = DB::table('S002V01TUSUA')->where([
+                ['USUA_IDUS', '=', $plan->USRREG],
+                ['USUA_NULI', '=', '1'],
+            ])->first();
+
+            $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
+
+            if(!is_null($plan->USRMOD)){
+                $usrMod = DB::table('S002V01TUSUA')->where([
+                    ['USUA_IDUS', '=', $plan->USRMOD],
+                    ['USUA_NULI', '=', '1'],
+                ])->first();
+
+                $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+                $plan->USRMOD = $usrModName . " (" . $plan->USRMOD . ")";
+            }
+
+            $plansList[$key] = $plan;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M09GMCO',
+            'S002V01F02PLAN',
+            'S002V01P01ASPL',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó los planes de mantenimiento registrados.",
+            $idUser,
+            $nowStr,
+            'S002V01S02GEME'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $plansList);
+    }
+
+    public function getMaintenancePlan($idPlan, $idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
+        }
+
+        $idPlan = $this->encryptionController->decrypt($idPlan);
+        if(!$idPlan){
+            return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no está encriptado correctamente.', [], 400);
+        }
+
+        $plan = DB::table('S002V01TPMCO')->select([
+            'PMCO_IDPM AS ID_PLAN',
+            'PMCO_EQIN AS EQUIPAMIENTO',
+            'PMCO_LRUI AS LRU',
+            'PMCO_EFEQ AS ESTADO_FUNCIONAMIENTO_EQUIPAMIENTO',
+            'PMCO_EFLR AS ESTADO_FUNCIONAMIENTO_LRU',
+            'PMCO_DESC AS DESCRIPCION',
+            'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
+            'PMCO_DTIN AS DURACION_TOTAL',
+            'PMCO_CLAS AS CLASIFICACION',
+            'PMCO_ESRE AS ESPECIALIDADES_REQUERIDAS',
+            'PMCO_COES AS CONFIGURACION_OPERARIOS',
+            'PMCO_COME AS COMENTARIOS',
+            'PMCO_RECU AS RECURSOS',
+            'PMCO_DEAD AS DETALLES_ADICIONALES',
+            'PMCO_DORE AS DOCUMENTOS_RELACIONADOS',
+            'PMCO_CORE AS CONTADOR',
+            'CONA_IDSC AS SCADA',
+            'ACTI_IDAC AS ACTIVADOR',
+            'ACTI_PRIO AS PRIORIDAD',
+            'ACTI_COAC AS SINTOMA',
+            'PMCO_ESTA AS ESTADO',
+            'PMCO_USRE AS USRREG',
+            'PMCO_FERE AS FECREG',
+            'PMCO_USMO AS USRMOD',
+            'PMCO_FEMO AS FECMOD',
+        ])->where([
+            ['PMCO_NULI', '=', $line],
+            ['PMCO_IDPM', '=', $idPlan]
+        ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')
+        ->join('S002V01TCONA', 'CONA_IDCO', '=', 'PMCO_CORE')->first();
+
+        if(is_null($plan)){
+            return $this->responseController->makeResponse(true, 'El plan solicitado no existe.', [], 404);
+        }
+
+        $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
+        $equipment = DB::table('S002V01TEQUI')->where([
+            ['EQUI_NULI', '=', $line],
+            ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
+        ])->first();
+
+        $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
+        $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
+
+        if(!is_null($plan->LRU)){
+            $lru = DB::table('S002V01TEQUI')->where([
+                ['EQUI_NULI', '=', $line],
+                ['EQUI_COEQ', '=', $plan->LRU]
+            ])->first();
+
+            $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
+            $plan->LRU = $this->encryptionController->encrypt($lruLabel);
+        }
+
+        $documentsArr = json_decode($plan->DOCUMENTOS_RELACIONADOS, true);
+        $documentsFn = [];
+        foreach($documentsArr as $document){
+            $documentCodeArr0 = explode('=', $document['ID']);
+            $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
+
+            $documentObj = DB::table('S002V01TAFAL')->where([
+                ['AFAL_NULI', '=', $line],
+                ['AFAL_COMO', '=', $documentCodeArr1[1]],
+                ['AFAL_CLDO', '=', $documentCodeArr1[2]],
+                ['AFAL_FECR', '=', $documentCodeArr1[3]],
+                ['AFAL_NUSE', '=', $documentCodeArr1[4]],
+                ['AFAL_NUVE', '=', $documentCodeArr0[1]],
+            ])->first();
+
+            $documentsFn[] = [
+                'id' => $this->encryptionController->encrypt($document['ID']),
+                'name' => $document['ID'],
+                'size' => $documentObj->AFAL_TAMA,
+                'type' => $document['TYPE']
+            ];
+        }
+
+        $plan->DOCUMENTOS_RELACIONADOS = json_encode($documentsFn);
+        $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
+        $plan->SCADA = $this->encryptionController->encrypt($plan->SCADA);
+        $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
+        $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
+
+        $activationConfig = json_decode($plan->SINTOMA, true);
+        $plan->SINTOMA = $this->encryptionController->encrypt($activationConfig['sign']);
+
+        $usrReg = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $plan->USRREG]
+        ])->first();
+
+        $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+        $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
+
+        if(!is_null($plan->USRMOD)){
+            $usrMod = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $plan->USRMOD]
+            ])->first();
+    
+            $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+            $plan->USRMOD = $usrModName . " (" . $plan->USRMOD . ")";
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M09GMCO',
+            'S002V01F02PLAN',
+            'S002V01P01ASPL',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó el plan de mantenimiento #$idPlan.",
+            $idUser,
+            $nowStr,
+            'S002V01S02GEME'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $plan);
+    }
+
+    public function updateMaintenancePlan(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_plan' => 'required|string',
+            'equipment' => 'required|string',
+            'equipment_status' => 'required|string|in:DE,DP,EF',
+            'lru' => 'string',
+            'lru_status' => 'string|in:DE,DP,EF',
+            'description' => 'required|string|min:15',
+            'inm_time' => 'required|numeric',
+            'total_duration' => 'required|numeric',
+            'classification' => 'required|string|max:100',
+            'specialties' => 'required|json',
+            'specialties_conf' => 'required|json',
+            'resources' => 'required|json',
+            'attached' => 'required|json',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPlan = $this->encryptionController->decrypt($form['id_plan']);
+        if(!$idPlan){
+            return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
+        }
+
+        $plan = DB::table('S002V01TPMCO')->where([
+            ['PMCO_NULI', '=', $form['linea']],
+            ['PMCO_IDPM', '=', $idPlan]
+        ])->first();
+        
+        if(is_null($plan)){
+            return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
+        }else if($plan->PMCO_ESTA == 'Eliminado'){
+            return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
+        }
+
+        $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
+        if(!$equipmentCode){
+            return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
+        }
+
+        $equipment = DB::table('S002V01TEQUI')->where([
+            ['EQUI_COEQ', '=', $equipmentCode],
+            ['EQUI_NULI', '=', $form['linea']]
+        ])->first();
+        
+        if(is_null($equipment)){
+            return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
+        }
+
+        $lrui = null;
+        $eflr = null;
+        if(isset($form['lru'])){
+            $lruCode = $this->encryptionController->decrypt($form['lru']);
+            if(!$lruCode){
+                return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
+            }
+
+            $lru = DB::table('S002V01TEQUI')->where([
+                ['EQUI_COEQ', '=', $lruCode],
+                ['EQUI_NULI', '=', $form['linea']]
+            ])->first();
+            
+            if(is_null($lru)){
+                return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
+            }
+
+            if(!isset($form['lru_status'])){
+                return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
+            }
+
+            $lrui = $lruCode;
+            $eflr = $form['lru_status'];
+        }
+
+        $planCounter = DB::table('S002V01TCONA')->where([
+            ['CONA_NULI', '=', $form['linea']],
+            ['CONA_IDCO', '=', $plan->PMCO_CORE]
+        ])->first();
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $counterEquipment = $planCounter->CONA_COEQ;
+        
+        if(is_null($lrui) && $counterEquipment != $equipmentCode){
+            DB::table('S002V01TCONA')->where([
+                ['CONA_NULI', '=', $form['linea']],
+                ['CONA_IDCO', '=', $plan->PMCO_CORE]
+            ])->update([
+                'CONA_COEQ' => $equipmentCode,
+                'CONA_USMO' => $idUser,
+                'CONA_FEMO' => $nowStr
+            ]);
+        }else if($lrui != $counterEquipment){
+            DB::table('S002V01TCONA')->where([
+                ['CONA_NULI', '=', $form['linea']],
+                ['CONA_IDCO', '=', $plan->PMCO_CORE]
+            ])->update([
+                'CONA_COEQ' => $lrui,
+                'CONA_USMO' => $idUser,
+                'CONA_FEMO' => $nowStr
+            ]);
+        }
+        
+        $specialtiesArr = json_decode($form['specialties'], true);
+        if(count($specialtiesArr) == 0){
+            return $this->responseController->makeResponse(true, 'El arreglo de especialidades está vacío.', [], 400);
+        }
+
+        $specialtiesDec = [];
+        foreach($specialtiesArr as $specialty){
+            $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
+        }
+
+        $specialtiesStr = json_encode($specialtiesDec);
+        $attachedArr = json_decode($form['attached'], true);
+        if(count($attachedArr) == 0){
+            return $this->responseController->makeResponse(true, 'El arreglo de documentos está vacío.', [], 400);
+        }
+
+        $attachedArrFn = [];
+        foreach($attachedArr as $key=>$attached){
+            $idDec = $this->encryptionController->decrypt($attached['id']);
+            if(!$idDec){
+                return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
+            }
+
+            if($attached['isFinalFile']){
+                $documentCodeArr0 = explode('=', $idDec);
+                $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
+
+                $file = DB::table('S002V01TAFAL')->where([
+                    ['AFAL_NULI', '=', $form['linea']],
+                    ['AFAL_COMO', '=', $documentCodeArr1[1]],
+                    ['AFAL_CLDO', '=', $documentCodeArr1[2]],
+                    ['AFAL_FECR', '=', $documentCodeArr1[3]],
+                    ['AFAL_NUSE', '=', $documentCodeArr1[4]],
+                    ['AFAL_NUVE', '=', $documentCodeArr0[1]],
+                ])->first();
+    
+                if(is_null($file)){
+                    return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
+                }else if($file->AFAL_ESTA == 'Eliminado'){
+                    return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
+                }
+                
+                $attachedArrFn[] = [
+                    'ID' => $idDec,
+                    'TYPE' => $attached['type']
+                ];
+            }else{
+                $tempFile = DB::table('S002V01TARTE')->where([
+                    ['ARTE_IDAR', '=', $idDec],
+                    ['ARTE_NULI', '=', $form['linea']]
+                ])->first();
+    
+                if(is_null($tempFile)){
+                    return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
+                }else if($tempFile->ARTE_ESTA == 'Eliminado'){
+                    return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
+                }
+    
+                $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
+                if(!$finalFile[0]){
+                    return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
+                }else{
+                    $attachedArrFn[] = [
+                        'ID' => $finalFile[1],
+                        'TYPE' => $attached['type']
+                    ];
+                }
+            }
+        }
+        
+        $come = isset($form['comments']) ? $form['comments'] : null;
+        $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
+        $dore = json_encode($attachedArrFn);
+
+        DB::table('S002V01TPMCO')->where([
+            ['PMCO_NULI', '=', $form['linea']],
+            ['PMCO_IDPM', '=', $idPlan]
+        ])->update([
+            'PMCO_EQIN' => $equipmentCode,
+            'PMCO_LRUI' => $lrui,
+            'PMCO_EFEQ' => $form['equipment_status'],
+            'PMCO_EFLR' => $eflr,
+            'PMCO_DESC' => $form['description'],
+            'PMCO_TIES' => $form['inm_time'],
+            'PMCO_DTIN' => $form['total_duration'],
+            'PMCO_CLAS' => $form['classification'],
+            'PMCO_ESRE' => $specialtiesStr,
+            'PMCO_COES' => $form['specialties_conf'],
+            'PMCO_COME' => $come,
+            'PMCO_RECU' => $form['resources'],
+            'PMCO_DEAD' => $dead,
+            'PMCO_DORE' => $dore,
+            'PMCO_USMO' => $idUser,
+            'PMCO_FEMO' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02PLAN',
+            'S002V01P01ASPL',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el plan de mantenimiento correctivo #$idPlan.",
+            $idUser,
+            $nowStr,
+            'S002V01S02GEME'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function deleteMaintenancePlan(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_plan' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idPlan = $this->encryptionController->decrypt($form['id_plan']);
+        if(!$idPlan){
+            return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
+        }
+
+        $plan = DB::table('S002V01TPMCO')->where([
+            ['PMCO_NULI', '=', $form['linea']],
+            ['PMCO_IDPM', '=', $idPlan]
+        ])->first();
+        
+        if(is_null($plan)){
+            return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
+        }else if($plan->PMCO_ESTA == 'Eliminado'){
+            return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        DB::table('S002V01TPMCO')->where([
+            ['PMCO_NULI', '=', $form['linea']],
+            ['PMCO_IDPM', '=', $idPlan]
+        ])->update([
+            'PMCO_ESTA' => 'Eliminado',
+            'PMCO_USMO' => $idUser,
+            'PMCO_FEMO' => $nowStr,
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02PLAN',
+            'S002V01P01ASPL',
+            'Eliminación',
+            "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el plan de mantenimiento correctivo #$idPlan.",
+            $idUser,
+            $nowStr,
+            'S002V01S02GEME'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function registerWorkGroup(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'work_group_name' => 'required|string|max:100|min:8',
+            'related_teams' => 'required|json',
+            'specialty' => 'required|string|max:100|min:8',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $relatedTeamsArr = json_decode($form['related_teams'], true);
+        if(count($relatedTeamsArr) < 2){
+            return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
+        }
+
+        $relatedTeamsArrDec = [];
+        foreach($relatedTeamsArr as $key=>$team){
+            $itemDec = $this->encryptionController->decrypt($team);
+            if(!$itemDec){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
+            }
+
+            $workTeam = DB::table('S002V01TEQMA')->where([
+                ['EQMA_NULI', '=', $form['linea']],
+                ['EQMA_IDEQ', '=', $itemDec]
+            ])->first();
+
+            if(is_null($workTeam)){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
+            }else if($workTeam->EQMA_ESTA == 'Eliminado'){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
+            }
+
+            $relatedTeamsArrDec[] = $itemDec;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $relatedTeamsStr = json_encode($relatedTeamsArrDec);
+        $idWorkGroup = DB::table('S002V01TGMCO')->insertGetId([
+            'GMCO_NULI' => $form['linea'],
+            'GMCO_NGMC' => $form['work_group_name'],
+            'GMCO_EQRE' => $relatedTeamsStr,
+            'GMCO_ESPE' => $form['specialty'],
+            'GMCO_USRE' => $idUser,
+            'GMCO_FERE' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02AEMA',
+            'S002V01P01AEOP',
+            'Registro',
+            "El usuario $name (" . $usr->USUA_IDUS . ") registró el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
+            $idUser,
+            $nowStr,
+            'S002V01S04FUFL'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function getWorkGroups($idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
+        }
+
+        $workGroups = DB::table('S002V01TGMCO')->select([
+            'GMCO_IDGM AS ID_GRUPO',
+            'GMCO_NGMC AS NOMBRE_GRUPO',
+            'GMCO_ESPE AS ESPECIALIDAD',
+            'GMCO_ESTA AS ESTADO',
+            'GMCO_USRE AS USUREG',
+            'GMCO_FERE AS FECREG',
+            'GMCO_USMO AS USUMOD',
+            'GMCO_FEMO AS FECMOD'
+        ])->where('GMCO_NULI', '=', $line)->get()->all();
+
+        foreach($workGroups as $key=>$group){
+            $group->ID_GRUPO = $this->encryptionController->encrypt($group->ID_GRUPO);
+
+            $usrReg = DB::table('S002V01TUSUA')->where([
+                ['USUA_IDUS', '=', $group->USUREG],
+                ['USUA_NULI', '=', $line]
+            ])->first();
+
+            $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $group->USUREG = $usrRegName . " (" . $group->USUREG . ')';
+
+            if(!is_null($group->USUMOD)){
+                $usrMod = DB::table('S002V01TUSUA')->where([
+                    ['USUA_IDUS', '=', $group->USUMOD],
+                    ['USUA_NULI', '=', $line]
+                ])->first();
+
+                $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+                $group->USUMOD = $usrModName . " (" . $group->USUMOD . ')';
+            }
+
+            $workGroups[$key] = $group;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M09GMCO',
+            'S002V01F02AEMA',
+            'S002V01P01AEOP',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó los grupos de trabajo registrados.",
+            $idUser,
+            $nowStr,
+            'S002V01S04FUFL'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $workGroups);
+    }
+
+    public function getWorkGroup($idGroup, $idUser, $line) {
+        DB::enableQueryLog();
+
+        $idUser = $this->encryptionController->decrypt($idUser);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $line],
+            ['USUA_IDUS', '=', $idUser],
+        ])->first();
+
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
+        }
+
+        $idGroup = $this->encryptionController->decrypt($idGroup);
+        if(!$idGroup){
+            return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no está encriptado correctamente', [], 400);
+        }
+
+        $workGroup = DB::table('S002V01TGMCO')->select([
+            'GMCO_IDGM AS ID_GRUPO',
+            'GMCO_NGMC AS NOMBRE_GRUPO',
+            'GMCO_EQRE AS EQUIPOS_RELACIONADOS',
+            'GMCO_ESPE AS ESPECIALIDAD',
+            'GMCO_ESTA AS ESTADO',
+            'GMCO_USRE AS USUREG',
+            'GMCO_FERE AS FECREG',
+            'GMCO_USMO AS USUMOD',
+            'GMCO_FEMO AS FECMOD'
+        ])->where([
+            ['GMCO_IDGM', '=', $idGroup],
+            ['GMCO_NULI', '=', $line]
+        ])->first();
+
+        if(is_null($workGroup)){
+            return $this->responseController->makeResponse(true, 'El grupo de trabajo consultado no está registrado.', [], 404);
+        }
+
+        $workGroup->ID_GRUPO = $this->encryptionController->encrypt($workGroup->ID_GRUPO);
+        $relatedTeamsArr = json_decode($workGroup->EQUIPOS_RELACIONADOS, true);
+        
+        $relatedTeams = [];
+        foreach($relatedTeamsArr as $team){
+            $teamInfo = DB::table('S002V01TEQMA')->where([
+                ['EQMA_NULI', '=', $line],
+                ['EQMA_IDEQ', '=', $team]
+            ])->first();
+
+            $relatedTeams[] = [
+                'ID_EQUIPO' => $this->encryptionController->encrypt($teamInfo->EQMA_IDEQ),
+                'NOMBRE_EQUIPO' => $teamInfo->EQMA_NOMB,
+                'ESPECIALIDAD' => $teamInfo->EQMA_ESPE
+            ];
+        }
+
+        $workGroup->EQUIPOS_RELACIONADOS = json_encode($relatedTeams);
+        $usrReg = DB::table('S002V01TUSUA')->where([
+            ['USUA_IDUS', '=', $workGroup->USUREG],
+            ['USUA_NULI', '=', $line]
+        ])->first();
+
+        $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+        $workGroup->USUREG = $usrRegName . " (" . $workGroup->USUREG . ')';
+
+        if(!is_null($workGroup->USUMOD)){
+            $usrMod = DB::table('S002V01TUSUA')->where([
+                ['USUA_IDUS', '=', $workGroup->USUMOD],
+                ['USUA_NULI', '=', $line]
+            ])->first();
+
+            $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+            $workGroup->USUMOD = $usrModName . " (" . $workGroup->USUMOD . ')';
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $line,
+            'S002V01M09GMCO',
+            'S002V01F02AEMA',
+            'S002V01P01AEOP',
+            'Consulta',
+            "El usuario $name (" . $usr->USUA_IDUS . ") consultó el grupo de trabajo " . $workGroup->NOMBRE_GRUPO . " ($idGroup).",
+            $idUser,
+            $nowStr,
+            'S002V01S04FUFL'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
+        return $this->responseController->makeResponse(false, 'EXITO.', $workGroup);
+    }
+
+    public function updateWorkGroup(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_work_group' => 'required|string',
+            'work_group_name' => 'required|string|max:100|min:8',
+            'related_teams' => 'required|json',
+            'specialty' => 'required|string|max:100|min:8',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
+        if(!$idWorkGroup){
+            return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
+        }
+
+        $workGroup = DB::table('S002V01TGMCO')->where([
+            ['GMCO_NULI', '=', $form['linea']],
+            ['GMCO_IDGM', '=', $idWorkGroup]
+        ])->first();
+        
+        if(is_null($workGroup)){
+            return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
+        }
+
+        $relatedTeamsArr = json_decode($form['related_teams'], true);
+        if(count($relatedTeamsArr) < 2){
+            return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
+        }
+
+        $relatedTeamsArrDec = [];
+        foreach($relatedTeamsArr as $key=>$team){
+            $itemDec = $this->encryptionController->decrypt($team);
+            if(!$itemDec){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
+            }
+
+            $workTeam = DB::table('S002V01TEQMA')->where([
+                ['EQMA_NULI', '=', $form['linea']],
+                ['EQMA_IDEQ', '=', $itemDec]
+            ])->first();
+
+            if(is_null($workTeam)){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
+            }else if($workTeam->EQMA_ESTA == 'Eliminado'){
+                return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
+            }
+
+            $relatedTeamsArrDec[] = $itemDec;
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        $relatedTeamsStr = json_encode($relatedTeamsArrDec);
+        DB::table('S002V01TGMCO')->where([
+            ['GMCO_NULI', '=', $form['linea']],
+            ['GMCO_IDGM', '=', $idWorkGroup]
+        ])->update([
+            'GMCO_NGMC' => $form['work_group_name'],
+            'GMCO_EQRE' => $relatedTeamsStr,
+            'GMCO_ESPE' => $form['specialty'],
+            'GMCO_USMO' => $idUser,
+            'GMCO_FEMO' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02AEMA',
+            'S002V01P01AEOP',
+            'Actualización',
+            "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
+            $idUser,
+            $nowStr,
+            'S002V01S04FUFL'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
+
+    public function deleteWorkGroup(Request $request) {
+        DB::enableQueryLog();
+        $validator = Validator::make($request->all(), [
+            'id_user' => 'required|string',
+            'linea' => 'required|integer',
+            'id_work_group' => 'required|string',
+        ]);
+ 
+        if($validator->fails()){
+            return $this->responseController->makeResponse(
+                true,
+                "Se encontraron uno o más errores.",
+                $this->responseController->makeErrors(
+                    $validator->errors()->messages()
+                ),
+                401
+            );
+        }
+
+        $form = $request->all();
+        $idUser = $this->encryptionController->decrypt($form['id_user']);
+        if(!$idUser){
+            return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
+        }
+
+        $usr = DB::table('S002V01TUSUA')->where([
+            ['USUA_NULI', '=', $form['linea']],
+            ['USUA_IDUS', '=', $idUser]
+        ])->first();
+        
+        if(is_null($usr)){
+            return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
+        }
+
+        $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
+        if(!$idWorkGroup){
+            return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
+        }
+
+        $workGroup = DB::table('S002V01TGMCO')->where([
+            ['GMCO_NULI', '=', $form['linea']],
+            ['GMCO_IDGM', '=', $idWorkGroup]
+        ])->first();
+        
+        if(is_null($workGroup)){
+            return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
+        }
+
+        $now = $this->functionsController->now();
+        $nowStr = $now->toDateTimeString();
+        DB::table('S002V01TGMCO')->where([
+            ['GMCO_NULI', '=', $form['linea']],
+            ['GMCO_IDGM', '=', $idWorkGroup]
+        ])->update([
+            'GMCO_ESTA' => 'Eliminado',
+            'GMCO_USMO' => $idUser,
+            'GMCO_FEMO' => $nowStr
+        ]);
+
+        $actions = DB::getQueryLog();
+        $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
+        
+        $idac = $this->functionsController->registerActivity(
+            $form['linea'],
+            'S002V01M09GMCO',
+            'S002V01F02AEMA',
+            'S002V01P01AEOP',
+            'Eliminación',
+            "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el grupo de trabajo #$idWorkGroup.",
+            $idUser,
+            $nowStr,
+            'S002V01S04FUFL'
+        );
+
+        $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
+        return $this->responseController->makeResponse(false, 'EXITO.');
+    }
 }

文件差異過大導致無法顯示
+ 896 - 95
sistema-mantenimiento-back/app/Http/Controllers/EquipmentManagementController.php


+ 6 - 0
sistema-mantenimiento-back/app/Http/Controllers/LoginController.php

@@ -105,6 +105,11 @@ class LoginController extends Controller{
             return $this->responseController->makeResponse(true, "La contraseña es incorrecta, intento $attempts de 10.", [], 401);
         }
 
+        $controlPanel = DB::table('S002V01TPACO')->where([
+            ['PACO_NULI', '=', $login['linea']],
+            ['PACO_IDPC', '=', $usr->USUA_PCRE]
+        ])->first();
+
         DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $usr->USUA_IDUS)->update([
             "USUA_ININ" => 0,
             "USUA_ESTA" => 'Activo'
@@ -170,6 +175,7 @@ class LoginController extends Controller{
             "NOMBREUSUARIO" => $this->encryptionController->encrypt($usr->USUA_NOMB),
             "CORREO" => $this->encryptionController->encrypt($usr->USUA_COEL),
             "PERFIL" => $this->encryptionController->encrypt($usr->USUA_PERF),
+            "PANEL" => isset($controlPanel) ? $this->encryptionController->encrypt($usr->USUA_PCRE) : null,
             "PERMISOS" => $permissions,
             "TOKEN" => $token,
         ]);

+ 4 - 5
sistema-mantenimiento-back/app/Http/Controllers/SystemAdministratorController.php

@@ -1799,12 +1799,12 @@ class SystemAdministratorController extends Controller{
             return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
         }
 
-        $maintenanceModeExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
+        $maintenanceModeExists = file_exists('C:\inetpub\wwwroot\sam\storage\app\files\maintenance_mode.json');
         if(!$maintenanceModeExists){
             return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
         }
-        
-        $maintenanceStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
+
+        $maintenanceStr = file_get_contents('C:\inetpub\wwwroot\sam\storage\app\files\maintenance_mode.json');
         $maintenanceArr = json_decode($maintenanceStr, true);
 
         $now = $this->functionsController->now();
@@ -2906,8 +2906,7 @@ class SystemAdministratorController extends Controller{
             return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
         }
 
-        
-        $iconsStr = file_get_contents("C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\storage\\app\\files\\icons.json");
+        $iconsStr = file_get_contents("C:\\inetpub\\wwwroot\\sam\\storage\\app\\files\\icons.json");
         $iconsArr = json_decode($iconsStr, true);
         $icons = $iconsArr['icons'];
 

+ 67 - 24
sistema-mantenimiento-back/app/Http/Controllers/UsersProfilesController.php

@@ -40,17 +40,27 @@ class UsersProfilesController extends Controller{
         $users = DB::table('S002V01TUSUA')
         ->join('S002V01TPERF', 'USUA_PERF', '=', 'PERF_IDPE')
         ->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')
+        ->leftJoin('S002V01TPACO', 'USUA_PCRE', '=', 'PACO_IDPC')
         ->select(
             'USUA_IDUS as IDUSUARIO',
             'USUA_NOMB as NOMBRE',
             'USUA_APPA as APEPAT',
             'USUA_APMA as APEMAT',
             'USUA_COEL as EMAIL',
-            'PERF_NOPE as PERFIL',
+            DB::raw("CONCAT(PERF_NOPE, ' (', PERF_IDPE, ')') AS PERFIL"),
+            DB::raw("IF(ISNULL(PACO_IDPC), FALSE, TRUE) AS TIENE_PANEL"),
+            DB::raw("IF(ISNULL(PACO_IDPC), '-', CONCAT(PACO_NPCO, ' (', PACO_IDPC, ')')) AS PANEL_CONTROL"),
             'USUA_ESTA as ESTATUS',
             'BIAC_FECO as ULCON'
         )->where('USUA_NULI', '=', $line)->get()->all();
 
+        foreach($users as $key=>$user){
+            $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
+            $user->TIENE_PANEL = $user->TIENE_PANEL == 1;
+
+            $users[$key] = $user;
+        }
+
         $now = $this->functionsController->now();
         $nowStr = $now->toDateTimeString();
         $actions = DB::getQueryLog();
@@ -158,13 +168,46 @@ class UsersProfilesController extends Controller{
         }
         
         $profiles = DB::table('S002V01TPERF')->select(
-            'PERF_IDPE as IDPERFIL',
-            'PERF_NOPE as NOMBREPERFIL',
-            'PERF_ESTA as ESTATUS',
-            'PERF_PERM as PERMISOS',
-            'PERF_FEMO as FECHAMODIFICACION',
-            'PERF_FERE as FECHACREACION'
-        )->orderBy('PERF_ESTA', 'asc')->orderBy('PERF_IDPE', 'asc')->get()->all();
+            'PERF_IDPE AS IDPERFIL',
+            'PERF_NOPE AS NOMBREPERFIL',
+            'PERF_PERM AS PERMISOS',
+            'PERF_ESTA AS ESTADO',
+            'PERF_USRE AS USRREG',
+            'PERF_FERE AS FECREG',
+            'PERF_USMO AS USRMOD',
+            'PERF_FEMO AS FECMOD',
+        )->where('PERF_NULI', '=', $line)->orderBy('PERF_IDPE', 'desc')->get()->all();
+
+        foreach($profiles as $key=>$profile){
+            $relatedUsers = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_PERF', '=', $profile->IDPERFIL]
+            ])->get()->all();
+
+            $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
+            $profile->PERMISOS = $this->encryptionController->encrypt($profile->PERMISOS);
+
+            $usrReg = DB::table('S002V01TUSUA')->where([
+                ['USUA_NULI', '=', $line],
+                ['USUA_IDUS', '=', $profile->USRREG]
+            ])->first();
+
+            $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
+            $profile->USRREG = $usrRegName . " (" . $profile->USRREG . ")";
+
+            if(!is_null($profile->USRMOD)){
+                $usrMod = DB::table('S002V01TUSUA')->where([
+                    ['USUA_NULI', '=', $line],
+                    ['USUA_IDUS', '=', $profile->USRMOD]
+                ])->first();
+
+                $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
+                $profile->USRMOD = $usrModName . " (" . $profile->USRMOD . ")";
+            }
+
+            $profile->USUARIOS_RELACIONADOS = count($relatedUsers);
+            $profiles[$key] = $profile;
+        }
 
         $now = $this->functionsController->now();
         $nowStr = $now->toDateTimeString();
@@ -187,7 +230,7 @@ class UsersProfilesController extends Controller{
         return $this->responseController->makeresponse(false, "EXITO", $profiles);
     }
 
-    public function getProfile($id, $idUser, $line){
+    public function getProfile($idProfile, $idUser, $line){
         DB::enableQueryLog();
 
         $idUser = $this->encryptionController->decrypt($idUser);
@@ -195,11 +238,6 @@ class UsersProfilesController extends Controller{
             return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
         }
 
-        $id = $this->encryptionController->decrypt($id);
-        if(!$id){
-            return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
-        }
-
         $usr = DB::table('S002V01TUSUA')->where([
             ['USUA_IDUS', '=', $idUser],
             ['USUA_NULI', '=', $line],
@@ -209,22 +247,29 @@ class UsersProfilesController extends Controller{
             return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
         }
 
+        $idProfile = $this->encryptionController->decrypt($idProfile);
+        if(!$idProfile){
+            return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
+        }
+
         $profile = DB::table('S002V01TPERF')->select(
             'PERF_IDPE AS IDPERFIL',
             'PERF_NOPE AS NOMBREPERFIL',
             'PERF_ESTA AS ESTATUS',
             'PERF_PERM AS PERMISOS',
         )->where([
-            ['PERF_IDPE', '=', $id],
+            ['PERF_IDPE', '=', $idProfile],
             ['PERF_NULI', '=', $line],
         ])->first();
 
         if(is_null($profile)){
             return $this->responseController->makeResponse(true, "El perfil consultado no existe.", [], 404);
         }
-        
+
+        $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
         $profilePermissions = json_decode($profile->PERMISOS, true);
         $permissions = [];
+
         $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
         $moduleIndex = 0;
         foreach($modules as $module){
@@ -234,7 +279,6 @@ class UsersProfilesController extends Controller{
             ])->get()->all();
             
             $permissionsPerSubmodule = [];
-            $hasSubmodules = false;
             $submoduleIndex = 0;
             foreach($submodules as $submodule){
                 $functions = DB::table('S002V01TFUNC')->where([
@@ -260,7 +304,7 @@ class UsersProfilesController extends Controller{
                         }
                         
                         $permissionsPerScreen[] = [
-                            'id' => $screen->PANT_IDPA,
+                            'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
                             'name' => $screen->PANT_NOMB,
                             'access' => $screenAccess
                         ];
@@ -274,7 +318,7 @@ class UsersProfilesController extends Controller{
                     }
 
                     $permissionsPerFunction[] = [
-                        'id' => $function->FUNC_IDFU,
+                        'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
                         'name' => $function->FUNC_NOMB,
                         'access' => $functionAcces,
                         'children' => $permissionsPerScreen,
@@ -289,13 +333,12 @@ class UsersProfilesController extends Controller{
                 }
 
                 $permissionsPerSubmodule[] = [
-                    'id' => $submodule->SUBM_IDSM,
+                    'id' => $this->encryptionController->encrypt($submodule->SUBM_IDSM),
                     'name' => $submodule->SUBM_NOMB,
                     'access' => $submoduleAccess,
                     'children' => $permissionsPerFunction,
                 ];
 
-                $hasSubmodules = true;
                 $submoduleIndex++;
             }
             
@@ -322,7 +365,7 @@ class UsersProfilesController extends Controller{
                     }
 
                     $permissionsPerScreen[] = [
-                        'id' => $screen->PANT_IDPA,
+                        'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
                         'name' => $screen->PANT_NOMB,
                         'access' => $screenAccess
                     ];
@@ -336,7 +379,7 @@ class UsersProfilesController extends Controller{
                 }
 
                 $permissionsPerFunction[] = [
-                    'id' => $function->FUNC_IDFU,
+                    'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
                     'name' => $function->FUNC_NOMB,
                     'access' => $functionAcces,
                     'children' => $permissionsPerScreen,
@@ -352,7 +395,7 @@ class UsersProfilesController extends Controller{
             $moduleAccess = $profilePermissions['permissions'][$moduleIndex]['access'];
 
             $permissions[] = [
-                'id' => $module->MODU_IDMO,
+                'id' => $this->encryptionController->encrypt($module->MODU_IDMO),
                 'name' => $module->MODU_NOMO,
                 'access' => $moduleAccess,
                 'children' => $permissionsArr,

+ 35 - 0
sistema-mantenimiento-back/routes/api.php

@@ -268,7 +268,14 @@ Route::middleware(['jwt.auth'])->group(function(){
     Route::get("/equipment/consult/{idUser}/{line}",                                    "App\Http\Controllers\EquipmentManagementController@getEquipments");
     Route::get("/equipment/consult/by-subfamily/{family}/{subfamily}/{idUser}/{line}",  "App\Http\Controllers\EquipmentManagementController@getEquipmentsBySubfamily");
     Route::get("/equipment/consult/by-parent/{parent}/{idUser}/{line}",                 "App\Http\Controllers\EquipmentManagementController@getEquipmentsByParent");
+    Route::get("/equipment/consult/by-code-type/{codeType}/{idUser}/{line}",            "App\Http\Controllers\EquipmentManagementController@getEquipmentsByCodeType");
     Route::get("/equipment/consult/only/{code}/{idUser}/{line}",                        "App\Http\Controllers\EquipmentManagementController@getEquipmentDetails");
+    Route::get("/equipment/consult/types/{idUser}/{line}",                              "App\Http\Controllers\EquipmentManagementController@getEquipmentTypes");
+    Route::get("/equipment/consult/by-type/{equipmentType}/{idUser}/{line}",            "App\Http\Controllers\EquipmentManagementController@getEquipmentsByType");
+    Route::get("/equipment/consult/by-kilometer/{startPK}/{endPK}/{idUser}/{line}",     "App\Http\Controllers\EquipmentManagementController@getEquipmentsByKilometer");
+    Route::get("/equipment/consult/by-train-area/{car}/{area}/{idUser}/{line}",         "App\Http\Controllers\EquipmentManagementController@getEquipmentsByTrainArea");
+    Route::get("/equipment/consult/by-pcc-position/{coord}/{element}/{idUser}/{line}",  "App\Http\Controllers\EquipmentManagementController@getEquipmentsByPCCIntersection");
+    Route::get("/arborescence/consult/by-date/{date}/{idUser}/{line}",                  "App\Http\Controllers\EquipmentManagementController@getArborescenceByDate");
     Route::post("/family/register",                                                     "App\Http\Controllers\EquipmentManagementController@registerFamily");
     Route::post("/family/update",                                                       "App\Http\Controllers\EquipmentManagementController@updateFamily");
     Route::post("/family/delete",                                                       "App\Http\Controllers\EquipmentManagementController@deleteFamily");
@@ -281,6 +288,9 @@ Route::middleware(['jwt.auth'])->group(function(){
     Route::post("/equipment/pre-codification",                                          "App\Http\Controllers\EquipmentManagementController@saveEquipmentPreCodified");
     Route::post("/equipment/pre-codification-stock",                                    "App\Http\Controllers\EquipmentManagementController@saveEquipmentPreCodifiedStock");
     Route::post("/equipment/pre-codification/status/update",                            "App\Http\Controllers\EquipmentManagementController@changePreCodedEquipmentStatus");
+    Route::post("/equipment/graphic-arborescence",                                      "App\Http\Controllers\EquipmentManagementController@generateGraphicArborescence");
+    Route::post("/equipment/update-security-criticality",                               "App\Http\Controllers\EquipmentManagementController@updateSecurityCriticality");
+    Route::post("/equipment/generate-equipment-file",                                   "App\Http\Controllers\EquipmentManagementController@generateEquipmentFile");
     //Módulo gestión de mantenimiento correctivo
     Route::get("corrective-maintenance/get-work-orders/{idUser}/{line}",                "App\Http\Controllers\CorrectiveMaintenanceController@getWorkOrders");
     Route::get("corrective-maintenance/get-work-order/{idOrder}/{idUser}/{line}",       "App\Http\Controllers\CorrectiveMaintenanceController@getWorkOrder");
@@ -291,6 +301,10 @@ Route::middleware(['jwt.auth'])->group(function(){
     Route::get("corrective-maintenance/get-block-registers/{idUser}/{line}",            "App\Http\Controllers\CorrectiveMaintenanceController@getBlockRegisters");
     Route::get("corrective-maintenance/get-work-order-status-history/{ord}/{usr}/{li}", "App\Http\Controllers\CorrectiveMaintenanceController@getWorkOrderStatusHistory");
     Route::get("corrective-maintenance/get-reports/{type}/{sd}/{ed}/{idUser}/{line}",   "App\Http\Controllers\CorrectiveMaintenanceController@getReports");
+    Route::get("corrective-maintenance/get-maintenance-plans/{idUser}/{line}",          "App\Http\Controllers\CorrectiveMaintenanceController@getMaintenancePlans");
+    Route::get("corrective-maintenance/get-maintenance-plan/{idPlan}/{idUser}/{line}",  "App\Http\Controllers\CorrectiveMaintenanceController@getMaintenancePlan");
+    Route::get("corrective-maintenance/get-work-groups/{idUser}/{line}",                "App\Http\Controllers\CorrectiveMaintenanceController@getWorkGroups");
+    Route::get("corrective-maintenance/get-work-group/{idGroup}/{idUser}/{line}",       "App\Http\Controllers\CorrectiveMaintenanceController@getWorkGroup");
     Route::post("corrective-maintenance/register-work-order",                           "App\Http\Controllers\CorrectiveMaintenanceController@registerWorkOrder");
     Route::post("corrective-maintenance/update-work-order",                             "App\Http\Controllers\CorrectiveMaintenanceController@updateWorkOrder");
     Route::post("corrective-maintenance/delete-work-order",                             "App\Http\Controllers\CorrectiveMaintenanceController@deleteWorkOrder");
@@ -304,6 +318,27 @@ Route::middleware(['jwt.auth'])->group(function(){
     Route::post("corrective-maintenance/register-block",                                "App\Http\Controllers\CorrectiveMaintenanceController@registerBlock");
     Route::post("corrective-maintenance/unblock-register",                              "App\Http\Controllers\CorrectiveMaintenanceController@unblockRegister");
     Route::post("corrective-maintenance/generate-report",                               "App\Http\Controllers\CorrectiveMaintenanceController@generateReport");
+    Route::post("corrective-maintenance/register-maintenance-plan",                     "App\Http\Controllers\CorrectiveMaintenanceController@registerMaintnencePlan");
+    Route::post("corrective-maintenance/update-maintenance-plan",                       "App\Http\Controllers\CorrectiveMaintenanceController@updateMaintenancePlan");
+    Route::post("corrective-maintenance/delete-maintenance-plan",                       "App\Http\Controllers\CorrectiveMaintenanceController@deleteMaintenancePlan");
+    Route::post("corrective-maintenance/create-work-group",                             "App\Http\Controllers\CorrectiveMaintenanceController@registerWorkGroup");
+    Route::post("corrective-maintenance/update-work-group",                             "App\Http\Controllers\CorrectiveMaintenanceController@updateWorkGroup");
+    Route::post("corrective-maintenance/delete-work-group",                             "App\Http\Controllers\CorrectiveMaintenanceController@deleteWorkGroup");
+    //Módulo panel de control y seguimiento de actividades
+    Route::get("control-panel/get-panels/{idUser}/{line}",                              "App\Http\Controllers\ControlPanelController@getPanels");
+    Route::get("control-panel/get-counters-list/{idUser}/{line}",                       "App\Http\Controllers\ControlPanelController@getCountersList");
+    Route::get("control-panel/get-panel/{idPanel}/{idUser}/{line}",                     "App\Http\Controllers\ControlPanelController@getPanel");
+    Route::get("control-panel/get-info-to-excel/{idElement}/{module}/{idUser}/{line}",  "App\Http\Controllers\ControlPanelController@getInfoToExcel");
+    Route::get("control-panel/get-broadcast-lists/{idUser}/{line}",                     "App\Http\Controllers\ControlPanelController@getBroadcastLists");
+    Route::get("control-panel/get-broadcast-list/{idList}/{idUser}/{line}",             "App\Http\Controllers\ControlPanelController@getBroadcastList");
+    Route::post("control-panel/register-panel",                                         "App\Http\Controllers\ControlPanelController@registerPanel");
+    Route::post("control-panel/update-panel",                                           "App\Http\Controllers\ControlPanelController@updatePanel");
+    Route::post("control-panel/update-panel-elements",                                  "App\Http\Controllers\ControlPanelController@updatePanelElements");
+    Route::post("control-panel/update-panel-associations",                              "App\Http\Controllers\ControlPanelController@updatePanelAssociations");
+    Route::post("control-panel/delete-panel",                                           "App\Http\Controllers\ControlPanelController@deletePanel");
+    Route::post("control-panel/register-broadcast-list",                                "App\Http\Controllers\ControlPanelController@registerBroadcastList");
+    Route::post("control-panel/update-broadcast-list",                                  "App\Http\Controllers\ControlPanelController@updateBroadcastList");
+    Route::post("control-panel/delete-broadcast-list",                                  "App\Http\Controllers\ControlPanelController@deleteBroadcastList");
 });
 
 // Module (FUNCIONALES)

部分文件因文件數量過多而無法顯示