| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?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;
- class SymptomController extends Controller
- {
- private $responseController;
- private $encController;
- public function __construct( ) {
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- }
- 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'];
- $currentDate = Carbon::now()->timezone('America/Mazatlan')->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'];
- $currentDate = Carbon::now()->timezone('America/Mazatlan')->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'];
- $currentDate = Carbon::now()->timezone('America/Mazatlan')->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");
- }
- }
|