Преглед изворни кода

Implementación de función de lista de sintomas en end-points

JeanBenitez пре 2 година
родитељ
комит
29b37fa859

+ 107 - 38
sistema-mantenimiento-back/app/Http/Controllers/CatalogFailureController.php

@@ -51,7 +51,7 @@ class CatalogFailureController extends Controller
         return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getFailures);
     }
 
-    public function getFailuresActives() {
+    public function getFailuresActives($user, $line) {
         try {
             $getFailures = DB::table('S002V01TLIFA')
                 ->where('LIFA_ESTA', '=', 'Activo')
@@ -107,8 +107,8 @@ class CatalogFailureController extends Controller
             try {
                 $arrEquipment = DB::table('S002V01TLFEQ')
                     ->where('LFEQ_IDFA', '=', $arrFailures['ID_FALLA'])
-                    ->where('LDEQ_NULI', '=', $line)
-                    ->where('LEFQ_ESTA', '=', 'Activo')
+                    ->where('LFEQ_NULI', '=', $line)
+                    ->where('LFEQ_ESTA', '=', 'Activo')
                     ->where('EQUI_NULI', '=', $line)
                     ->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'LFEQ_COEQ')
                     ->get([
@@ -139,8 +139,6 @@ class CatalogFailureController extends Controller
             $arrFailures['EQUIPAMIENTOS'] = $arrEquipment;
         }
 
-        
-
         return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailures);
     }
 
@@ -168,7 +166,7 @@ class CatalogFailureController extends Controller
         $requestData = $request->all();
 
         try {
-            $user = $this->encController->decrypt($request['USUARIO']);
+            $user = $this->encController->decrypt($requestData['USUARIO']);
         } catch (\Throwable $th) {
             DB::rollBack();
             return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", [], 500);
@@ -211,7 +209,7 @@ class CatalogFailureController extends Controller
         foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
             try {
                 $validateRegisterEquipment = DB::table('S002V01TLFEQ')->insert([
-                    'LDEQ_NULI' => $requestData['NUMERO_LINEA'],
+                    'LFEQ_NULI' => $requestData['NUMERO_LINEA'],
                     'LFEQ_IDFA' => $idFailure,
                     'LFEQ_COEQ' => $equipment,
                     'LFEQ_USRE' => $user,
@@ -266,7 +264,6 @@ class CatalogFailureController extends Controller
 
         DB::beginTransaction();
         $requestData = $request->all();
-
         try {
             $user = $this->encController->decrypt($request['USUARIO']);
         } catch (\Throwable $th) {
@@ -312,30 +309,30 @@ class CatalogFailureController extends Controller
         }
 
         foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
-
             try {
                 $validateExists = DB::table('S002V01TLFEQ')
                     ->where('LFEQ_IDFA', '=', $requestData['ID_FALLA'])
-                    ->where('LEFQ_COEQ', '=', $equipment)
                     ->where('LFEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                    ->where('LFEQ_COEQ', '=', $equipment)
                     ->exists();
             } catch (\Throwable $th) {
                 DB::rollBack();
                 return $this->responseController->makeResponse(
                     true, 
-                    "ERR_FAILURES_UPD004: No se pudo modificar el formulario en la lista de falla.", 
-                    [], 
+                    "ERR_FAILURES_UPD004: Ocurrió un error al consultar el equipamiento.", 
+                    $th->getMessage(), 
                     500
                 );
             }
-
+    
             if ( $validateExists ) {
                 try {
                     $validate = DB::table('S002V01TLFEQ')
-                        ->where('LDEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->where('LFEQ_NULI', '=', $requestData['NUMERO_LINEA'])
                         ->where('LFEQ_IDFA', '=', $requestData['ID_FALLA'])
+                        ->where('LFEQ_COEQ', '=', $equipment)
                         ->update([
-                            'LFEQ_COEQ' => $equipment,
+                            'LFEQ_ESTA' => 'Activo',
                             'LFEQ_USMO' => $user,
                             'LFEQ_FEMO' => $currentDate,
                             'LFEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
@@ -352,7 +349,7 @@ class CatalogFailureController extends Controller
             } else {
                 try {
                     $validate = DB::table('S002V01TLFEQ')->insert([
-                        'LDEQ_NULI' => $requestData['NUMERO_LINEA'],
+                        'LFEQ_NULI' => $requestData['NUMERO_LINEA'],
                         'LFEQ_IDFA' => $requestData['ID_FALLA'],
                         'LFEQ_COEQ' => $equipment,
                         'LFEQ_USRE' => $user,
@@ -379,6 +376,63 @@ class CatalogFailureController extends Controller
                 );
             }
         }
+
+        try {
+            $getListEquipment = DB::table('S002V01TLFEQ')
+                ->where('LFEQ_IDFA', '=', $requestData['ID_FALLA'])
+                ->where('LFEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->get([
+                    'LFEQ_IDLF',
+                    'LFEQ_IDFA',
+                    'LFEQ_COEQ',
+                    'LFEQ_ESTA',
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_FAILURES_UPD008: Ocurrió un error al consultar la lista de equipamientos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrListEquipment = json_decode( json_encode($getListEquipment), true );
+        
+        foreach ($arrListEquipment as $keyListEquipment => $listEquipment) {
+            if( !in_array($listEquipment['LFEQ_COEQ'], $requestData['EQUIPAMIENTOS']) ) {
+                try {
+                    $validateDelete = DB::table('S002V01TLFEQ')
+                        ->where('LFEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->where('LFEQ_IDFA', '=', $requestData['ID_FALLA'])
+                        ->where('LFEQ_COEQ', '=', $listEquipment['LFEQ_COEQ'])
+                        ->update([
+                            'LFEQ_ESTA' => 'Eliminado',
+                            'LFEQ_USMO' => $user,
+                            'LFEQ_FEMO' => $currentDate,
+                            'LFEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                        ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_FAILURES_UPD009: Ocurrió un error al eliminar de la lista de falla el equipamiento ". $listEquipment['LFEQ_COEQ'].".", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+
+                if ( !$validateDelete ) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_FAILURES_UPD010: No se pudo eliminar de la lista de falla el equipamiento ". $listEquipment['LFEQ_COEQ'].".", 
+                        [], 
+                        500
+                    );
+                }
+            }
+        }
         
         DB::commit();
         return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
@@ -400,60 +454,75 @@ class CatalogFailureController extends Controller
         }
 
         DB::beginTransaction();
-        $request = $request->all();
-
-        $idFailure = trim($request['ID_FALLA']);
+        $requestData = $request->all();
         
         try {
             $user = $this->encController->decrypt($request['USUARIO']);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL001: No se pudo obtener el usuario.", $th->getMessage(), 500);
         }
-        $line = $request['NUMERO_LINEA'];
-
+        
         $now = $this->functionsController->now();
         $currentDate = $now->toDateTimeString();
 
         try {
             $exist = DB::table('S002V01TLIFA')
-                ->where([
-                    ['LIFA_IDFA', '=', $idFailure],
-                    ['LIFA_NULI', '=', $line]
-                ])
-                ->get();
+                ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
+                ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->exists();
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL001: Ocurrió un error al consultar en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
         }
-
         
         if (!$exist) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL002: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL003: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
         }
 
         try {
             $validateUpdate = DB::table('S002V01TLIFA')
-                ->where([
-                    ['LIFA_IDFA', '=', $idFailure],
-                    ['LIFA_NULI', '=', $line]
-                ])
+                ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
+                ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
                 ->update([
-                    'LIFA_ESTA' => 'test',
+                    'LIFA_ESTA' => 'Eliminado',
                     'LIFA_USMO' => $user,
                     'LIFA_FEMO' => $currentDate,
                     'LIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
                 ]);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL003: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL004: Ocurrió un error al modificar el formulario en la base de datos.", $th->getMessage(), 500);
+        }
+        if (!$validateUpdate) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL005: No se pudo modificar el formulario en la base de datos.", [], 500);
         }
 
+        try {
+            $validateDelete = DB::table('S002V01TLFEQ')
+                ->where('LFEQ_IDFA', '=', $requestData['ID_FALLA'])
+                ->where('LFEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LFEQ_ESTA' => 'Eliminado',
+                    'LFEQ_USMO' => $user,
+                    'LFEQ_FEMO' => $currentDate,
+                    'LFEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_FAILURES_DEL006: Ocurrió un error al eliminar la lista de equipamientos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
 
-        if (!$validateUpdate) {
+        if ( !$validateDelete ) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL004: No se pudo modificar el formulario en la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_DEL007: No se pudo eliminar la lista de equipamientos.", [], 500);
         }
 
         DB::commit();

+ 75 - 86
sistema-mantenimiento-back/app/Http/Controllers/CatalogMeasuresController.php

@@ -27,19 +27,19 @@ class CatalogMeasuresController extends Controller
         $this->functionsController = new FunctionsController();
     }
 
-    public function getMeasures($line) {
+    public function getMeasures($user, $line) {
         try {
             $getMeasures = DB::table('S002V01TLIME')
                 ->where('LIME_NULI', '=', $line)
                 ->get([
-                    'LIME_IDME', // ID_MEDIDA
-                    'LIME_MEDI', // MEDIDA
-                    'LIME_ACRO', // ACRONIMO
-                    'LIME_ESTA', // ESTADO
-                    'LIME_USRE', // USUARIO_REGISTRA
-                    'LIME_FERE', // FECHA_REGISTRA
-                    'LIME_USMO', // USUARIO_MODIFICA
-                    'LIME_FEMO', // FECHA_MODIFICA
+                    'LIME_IDME AS ID_MEDIDA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LIME_ESTA AS ESTADO',
+                    'LIME_USRE AS USUARIO_REGISTRA ',
+                    'LIME_FERE AS FECHA_REGISTRA',
+                    'LIME_USMO AS USUARIO_MODIFICA',
+                    'LIME_FEMO AS FECHA_MODIFICA',
                 ]);
         } catch (\Throwable $th) {
             return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_GET000: No se pudo realizar la consulta a la base.", [], 500);
@@ -47,17 +47,16 @@ class CatalogMeasuresController extends Controller
         return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getMeasures);
     }
 
-    public function getMeasuresActives() {
+    public function getMeasuresActives($user, $line) {
         try {
             $getMeasures = DB::table('S002V01TLIME')
                 ->where('LIME_ESTA', '=', 'Activo')
-                ->where('LIME_NULI', '=', 1)
+                ->where('LIME_NULI', '=', $line)
                 ->get([
                     'LIME_IDME AS ID_MEDIDA',
-                    'LIME_MEDI AS MEDIDA',
-                    'LIME_ACRO AS ACRONIMO',
-                    'LIME_ESTA AS ESTADO',
-                    'LIME_USRE AS USUARIO_REGISTRA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LIME_USRE AS USUARIO_REGISTRA ',
                     'LIME_FERE AS FECHA_REGISTRA',
                     'LIME_USMO AS USUARIO_MODIFICA',
                     'LIME_FEMO AS FECHA_MODIFICA',
@@ -70,8 +69,8 @@ class CatalogMeasuresController extends Controller
 
     public function registerMeasures(Request $request) {
         $validator = Validator::make($request->all(), [
-            'MEDIDA' => 'required|string',
-            'ACRONIMO' => 'required|string',
+            'NOMBRE_MEDIDA' => 'required|string',
+            'ACRONIMO_MEDIDA' => 'required|string',
             'NUMERO_LINEA' => 'required|string',
             'USUARIO' => 'required|string',
         ]);
@@ -85,50 +84,46 @@ class CatalogMeasuresController extends Controller
         }
 
         DB::beginTransaction();
-        $request = $request->all();
+        $requestData = $request->all();
 
-        $measurement = trim($request['MEDIDA']);
-        $acronym = trim($request['ACRONIMO']);
         try {
-            $user = $this->encController->decrypt($request['USUARIO']);
+            $user = $this->encController->decrypt($requestData['USUARIO']);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
         }
-        $line = $request['NUMERO_LINEA'];
 
         $now = $this->functionsController->now();
         $currentDate = $now->toDateTimeString();
 
-        $arrInsert = [
-            'LIME_MEDI' => $measurement,
-            'LIME_ACRO' => $acronym,
-            'LIME_NULI' => $line,
-            'LIME_USRE' => $user,
-            'LIME_FERE' => $currentDate,
-            'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
-        ];
         try {
-            $response = DB::table('S002V01TLIME')->insert($arrInsert);
+            $validateRegister = DB::table('S002V01TLIME')->insert([
+                'LIME_NOME' => $requestData['NOMBRE_MEDIDA'],
+                'LIME_ACME' => $requestData['ACRONIMO_MEDIDA'],
+                'LIME_NULI' => $requestData['NUMERO_LINEA'],
+                'LIME_USRE' => $user,
+                'LIME_FERE' => $currentDate,
+                'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+            ]);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_REG001: Ocurrió un error al insertar el formulario en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_REG001: Ocurrió un error al insertar el formulario en la base de datos.", $th->getMessage(), 500);
         }
 
-        if (!$response) {
+        if (!$validateRegister) {
             DB::rollBack();
             return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_REG002: No se pudo insertar el formulario en la base de datos.", [], 500);
         }
+
         DB::commit();
         return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
-
     }
 
     public function updateMeasures(Request $request) {
         $validator = Validator::make($request->all(), [
             'ID_MEDIDA' => 'required|string',
-            'MEDIDA' => 'required|string',
-            'ACRONIMO' => 'required|string',
+            'NOMBRE_MEDIDA' => 'required|string',
+            'ACRONIMO_MEDIDA' => 'required|string',
             'NUMERO_LINEA' => 'required|string',
             'USUARIO' => 'required|string',
         ]);
@@ -142,51 +137,48 @@ class CatalogMeasuresController extends Controller
         }
 
         DB::beginTransaction();
-        $request = $request->all();
+        $requestData = $request->all();
 
-        $idMeasures = trim($request['ID_MEDIDA']);
-        $measurement = trim($request['MEDIDA']);
-        $acronym = trim($request['ACRONIMO']);
         try {
             $user = $this->encController->decrypt($request['USUARIO']);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
         }
-        $line = $request['NUMERO_LINEA'];
-        
-        $now = $this->functionsController->now();
-        $currentDate = $now->toDateTimeString();
 
         try {
-            $exist = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $idMeasures)->exists();
+            $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists();
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD001: Ocurrió un error al consultar en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
         }
-
-        if (!$exist) {
+        if (!$validateExists) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD002: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD003: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
         }
 
-        $arrUpdate = [
-            'LIME_MEDI' => $measurement,
-            'LIME_ACRO' => $acronym,
-            'LIME_USMO' => $user,
-            'LIME_FEMO' => $currentDate,
-            'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
-        ];
+        $now = $this->functionsController->now();
+        $currentDate = $now->toDateTimeString();
+
         try {
-            $response = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $idMeasures)->where('LIME_NULI', '=', $line)->update($arrUpdate);
+            $validateUpdate = DB::table('S002V01TLIME')
+                ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
+                ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LIME_NOME' => $requestData['NOMBRE_MEDIDA'],
+                    'LIME_ACME' => $requestData['ACRONIMO_MEDIDA'],
+                    'LIME_USMO' => $user,
+                    'LIME_FEMO' => $currentDate,
+                    'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD003: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD004: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500);
         }
 
-        if (!$response) {
+        if ( !$validateUpdate ) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD004: No se pudo modificar el formulario en la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD005: No se pudo modificar el formulario en la base de datos.", [], 500);
         }
 
         DB::commit();
@@ -209,49 +201,46 @@ class CatalogMeasuresController extends Controller
         }
 
         DB::beginTransaction();
-        $request = $request->all();
+        $requestData = $request->all();
 
-        $idMeasures = trim($request['ID_MEDIDA']);
-        $line = $request['NUMERO_LINEA'];
-        
-        $now = $this->functionsController->now();
-        $currentDate = $now->toDateTimeString();
-        
         try {
             $user = $this->encController->decrypt($request['USUARIO']);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_FAILURES_REG001: No se pudo obtener el usuario.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL001: No se pudo obtener el usuario.", [], 500);
         }
 
         try {
-            $exist = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $idMeasures)->exists();
+            $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists();
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL001: Ocurrió un error al consultar en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
         }
-
-        if (!$exist) {
+        if (!$validateExists) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL002: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL003: La medida no existe.", [], 500);
         }
 
-        $arrUpdate = [
-            'LIME_ESTA' => 'Eliminado',
-            'LIME_USMO' => $user,
-            'LIME_FEMO' => $currentDate,
-            'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
-        ];
+        $now = $this->functionsController->now();
+        $currentDate = $now->toDateTimeString();
+
         try {
-            $response = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $idMeasures)->where('LIME_NULI', '=', $line)->update($arrUpdate);
+            $validateDelete = DB::table('S002V01TLIME')
+                ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
+                ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LIME_ESTA' => 'Eliminado',
+                    'LIME_USMO' => $user,
+                    'LIME_FEMO' => $currentDate,
+                    'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
         } catch (\Throwable $th) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL003: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL004: Ocurrió un error al eliminar la medida base de datos.", $th, 500);
         }
-
-        if (!$response) {
+        if (!$validateDelete) {
             DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL004: No se pudo modificar el formulario en la base de datos.", [], 500);
+            return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL005: No se pudo eliminar la medida en la base de datos..", [], 500);
         }
 
         DB::commit();

+ 844 - 0
sistema-mantenimiento-back/app/Http/Controllers/CatalogSymptomController.php

@@ -0,0 +1,844 @@
+<?php
+/*
+    Desarrollador: Ing. Jean Jairo Benitez Meza
+    Ultima Modificación: 11/04/2023
+    Módulo: Analisis de Fallas
+*/
+namespace App\Http\Controllers;
+
+use App\Http\Controllers\Controller;
+use App\Http\Controllers\ResponseController;
+use App\Http\Controllers\EncryptionController;
+use Illuminate\Http\Request;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Validator;
+use App\Http\Controllers\FunctionsController;
+
+class CatalogSymptomController extends Controller
+{
+    private $responseController;
+    private $encController;
+    private $functionsController;
+
+    public function __construct( ) {
+        $this->responseController = new ResponseController();
+        $this->encController = new EncryptionController();
+        $this->functionsController = new FunctionsController();
+    }
+
+    public function getSymptoms($user, $line) {
+        try {
+            $getSymptom = DB::table('S002V01TLISI')
+                ->where('LISI_NULI', '=', $line)
+                ->where('LIME_NULI', '=', $line)
+                ->where('LIME_ESTA', '=', 'Activo')
+                ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
+                ->get([
+                    'LISI_IDSI AS ID_SINTOMA',
+                    'LISI_NOSI AS NOMBRE_SINTOMA',
+                    'LISI_CLAS AS CLASIFICACION',
+                    'LISI_CAUS AS CAUSA',
+                    'LISI_DESC AS DESCRIPCION',
+                    'LISI_SOLU AS SOLUCION',
+                    'LISI_LIVA AS LIMITE_VALOR',
+                    'LIME_IDME AS ID_MEDIDA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LISI_ESTA AS ESTADO',
+                    'LISI_USRE AS USUARIO_REGISTRA',
+                    'LISI_FERE AS FECHA_REGISTRA',
+                    'LISI_USMO AS USUARIO_MODIFICA',
+                    'LISI_FEMO AS FECHA_MODIFICA',
+                ]);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_GET000: No se pudo realizar la consulta a la base.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrSymtoms = json_decode( json_encode($getSymptom), true );
+
+        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
+    }
+
+    public function getSymptomsActives($user, $line) {
+        try {
+            $getSymptom = DB::table('S002V01TLISI')
+                ->where('LISI_NULI', '=', $line)
+                ->where('LISI_ESTA', '=', 'Activo')
+                ->where('LIME_NULI', '=', $line)
+                ->where('LIME_ESTA', '=', 'Activo')
+                ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
+                ->get([
+                    'LISI_IDSI AS ID_SINTOMA',
+                    'LISI_NOSI AS NOMBRE_SINTOMA',
+                    'LISI_CLAS AS CLASIFICACION',
+                    'LISI_CAUS AS CAUSA',
+                    'LISI_DESC AS DESCRIPCION',
+                    'LISI_SOLU AS SOLUCION',
+                    'LISI_LIVA AS LIMITE_VALOR',
+                    'LIME_IDME AS ID_MEDIDA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LISI_ESTA AS ESTADO',
+                    'LISI_USRE AS USUARIO_REGISTRA',
+                    'LISI_FERE AS FECHA_REGISTRA',
+                    'LISI_USMO AS USUARIO_MODIFICA',
+                    'LISI_FEMO AS FECHA_MODIFICA',
+                ]);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_GETACTIVE000: No se pudo realizar la consulta a la base.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrSymtoms = json_decode( json_encode($getSymptom), true );
+        
+        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
+    }
+
+    public function getSymptomsByEquipment($equipment, $user, $line) {
+        try {
+            $equipment = $this->encController->decrypt($equipment);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GETBYEQUIPMENT000: No se pudo obtener el equipamiento.", $th->getMessage(), 500);
+        }
+
+        try {
+            $getSymptom = DB::table('S002V01TLSEQ')
+                ->where('LSEQ_NULI', '=', $line)
+                ->where('LSEQ_ESTA', '=', 'Activo')
+                ->where('LSEQ_COEQ', '=', $equipment)
+                ->where('LISI_NULI', '=', $line)
+                ->where('LISI_ESTA', '=', 'Activo')
+                ->join('S002V01TLISI', 'LISI_IDSI', '=', 'LSEQ_IDSI')
+                ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
+                ->get([
+                    'LISI_IDSI AS ID_SINTOMA',
+                    'LISI_NOSI AS NOMBRE_SINTOMA',
+                    'LISI_CLAS AS CLASIFICACION',
+                    'LISI_CAUS AS CAUSA',
+                    'LISI_DESC AS DESCRIPCION',
+                    'LISI_SOLU AS SOLUCION',
+                    'LISI_LIVA AS LIMITE_VALOR',
+                    'LIME_IDME AS ID_MEDIDA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LISI_ESTA AS ESTADO',
+                    'LISI_USRE AS USUARIO_REGISTRA',
+                    'LISI_FERE AS FECHA_REGISTRA',
+                    'LISI_USMO AS USUARIO_MODIFICA',
+                    'LISI_FEMO AS FECHA_MODIFICA',
+                ]);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_GETBYEQUIPMENT001: No se pudo realizar la consulta a la base.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrSymtoms = json_decode( json_encode($getSymptom), true );
+        
+        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
+    }
+
+    public function getSymptomById($idSymptom, $user, $line) {
+
+        try {
+            $idSymptom = $this->encController->decrypt($idSymptom);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GETBYID000: No se pudo obtener el ID del síntoma.", $th->getMessage(), 500);
+        }
+
+        try {
+            $arrSymptom = (array) DB::table('S002V01TLISI')
+                ->where('LISI_IDSI', '=', $idSymptom)
+                ->where('LISI_NULI', '=', $line)
+                ->where('LISI_ESTA', '=', 'Activo')
+                ->where('LIME_NULI', '=', $line)
+                ->where('LIME_ESTA', '=', 'Activo')
+                ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
+                ->first([
+                    'LISI_IDSI AS ID_SINTOMA',
+                    'LISI_NOSI AS NOMBRE_SINTOMA',
+                    'LISI_CLAS AS CLASIFICACION',
+                    'LISI_CAUS AS CAUSA',
+                    'LISI_DESC AS DESCRIPCION',
+                    'LISI_SOLU AS SOLUCION',
+                    'LISI_LIVA AS LIMITE_VALOR',
+                    'LIME_IDME AS ID_MEDIDA',
+                    'LIME_NOME AS NOMBRE_MEDIDA',
+                    'LIME_ACME AS ACRONIMO_MEDIDA',
+                    'LISI_ESTA AS ESTADO',
+                    'LISI_USRE AS USUARIO_REGISTRA',
+                    'LISI_FERE AS FECHA_REGISTRA',
+                    'LISI_USMO AS USUARIO_MODIFICA',
+                    'LISI_FEMO AS FECHA_MODIFICA',
+                ]);
+        } catch (\Throwable $th) {
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_GETBYID001: No se pudo realizar la consulta a la base.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        if ( !empty($arrSymptom) ) {
+            try {
+                $arrEquipment = DB::table('S002V01TLSEQ')
+                    ->where('LSEQ_IDSI', '=', $idSymptom)
+                    ->where('LSEQ_NULI', '=', $line)
+                    ->where('LSEQ_ESTA', '=', 'Activo')
+                    ->where('EQUI_NULI', '=', $line)
+                    ->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'LSEQ_COEQ')
+                    ->get([
+                        'EQUI_COEQ AS CODIGO',
+                        'EQUI_TIPO AS TIPO',
+                        'EQUI_MODE AS MODELO',
+                        'EQUI_IDEQ AS ID_EQUIPO',
+                        'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
+                        'EQUI_ELOR AS ELEMENTO_ORIGEN',
+                        'EQUI_TICO AS TIPO_CODIGO'
+                    ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_GETBYID002: No se pudo realizar la consulta a la base.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+
+            $arrEquipment = json_decode( json_encode($arrEquipment), true );
+
+            foreach ($arrEquipment as $keyEquipment => $equipment) {
+                $equipment['ID_EQUIPO'] = strval($equipment['ID_EQUIPO']);
+                $arrEquipment[$keyEquipment] = $equipment;
+            }
+            $arrSymptom['EQUIPAMIENTOS'] = $arrEquipment;
+
+
+            try {
+                $arrFailure = DB::table('S002V01TLFLS')
+                    ->where('LFLS_IDSI', '=', $idSymptom)
+                    ->where('LFLS_NULI', '=', $line)
+                    ->where('LFLS_ESTA', '=', 'Activo')
+                    ->where('LIFA_NULI', '=', $line)
+                    ->where('LIFA_ESTA', '=', 'Activo')
+                    ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'LFLS_IDFA')
+                    ->get([
+                        'LIFA_IDFA AS ID_FALLA',
+                        'LIFA_NOFA AS NOMBRE_FALLA',
+                        'LIFA_NIVE AS NIVEL_CRITICIDAD',
+                        'LIFA_CAUS AS CAUSA_FALLA',
+                        'LIFA_SOLU AS SOLICION',
+                        'LIFA_DESC AS DESCRIPCION',
+                    ]);
+            } catch (\Throwable $th) {
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_GETBYID003: No se pudo realizar la consulta a la base.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+            $arrFailure = json_decode( json_encode($arrFailure), true );
+
+            $arrSymptom['FALLAS'] = $arrFailure;
+        }
+
+        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymptom);
+    }
+
+    public function registerSymptom(Request $request) {
+        $validator = Validator::make($request->all(), [
+            'NOMBRE_SINTOMA' => 'required|string',
+            'CLASIFICACION' => 'required|string',
+            'CAUSA' => 'required|string', 
+            'DESCRIPCION' => 'required|string', 
+            'SOLUCION' => 'required|string', 
+            'LIMITE_VALOR' => 'required|string', 
+            'ID_MEDIDA' => 'required|string', 
+            'FALLAS' => 'required|array', 
+            'EQUIPAMIENTOS' => 'required|array',
+            'USUARIO' => 'required|string', 
+            'NUMERO_LINEA' => 'required|string', 
+
+        ]);
+        if ($validator->fails()) {
+            return $this->responseController->makeResponse(
+                true,
+                "ERR_SYMPTOM_REG000: Se encontraron uno o más errores.",
+                $this->responseController->makeErrors($validator->errors()->messages()),
+                401
+            );
+        }
+
+        DB::beginTransaction();
+        $requestData = $request->all();
+
+        try {
+            $user = $this->encController->decrypt($requestData['USUARIO']);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
+        }
+
+        $now = $this->functionsController->now();
+        $currentDate = $now->toDateTimeString();
+
+        try {
+            $idSymptom = DB::table('S002V01TLISI')->insertGetId([
+                'LISI_NULI' => $requestData['NUMERO_LINEA'],
+                'LISI_NOSI' => $requestData['NOMBRE_SINTOMA'],
+                'LISI_CLAS' => $requestData['CLASIFICACION'],
+                'LISI_CAUS' => $requestData['CAUSA'],
+                'LISI_SOLU' => $requestData['SOLUCION'],
+                'LISI_DESC' => $requestData['DESCRIPCION'],
+                'LISI_LIVA' => $requestData['LIMITE_VALOR'],
+                'LISI_IDME' => $requestData['ID_MEDIDA'],
+                'LISI_USRE' => $user,
+                'LISI_FERE' => $currentDate,
+                'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+            ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_REG002: Ocurrió un error en el registro de la lista de síntoma en la base de datos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        if ( !$idSymptom ) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_REG003: No se pudo hacer el registro de la lista de síntoma en la base de datos.", 
+                [], 
+                500
+            );
+        }
+
+        foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
+            try {
+                $validateRegisterEquipment = DB::table('S002V01TLSEQ')->insert([
+                    'LSEQ_NULI' => $requestData['NUMERO_LINEA'],
+                    'LSEQ_IDSI' => $idSymptom,
+                    'LSEQ_COEQ' => $equipment,
+                    'LSEQ_USRE' => $user,
+                    'LSEQ_FERE' => $currentDate,
+                    'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+            } catch (\Throwable $th) {
+                DB::rollBack();
+                return $this->responseController->makeResponse( 
+                    true, 
+                    "ERR_SYMPTOM_REG004: Ocurrió un error al registrar el formulario en la lista de síntomas.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+
+            if ( !$validateRegisterEquipment ) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_REG005: No se pudo registrar el equipamiento $equipment en la lista de síntomas.", 
+                    [], 
+                    500
+                );
+            }
+        }
+
+        foreach ($requestData['FALLAS'] as $keyFailure => $failure) {
+            try {
+                $validateRegisterFailure = DB::table('S002V01TLFLS')->insert([
+                    'LFLS_NULI' => $requestData['NUMERO_LINEA'],
+                    'LFLS_IDFA' => $failure,
+                    'LFLS_IDSI' => $idSymptom,
+                    'LFLS_USRE' => $user,
+                    'LFLS_FERE' => $currentDate,
+                    'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+            } catch (\Throwable $th) {
+                DB::rollBack();
+                return $this->responseController->makeResponse( 
+                    true, 
+                    "ERR_SYMPTOM_REG006: Ocurrió un error al registrar el formulario en la lista de síntomas.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+
+            if ( !$validateRegisterFailure ) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_REG007: No se pudo registrar el equipamiento $equipment en la lista de síntomas.", 
+                    [], 
+                    500
+                );
+            }
+        }
+
+        DB::commit();
+        return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
+    }
+
+    public function updateSymptom(Request $request) {
+        $validator = Validator::make($request->all(), [
+            'ID_SINTOMA' => 'required|integer',
+            'NOMBRE_SINTOMA' => 'required|string',
+            'CLASIFICACION' => 'required|string',
+            'CAUSA' => 'required|string', 
+            'DESCRIPCION' => 'required|string', 
+            'SOLUCION' => 'required|string', 
+            'LIMITE_VALOR' => 'required|string', 
+            'ID_MEDIDA' => 'required|string', 
+            'FALLAS' => 'required|array', 
+            'EQUIPAMIENTOS' => 'required|array',
+            'USUARIO' => 'required|string', 
+            'NUMERO_LINEA' => 'required|string', 
+
+        ]);
+        if ($validator->fails()) {
+            return $this->responseController->makeResponse(
+                true,
+                "ERR_SYMPTOM_UPD000: Se encontraron uno o más errores.",
+                $this->responseController->makeErrors($validator->errors()->messages()),
+                401
+            );
+        }
+
+        DB::beginTransaction();
+        $requestData = $request->all();
+
+        try {
+            $user = $this->encController->decrypt($requestData['USUARIO']);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
+        }
+
+        $now = $this->functionsController->now();
+        $currentDate = $now->toDateTimeString();
+
+        try {
+            $validateUpdate = DB::table('S002V01TLISI')
+                ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LISI_NOSI' => $requestData['NOMBRE_SINTOMA'],
+                    'LISI_CLAS' => $requestData['CLASIFICACION'],
+                    'LISI_CAUS' => $requestData['CAUSA'],
+                    'LISI_SOLU' => $requestData['SOLUCION'],
+                    'LISI_DESC' => $requestData['DESCRIPCION'],
+                    'LISI_LIVA' => $requestData['LIMITE_VALOR'],
+                    'LISI_IDME' => $requestData['ID_MEDIDA'],
+                    'LISI_USMO' => $user,
+                    'LISI_FEMO' => $currentDate,
+                    'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_UPD002: Ocurrió un error en el registro de la lista de síntoma en la base de datos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        if ( !$validateUpdate ) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_UPD003: Ocurrió un error en la modificación de la lista de síntoma en la base de datos.", 
+                [], 
+                500
+            );
+        }
+
+        foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
+            try {
+                $validateExists = DB::table('S002V01TLSEQ')
+                    ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
+                    ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                    ->where('LSEQ_COEQ', '=', $equipment)
+                    ->exists();
+            } catch (\Throwable $th) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_UPD004: Ocurrió un error al consultar el equipamiento.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+    
+            if ( $validateExists ) {
+                try {
+                    $validate = DB::table('S002V01TLSEQ')
+                        ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
+                        ->where('LSEQ_COEQ', '=', $equipment)
+                        ->update([
+                            'LSEQ_ESTA' => 'Activo',
+                            'LSEQ_USMO' => $user,
+                            'LSEQ_FEMO' => $currentDate,
+                            'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                        ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD005: Ocurrió un error al modificar el formulario en la lista de falla el equipamiento $equipment.", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+            } else {
+                try {
+                    $validate = DB::table('S002V01TLSEQ')->insert([
+                        'LSEQ_NULI' => $requestData['NUMERO_LINEA'],
+                        'LSEQ_IDSI' => $requestData['ID_SINTOMA'],
+                        'LSEQ_COEQ' => $equipment,
+                        'LSEQ_USRE' => $user,
+                        'LSEQ_FERE' => $currentDate,
+                        'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                    ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD006: Ocurrió un error al registrar el formulario en la lista de falla el equipamiento $equipment.", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+            }
+            if ( !$validate ) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_UPD007: No se pudo modificar el equipamiento $equipment en la lista de fallas.", 
+                    [], 
+                    500
+                );
+            }
+        }
+
+        try {
+            $getListEquipment = DB::table('S002V01TLSEQ')
+                ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->get([
+                    'LSEQ_IDLS',
+                    'LSEQ_IDSI',
+                    'LSEQ_COEQ',
+                    'LSEQ_ESTA',
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_UPD008: Ocurrió un error al consultar la lista de equipamientos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrListEquipment = json_decode( json_encode($getListEquipment), true );
+        
+        foreach ($arrListEquipment as $keyListEquipment => $listEquipment) {
+            if( !in_array($listEquipment['LSEQ_COEQ'], $requestData['EQUIPAMIENTOS']) ) {
+                try {
+                    $validateDelete = DB::table('S002V01TLSEQ')
+                        ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
+                        ->where('LSEQ_COEQ', '=', $listEquipment['LSEQ_COEQ'])
+                        ->update([
+                            'LSEQ_ESTA' => 'Eliminado',
+                            'LSEQ_USMO' => $user,
+                            'LSEQ_FEMO' => $currentDate,
+                            'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                        ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD009: Ocurrió un error al eliminar de la lista de falla el equipamiento ". $listEquipment['LSEQ_COEQ'].".", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+
+                if ( !$validateDelete ) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD010: No se pudo eliminar de la lista de falla el equipamiento ". $listEquipment['LFEQ_COEQ'].".", 
+                        [], 
+                        500
+                    );
+                }
+            }
+        }
+
+        foreach ($requestData['FALLAS'] as $keyFailure => $failure) {
+            try {
+                $validateExists = DB::table('S002V01TLFLS')
+                    ->where('LFLS_IDFA', '=', $failure)
+                    ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
+                    ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
+                    ->exists();
+            } catch (\Throwable $th) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_UPD011: Ocurrió un error al consultar la falla.", 
+                    $th->getMessage(), 
+                    500
+                );
+            }
+
+            if ( $validateExists ) {
+                try {
+                    $validate = DB::table('S002V01TLFLS')
+                        ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->where('LFLS_IDFA', '=', $failure)
+                        ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
+                        ->update([
+                            'LFLS_ESTA' => 'Activo',
+                            'LFLS_USMO' => $user,
+                            'LFLS_FEMO' => $currentDate,
+                            'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                        ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD012: Ocurrió un error al modificar el formulario en la lista de falla del síntoma.", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+            } else {
+                try {
+                    $validate = DB::table('S002V01TLFLS')->insert([
+                        'LFLS_NULI' => $requestData['NUMERO_LINEA'],
+                        'LFLS_IDSI' => $requestData['ID_SINTOMA'],
+                        'LFLS_IDFA' => $failure,
+                        'LFLS_USRE' => $user,
+                        'LFLS_FERE' => $currentDate,
+                        'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                    ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD013: Ocurrió un error al registrar el formulario en la lista de falla del síntoma.", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+            }
+            if ( !$validate ) {
+                DB::rollBack();
+                return $this->responseController->makeResponse(
+                    true, 
+                    "ERR_SYMPTOM_UPD014: No se pudo modificar la lista de fallas.", 
+                    [], 
+                    500
+                );
+            }
+        }
+
+        try {
+            $arrListFaliure = DB::table('S002V01TLFLS')
+                ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->get([
+                    'LFLS_IDFA',
+                    'LFLS_IDSI',
+                    'LFLS_ESTA',
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_UPD015: Ocurrió un error al consultar la lista de fallas del síntoma.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+
+        $arrListFaliure = json_decode( json_encode($arrListFaliure), true );
+        
+        foreach ($arrListFaliure as $keyListFaliure => $listFaliure) {
+            if( !in_array($listFaliure['LFLS_IDFA'], $requestData['FALLAS']) ) {
+                try {
+                    $validateDelete = DB::table('S002V01TLFLS')
+                        ->where('LFLS_IDFA', '=', $listFaliure['LFLS_IDFA'])
+                        ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
+                        ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
+                        ->update([
+                            'LFLS_ESTA' => 'Eliminado',
+                            'LFLS_USMO' => $user,
+                            'LFLS_FEMO' => $currentDate,
+                            'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                        ]);
+                } catch (\Throwable $th) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD016: Ocurrió un error al eliminar las falla ".$listFaliure['LFLS_IDFA']." del síntoma.", 
+                        $th->getMessage(), 
+                        500
+                    );
+                }
+
+                if ( !$validateDelete ) {
+                    DB::rollBack();
+                    return $this->responseController->makeResponse( 
+                        true, 
+                        "ERR_SYMPTOM_UPD017: No se pudo eliminar la falla ".$listFaliure['LFLS_IDFA']." del síntoma.", 
+                        [], 
+                        500
+                    );
+                }
+            }
+        }
+
+        DB::commit();
+        return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
+    }
+
+    public function deleteSymptom(Request $request) {
+        $validator = Validator::make($request->all(), [
+            'ID_SINTOMA' => 'required|string',
+            'NUMERO_LINEA' => 'required|string',
+            'USUARIO' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return $this->responseController->makeResponse(
+                true,
+                "ERR_SYMPTOM_DEL000: Se encontraron uno o más errores.",
+                $this->responseController->makeErrors($validator->errors()->messages()),
+                401
+            );
+        }
+
+        DB::beginTransaction();
+        $requestData = $request->all();
+
+        try {
+            $user = $this->encController->decrypt($requestData['USUARIO']);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL001: No se pudo obtener el usuario.", $th->getMessage(), 500);
+        }
+
+        $now = $this->functionsController->now();
+        $currentDate = $now->toDateTimeString();
+
+        try {
+            $exist = DB::table('S002V01TLISI')
+                ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->exists();
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
+        }
+        
+        if (!$exist) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL003: El archivo no existe.", [], 500);
+        }
+
+        try {
+            $validateDelete = DB::table('S002V01TLISI')
+                ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LIFA_ESTA' => 'Eliminado',
+                    'LIFA_USMO' => $user,
+                    'LIFA_FEMO' => $currentDate,
+                    'LIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL004: Ocurrió un error al eliminar el síntoma de la base de datos.", $th->getMessage(), 500);
+        }
+        if ( !$validateDelete ) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL005: No se pudo eliminar el síntoma de la base de datos.", [], 500);
+        }
+
+
+        try {
+            $validateDelete = DB::table('S002V01TLISI')
+                ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LISI_ESTA' => 'Eliminado',
+                    'LISI_USMO' => $user,
+                    'LISI_FEMO' => $currentDate,
+                    'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_DEL006: Ocurrió un error al eliminar la lista de equipamientos.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+        if ( !$validateDelete ) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL007: No se pudo eliminar la lista de equipamientos.", [], 500);
+        }
+
+        try {
+            $validateDelete = DB::table('S002V01TLFLS')
+                ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
+                ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
+                ->update([
+                    'LFLS_ESTA' => 'Eliminado',
+                    'LFLS_USMO' => $user,
+                    'LFLS_FEMO' => $currentDate,
+                    'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
+                ]);
+        } catch (\Throwable $th) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(
+                true, 
+                "ERR_SYMPTOM_DEL008: Ocurrió un error al eliminar la lista de fallas.", 
+                $th->getMessage(), 
+                500
+            );
+        }
+        if ( !$validateDelete ) {
+            DB::rollBack();
+            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL009: No se pudo eliminar la lista de fallas.", [], 500);
+        }
+        
+        DB::commit();
+        return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
+    }
+
+}

+ 0 - 335
sistema-mantenimiento-back/app/Http/Controllers/SymptomController.php

@@ -1,335 +0,0 @@
-<?php
-/*
-    Desarrollador: Ing. Jean Jairo Benitez Meza
-    Ultima Modificación: 11/04/2023
-    Módulo: Analisis de Fallas
-*/
-namespace App\Http\Controllers;
-
-use App\Http\Controllers\Controller;
-use App\Http\Controllers\ResponseController;
-use App\Http\Controllers\EncryptionController;
-use Illuminate\Http\Request;
-use Illuminate\Support\Carbon;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Validator;
-use App\Http\Controllers\FunctionsController;
-
-class SymptomController extends Controller
-{
-    private $responseController;
-    private $encController;
-    private $functionsController;
-
-    public function __construct( ) {
-        $this->responseController = new ResponseController();
-        $this->encController = new EncryptionController();
-        $this->functionsController = new FunctionsController();
-    }
-
-    public function getSymptom($line) {
-        try {
-            $getSymptom = DB::table('S002V01TSINT')
-                ->join('S002V01TLIFA', 'SINT_IDFA', '=', 'LIFA_IDFA')
-                ->join('S002V01TLIME', 'SINT_IDME', '=', 'LIME_IDME')
-                ->where('SINT_NULI', '=', $line)
-                ->get([
-                    'SINT_NUSI', // NUMERO_SINTOMA
-                    'SINT_COEQ', // CODIGO_EQUIPAMIENTO
-                    'SINT_IDFA', // ID_FALLA
-                    'LIFA_NOFA', // NOMBRE_FALLA
-                    'SINT_CAUS', // CAUSA
-                    'SINT_CLAS', // CLASIFICACION
-                    'SINT_COME', // COMENTARIOS
-                    'SINT_LIVA', // LIMITE_VALOR
-                    'SINT_IDME', // ID_MEDIDA
-                    'LIME_MEDI', // NOMBRE_MEDIDA
-                    'LIME_ACRO', // ACRONIMO_MEDIDA
-                    'SINT_ESTA', // ESTADO
-                    'SINT_USRE', // USUARIO_REGISTRA
-                    'SINT_FERE', // FECHA_REGISTRA
-                    'SINT_USMO', // USUARIO_MODIFICA
-                    'SINT_FEMO', // FECHA_MODIFICA
-                ]);
-        } catch (\Throwable $th) {
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GET000: No se pudo realizar la consulta a la base.", [], 500);
-        }
-        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getSymptom);
-    }
-
-    public function registerSymptom(Request $request) {
-        $validator = Validator::make($request->all(), [
-            'CODIGO_EQUIPAMIENTO' => 'required|string',
-            'ID_FALLA' => 'required|string',
-            'CAUSA' => 'required|string',
-            'CLASIFICACION' => 'required|string',
-            'COMENTARIOS' => 'required|string',
-            'LIMITE_VALOR' => 'required|string',
-            'ID_MEDIDA' => 'required|string',
-            'NUMERO_LINEA' => 'required|string',
-            'USUARIO' => 'required|string',
-        ]);
-        if ($validator->fails()) {
-            return $this->responseController->makeResponse(
-                true,
-                "ERR_SYMPTOM_REG000: Se encontraron uno o más errores.",
-                $this->responseController->makeErrors($validator->errors()->messages()),
-                401
-            );
-        }
-
-        DB::beginTransaction();
-        $request = $request->all();
-
-        try {
-            $user = $this->encController->decrypt($request['USUARIO']);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG001: No se pudo obtener el usuario.", [], 500);
-        }
-        $line = $request['NUMERO_LINEA'];
-        
-        $now = $this->functionsController->now();
-        $currentDate = $now->toDateTimeString();
-
-        // Se valida que exista el ID de la lista de medidas
-        try {
-            $existMeasure = DB::table('S002V01TLIME')
-                ->where('LIME_IDME', '=', $request['ID_MEDIDA'])
-                ->where('LIME_NULI', '=', $line)
-                ->where('LIME_ESTA', '=', 'Activo')
-                ->exists();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG002: Ocurrió al consultar la lista de medidas.", [], 500);
-        }
-        if ( !$existMeasure ) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG003: No existe la medida seleccionada.", [], 500);
-        }
-
-        // Se valida que exista el ID de la lista de fallas
-        try {
-            $existFailure = DB::table('S002V01TLIFA')
-                ->where('LIFA_IDFA', '=', $request['ID_FALLA'])
-                ->where('LIFA_NULI', '=', $line)
-                ->where('LIFA_ESTA', '=', 'Activo')
-                ->get();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG004: Ocurrió un error al consultar en la base de datos.", [], 500);
-        }
-        if (!$existFailure) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG005: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
-        }
-
-        $arrInsert = [
-            'SINT_COEQ' => trim($request['CODIGO_EQUIPAMIENTO']),
-            'SINT_IDFA' => trim($request['ID_FALLA']),
-            'SINT_CAUS' => trim($request['CAUSA']),
-            'SINT_CLAS' => trim($request['CLASIFICACION']),
-            'SINT_COME' => trim($request['COMENTARIOS']),
-            'SINT_LIVA' => trim($request['LIMITE_VALOR']),
-            'SINT_IDME' => trim($request['ID_MEDIDA']),
-            'SINT_NULI' => $line,
-            'SINT_USRE' => $user,
-            'SINT_FERE' => $currentDate,
-            'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP')
-        ];
-        try {
-            $response = DB::table('S002V01TSINT')->insert($arrInsert);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG006: Ocurrió un error al insertar el formulario en la base de datos.", [], 500);
-        }
-
-        if (!$response) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG007: No se pudo insertar el formulario en la base de datos.", [], 500);
-        }
-        DB::commit();
-        return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
-    }
-
-    public function updateSymptom(Request $request) {
-        $validator = Validator::make($request->all(), [
-            'NUMERO_SINTOMA' => 'required|string',
-            'CODIGO_EQUIPAMIENTO' => 'required|string',
-            'ID_FALLA' => 'required|string',
-            'CAUSA' => 'required|string',
-            'CLASIFICACION' => 'required|string',
-            'COMENTARIOS' => 'required|string',
-            'LIMITE_VALOR' => 'required|string',
-            'ID_MEDIDA' => 'required|string',
-            'NUMERO_LINEA' => 'required|string',
-            'USUARIO' => 'required|string',
-        ]);
-        if ($validator->fails()) {
-            return $this->responseController->makeResponse(
-                true,
-                "ERR_SYMPTOM_UPD000: Se encontraron uno o más errores.",
-                $this->responseController->makeErrors($validator->errors()->messages()),
-                401
-            );
-        }
-
-        DB::beginTransaction();
-        $request = $request->all();
-
-        try {
-            $user = $this->encController->decrypt($request['USUARIO']);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD001: No se pudo obtener el usuario.", [], 500);
-        }
-        $line = $request['NUMERO_LINEA'];
-
-        $now = $this->functionsController->now();
-        $currentDate = $now->toDateTimeString();
-
-        // Se valida que exista el ID del síntoma
-        try {
-            $exist = DB::table('S002V01TSINT')
-                ->where('SINT_NUSI', '=', $request['NUMERO_SINTOMA'])
-                ->where('SINT_NULI', '=', $line)
-                ->exists();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD002: Ocurrió un error al consultar en la base de datos.", [], 500);
-        }
-        if (!$exist) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD003: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
-        }
-
-
-        // Se valida que exista el ID de la lista de medidas
-        try {
-            $existMeasure = DB::table('S002V01TLIME')
-                ->where('LIME_IDME', '=', $request['ID_MEDIDA'])
-                ->where('LIME_NULI', '=', $line)
-                ->where('LIME_ESTA', '=', 'Activo')
-                ->exists();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD004: Ocurrió al consultar la lista de medidas.", [], 500);
-        }
-        if ( !$existMeasure ) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD005: No existe la medida seleccionada.", [], 500);
-        }
-
-
-        // Se valida que exista el ID de la lista de fallas
-        try {
-            $existFailure = DB::table('S002V01TLIFA')
-                ->where('LIFA_IDFA', '=', $request['ID_FALLA'])
-                ->where('LIFA_NULI', '=', $line)
-                ->where('LIFA_ESTA', '=', 'Activo')
-                ->exists();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD006: Ocurrió un error al consultar la lista de fallas.", [], 500);
-        }
-        if (!$existFailure) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD007: No existe la falla seleccionada.", [], 500);
-        }
-
-        $arrUpdate = [
-            'SINT_COEQ' => trim($request['CODIGO_EQUIPAMIENTO']),
-            'SINT_IDFA' => trim($request['ID_FALLA']),
-            'SINT_CAUS' => trim($request['CAUSA']),
-            'SINT_CLAS' => trim($request['CLASIFICACION']),
-            'SINT_COME' => trim($request['COMENTARIOS']),
-            'SINT_LIVA' => trim($request['LIMITE_VALOR']),
-            'SINT_IDME' => trim($request['ID_MEDIDA']),
-            'SINT_USMO' => $user,
-            'SINT_FEMO' => $currentDate,
-            'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP')
-        ];
-        try {
-            $response = DB::table('S002V01TSINT')->where('SINT_NUSI', '=', $request['NUMERO_SINTOMA'])->where('SINT_NULI', '=', $line)->update($arrUpdate);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD008: Ocurrió un error al modificar el formulario en la base de datos.", [], 500);
-        }
-
-        if (!$response) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD009: No se pudo modificar el formulario en la base de datos.", [], 500);
-        }
-
-        DB::commit();
-        return $this->responseController->makeResponse(true, "EXITO: Modificación Exitosa");
-    }
-
-    public function deleteSymptom(Request $request) {
-        $validator = Validator::make($request->all(), [
-            'NUMERO_SINTOMA' => 'required|string',
-            'NUMERO_LINEA' => 'required|string',
-            'USUARIO' => 'required|string',
-        ]);
-        if ($validator->fails()) {
-            return $this->responseController->makeResponse(
-                true,
-                "ERR_SYMPTOM_DEL000: Se encontraron uno o más errores.",
-                $this->responseController->makeErrors($validator->errors()->messages()),
-                401
-            );
-        }
-
-        DB::beginTransaction();
-        $request = $request->all();
-
-        $idSymptom = trim($request['NUMERO_SINTOMA']);
-        $line = $request['NUMERO_LINEA'];
-        
-        $now = $this->functionsController->now();
-        $currentDate = $now->toDateTimeString();
-        
-        try {
-            $user = $this->encController->decrypt($request['USUARIO']);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL001: No se pudo obtener el usuario.", [], 500);
-        }
-
-        try {
-            $exist = DB::table('S002V01TSINT')
-                ->where('SINT_NUSI', '=', $idSymptom)
-                ->where('SINT_NULI', '=', $line)
-                ->exists();
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL002: Ocurrió un error al consultar en la base de datos.", [], 500);
-        }
-        if (!$exist) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL003: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
-        }
-
-        $arrUpdate = [
-            'SINT_ESTA' => 'Eliminado',
-            'SINT_USMO' => $user,
-            'SINT_FEMO' => $currentDate,
-            'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
-        ];
-        try {
-            $response = DB::table('S002V01TSINT')->where('SINT_NUSI', '=', $idSymptom)->where('SINT_NULI', '=', $line)->update($arrUpdate);
-        } catch (\Throwable $th) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL004: Ocurrió un error al modificar el formulario en la base de datos.", [], 500);
-        }
-
-        if (!$response) {
-            DB::rollBack();
-            return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL005: No se pudo modificar el formulario en la base de datos.", [], 500);
-        }
-
-        DB::commit();
-        return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
-    }
-
-}

+ 27 - 24
sistema-mantenimiento-back/routes/api.php

@@ -18,7 +18,7 @@ use App\Http\Controllers\DispatchController;
 use App\Http\Controllers\CatalogFailureController;
 use App\Http\Controllers\FailureController;
 use App\Http\Controllers\CatalogMeasuresController;
-use App\Http\Controllers\SymptomController;
+use App\Http\Controllers\CatalogSymptomController;
 use App\Http\Controllers\StockController;
 use App\Http\Controllers\LocateController;
 use App\Http\Controllers\DocumentManagementController;
@@ -374,30 +374,33 @@ Route::middleware(['jwt.auth'])->group(function(){
     Route::post('acquisition-management/invoice/compare-invoice',                             [InvoiceControlController::class, 'compareInvoice']);
 
     // Module: ANFA
-    Route::get ('failure-analysis/get-catalog-failure/{user}/{line}',                       [CatalogFailureController::class,  'getFailures']);
-    Route::get ('failure-analysis/get-catalog-failure-by-id/{idFailure}/{user}/{line}',     [CatalogFailureController::class,  'getFailureById']);
-    Route::post('failure-analysis/register-catalog-failure',                                [CatalogFailureController::class,  'registerFailures']);
-    Route::post('failure-analysis/update-catalog-failure',                                  [CatalogFailureController::class,  'updateFailures']);
-    Route::post('failure-analysis/delete-catalog-failure',                                  [CatalogFailureController::class,  'deleteFailures']);
-    Route::get ('failure-analysis/get-failure/{user}/{line}',                               [FailureController::class,         'getFault']);
-    Route::post('failure-analysis/get-failure-by-equipment',                                [FailureController::class,         'getFaultByEquipment']);
-    Route::post('failure-analysis/register-failure',                                        [FailureController::class,         'registerFault']);
-    Route::post('failure-analysis/update-failure',                                          [FailureController::class,         'updateFault']);
-    Route::post('failure-analysis/delete-failure',                                          [FailureController::class,         'deleteFault']);
-    Route::get ('failure-analysis/get-catalog-measures/{user}/{line}',                      [CatalogMeasuresController::class, 'getMeasures']);
-    Route::post('failure-analysis/register-catalog-measures',                               [CatalogMeasuresController::class, 'registerMeasures']);
-    Route::post('failure-analysis/update-catalog-measures',                                 [CatalogMeasuresController::class, 'updateMeasures']);
-    Route::post('failure-analysis/delete-catalog-measures',                                 [CatalogMeasuresController::class, 'deleteMeasures']);
-    Route::get ('failure-analysis/get-symptom/{user}/{line}',                               [SymptomController::class,         'getSymptom']);
-    Route::post('failure-analysis/register-symptom',                                        [SymptomController::class,         'registerSymptom']);
-    Route::post('failure-analysis/update-symptom',                                          [SymptomController::class,         'updateSymptom']);
-    Route::post('failure-analysis/delete-symptom',                                          [SymptomController::class,         'deleteSymptom']);
-    
-    Route::get ('locate/postal-code-data/{postal_code}/{line_number}',                                              [LocateController::class,        'getDataByPostalCode']);
-    Route::get ('locate/countries/{line_number}',                                                                   [LocateController::class,        'getCountries']);
-    Route::get ('locate/suburb-by-postal-code/{postal_code}/{line_number}',                                         [LocateController::class,        'getSuburbByPostalCode']);
-    Route::get ('locate/get-locate-by-cp/{cp}',                                                                     [LocateController::class, 'getLocateByCP']);
+    Route::get ('failure-analysis/get-list-failure/{user}/{line}',                       [CatalogFailureController::class,  'getFailures']);
+    Route::get ('failure-analysis/get-list-failure-actives/{user}/{line}',               [CatalogFailureController::class,  'getFailuresActives']);
+    Route::get ('failure-analysis/get-list-failure-by-id/{idFailure}/{user}/{line}',     [CatalogFailureController::class,  'getFailureById']);
+    Route::post('failure-analysis/register-list-failure',                                [CatalogFailureController::class,  'registerFailures']);
+    Route::post('failure-analysis/update-list-failure',                                  [CatalogFailureController::class,  'updateFailures']);
+    Route::post('failure-analysis/delete-list-failure',                                  [CatalogFailureController::class,  'deleteFailures']);
+
+    // Route::get ('failure-analysis/get-failure/{user}/{line}',                               [FailureController::class,         'getFault']);
+    // Route::post('failure-analysis/get-failure-by-equipment',                                [FailureController::class,         'getFaultByEquipment']);
+    // Route::post('failure-analysis/register-failure',                                        [FailureController::class,         'registerFault']);
+    // Route::post('failure-analysis/update-failure',                                          [FailureController::class,         'updateFault']);
+    // Route::post('failure-analysis/delete-failure',                                          [FailureController::class,         'deleteFault']);
+
+    Route::get ('failure-analysis/get-symptoms/{user}/{line}',                              [CatalogSymptomController::class,  'getSymptoms']);
+    Route::get ('failure-analysis/get-symptoms-actives/{user}/{line}',                      [CatalogSymptomController::class,  'getSymptomsActives']);
+    Route::get ('failure-analysis/get-symptoms-by-equipment/{equipment}/{user}/{line}',     [CatalogSymptomController::class,  'getSymptomsByEquipment']);
+    Route::get ('failure-analysis/get-symptom-by-id/{idSymptom}/{user}/{line}',             [CatalogSymptomController::class,  'getSymptomById']);
+    Route::post('failure-analysis/register-symptom',                                        [CatalogSymptomController::class,  'registerSymptom']);
+    Route::post('failure-analysis/update-symptom',                                          [CatalogSymptomController::class,  'updateSymptom']);
+    Route::post('failure-analysis/delete-symptom',                                          [CatalogSymptomController::class,  'deleteSymptom']);
 
+    // Module: COAC
+    Route::get ('counters-and-triggers/get-catalog-measures/{user}/{line}',                      [CatalogMeasuresController::class, 'getMeasures']);
+    Route::get ('counters-and-triggers/get-catalog-measures-actives/{user}/{line}',              [CatalogMeasuresController::class, 'getMeasuresActives']);
+    Route::post('counters-and-triggers/register-catalog-measures',                               [CatalogMeasuresController::class, 'registerMeasures']);
+    Route::post('counters-and-triggers/update-catalog-measures',                                 [CatalogMeasuresController::class, 'updateMeasures']);
+    Route::post('counters-and-triggers/delete-catalog-measures',                                 [CatalogMeasuresController::class, 'deleteMeasures']);
 
     
     // Module: GEIN