| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?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 CatalogMeasuresController 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 getMeasures($user, $line) {
- try {
- $getMeasures = DB::table('S002V01TLIME')
- ->where('LIME_NULI', '=', $line)
- ->get([
- '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);
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getMeasures);
- }
- public function getMeasuresActives($user, $line) {
- try {
- $getMeasures = DB::table('S002V01TLIME')
- ->where('LIME_ESTA', '=', 'Activo')
- ->where('LIME_NULI', '=', $line)
- ->get([
- 'LIME_IDME AS ID_MEDIDA',
- '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',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_GET000: No se pudo realizar la consulta a la base.", [], 500);
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getMeasures);
- }
- public function registerMeasures(Request $request) {
- $validator = Validator::make($request->all(), [
- 'NOMBRE_MEDIDA' => 'required|string',
- 'ACRONIMO_MEDIDA' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- 'USUARIO' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_MEASUREMENT_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_FAILURES_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $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->getMessage(), 500);
- }
- 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',
- 'NOMBRE_MEDIDA' => 'required|string',
- 'ACRONIMO_MEDIDA' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- 'USUARIO' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_MEASUREMENT_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($request['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD003: No se pudo encontrar el registro dentro de la base de datos.", [], 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $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_UPD004: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500);
- }
- if ( !$validateUpdate ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD005: No se pudo modificar el formulario en la base de datos.", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- public function deleteMeasures(Request $request) {
- $validator = Validator::make($request->all(), [
- 'ID_MEDIDA' => 'required|integer',
- 'NUMERO_LINEA' => 'required|integer',
- 'USUARIO' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_MEASUREMENT_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($request['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL001: No se pudo obtener el usuario.", [], 500);
- }
- try {
- $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL003: La medida no existe.", [], 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $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_DEL004: Ocurrió un error al eliminar la medida base de datos.", $th, 500);
- }
- if (!$validateDelete) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL005: No se pudo eliminar la medida en la base de datos..", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
- }
- }
|