| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- class ProcessManagementController extends Controller
- {
- private $responseController;
- private $encController;
- private $resourcesController;
- private $documentManagementController;
- private $functionsController;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->resourcesController = new ResourcesController();
- $this->documentManagementController = new DocumentManagementController();
- $this->functionsController = new FunctionsController();
- }
- public function getWorkflows($user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- try {
- $arrWorkflow = DB::table('S002V01TFLTR')
- ->where('FLTR_NULI', '=', $line)
- ->join('S002V01TMODU', 'MODU_IDMO', '=', 'FLTR_IDMO')
- ->get([
- 'FLTR_IDFT AS ID_FLUJO',
- 'FLTR_NOFT AS NOMBRE_FLUJO',
- 'FLTR_DEFT AS DESCRIPCION_FLUJO',
- 'FLTR_ESAU AS AUTOMATICO',
- 'FLTR_TIFT AS TIPO_FLUJO',
- 'MODU_IDMO AS ID_MODULO',
- 'MODU_NOMO AS NOMBRE_MODULO',
- 'FLTR_ESPR AS PREDEFINIDO',
- 'FLTR_ESTA AS ESTADO',
- 'FLTR_USRE AS USUARIO_REGISTRA',
- 'FLTR_FERE AS FECHA_REGISTRA',
- 'FLTR_USMO AS USUARIO_MODIFICA',
- 'FLTR_FEMO AS FECHA_MODIFICA',
- ]);
- $arrWorkflow = json_decode(json_encode($arrWorkflow), true);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los flujos de trabajo.', $th->getMessage(), 500);
- }
- $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrWorkflow, $line);
- if ($responseCheckLatestUpdate['error']) {
- return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
- }
- $arrWorkflow = $responseCheckLatestUpdate['response'];
- foreach ($arrWorkflow as $key => $workflow) {
- $workflow['ID_FLUJO'] = '#'.$workflow['ID_FLUJO'];
- if ($workflow['TIPO_FLUJO'] === 'S') {
- $workflow['TIPO_FLUJO'] = 'Solicitud';
- } else if ($workflow['TIPO_FLUJO'] === 'F') {
- $workflow['TIPO_FLUJO'] = 'Formulario';
- }
- $arrWorkflow[$key] = $workflow;
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWorkflow);
- }
- public function getWorkflow($idWorkflow, $user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $idWorkflow = $this->encController->decrypt($idWorkflow);
- if (is_null($idWorkflow)) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el ID del workflow.', [], 401);
- }
- try {
- $validateExists = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $line)
- ->where('FLTR_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al verificar el workflow.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- return $this->responseController->makeResponse(true, "El workflow no existe.", [], 500);
- }
- try {
- $arrWorkflow = (array) DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $line)
- ->where('FLTR_ESTA', '=', 'Activo')
- ->first([
- 'FLTR_NOFT AS NOMBRE_FLUJO',
- 'FLTR_DEFT AS DESCRIPCION_FLUJO',
- 'FLTR_ESAU AS AUTOMATICO',
- 'FLTR_TIFT AS TIPO_FLUJO',
- 'FLTR_IDMO AS MODULO',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los flujos de trabajo.', $th->getMessage(), 500);
- }
- $arrWorkflow['AUTOMATICO'] = $arrWorkflow['AUTOMATICO'] === 'Si' ? true : false;
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWorkflow);
- }
- public function registerWorkflow(Request $request) {
- $validator = Validator::make($request->all(), [
- 'NOMBRE_FLUJO' => 'required|string',
- 'DESCRIPCION_FLUJO' => 'required|string',
- 'AUTOMATICO' => 'required|boolean',
- 'TIPO_FLUJO' => 'required|string|in:S,F',
- 'MODULO' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_REG001:'.$arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TFLTR')->insert([
- 'FLTR_NULI' => $requestData['NUMERO_LINEA'],
- 'FLTR_NOFT' => $requestData['NOMBRE_FLUJO'],
- 'FLTR_DEFT' => $requestData['DESCRIPCION_FLUJO'],
- 'FLTR_ESAU' => $requestData['AUTOMATICO'] ? 'Si' : 'No',
- 'FLTR_TIFT' => $requestData['TIPO_FLUJO'],
- 'FLTR_IDMO' => $requestData['MODULO'],
- 'FLTR_USRE' => $user,
- 'FLTR_FERE' => $currentDate,
- 'FLTR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'Ocurrió un error al insertar el flujo de trabajo.', $th->getMessage(), 500);
- }
- if (!$validateInsert) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'No se pudo insertar el flujo de trabajo.', [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
- }
- public function updateWorkflow(Request $request, $idWorkflow) {
- $validator = Validator::make($request->all(), [
- 'NOMBRE_FLUJO' => 'required|string',
- 'DESCRIPCION_FLUJO' => 'required|string',
- 'AUTOMATICO' => 'required|boolean',
- 'TIPO_FLUJO' => 'required|string|in:S,F',
- 'MODULO' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $idWorkflow = $this->encController->decrypt($idWorkflow);
- if (is_null($idWorkflow)) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el ID del workflow.', [], 401);
- }
- try {
- $lastWorkflow = (array) DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('FLTR_ESTA', '=', 'Activo')
- ->first();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al verificar el workflow.", $th->getMessage(), 500);
- }
- if (empty($lastWorkflow)) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "El workflow no existe.", [], 500);
- }
- $strLast = $lastWorkflow['FLTR_HICA'];
- $arrLast = array();
- if (is_null($strLast)) {
- unset($lastWorkflow['FLTR_HICA']);
- $arrLast[] = $lastWorkflow;
- } else {
- $arrLast = json_decode($strLast);
- unset($lastWorkflow['FLTR_HICA']);
- $arrLast[] = $lastWorkflow;
- }
- $last = json_encode($arrLast);
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateUpdate = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('FLTR_ESTA', '=', 'Activo')
- ->update([
- 'FLTR_NOFT' => $requestData['NOMBRE_FLUJO'],
- 'FLTR_DEFT' => $requestData['DESCRIPCION_FLUJO'],
- 'FLTR_ESAU' => $requestData['AUTOMATICO'] ? 'Si' : 'No',
- 'FLTR_TIFT' => $requestData['TIPO_FLUJO'],
- 'FLTR_IDMO' => $requestData['MODULO'],
- 'FLTR_HICA' => $last,
- 'FLTR_USMO' => $user,
- 'FLTR_FEMO' => $currentDate,
- 'FLTR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'Ocurrió un error al modificar el flujo de trabajo.', $th->getMessage(), 500);
- }
- if (!$validateUpdate) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'No se pudo modificar el flujo de trabajo.', [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- public function deleteWorkflow(Request $request, $idWorkflow) {
- $validator = Validator::make($request->all(), [
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $idWorkflow = $this->encController->decrypt($idWorkflow);
- if (is_null($idWorkflow)) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el ID del workflow.', [], 401);
- }
- try {
- $validateExists = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('FLTR_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al verificar el workflow.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "El workflow no existe.", [], 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateDelete = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('FLTR_ESTA', '=', 'Activo')
- ->update([
- 'FLTR_ESTA' => 'Eliminado',
- 'FLTR_USMO' => $user,
- 'FLTR_FEMO' => $currentDate,
- 'FLTR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'Ocurrió un error al eliminar el flujo de trabajo.', $th->getMessage(), 500);
- }
- if (!$validateDelete) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'No se pudo eliminar el flujo de trabajo.', [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
- }
- public function getHistoryWorkflow($idWorkflow, $user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $idWorkflow = $this->encController->decrypt($idWorkflow);
- if (is_null($idWorkflow)) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el ID del workflow.', [], 401);
- }
- try {
- $validateExists = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al verificar el workflow.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- return $this->responseController->makeResponse(true, "El workflow no existe.", [], 500);
- }
- try {
- $workflow = (array) DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $line)
- ->first([
- 'FLTR_HICA AS HISTORIAL',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los flujos de trabajo.', $th->getMessage(), 500);
- }
- if (empty($workflow)) {
- return $this->responseController->makeResponse(false, "No se encontró información en el historial.", [], 500);
- }
-
- if (is_null($workflow['HISTORIAL'])) {
- return $this->responseController->makeResponse(false, "No se encontró información en el historial.", [], 500);
- }
- $arrClaves = [
- 'FLTR_NOFT' => 'NOMBRE_FLUJO',
- 'FLTR_DEFT' => 'DESCRIPCION_FLUJO',
- 'FLTR_ESAU' => 'AUTOMATICO',
- 'FLTR_IDMO' => 'MODULO',
- 'FLTR_TIFT' => 'TIPO_FLUJO',
- 'FLTR_ESTA' => 'ESTADO',
- 'FLTR_ESPR' => 'PREDEFINIDO',
- 'FLTR_USRE' => 'USUARIO_REGISTRA',
- 'FLTR_FERE' => 'FECHA_REGISTRA',
- 'FLTR_USMO' => 'USUARIO_MODIFICA',
- 'FLTR_FEMO' => 'FECHA_MODIFICA',
- ];
- $arrHistory = array();
- $arrHistoryTemp = json_decode($workflow['HISTORIAL'], true);
- foreach ($arrHistoryTemp as $keyHistory => $historyTemp) {
- foreach ($historyTemp as $key => $value) {
- if (array_key_exists($key, $arrClaves)) {
- if ($key === 'FLTR_IDMO') {
- try {
- $module = (array) DB::table('S002V01TMODU')
- ->where('MODU_IDMO', '=', $value)
- ->where('MODU_NULI', '=', $line)
- ->first();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los módulos del flujo de trabajo.', $th->getMessage(), 500);
- }
- if (empty($module)) {
- return $this->responseController->makeResponse(false, "No se encontró información del módulo del flujo de trabajo.", [], 500);
- }
- $value = $module['MODU_NOMO'];
- }
- if ($key === 'FLTR_TIFT' && $value === 'S') {
- $value = 'Solicitud';
- }
- if ($key === 'FLTR_TIFT' && $value === 'F') {
- $value = 'Formulario';
- }
- $arrHistory[$keyHistory][$arrClaves[$key]] = $value;
- }
- }
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrHistory);
- }
- public function getProcessWorkflow($idWorkflow, $user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $idWorkflow = $this->encController->decrypt($idWorkflow);
- if (is_null($idWorkflow)) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el ID del workflow.', [], 401);
- }
- try {
- $validateExists = DB::table('S002V01TFLTR')
- ->where('FLTR_IDFT', '=', $idWorkflow)
- ->where('FLTR_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al verificar el workflow.", $th->getMessage(), 500);
- }
- if (!$validateExists) {
- return $this->responseController->makeResponse(true, "El workflow no existe.", [], 500);
- }
- try {
- $arrWorks = DB::table('S002V01TTRAB')
- ->where('TRAB_IDFT', '=', $idWorkflow)
- ->where('TRAB_ESTA', '=', 'Activo')
- ->where('TRAB_NULI', '=', $line)
- ->get([
- 'TRAB_IDTR AS ID_TRABAJO',
- 'TRAB_NOTR AS NOMBRE_TRABAJO',
- 'TRAB_DETR AS DESCRIPCION_TRABAJO',
- 'TRAB_SECU AS SECUENCIA',
- 'TRAB_SISE AS SIGUIENTE_SECUENCIA',
- 'TRAB_CASE AS CAMBIO_SECUENCIA',
- 'TRAB_DISP AS DISPONIBLE',
- 'TRAB_COMP AS COMPLETO',
- 'TRAB_FUVA AS VALIDADO',
- 'TRAB_ESCO AS CONDICIONAL',
- 'TRAB_USRE AS USUARIO_REGISTRA',
- 'TRAB_FERE AS FECHA_REGISTRA',
- 'TRAB_USMO AS USUARIO_MODIFICA',
- 'TRAB_FEMO AS FECHA_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los trabajos.', $th->getMessage(), 500);
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWorks);
- }
- public function getTastks($user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- }
- }
|