| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Http\File;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- class ControlPanelController extends Controller{
- private $responseController;
- private $encryptionController;
- private $functionsController;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- }
- public function getPanels($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $panels = DB::table('S002V01TPACO')->select([
- 'PACO_IDPC AS ID_PANEL',
- 'PACO_NPCO AS NOMBRE_PANEL',
- 'PACO_ORPA AS ORIENTACION',
- 'PACO_ESTA AS ESTADO',
- 'PACO_USRE AS USRREG',
- 'PACO_FERE AS FECREG',
- 'PACO_USMO AS USRMOD',
- 'PACO_FEMO AS FECMOD'
- ])->where('PACO_NULI', '=', $line)->get()->all();
- foreach($panels as $key=>$panel){
- $relatedUsers = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_PCRE', '=', $panel->ID_PANEL]
- ])->get()->all();
- $panel->USUARIOS_RELACIONADOS = count($relatedUsers);
- $panel->ID_PANEL = $this->encryptionController->encrypt($panel->ID_PANEL);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $panel->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $panel->USRREG = $usrRegName . " (" . $panel->USRREG . ")";
- if(!is_null($panel->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $panel->USRMOD]
- ])->first();
-
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $panel->USRMOD = $usrModName . " (" . $panel->USRMOD . ")";
- }
- $panels[$key] = $panel;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los paneles de control registrados.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $panels);
- }
- public function registerPanel(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'panel_name' => 'required|string|max:100',
- 'orientation' => 'required|string|in:H,V',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $orientations = ['V' => 'Vertical', 'H' => 'Horizontal'];
- $orientation = $orientations[$form['orientation']];
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $panelID = DB::table('S002V01TPACO')->insertGetId([
- 'PACO_NULI' => $form['linea'],
- 'PACO_NPCO' => $form['panel_name'],
- 'PACO_INRE' => '[]',
- 'PACO_ORPA' => $orientation,
- 'PACO_USRE' => $idUser,
- 'PACO_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el panel de control $form[panel_name] ($panelID).",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updatePanel(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_panel' => 'required|string',
- 'panel_name' => 'required|string|max:100',
- 'orientation' => 'required|string|in:H,V',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idPanel = $this->encryptionController->decrypt($form['id_panel']);
- if(!$idPanel){
- return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
- }
- $panel = DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->first();
-
- if(is_null($panel)){
- return $this->responseController->makeResponse(true, 'El panel que desea actualizar no existe.', [], 404);
- }
- $orientations = ['V' => 'Vertical', 'H' => 'Horizontal'];
- $orientation = $orientations[$form['orientation']];
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->update([
- 'PACO_NPCO' => $form['panel_name'],
- 'PACO_ORPA' => $orientation,
- 'PACO_USMO' => $idUser,
- 'PACO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el panel de control #$idPanel.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getCountersList($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $counters = DB::table('S002V01TCONA')->select([
- 'CONA_IDCO AS ID_CONTADOR',
- 'CONA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO_EQUIPAMIENTO'
- ])->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'CONA_COEQ')->where([
- ['CONA_NULI', '=', $line],
- ])->get()->all();
- foreach($counters as $key=>$counter){
- $counterLastMeasures = DB::table('S002V01TMEDI')->select([
- 'MEDI_IDME AS ID_MEDIDA',
- 'MEDI_CORE AS CONTADOR',
- 'MEDI_VALO AS VALOR',
- 'MEDI_WSRE AS ID_SERVICIO_WEB',
- 'LSWE_URLX AS URL_SERVICIO_WEB',
- 'MEDI_HORE AS HORA_REGISTRO',
- ])->join('S002V01TLSWE', 'LSWE_IDSW', '=', 'MEDI_WSRE')->where([
- ['MEDI_NULI', '=', $line],
- ['MEDI_CORE', '=', $counter->ID_CONTADOR]
- ])->orderBy('MEDI_IDME', 'desc')
- ->offset(0)->limit(10)->get()->all();
- foreach($counterLastMeasures as $key0=>$measure){
- $measure->ID_MEDIDA = $this->encryptionController->encrypt($measure->ID_MEDIDA);
- $measure->CONTADOR = $this->encryptionController->encrypt($measure->CONTADOR);
- $measure->ID_SERVICIO_WEB = $this->encryptionController->encrypt($measure->ID_SERVICIO_WEB);
- $counterLastMeasures[$key0] = $measure;
- }
- $counter->LAST_MEASURES = $counterLastMeasures;
- $counter->ID_CONTADOR = $this->encryptionController->encrypt($counter->ID_CONTADOR);
- $counter->CODIGO_EQUIPAMIENTO = $this->encryptionController->encrypt($counter->CODIGO_EQUIPAMIENTO);
- $counter->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($counter->ID_EQUIPAMIENTO);
- $counters[$key] = $counter;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los indicadores disponibles.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $counters);
- }
- public function getPanel($idPanel, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idPanel = $this->encryptionController->decrypt($idPanel);
- if(!$idPanel){
- return $this->responseController->makeResponse(true, 'El ID del panel solicitado no está encriptado correctamente', [], 400);
- }
- $panel = DB::table('S002V01TPACO')->select([
- 'PACO_IDPC AS ID_PANEL',
- 'PACO_NPCO AS NOMBRE_PANEL',
- 'PACO_INRE AS INDICADORES_RELACIONADOS',
- 'PACO_ORPA AS ORIENTACION',
- 'PACO_ESTA AS ESTADO',
- 'PACO_USRE AS USRREG',
- 'PACO_FERE AS FECREG',
- 'PACO_USMO AS USRMOD',
- 'PACO_FEMO AS FECMOD'
- ])->where([
- ['PACO_NULI', '=', $line],
- ['PACO_IDPC', '=', $idPanel]
- ])->first();
- $panel->ID_PANEL = $this->encryptionController->encrypt($panel->ID_PANEL);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $panel->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $panel->USRREG = $usrRegName . " (" . $panel->USRREG . ")";
- if(!is_null($panel->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $panel->USRMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $panel->USRMOD = $usrModName . " (" . $panel->USRMOD . ")";
- }
- $panelElementsArr = json_decode($panel->INDICADORES_RELACIONADOS, true);
- foreach($panelElementsArr as $key=>$element){
- $element['module'] = $this->encryptionController->encrypt($element['module']);
- $element['idElement'] = $this->encryptionController->encrypt($element['idElement']);
- $panelElementsArr[$key] = $element;
- }
- $panel->INDICADORES_RELACIONADOS = json_encode($panelElementsArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el panel de control #$idPanel.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $panel);
- }
- public function updatePanelElements(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_panel' => 'required|string',
- 'elements' => 'required|json',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idPanel = $this->encryptionController->decrypt($form['id_panel']);
- if(!$idPanel){
- return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
- }
- $panel = DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->first();
-
- if(is_null($panel)){
- return $this->responseController->makeResponse(true, 'El panel que desea actualizar no existe.', [], 404);
- }
- $elementsArr = json_decode($form['elements'], true);
- foreach($elementsArr as $key=>$element){
- if(!isset($element['module']) || !isset($element['idElement'])){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key tiene un formato inválido.", [], 400);
- }
- $element['module'] = $this->encryptionController->decrypt($element['module']);
- if(!$element['module']){
- return $this->responseController->makeResponse(true, "El módulo del elemento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- $element['idElement'] = $this->encryptionController->decrypt($element['idElement']);
- if(!$element['idElement']){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- $elementsArr[$key] = $element;
- }
- $elementsStr = json_encode($elementsArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->update([
- 'PACO_INRE' => $elementsStr,
- 'PACO_USMO' => $idUser,
- 'PACO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó los elementos del panel de control #$idPanel.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updatePanelAssociations(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_panel' => 'required|string',
- 'associated_users' => 'required|json',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idPanel = $this->encryptionController->decrypt($form['id_panel']);
- if(!$idPanel){
- return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
- }
- $panel = DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->first();
-
- if(is_null($panel)){
- return $this->responseController->makeResponse(true, 'El panel que desea actualizar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $associatedUsersArr = json_decode($form['associated_users'], true);
- $associatedUsersArrDec = [];
- //Actualizar las asociaciones hechas en el front
- foreach($associatedUsersArr as $key=>$idAssociatedUser){
- $idAssociatedUserDec = $this->encryptionController->decrypt($idAssociatedUser);
- if(!$idAssociatedUserDec){
- return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de usuarios asociados no fue encriptado correctamente.", [], 400);
- }
- $associatedUsersArrDec[] = $idAssociatedUserDec;
- $associatedUser = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idAssociatedUserDec]
- ])->first();
-
- if(is_null($associatedUser)){
- return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de usuarios asociados no existe.", [], 404);
- }
- DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idAssociatedUserDec]
- ])->update([
- 'USUA_PCRE' => $idPanel,
- 'USUA_USMO' => $idUser,
- 'USUA_FEMO' => $nowStr,
- ]);
- }
- //Actualizar las asociaciones de los usuarios en la tabla
- $users = DB::table('S002V01TUSUA')->where('USUA_NULI', '=', $form['linea'])->get()->all();
- foreach($users as $user){
- if(!in_array($user->USUA_IDUS, $associatedUsersArrDec)){
- if($user->USUA_PCRE == intval($idPanel)){
- DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $user->USUA_IDUS]
- ])->update([
- 'USUA_PCRE' => 0,
- 'USUA_USMO' => $idUser,
- 'USUA_FEMO' => $nowStr,
- ]);
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó los usuarios asociados al panel #$idPanel.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deletePanel(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_panel' => 'required|string',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idPanel = $this->encryptionController->decrypt($form['id_panel']);
- if(!$idPanel){
- return $this->responseController->makeResponse(true, 'El ID del panel que desea acualizar no fue encriptado correctamente.', [], 400);
- }
- $panel = DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->first();
-
- if(is_null($panel)){
- return $this->responseController->makeResponse(true, 'El panel que desea actualizar no existe.', [], 404);
- }
- $relatedUsers = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_PCRE', '=', $idPanel]
- ])->get()->all();
- if(count($relatedUsers) > 0){
- return $this->responseController->makeResponse(true, 'El panel de control no se peuede eliminar porque tiene usuarios relacionados.', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPACO')->where([
- ['PACO_NULI', '=', $form['linea']],
- ['PACO_IDPC', '=', $idPanel]
- ])->update([
- 'PACO_ESTA' => 'Eliminado',
- 'PACO_USMO' => $idUser,
- 'PACO_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F04MIIG',
- 'S002V01P01PCIN',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el panel de control #$idPanel.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getInfoToExcel($indicator, $idModule, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idModule = $this->encryptionController->decrypt($idModule);
- if(!$idModule){
- return $this->responseController->makeResponse(true, 'El ID del módulo seleccionado no está encriptado correctamente', [], 400);
- }
- $module = DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idModule]
- ])->first();
- if(is_null($module)){
- return $this->responseController->makeResponse(true, 'El módulo relacionado no está registrado', [], 404);
- }
- $indicator = $this->encryptionController->decrypt($indicator);
- if(!$indicator){
- return $this->responseController->makeResponse(true, 'El ID del indicador seleccionado no está encriptado correctamente', [], 400);
- }
- $spreadsheet = null;
- switch($idModule){
- case "S002V01M06COAC":
- $activator = DB::table('S002V01TACTI')->where([
- ['ACTI_NULI', '=', $line],
- ['ACTI_CORE', '=', $indicator]
- ])->first();
- $unitStr = "";
- if($activator->ACTI_TIAC == 'Medida' || $activator == 'Valor'){
- $configArr = json_decode($activator->ACTI_COAC, true);
- $unit = DB::table('S002V01TLIME')->where([
- ['LIME_NULI', '=', $line],
- ['LIME_IDME', '=', $configArr['unit']],
- ['LIME_MAGN', '=', $configArr['magnitude']],
- ])->first();
- $unitStr = $unit->LIME_ACME;
- }else if($activator->ACTI_TIAC == 'Sintoma'){
- $configArr = json_decode($activator->ACTI_COAC, true);
- $sign = DB::table('S002V01TLISI')->where([
- ['LISI_NULI', '=', $line],
- ['LISI_IDSI', '=', $configArr['sign']]
- ])->first();
- $unit = DB::table('S002V01TLIME')->where([
- ['LIME_NULI', '=', $line],
- ['LIME_IDME', '=', $sign->LISI_IDME],
- ])->first();
- $unitStr = $unit->LIME_ACME;
- }
- $measures = DB::table('S002V01TMEDI')->select([
- 'MEDI_IDME AS ID_MEDIDA',
- 'MEDI_CORE AS CONTADOR',
- 'MEDI_VALO AS VALOR',
- DB::raw("CONCAT(LSWE_URLX, ' (', MEDI_WSRE, ')') AS SERVICIO_WEB"),
- 'MEDI_HORE AS HORA_REGISTRO',
- ])->join('S002V01TLSWE', 'LSWE_IDSW', '=', 'MEDI_WSRE')->where([
- ['MEDI_NULI', '=', $line],
- ['MEDI_CORE', '=', $indicator]
- ])->orderBy('MEDI_IDME', 'desc')->get()->all();
- foreach($measures as $key=>$measure){
- $measure->VALOR = trim($measure->VALOR . " $unitStr");
- $measure->HORA_REGISTRO = $this->functionsController->buildProjectDate($measure->HORA_REGISTRO);
- $measures[$key] = $measure;
- }
- $columns = ['ID', 'CONTADOR', 'VALOR', 'WEB SERVICE', 'REGISTRO'];
- $spreadsheet = $this->exportExcel($measures, $columns);
- break;
- }
- if(is_null($spreadsheet)){
- return $this->responseController->makeResponse(true, 'La hoja de cálculo no pudo ser generada', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
-
- $dateTimeArr = explode(" ", $nowStr);
- $dateArr = explode("-", $dateTimeArr[0]);
- $year = substr($dateArr[0], 2);
- $como = 'PCSA';
- $cldo = 'IN';
- $fecr = $year . $dateArr[1] . $dateArr[2];
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ])->orderBy('AFAL_NUSE', 'desc')->first();
- $nuse = "";
- if(is_null($sec)){
- $nuse = '000001';
- }else{
- $secu = "" . intval($sec->AFAL_NUSE) + 1 . "";
- $nuse = "";
- for($i = strlen($secu); $i < 6; $i++){
- $nuse .= "0";
- }
- $nuse = $nuse . $secu;
- }
- $timestamp = $now->timestamp;
- $noar = "informe_panel_control_$timestamp";
- $exte = "xlsx";
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ['AFAL_NOAR', '=', $noar],
- ['AFAL_EXTE', '=', $exte],
- ])->orderBy('AFAL_NUVE', 'desc')->first();
- $nuve = "";
- if(is_null($ver)){
- $nuve = "01";
- }else{
- $vers = intval($ver->AFAL_NUVE) + 1;
- $nuve = $vers < 10 ? "0$vers" : "$vers";
- }
- $line = $line < 10 ? "0$line" : "$line";
- $filePath = 'C:\inetpub\wwwroot\sam\public_files\\';
- $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
-
- $tempFile = $filePath . $fileName;
- if(file_exists($tempFile)){
- unlink($tempFile);
- }
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
- $writer->save($tempFile);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F03EDJC',
- '-',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el archivo #$fileName.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['report' => $this->encryptionController->encrypt($fileName)]);
- }
- private function exportExcel($data, $columns) : Spreadsheet {
- $spreadsheet = new Spreadsheet;
- $spreadsheet->getProperties()->setCreator('STC');
- $worksheet = $spreadsheet->getActiveSheet();
- $startRow = 2;
- $startColumn = 2;
- $endRow = count($data) + $startRow;
- $endColumn = count($columns) + $startColumn;
- for($row = $startRow; $row <= $endRow; $row++){
- $rowIndex = $row - 2;
- $rowInfo = $rowIndex == 0 ? $columns : (array) $data[$rowIndex - 1];
- $rowHeaders = array_keys($rowInfo);
- for($col = $startColumn; $col < $endColumn; $col++){
- $colIndex = $col - 2;
- $colName = $rowHeaders[$colIndex];
- $colValue = $rowInfo[$colName];
- $colStr = Coordinate::stringFromColumnIndex($col);
- if($rowIndex == 0){
- $worksheet->setCellValue($colStr . $row, $colValue)->getStyle($colStr . $row)->getFill()
- ->setFillType(Fill::FILL_SOLID)
- ->getStartColor()->setRGB('B7BCC4');
- $worksheet->getStyle($colStr . $row)->getFont()->setBold(true);
- $worksheet->getStyle($colStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }else{
- $worksheet->setCellValue($colStr . $row, $colValue);
- }
- $worksheet->getColumnDimension($colStr)->setAutoSize(true);
- }
- }
- return $spreadsheet;
- }
- public function registerBroadcastList(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'list_name' => 'required|string|max:75',
- 'related_users' => 'required|json'
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $relatedUsers = json_decode($form['related_users'], true);
- if(count($relatedUsers) < 2){
- return $this->responseController->makeResponse(true, 'La lista de difusión debe tener al menos 2 usuarios relacionados.', [], 400);
- }
- foreach($relatedUsers as $key=>$user){
- $user = $this->encryptionController->decrypt($user);
- if(!$user){
- return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de integrantes no fue encriptado correctamente.", [], 400);
- }
- $userInfo = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $user]
- ])->first();
-
- if(is_null($userInfo)){
- return $this->responseController->makeResponse(true, "El usuario en la posición $key no existe.", [], 404);
- }else if($userInfo->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El usuario en la posición $key está eliminado.", [], 404);
- }
- $relatedUsers[$key] = $user;
- }
- $relatedUsersStr = json_encode($relatedUsers);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idList = DB::table('S002V01TLIDI')->insertGetId([
- 'LIDI_NULI' => $form['linea'],
- 'LIDI_NLDI' => $form['list_name'],
- 'LIDI_INLI' => $relatedUsersStr,
- 'LIDI_USRE' => $idUser,
- 'LIDI_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F01CLDI',
- 'S002V01P01ASPE',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la lista de difusión #$idList.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getBroadcastLists($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $lists = DB::table('S002V01TLIDI')->select([
- 'LIDI_IDLD AS ID_LISTA',
- 'LIDI_NLDI AS NOMBRE_LISTA',
- 'LIDI_ESTA AS ESTADO',
- 'LIDI_USRE AS USRREG',
- 'LIDI_FERE AS FECREG',
- 'LIDI_USMO AS USRMOD',
- 'LIDI_FEMO AS FECMOD'
- ])->where('LIDI_NULI', '=', $line)->get()->all();
- foreach($lists as $key=>$list){
- $list->ID_LISTA = $this->encryptionController->encrypt($list->ID_LISTA);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $list->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $list->USRREG = $usrRegName . ' (' . $list->USRREG . ')';
- if(!is_null($list->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $list->USRMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $list->USRMOD = $usrModName . ' (' . $list->USRMOD . ')';
- }
- $lists[$key] = $list;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F01CLDI',
- 'S002V01P01ASPE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las listas de difusión registradas.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $lists);
- }
- public function getBroadcastList($idList, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idList = $this->encryptionController->decrypt($idList);
- if(!$idList){
- return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
- }
- $broadcastList = DB::table('S002V01TLIDI')->select([
- 'LIDI_IDLD AS ID_LISTA',
- 'LIDI_NLDI AS NOMBRE_LISTA',
- 'LIDI_INLI AS INTEGRANTES',
- 'LIDI_ESTA AS ESTADO',
- 'LIDI_USRE AS USRREG',
- 'LIDI_FERE AS FECREG',
- 'LIDI_USMO AS USRMOD',
- 'LIDI_FEMO AS FECMOD'
- ])->where([
- ['LIDI_NULI', '=', $line],
- ['LIDI_IDLD', '=', $idList]
- ])->first();
- if(is_null($broadcastList)){
- return $this->responseController->makeResponse(true, 'La lista solicitada no existe.', [], 404);
- }else if($broadcastList->ESTADO == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La lista solicitada está eliminada.', [], 404);
- }
- $broadcastList->ID_LISTA = $this->encryptionController->encrypt($broadcastList->ID_LISTA);
- $usersList = json_decode($broadcastList->INTEGRANTES, true);
- $usersListFn = [];
- foreach($usersList as $key=>$userID){
- $user = DB::table('S002V01TUSUA')
- ->join('S002V01TPERF', 'PERF_IDPE', '=', 'USUA_PERF')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $userID]
- ])->first();
- $usersListFn[] = [
- 'ID_USUARIO' => $this->encryptionController->encrypt($user->USUA_IDUS),
- 'NOMBRE_USUARIO' => $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA),
- 'ID_PERFIL' => $this->encryptionController->encrypt($user->PERF_IDPE),
- 'NOMBRE_PERFIL' => $user->PERF_NOPE
- ];
- }
- $broadcastList->INTEGRANTES = json_encode($usersListFn);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $broadcastList->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $broadcastList->USRREG = $usrRegName . ' (' . $broadcastList->USRREG . ')';
- if(!is_null($broadcastList->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $broadcastList->USRMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $broadcastList->USRMOD = $usrModName . ' (' . $broadcastList->USRMOD . ')';
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M14PCSA',
- 'S002V01F01CLDI',
- 'S002V01P01ASPE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la lista de difusión #$idList.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $broadcastList);
- }
- public function updateBroadcastList(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'list_name' => 'required|string|max:75',
- 'related_users' => 'required|json',
- 'id_list' => 'required|string',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idList = $this->encryptionController->decrypt($form['id_list']);
- if(!$idList){
- return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
- }
- $list = DB::table('S002V01TLIDI')->where([
- ['LIDI_NULI', '=', $form['linea']],
- ['LIDI_IDLD', '=', $idList]
- ])->first();
-
- if(is_null($list)){
- return $this->responseController->makeResponse(true, 'La lista de difusión solicitada no existe.', [], 404);
- }
- $relatedUsers = json_decode($form['related_users'], true);
- if(count($relatedUsers) < 2){
- return $this->responseController->makeResponse(true, 'La lista de difusión debe tener al menos 2 usuarios relacionados.', [], 400);
- }
- foreach($relatedUsers as $key=>$user){
- $user = $this->encryptionController->decrypt($user);
- if(!$user){
- return $this->responseController->makeResponse(true, "El ID del usuario en la posición $key del arreglo de integrantes no fue encriptado correctamente.", [], 400);
- }
- $userInfo = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $user]
- ])->first();
-
- if(is_null($userInfo)){
- return $this->responseController->makeResponse(true, "El usuario en la posición $key no existe.", [], 404);
- }else if($userInfo->USUA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El usuario en la posición $key está eliminado.", [], 404);
- }
- $relatedUsers[$key] = $user;
- }
- $relatedUsersStr = json_encode($relatedUsers);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLIDI')->where([
- ['LIDI_NULI', '=', $form['linea']],
- ['LIDI_IDLD', '=', $idList]
- ])->update([
- 'LIDI_NLDI' => $form['list_name'],
- 'LIDI_INLI' => $relatedUsersStr,
- 'LIDI_USMO' => $idUser,
- 'LIDI_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F01CLDI',
- 'S002V01P01ASPE',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la lista de difusión #$idList.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteBroadcastList(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_list' => 'required|string',
- ]);
-
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idList = $this->encryptionController->decrypt($form['id_list']);
- if(!$idList){
- return $this->responseController->makeResponse(true, 'El ID de la lista solicitada no está encriptado correctamente', [], 400);
- }
- $list = DB::table('S002V01TLIDI')->where([
- ['LIDI_NULI', '=', $form['linea']],
- ['LIDI_IDLD', '=', $idList]
- ])->first();
-
- if(is_null($list)){
- return $this->responseController->makeResponse(true, 'La lista de difusión solicitada no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLIDI')->where([
- ['LIDI_NULI', '=', $form['linea']],
- ['LIDI_IDLD', '=', $idList]
- ])->update([
- 'LIDI_ESTA' => 'Eliminado',
- 'LIDI_USMO' => $idUser,
- 'LIDI_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M14PCSA',
- 'S002V01F01CLDI',
- 'S002V01P01ASPE',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la lista de difusión #$idList.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- }
|