| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Support\Facades\DB;
- class ResourcesController extends Controller
- {
- private $responseController;
- public $arrAlphabet;
- public $encController;
- public $functionsController;
- public $arrClasificateDocument;
- public $arrStatesEquipment;
- public $pathService;
- public function __construct() {
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->arrAlphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
- $this->arrClasificateDocument = array(
- 'AV' => 'Avisos',
- 'AU' => 'Audios',
- 'CA' => 'Catálogos',
- 'CE' => 'Certificaciones',
- 'CO' => 'Contratos',
- 'DP' => 'Diagramas o Planos',
- 'FA' => 'Facturas',
- 'FI' => 'Ficheros',
- 'FO' => 'Fotografías',
- 'IN' => 'Informes',
- 'LA' => 'Layouts',
- 'OR' => 'Órdenes',
- 'PL' => 'Plantillas',
- 'RE' => 'Referencias',
- 'VI' => 'Videos',
- );
- $this->arrStatesEquipment = array(
- 'A' => 'Adquisición',
- 'S' => 'Stock',
- 'T' => 'Traslado',
- 'I' => 'Instalación',
- 'R' => 'Reparación',
- 'D' => 'Disposición',
- );
- // $this->pathService = 'C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back';
- $this->pathService = 'C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back';
- }
- // Se utiliza para rellenar un número con ceros a la izquierda
- public function formatSecuence($cont, $length){
- $longigud = strlen($cont);
- $aumentar = $length - $longigud;
- $contador = '';
- for ($i = 0; $i < $aumentar; $i++) {
- $contador .= '0';
- }
- $contador .= $cont === 0 ? 1 : $cont;
- return $contador;
- }
- // Se obtiene el usuario encriptado
- // Se desencripta y se verfica que exista
- // Regresa el usuario desencriptado
- public function checkUserEnc(string $encUser, string $line): Array {
- $arrResponse = array( 'error' => false, 'msg' => '', 'response' => [] );
- try {
- $user = $this->encController->decrypt($encUser);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió un error al desencriptar el ID del usuario.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- try {
- $validateUser = DB::table('S002V01TUSUA')
- ->where('USUA_NULI', '=', $line)
- ->where('USUA_IDUS', '=', $user)
- ->exists();
- } catch(\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al verificar la existencia del usuario.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- if (!$validateUser) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El usuario no existe.';
- $arrResponse['response'] = [];
- return $arrResponse;
- }
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Usuario validado';
- $arrResponse['response'] = $user;
- return $arrResponse;
- }
- public function checkUserDec($decUser, $line) {
- $arrResponse = array( 'error' => false, 'msg' => '', 'response' => [] );
- try {
- $validateUser = DB::table('S002V01TUSUA')
- ->where('USUA_NULI', '=', $line)
- ->where('USUA_IDUS', '=', $decUser)
- ->exists();
- } catch(\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al verificar la existencia del usuario.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- if (!$validateUser) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El usuario no existe.';
- $arrResponse['response'] = [];
- return $arrResponse;
- }
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Usuario validado';
- $arrResponse['response'] = $decUser;
- return $arrResponse;
- }
- public function validateAddress($codigoPostal, $idColonia, $idMunicipio, $idLocalidad = null, $idEstado, $idPais, $line): Array {
- $arrResponse = array( 'error' => false, 'msg' => '', 'response' => [] );
- // Se obtiene el resultado si existe el código del país
- try {
- $validatePais = DB::table('S002V01TPAIS')
- ->where('PAIS_IDPA', '=', $idPais)
- ->where('PAIS_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el país.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validatePais) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El país ingresado no se encuentra en la lista de países.';
- return $arrResponse;
- }
- // Se valida que los paises sean MEX, USA y CAN para verificar el estado/entidad federativa del país
- // Por otro lado, el método se terminará y mandará un estado correcto.
- if($idPais !== 'MEX' && $idPais !== 'USA' && $idPais !== 'CAN') {
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Correcto';
- return $arrResponse;
- }
- // Se obtiene el resultado si existe el código del estado relacionado al páis
- try {
- $validateEstado = DB::table('S002V01TESTA')
- ->where('ESTA_COPA', '=', $idPais)
- ->where('ESTA_COES', '=', $idEstado)
- ->where('ESTA_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el estado.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validateEstado) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El estado ingresado no se encuentra en la lista de países y estados.';
- return $arrResponse;
- }
-
- // Se valida que el país ingresado sea MEX para verificar el municipio, localidad, colonia y código postal
- // Por otro lado, el método de terminará y mandará un estado correcto.
- if($idPais !== 'MEX') {
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Correcto';
- return $arrResponse;
- }
- // Se obtiene el resultado si existe el código del municipio relacionado al estado
- try {
- $validateMunicipio = DB::table('S002V01TMUNI')
- ->where('MUNI_COES', '=', $idEstado)
- ->where('MUNI_COMU', '=', $idMunicipio)
- ->where('MUNI_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el municipio.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validateMunicipio) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El municipio ingresado ('.$idMunicipio.') no se encuentra en la lista de países, estados y municipios.';
- return $arrResponse;
- }
- // Se verifica si el campo localidad exista para poder validarlo
- if (!is_null($idLocalidad)) {
- // Se obtiene el resultado si existe el código de la localidad relacionado al estado
- try {
- $validateLocalidad = DB::table('S002V01TLOCA')
- ->where('LOCA_COES', '=', $idEstado)
- ->where('LOCA_COLO', '=', $idLocalidad)
- ->where('LOCA_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar la localidad.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validateLocalidad) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La localidad ingresada no se encuentra en la lista de países, estados, municipios y localidades.';
- return $arrResponse;
- }
- }
- // Se obtiene el resultado si existe el código de la colonia relacionada al código postal
- try {
- $validateColonia = DB::table('S002V01TCOLO')
- ->where('COLO_COPO', '=', $codigoPostal)
- ->where('COLO_COCO', '=', $idColonia)
- ->where('COLO_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar la colonia.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validateColonia) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La colonia ingresada no se encuentra en la lista de países, estados, municipios y códigos postales.';
- return $arrResponse;
- }
-
- // Se obtiene el resultado si existe el código postal relacionado al estado
- try {
- $validateCodigoPostal = DB::table('S002V01TCOPO')
- ->where('COPO_COES', '=', $idEstado)
- ->where('COPO_COPO', '=', $codigoPostal)
- ->where('COPO_NULI', '=', $line)
- ->exists();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el código postal.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$validateCodigoPostal) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El código postal ingresado no se encuentra en la lista de países, estados, municipios y colonias.';
- return $arrResponse;
- }
- return $arrResponse;
- }
- public function getAddress($codigoPostal, $idColonia, $idMunicipio, $idLocalidad = null, $idEstado, $idPais, $line): Array {
- $arrResponse = array( 'error' => false, 'msg' => '', 'response' => [] );
- // Se obtiene el resultado si existe el código del país
- try {
- $arrPais = (array) DB::table('S002V01TPAIS')
- ->where('PAIS_IDPA', '=', $idPais)
- ->where('PAIS_NULI', '=', $line)
- ->first([
- 'PAIS_IDPA',
- 'PAIS_NOMB'
- ]);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el país.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (empty($arrPais)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El país ingresado no se encuentra en la lista de países.';
- return $arrResponse;
- }
- $arrResponse['response']['PAIS'] = $arrPais['PAIS_NOMB'].' ('.$arrPais['PAIS_IDPA'].')';
- // Se valida que los paises sean MEX, USA y CAN para verificar el estado/entidad federativa del país
- // Por otro lado, el método se terminará y mandará un estado correcto.
- if($idPais !== 'MEX' && $idPais !== 'USA' && $idPais !== 'CAN') {
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Correcto';
- return $arrResponse;
- }
- // Se obtiene el resultado si existe el código del estado relacionado al páis
- try {
- $arrEstado = (array) DB::table('S002V01TESTA')
- ->where('ESTA_COPA', '=', $idPais)
- ->where('ESTA_COES', '=', $idEstado)
- ->where('ESTA_NULI', '=', $line)
- ->first();
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el estado.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (empty($arrEstado)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El estado ingresado no se encuentra en la lista de países y estados.';
- return $arrResponse;
- }
- $arrResponse['response']['ENTIDAD_FEDERATIVA'] = $arrEstado['ESTA_NOES'].' ('.$arrEstado['ESTA_COES'].')';
-
- // Se valida que el país ingresado sea MEX para verificar el municipio, localidad, colonia y código postal
- // Por otro lado, el método de terminará y mandará un estado correcto.
- if($idPais !== 'MEX') {
- $arrResponse['error'] = false;
- $arrResponse['msg'] = 'Correcto';
- return $arrResponse;
- }
- // Se obtiene el resultado si existe el código del municipio relacionado al estado
- try {
- $arrMunicipio = (array) DB::table('S002V01TMUNI')
- ->where('MUNI_COES', '=', $idEstado)
- ->where('MUNI_COMU', '=', $idMunicipio)
- ->where('MUNI_NULI', '=', $line)
- ->first(['MUNI_COMU','MUNI_NOMU']);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el municipio.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$arrMunicipio) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El municipio ingresado ('.$idMunicipio.') no se encuentra en la lista de países, estados y municipios.';
- return $arrResponse;
- }
- $arrResponse['response']['MUNICIPIO'] = $arrMunicipio['MUNI_NOMU'].' ('.$arrMunicipio['MUNI_COMU'].')';
- // Se verifica si el campo localidad exista para poder validarlo
- if (!is_null($idLocalidad)) {
- // Se obtiene el resultado si existe el código de la localidad relacionado al estado
- try {
- $arrLocalidad = (array) DB::table('S002V01TLOCA')
- ->where('LOCA_COES', '=', $idEstado)
- ->where('LOCA_COLO', '=', $idLocalidad)
- ->where('LOCA_NULI', '=', $line)
- ->first(['LOCA_COLO','LOCA_NOLO']);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar la localidad.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$arrLocalidad) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La localidad ingresada no se encuentra en la lista de países, estados, municipios y localidades.';
- return $arrResponse;
- }
- $arrResponse['response']['LOCALIDAD'] = $arrLocalidad['LOCA_NOLO'].' ('.$arrLocalidad['LOCA_COLO'].')';
- } else {
- $arrResponse['response']['LOCALIDAD'] = null;
- }
- // Se obtiene el resultado si existe el código de la colonia relacionada al código postal
- try {
- $arrColonia = (array) DB::table('S002V01TCOLO')
- ->where('COLO_COPO', '=', $codigoPostal)
- ->where('COLO_COCO', '=', $idColonia)
- ->where('COLO_NULI', '=', $line)
- ->first(['COLO_COCO', 'COLO_NOCO']);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar la colonia.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$arrColonia) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La colonia ingresada no se encuentra en la lista de países, estados, municipios y códigos postales.';
- return $arrResponse;
- }
- $arrResponse['response']['COLONIA'] = $arrColonia['COLO_NOCO'].' ('.$arrColonia['COLO_COCO'].')';
-
- // Se obtiene el resultado si existe el código postal relacionado al estado
- try {
- $arrCodigoPostal = (array) DB::table('S002V01TCOPO')
- ->where('COPO_COES', '=', $idEstado)
- ->where('COPO_COPO', '=', $codigoPostal)
- ->where('COPO_NULI', '=', $line)
- ->first(['COPO_COPO']);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió al validar el código postal.';
- $arrResponse['response'] = $th->getMessage();
- return $arrResponse;
- }
- // En caso de que no exista, entonces se termina el método y se manda un estado incorrecto y su mensaje correspondiente
- if (!$arrCodigoPostal) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El código postal ingresado no se encuentra en la lista de países, estados, municipios y colonias.';
- return $arrResponse;
- }
- $arrResponse['response']['CODIGO_POSTAL'] = $arrCodigoPostal['COPO_COPO'];
- return $arrResponse;
- }
- public function checkLatestUpdate(array $arr, $line) {
- $arrResponse = array('error' => false, 'msg' => '', 'response' => []);
- $arrTemp = array();
- foreach ($arr as $keyValue => $value) {
- $value = (array) $value;
- if (!array_key_exists('USUARIO_REGISTRO', $value)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La clave USUARIO_REGISTRO no existe en el arreglo.';
- return $arrResponse;
- }
- if (!array_key_exists('FECHA_REGISTRO', $value)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La clave FECHA_REGISTRO no existe en el arreglo.';
- return $arrResponse;
- }
- if (!array_key_exists('USUARIO_MODIFICA', $value)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La clave USUARIO_MODIFICA no existe en el arreglo.';
- return $arrResponse;
- }
- if (!array_key_exists('FECHA_MODIFICA', $value)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'La clave FECHA_MODIFICA no existe en el arreglo.';
- return $arrResponse;
- }
- foreach ($value as $keyItem => $item) {
- if (
- $keyItem !== 'USUARIO_REGISTRO' &&
- $keyItem !== 'FECHA_REGISTRO' &&
- $keyItem !== 'USUARIO_MODIFICA' &&
- $keyItem !== 'FECHA_MODIFICA'
- ) {
- $arrTemp[$keyValue][$keyItem] = $item;
- }
- }
- $userNumber = '';
- if (is_null($value['USUARIO_MODIFICA'])) {
- $userNumber = $value['USUARIO_REGISTRO'];
- } else {
- $userNumber = $value['USUARIO_MODIFICA'];
- }
- $lastUpdate = '';
- if (is_null($value['FECHA_MODIFICA'])) {
- $lastUpdate = $value['FECHA_REGISTRO'];
- } else {
- $lastUpdate = $value['FECHA_MODIFICA'];
- }
- try {
- $user = (array) DB::table('S002V01TUSUA')
- ->where('USUA_NULI', '=', $line)
- ->where('USUA_IDUS', '=', $userNumber)
- ->first();
- } catch (\Throwable $th) {
- $arrResponse['msg'] = 'Ocurrió un error al obtener el usuario "'.$userNumber.'": '.$th->getMessage();
- }
- $nameUser = $user['USUA_NOMB'].' '.$user['USUA_APPA'];
- if ( !is_null($user['USUA_APMA']) ) {
- $nameUser .= ' '.$user['USUA_APMA'];
- }
- $arrTemp[$keyValue]['USUARIO_MODIFICA'] = $nameUser.' ('.$userNumber.')';
- $responseDatetime = $this->reformatDatetime($lastUpdate);
- if ($responseDatetime['error']) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = $responseDatetime['msg'];
- return $arrResponse;
- }
- $arrTemp[$keyValue]['FECHA_MODIFICA'] = $responseDatetime['response'];
- }
- $arrResponse['response'] = $arrTemp;
- return $arrResponse;
- }
- public function reformatDatetime($datetime) {
- $arrResponse = array('error' => false, 'msg' => '', 'response' => []);
- $arrDatetime = explode(' ', $datetime);
- if ($arrDatetime === false || count($arrDatetime) !== 2) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió un error al obtener el formato de la Datetime.';
- return $arrResponse;
- }
- $date = $arrDatetime[0];
- $time = $arrDatetime[1];
- $responseDate = $this->formatOnlyDate($date);
- if ($responseDate['error']) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = $responseDate['msg'];
- return $arrResponse;
- }
- $formatDate = $responseDate['response'];
-
- $responseTime = $this->formatOnlyTime($time);
- if ($responseTime['error']) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = $responseTime['msg'];
- return $arrResponse;
- }
- $formatTime = $responseTime['response'];
- $arrResponse['response'] = $formatDate.' '.$formatTime;
- return $arrResponse;
- }
- public function formatOnlyDate(string $date) {
- $arrResponse = array('error' => false, 'msg' => '', 'response' => []);
- $arrDate = explode('-', $date);
- if ($arrDate === false || count($arrDate) !== 3) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió un error al obtener el formato de la fecha.';
- return $arrResponse;
- }
- $arrResponse['response'] = $arrDate[2].'-'.$arrDate[1].'-'.$arrDate[0];
- return $arrResponse;
- }
- public function formatOnlyTime(string $time) {
- $arrResponse = array('error' => false, 'msg' => '', 'response' => []);
- $arrTime = explode(':', $time);
- if ($arrTime === false || count($arrTime) != 3) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió un error al obtener el formato de la hora.';
- return $arrResponse;
- }
- $arrSetTime = array( 13 => 1, 14 => 2, 15 => 3, 16 => 4, 17 => 5, 18 => 6, 19 => 7, 20 => 8, 21 => 9, 22 => 10, 23 => 11, 24 => 00);
- $hour = intval($arrTime[0]);
- $minute = intval($arrTime[1]);
- $second = intval($arrTime[2]);
- $format = 'AM';
- if (array_key_exists($hour, $arrSetTime)) {
- $format = 'PM';
- $hour = $arrSetTime[$hour];
- }
- $hour = $this->formatSecuence($hour, 2);
- $minute = $this->formatSecuence($minute, 2);
- $second = $this->formatSecuence($second, 2);
- $arrResponse['response'] = $hour.':'.$minute.':'.$second.' '.$format;
- return $arrResponse;
- }
- public function getUser($idUser, $line) {
- $arrResponse = array('error' => false, 'msg' => '', 'response' => []);
-
- try {
- $user = (array) DB::table('S002V01TUSUA')
- ->where('USUA_IDUS', '=', $idUser)
- ->where('USUA_NULI', '=', $line)
- ->first([
- 'USUA_NOMB AS NOMBRE',
- 'USUA_APPA AS APELLIDO_PATERNO',
- 'USUA_APMA AS APELLIDO_MATERNO',
- ]);
- } catch (\Throwable $th) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'Ocurrió un error al obtener el nombre del usuario.';
- return $arrResponse;
- }
-
- if (empty($user)) {
- $arrResponse['error'] = true;
- $arrResponse['msg'] = 'El usuario no existe.';
- return $arrResponse;
- }
- $nameUser = $user['NOMBRE'] . ' ' . $user['APELLIDO_PATERNO'];
- if (array_key_exists('APELLIDO_MATERNO', $user)) {
- $nameUser .= ' ' . $user['APELLIDO_MATERNO'];
- }
- $arrResponse['response'] = $nameUser;
- return $arrResponse;
- }
- public function formatBytes ($bytes, $decimal = 2) {
- if ($bytes === 0) {
- return '0 Bytes';
- }
- $k = 1024;
- $dm = $decimal < 0 ? 0 : $decimal;
- $sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- $i = floor(log($bytes) / log($k));
- return sprintf("%.{$dm}f", ($bytes / pow($k, $i))) . ' ' . $sizes[$i];
- }
- }
|