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); } } }