| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- <?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 App\Http\Controllers\ResourcesController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use App\Http\Controllers\FunctionsController;
- class SymptomListController extends Controller
- {
- private $responseController;
- private $encController;
- private $functionsController;
- private $resourcesController;
- public function __construct( ) {
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->resourcesController = new ResourcesController();
- }
- public function getSymptoms($user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- 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',
- ]);
- $arrSymtoms = json_decode( json_encode($getSymptom), true );
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_SYMPTOM_GET000: No se pudo realizar la consulta a la base.",
- $th->getMessage(),
- 500
- );
- }
- $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrSymtoms, $line);
- if ($responseCheckLatestUpdate['error']) {
- return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
- }
- $arrSymtoms = $responseCheckLatestUpdate['response'];
- 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|integer',
- ]);
- 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|integer',
- ]);
- 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|integer',
- '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([
- '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_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('S002V01TLSEQ')
- ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
- ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
- ->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_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");
- }
- }
|