Quellcode durchsuchen

Arreglo en consulta

MathewCordourier vor 2 Jahren
Ursprung
Commit
847b89318a
1 geänderte Dateien mit 99 neuen und 99 gelöschten Zeilen
  1. 99 99
      sistema-mantenimiento-back/app/Http/Controllers/EmployeeController.php

+ 99 - 99
sistema-mantenimiento-back/app/Http/Controllers/EmployeeController.php

@@ -399,105 +399,105 @@ class EmployeeController extends Controller
         }
     }
 
-    // Metodo para la activación logica de un empleado
-    public function updateToActiveStatus(Request $request, $id_employee)
-    {
-        try {
-            $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
-            $validator = Validator::make($request->all(), [
-                "SAVED_BY_USER" => ['required', 'digits:10']
-            ]);
-
-            if ($validator->fails()) {
-                return $this->response_controller->makeResponse(
-                    TRUE,
-                    'ERR_PERSONAL_REG001: Uno o más errores encontrados',
-                    $this->response_controller->makeErrors($validator->errors()->messages()),
-                    400
-                );
-            }
-
-            // Busca si el empleado existe
-            $search_employee = DB::table("S002V01TPERS")
-                ->select("PERS_IDPE")
-                ->where("PERS_IDPE", "=", $id_employee)
-                ->where('PERS_NULI', '=', $request->LINE_NUMBER)
-                ->first();
-
-            // Verifica si el objeto esta vacio
-            if (!isset($search_employee) && empty($search_employee)) {
-                return $this->response_controller
-                    ->makeResponse(TRUE, "ERR_PERSONAL_REG002: No se encontró al empleado", $search_employee, 500);
-            }
-
-            $user_register = DB::table('S002V01TUSUA')
-                ->select('USUA_IDUS as ID_USER')
-                ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
-                ->where('USUA_NULI', '=', $request->LINE_NUMBER)
-                ->first();
-
-            // Verifica si el objeto esta vacio
-            if (!isset($user_register) && empty($user_register)) {
-                return $this->response_controller
-                    ->makeResponse(TRUE, "ERR_USUARIO_REG003: Tu usuario no es válido para activar empleados", [], 500);
-            }
-
-            $check_workteam = DB::table("S002V01TEQMA")
-            ->select("S002V01TEQMA.ESTA as STATUS")
-            ->where("S002V01TPEEM.IDPE", '=', $id_employee)
-            ->join('S002V01TPEEM', 'S002V01TEQMA.EQMA_IDEQ', '=', 'S002V01TPEEM.PEEM_IDEM')
-            ->first();
-            
-            if($check_workteam->STATUS == "Eliminado"){
-                return $this->response_controller
-                ->makeResponse(TRUE, "ERR_EQUIPO_TRABAJO_REG004: El equipo de trabajo no esta activo", [], 500);
-            }
-
-            DB::beginTransaction(); # Para impedir que las actualizaciones queden incompletas
-
-            $UPDATE_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
-
-            $activate_employee = DB::table('S002V01TPERS')
-                ->where('PERS_IDPE', $id_employee)
-                ->where('PERS_NULI', '=', $request->LINE_NUMBER)
-                ->update([
-                    "PERS_ESTA" => "Activo",
-                    "PERS_USMO" => trim($request->SAVED_BY_USER),
-                    "PERS_FEMO" => $UPDATE_DATE,
-                    "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
-                ]);
-
-            // Verifica que la actualización fuera exitosa
-            if ($activate_employee < 1) {
-                return $this->response_controller
-                    ->makeResponse(TRUE, 'ERR_PERSONAL_REG005: Algo salió mal, error activando al empleado', [], 500);
-            }
-
-            $activate_employee = DB::table('S002V01TPEEM')
-                ->where('PEEM_IDPE', $id_employee)
-                ->where('PEEM_NULI', '=', $request->LINE_NUMBER)
-                ->update([
-                    "PEEM_ESTA" => "Activo",
-                    "PEEM_USMO" => trim($request->SAVED_BY_USER),
-                    "PEEM_FEMO" => $UPDATE_DATE,
-                    "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP')
-                ]);
-
-            // Verifica que la actualización fuera exitosa
-            if ($activate_employee < 1) {
-                DB::rollBack(); # Si no se logra eliminar al empleado en el equipo, se revierten los cambios previos
-                return $this->response_controller
-                    ->makeResponse(TRUE, 'ERR_PERSONAL_REG006: Algo salió mal, error activando al empleado del equipo', [], 500);
-            }
-
-            DB::commit(); # Para guardar los cambios en la base de datos
-            return $this->response_controller->makeResponse(FALSE, "Activación exitosa");
-
-        } catch (Throwable $th) {
-            return $this->response_controller->
-                makeResponse(TRUE, 'ERR_PERSONAL_REG007: Error inesperado', strtoupper($th->getMessage()), 500);
-        }
-    }
+     // Metodo para la activación logica de un empleado
+     public function updateToActiveStatus(Request $request, $id_employee)
+     {
+         try {
+             $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
+             $validator = Validator::make($request->all(), [
+                 "SAVED_BY_USER" => ['required', 'digits:10']
+             ]);
+ 
+             if ($validator->fails()) {
+                 return $this->response_controller->makeResponse(
+                     TRUE,
+                     'ERR_PERSONAL_REG001: Uno o más errores encontrados',
+                     $this->response_controller->makeErrors($validator->errors()->messages()),
+                     400
+                 );
+             }
+ 
+             // Busca si el empleado existe
+             $search_employee = DB::table("S002V01TPERS")
+                 ->select("PERS_IDPE")
+                 ->where("PERS_IDPE", "=", $id_employee)
+                 ->where('PERS_NULI', '=', $request->LINE_NUMBER)
+                 ->first();
+ 
+             // Verifica si el objeto esta vacio
+             if (!isset($search_employee) && empty($search_employee)) {
+                 return $this->response_controller
+                     ->makeResponse(TRUE, "ERR_PERSONAL_REG002: No se encontró al empleado", $search_employee, 500);
+             }
+ 
+             $user_register = DB::table('S002V01TUSUA')
+                 ->select('USUA_IDUS as ID_USER')
+                 ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
+                 ->where('USUA_NULI', '=', $request->LINE_NUMBER)
+                 ->first();
+ 
+             // Verifica si el objeto esta vacio
+             if (!isset($user_register) && empty($user_register)) {
+                 return $this->response_controller
+                     ->makeResponse(TRUE, "ERR_USUARIO_REG003: Tu usuario no es válido para activar empleados", [], 500);
+             }
+ 
+             $check_workteam = DB::table("S002V01TEQMA")
+             ->select("S002V01TEQMA.EQMA_ESTA as STATUS")
+             ->where("S002V01TPEEM.PEEM_IDPE", '=', $id_employee)
+             ->join('S002V01TPEEM', 'S002V01TEQMA.EQMA_IDEQ', '=', 'S002V01TPEEM.PEEM_IDEM')
+             ->first();
+             
+             if($check_workteam->STATUS == "Eliminado"){
+                 return $this->response_controller
+                 ->makeResponse(TRUE, "ERR_EQUIPO_TRABAJO_REG004: El equipo de trabajo no esta activo", [], 500);
+             }
+ 
+             DB::beginTransaction(); # Para impedir que las actualizaciones queden incompletas
+ 
+             $UPDATE_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
+ 
+             $activate_employee = DB::table('S002V01TPERS')
+                 ->where('PERS_IDPE', $id_employee)
+                 ->where('PERS_NULI', '=', $request->LINE_NUMBER)
+                 ->update([
+                     "PERS_ESTA" => "Activo",
+                     "PERS_USMO" => trim($request->SAVED_BY_USER),
+                     "PERS_FEMO" => $UPDATE_DATE,
+                     "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
+                 ]);
+ 
+             // Verifica que la actualización fuera exitosa
+             if ($activate_employee < 1) {
+                 return $this->response_controller
+                     ->makeResponse(TRUE, 'ERR_PERSONAL_REG005: Algo salió mal, error activando al empleado', [], 500);
+             }
+ 
+             $activate_employee = DB::table('S002V01TPEEM')
+                 ->where('PEEM_IDPE', $id_employee)
+                 ->where('PEEM_NULI', '=', $request->LINE_NUMBER)
+                 ->update([
+                     "PEEM_ESTA" => "Activo",
+                     "PEEM_USMO" => trim($request->SAVED_BY_USER),
+                     "PEEM_FEMO" => $UPDATE_DATE,
+                     "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP')
+                 ]);
+ 
+             // Verifica que la actualización fuera exitosa
+             if ($activate_employee < 1) {
+                 DB::rollBack(); # Si no se logra eliminar al empleado en el equipo, se revierten los cambios previos
+                 return $this->response_controller
+                     ->makeResponse(TRUE, 'ERR_PERSONAL_REG006: Algo salió mal, error activando al empleado del equipo', [], 500);
+             }
+ 
+             DB::commit(); # Para guardar los cambios en la base de datos
+             return $this->response_controller->makeResponse(FALSE, "Activación exitosa");
+ 
+         } catch (Throwable $th) {
+             return $this->response_controller->
+                 makeResponse(TRUE, 'ERR_PERSONAL_REG007: Error inesperado', strtoupper($th->getMessage()), 500);
+         }
+     }
 
     // Metodo para obtener a los usuarios que no son empleados y el enviado por path
     public function getAvaibleUsers($id_employee, $line_number)