| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Carbon;
- use Carbon\Exceptions\InvalidFormatException;
- use ElephantIO\Client;
- use Illuminate\Validation\Rule;
- 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 CorrectiveMaintenanceController extends Controller{
- private $responseController;
- private $encryptionController;
- private $functionsController;
- private $documentManagementController;
- private $notificationsController;
- private $socketClient;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->documentManagementController = new DocumentManagementController();
- $this->notificationsController = new NotificationsController();
- $url = 'http://localhost:3200';
- $this->socketClient = new Client(Client::engine(Client::CLIENT_4X, $url));
- $this->socketClient->initialize();
- $this->socketClient->of('/');
- }
- public function registerWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_responsible' => 'required|string',
- 'type_responsible' => 'required|string|in:U,S',
- 'description' => 'required|string|min:15',
- 'equipment' => 'required|string',
- 'start_date_time' => 'required|date',
- 'solution_time' => 'required|numeric',
- 'priority' => 'required|string',
- 'id_counter' => 'required|string',
- 'id_last_measure' => 'required|string',
- 'clasification' => 'required|string|max:50',
- 'staff' => 'required|json',
- 'security_management' => 'required|string',
- 'activation_type' => 'required|string|in:Manual,Automática',
- 'resources' => 'required|json',
- 'attached' => '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);
- }
-
- $idUserResponsible = $this->encryptionController->decrypt($form['id_responsible']);
- if(!$idUserResponsible){
- return $this->responseController->makeResponse(true, 'El ID del usuario responsable no fue encriptado correctamente.', [], 400);
- }
- $usrResponsible = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUserResponsible]
- ])->first();
-
- if(is_null($usrResponsible)){
- return $this->responseController->makeResponse(true, 'El usuario responsable de atender la solicitud no existe.', [], 404);
- }
- $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
- if(!$equipmentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento relacionado no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $equipmentCode],
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
- }
- if(floatval($form['solution_time']) <= 0){
- return $this->responseController->makeResponse(true, 'El tiempo de solución estimado debe ser mayor a cero.', [], 400);
- }
- $priority = $this->encryptionController->decrypt($form['priority']);
- if(!$priority){
- return $this->responseController->makeResponse(true, 'La prioridad relacionada no fue encriptada correctamente.', [], 400);
- }
- $validPriorities = ['1', '2', '3', '4'];
- if(!in_array($priority, $validPriorities)){
- return $this->responseController->makeResponse(true, 'La prioridad relacionada es inválida.', [], 400);
- }
- $idCounter = $this->encryptionController->decrypt($form['id_counter']);
- if(!$idCounter){
- return $this->responseController->makeResponse(true, 'El ID del contador relacionado no fue encriptado correctamente.', [], 400);
- }
- $counter = DB::table('S002V01TCONA')->where([
- ['CONA_IDCO', '=', $idCounter],
- ['CONA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($counter)){
- return $this->responseController->makeResponse(true, 'El contador relacionado no existe.', [], 404);
- }
- $idLastMeasure = $this->encryptionController->decrypt($form['id_last_measure']);
- if(!$idLastMeasure){
- return $this->responseController->makeResponse(true, 'El ID de la última medida del contador relacionado no fue encriptado correctamente.', [], 400);
- }
- $lastMeasure = 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_IDME', '=', $idLastMeasure],
- ['MEDI_NULI', '=', $form['linea']],
- ['MEDI_CORE', '=', $idCounter]
- ])->orderBy('MEDI_HORE', 'desc')->first();
-
- if(is_null($lastMeasure)){
- return $this->responseController->makeResponse(true, 'La última medida del contador relacionado no existe.', [], 404);
- }
- $staffArr = json_decode($form['staff'], true);
- if(count($staffArr) == 0){
- return $this->responseController->makeResponse(true, 'El arreglo del personal está vacío.', [], 400);
- }
- $staffArrFn = [];
- foreach($staffArr as $key=>$item){
- $itemArr = explode('-', $item);
- $idDec = $this->encryptionController->decrypt($itemArr[0]);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID en la posición $key del arreglo del personal no fue encriptado correctamente.", [], 400);
- }
- if($itemArr[1] == 'EQ'){
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $idDec],
- ['EQMA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($workTeam)){
- return $this->responseController->makeResponse(true, "El equipo de trabajo en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($workTeam->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El equipo de trabajo en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }else if($itemArr[1] == 'SU'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $idDec],
- ['PESU_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, "El subcontratista en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($subcontratist->PESU_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El subcontratista en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }else if($itemArr[1] == 'EM'){
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_IDPE', '=', $idDec],
- ['PERS_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, "El empleado en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($employee->PERS_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El empleado en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }
- }
- $staffStrFn = json_encode($staffArrFn);
- $idManagement = $this->encryptionController->decrypt($form['security_management']);
- if(!$idManagement){
- return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
- }
- $management = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->first();
- if(is_null($management)){
- return $this->responseController->makeResponse(true, 'La gerencia de seguridad seleccionada no está registrada.', [], 404);
- }
- //PENDIENTE REVISAR LOS RECURSOS
- $attachedArrFn = [];
- if(isset($form['attached'])){
- $attachedArr = json_decode($form['attached'], true);
- foreach($attachedArr as $key=>$attached){
- $idDec = $this->encryptionController->decrypt($attached['id']);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- if($attached['type'] == 'Existente'){
- $codeArr = explode('=', $idDec);
- $codeArr0 = explode('-', $codeArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['AFAL_COMO', '=', $codeArr0[1]],
- ['AFAL_CLDO', '=', $codeArr0[2]],
- ['AFAL_FECR', '=', $codeArr0[3]],
- ['AFAL_NUSE', '=', $codeArr0[4]],
- ['AFAL_NUVE', '=', $codeArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
- $attachedArrFn[] = $idDec;
- }else if($attached['type'] == 'Nuevo'){
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idDec],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $attachedArrFn[] = $finalFile[1];
- }
- }
- }
- }
- $activationType = $form['activation_type'][0];
- $attachedStrFn = json_encode($attachedArrFn);
- $lastMeasureStr = json_encode($lastMeasure);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryStr = json_encode([
- ['USUARIO' => $idUser, 'ESTADO' => 'PE', 'FECHA' => $nowStr]
- ]);
- $orderID = DB::table('S002V01TOTCO')->insertGetId([
- 'OTCO_NULI' => $form['linea'],
- 'OTCO_IDUR' => $idUserResponsible,
- 'OTCO_TURE' => $form['type_responsible'],
- 'OTCO_DEIN' => $form['description'],
- 'OTCO_EQIN' => $equipmentCode,
- 'OTCO_FIFA' => $form['start_date_time'],
- 'OTCO_TESO' => $form['solution_time'],
- 'OTCO_CORE' => $idCounter,
- 'OTCO_DRCO' => $lastMeasureStr,
- 'OTCO_PRIO' => $priority,
- 'OTCO_RHUT' => $form['resources'],
- 'OTCO_PEIN' => $staffStrFn,
- 'OTCO_TIAC' => $activationType,
- 'OTCO_DORE' => $attachedStrFn,
- 'OTCO_CLAS' => $form['clasification'],
- 'OTCO_GESE' => $idManagement,
- 'OTCO_HIES' => $statusHistoryStr,
- 'OTCO_ESOR' => 'PE',
- 'OTCO_USRE' => $idUser,
- 'OTCO_FERE' => $nowStr
- ]);
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$orderID",
- "Su usuario ha sido asignado como responsable de atender la orden de mantenimiento #$orderID.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
- ], [
- 'BOTON' => 'Validar orden',
- 'FUNCION' => 'validateCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($orderID)])
- ], [
- 'BOTON' => 'Ir al módulo',
- 'FUNCION' => 'openModule',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
- ]],
- [$idUserResponsible],
- $idUser,
- $form['linea'],
- $this->socketClient,
- $orderID,
- 'Correctivo'
- );
- $idOrderEnc = $this->encryptionController->encrypt($orderID);
- $socketData = ['idOrder' => $idOrderEnc];
- $this->socketClient->emit('new_corrective_work_order', $socketData);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la orden de trabajo correctivo #$orderID.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getWorkOrders($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);
- }
- $orders = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS ID_ORDEN',
- 'OTCO_EQIN AS CODIGO_EQUIPAMIENTO',
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO_EQUIPAMIENTO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'OTCO_FIFA AS FECHA_INICIO',
- 'OTCO_CORE AS CONTADOR',
- 'OTCO_FTIN AS FECHA_FIN',
- 'OTCO_TIAC AS TIPO_ACTIVACION',
- 'OTCO_IDUR AS ID_RESPONSABLE',
- 'OTCO_TURE AS TIPO_RESPONSABLE',
- 'OTCO_PRIO AS PRIORIDAD',
- 'OTCO_ESOR AS ESTADO'
- ])->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'OTCO_EQIN')
- ->where('OTCO_NULI', '=', $line)
- ->orderBy('OTCO_IDOT', 'desc')->get()->all();
- $subcontratistTypes = ['S' => 'Subcontratista', 'U' => 'Usuario'];
- $activationTypes = ['M' => 'Manual', 'A' => 'Automática'];
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
- foreach($orders as $key=>$order){
- if($order->TIPO_RESPONSABLE == 'U'){
- $userResponsible = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->ID_RESPONSABLE],
- ['USUA_NULI', '=', $line]
- ])->first();
- $userResponsibleName = $this->functionsController->joinName($userResponsible->USUA_NOMB, $userResponsible->USUA_APPA, $userResponsible->USUA_APMA);
- $order->ID_RESPONSABLE = $userResponsibleName . " (" . $order->ID_RESPONSABLE . ")";
- }else{
- $subcontratistResponsible = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $order->ID_RESPONSABLE]
- ])->first();
- $order->ID_RESPONSABLE = $subcontratistResponsible->PESU_RASO . " (" . $subcontratistResponsible->PESU_REFI . ") (" . $order->ID_RESPONSABLE . ")";
- }
- $order->TIPO_RESPONSABLE = $subcontratistTypes[$order->TIPO_RESPONSABLE];
- $order->ID_ORDEN = $this->encryptionController->encrypt($order->ID_ORDEN);
- $order->CODIGO_EQUIPAMIENTO = $this->encryptionController->encrypt($order->CODIGO_EQUIPAMIENTO);
- $order->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($order->ID_EQUIPAMIENTO);
- $order->CONTADOR = $this->encryptionController->encrypt($order->CONTADOR);
- $order->TIPO_ACTIVACION = $activationTypes[$order->TIPO_ACTIVACION];
- $order->PRIORIDAD = $this->encryptionController->encrypt($order->PRIORIDAD);
- $order->ESTADO = $orderStates[$order->ESTADO];
- $orders[$key] = $order;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F01GEOP',
- 'S002V01P01COOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las órdenes de mantenimiento correctivo registradas.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $orders);
- }
- public function getWorkOrder($idOrder, $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);
- }
- $idOrder = $this->encryptionController->decrypt($idOrder);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden solicitada no está encriptado correctamente', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS ID_ORDEN',
- 'OTCO_DEIN AS DESCRIPCION',
- 'OTCO_EQIN AS CODIGO_EQUIPAMIENTO',
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO_EQUIPAMIENTO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'OTCO_FIFA AS FECHA_INICIO',
- 'OTCO_TESO AS TIEMPO_ESTIMADO',
- 'OTCO_CORE AS CONTADOR',
- 'OTCO_DRCO AS MEDIDAS',
- 'OTCO_PRIO AS PRIORIDAD',
- 'OTCO_FTIN AS FECHA_FINAL',
- 'OTCO_DTIN AS DURACION_TOTAL',
- 'OTCO_RHUT AS RECURSOS',
- 'OTCO_PEIN AS PERSONAL',
- 'OTCO_TIAC AS TIPO_ACTIVACION',
- 'OTCO_IDUR AS ID_RESPONSABLE',
- 'OTCO_TURE AS TIPO_RESPONSABLE',
- 'OTCO_ANCO AS ANALISIS_COSTOS',
- 'OTCO_DORE AS DOCUMENTOS_RELACIONADOS',
- 'OTCO_CLAS AS CLASIFICACION',
- 'OTCO_COME AS COMENTARIOS',
- 'OTCO_GESE AS GERENCIA_SEGURIDAD',
- 'OTCO_CAEX AS CAMPOS_EXTRA',
- 'OTCO_ESOR AS ESTADO',
- 'OTCO_USRE AS USUREG',
- 'OTCO_FERE AS FECREG',
- 'OTCO_USMO AS USUMOD',
- 'OTCO_FEMO AS FECMOD'
- ])->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'OTCO_EQIN')
- ->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $line]
- ])->first();
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no está registrada.', [], 404);
- }
-
- $subcontratistTypes = ['S' => 'Subcontratista', 'U' => 'Usuario'];
- if($order->TIPO_RESPONSABLE == 'U'){
- $userResponsible = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->ID_RESPONSABLE],
- ['USUA_NULI', '=', $line]
- ])->first();
- $userResponsibleName = $this->functionsController->joinName($userResponsible->USUA_NOMB, $userResponsible->USUA_APPA, $userResponsible->USUA_APMA);
- $order->ID_RESPONSABLE = $userResponsibleName . " (" . $order->ID_RESPONSABLE . ")";
- }else{
- $subcontratistResponsible = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $order->ID_RESPONSABLE]
- ])->first();
- $order->ID_RESPONSABLE = $subcontratistResponsible->PESU_RASO . " (" . $subcontratistResponsible->PESU_REFI . ") (" . $order->ID_RESPONSABLE . ")";
- }
- $order->TIPO_RESPONSABLE = $subcontratistTypes[$order->TIPO_RESPONSABLE];
- $order->ID_ORDEN = $this->encryptionController->encrypt($order->ID_ORDEN);
- $order->CODIGO_EQUIPAMIENTO = $this->encryptionController->encrypt($order->CODIGO_EQUIPAMIENTO);
- $order->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($order->ID_EQUIPAMIENTO);
- $order->CONTADOR = $this->encryptionController->encrypt($order->CONTADOR);
- $measureArr = json_decode($order->MEDIDAS, true);
- $measureArr['CONTADOR'] = $this->encryptionController->encrypt($measureArr['CONTADOR']);
- $measureArr['ID_MEDIDA'] = $this->encryptionController->encrypt($measureArr['ID_MEDIDA']);
- $measureArr['ID_SERVICIO_WEB'] = $this->encryptionController->encrypt($measureArr['ID_SERVICIO_WEB']);
- $order->MEDIDAS = json_encode($measureArr);
- $order->PRIORIDAD = $this->encryptionController->encrypt($order->PRIORIDAD);
- $order->GERENCIA_SEGURIDAD = $this->encryptionController->encrypt($order->GERENCIA_SEGURIDAD);
-
- $staffArr = json_decode($order->PERSONAL, true);
- foreach($staffArr as $key=>$val){
- if($val['TYPE'] == 'EQ'){
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_NULI', '=', $line],
- ['EQMA_IDEQ', '=', $val['ID']]
- ])->first();
- $val['NAME'] = $workTeam->EQMA_NOMB . " (" . $val['ID'] . ")";
- }else if($val['TYPE'] == 'SU'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $val['ID']]
- ])->first();
- $val['NAME'] = $subcontratist->PESU_RASO . " (" . $subcontratist->PESU_REFI . ") (" . $val['ID'] . ")";
- }else if($val['TYPE'] == 'EM'){
- $employee = DB::table('S002V01TPERS')
- ->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')
- ->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $val['ID']]
- ])->first();
- $employeeName = $this->functionsController->joinName($employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA);
- $val['NAME'] = $employeeName . " (" . $employee->PERS_IDUS . ") (" . $val['ID'] . ")";;
- }
- $val['ID'] = $this->encryptionController->encrypt($val['ID']);
- $staffArr[$key] = $val;
- }
-
- $activationTypes = ['M' => 'Manual', 'A' => 'Automática'];
- $order->PERSONAL = json_encode($staffArr);
- $order->TIPO_ACTIVACION = $activationTypes[$order->TIPO_ACTIVACION];
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
- $order->ESTADO = $orderStates[$order->ESTADO];
- $documentsArr = json_decode($order->DOCUMENTOS_RELACIONADOS, true);
- $documentsFn = [];
- foreach($documentsArr as $document){
- $documentArr = explode('=', $document);
- $codeArr = explode('-', $documentArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $codeArr[1]],
- ['AFAL_CLDO', '=', $codeArr[2]],
- ['AFAL_FECR', '=', $codeArr[3]],
- ['AFAL_NUSE', '=', $codeArr[4]],
- ['AFAL_NUVE', '=', $documentArr[1]]
- ])->first();
- $documentsFn[] = [
- 'id' => $this->encryptionController->encrypt($document),
- 'name' => $file->AFAL_NOAR . '.' . $file->AFAL_EXTE,
- 'size' => $file->AFAL_TAMA,
- 'type' => 'Existente'
- ];
- }
- $order->DOCUMENTOS_RELACIONADOS = json_encode($documentsFn);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->USUREG],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usrReg)){
- $order->USUREG = "AUTOMÁTICO (0)";
- }else{
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $order->USUREG = $nameReg . " (" . $order->USUREG . ")";
- }
- if(!is_null($order->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->USUMOD],
- ['USUA_NULI', '=', $line]
- ])->first();
-
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $order->USUMOD = $nameMod . " (" . $order->USUMOD . ")";
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F01GEOP',
- 'S002V01P01COOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los detalles de la orden #$idOrder de mantenimiento correctivo registradas.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $order);
- }
- public function updateWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'description' => 'required|string|min:15',
- 'equipment' => 'required|string',
- 'start_date_time' => 'required|date',
- 'solution_time' => 'required|numeric',
- 'priority' => 'required|string',
- 'id_counter' => 'required|string',
- 'id_last_measure' => 'required|string',
- 'clasification' => 'required|string|max:50',
- 'staff' => 'required|json',
- 'security_management' => 'required|string',
- 'activation_type' => 'required|string|in:Manual,Automática',
- 'resources' => 'required|json',
- 'attached' => 'json',
- 'id_order' => '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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }
- $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
- if(!$equipmentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento relacionado no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $equipmentCode],
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
- }
- if(floatval($form['solution_time']) <= 0){
- return $this->responseController->makeResponse(true, 'El tiempo de solución estimado debe ser mayor a cero.', [], 400);
- }
- $priority = $this->encryptionController->decrypt($form['priority']);
- if(!$priority){
- return $this->responseController->makeResponse(true, 'La prioridad relacionada no fue encriptada correctamente.', [], 400);
- }
- $validPriorities = ['1', '2', '3', '4'];
- if(!in_array($priority, $validPriorities)){
- return $this->responseController->makeResponse(true, 'La prioridad relacionada es inválida.', [], 400);
- }
- $idCounter = $this->encryptionController->decrypt($form['id_counter']);
- if(!$idCounter){
- return $this->responseController->makeResponse(true, 'El ID del contador relacionado no fue encriptado correctamente.', [], 400);
- }
- $counter = DB::table('S002V01TCONA')->where([
- ['CONA_IDCO', '=', $idCounter],
- ['CONA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($counter)){
- return $this->responseController->makeResponse(true, 'El contador relacionado no existe.', [], 404);
- }
- $idLastMeasure = $this->encryptionController->decrypt($form['id_last_measure']);
- if(!$idLastMeasure){
- return $this->responseController->makeResponse(true, 'El ID de la última medida del contador relacionado no fue encriptado correctamente.', [], 400);
- }
- $lastMeasure = 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_IDME', '=', $idLastMeasure],
- ['MEDI_NULI', '=', $form['linea']],
- ['MEDI_CORE', '=', $idCounter]
- ])->orderBy('MEDI_HORE', 'desc')->first();
-
- if(is_null($lastMeasure)){
- return $this->responseController->makeResponse(true, 'La última medida del contador relacionado no existe.', [], 404);
- }
- $staffArr = json_decode($form['staff'], true);
- if(count($staffArr) == 0){
- return $this->responseController->makeResponse(true, 'El arreglo del personal está vacío.', [], 400);
- }
- $staffArrFn = [];
- foreach($staffArr as $key=>$item){
- $itemArr = explode('-', $item);
- $idDec = $this->encryptionController->decrypt($itemArr[0]);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID en la posición $key del arreglo del personal no fue encriptado correctamente.", [], 400);
- }
- if($itemArr[1] == 'EQ'){
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $idDec],
- ['EQMA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($workTeam)){
- return $this->responseController->makeResponse(true, "El equipo de trabajo en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($workTeam->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El equipo de trabajo en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }else if($itemArr[1] == 'SU'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $idDec],
- ['PESU_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, "El subcontratista en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($subcontratist->PESU_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El subcontratista en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }else if($itemArr[1] == 'EM'){
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_IDPE', '=', $idDec],
- ['PERS_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, "El empleado en la posición $key del arreglo del personal no existe.", [], 404);
- }else if($employee->PERS_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El empleado en la posición $key del arreglo del personal está eliminado.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $itemArr[1]
- ];
- }
- }
- $staffStrFn = json_encode($staffArrFn);
- $idManagement = $this->encryptionController->decrypt($form['security_management']);
- if(!$idManagement){
- return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
- }
- $management = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->first();
- if(is_null($management)){
- return $this->responseController->makeResponse(true, 'La gerencia de seguridad seleccionada no está registrada.', [], 404);
- }
- //PENDIENTE REVISAR LOS RECURSOS
- $attachedArrFn = [];
- if(isset($form['attached'])){
- $attachedArr = json_decode($form['attached'], true);
- foreach($attachedArr as $key=>$attached){
- $idDec = $this->encryptionController->decrypt($attached['id']);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- if($attached['type'] == 'Existente'){
- $codeArr = explode('=', $idDec);
- $codeArr0 = explode('-', $codeArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['AFAL_COMO', '=', $codeArr0[1]],
- ['AFAL_CLDO', '=', $codeArr0[2]],
- ['AFAL_FECR', '=', $codeArr0[3]],
- ['AFAL_NUSE', '=', $codeArr0[4]],
- ['AFAL_NUVE', '=', $codeArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
- $attachedArrFn[] = $idDec;
- }else if($attached['type'] == 'Nuevo'){
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idDec],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
- if(!$finalFile){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $attachedArrFn[] = $finalFile[1];
- }
- }
- }
- }
- $activationType = $form['activation_type'][0];
- $attachedStrFn = json_encode($attachedArrFn);
- $lastMeasureStr = json_encode($lastMeasure);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOTCO')->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->update([
- 'OTCO_DEIN' => $form['description'],
- 'OTCO_EQIN' => $equipmentCode,
- 'OTCO_FIFA' => $form['start_date_time'],
- 'OTCO_TESO' => $form['solution_time'],
- 'OTCO_CORE' => $idCounter,
- 'OTCO_DRCO' => $lastMeasureStr ,
- 'OTCO_PRIO' => $priority,
- 'OTCO_FTIN' => $order->OTCO_FTIN,
- 'OTCO_DTIN' => $order->OTCO_DTIN,
- 'OTCO_RHUT' => $form['resources'],
- 'OTCO_PEIN' => $staffStrFn,
- 'OTCO_TIAC' => $activationType,
- 'OTCO_ANCO' => $order->OTCO_ANCO,
- 'OTCO_DORE' => $attachedStrFn,
- 'OTCO_CLAS' => $form['clasification'],
- 'OTCO_COME' => $order->OTCO_COME,
- 'OTCO_GESE' => $idManagement,
- 'OTCO_CAEX' => $order->OTCO_CAEX,
- 'OTCO_ESOR' => $order->OTCO_ESOR,
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la orden de trabajo correctivo #$idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => '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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusHistoryArr[] = ['USUARIO' => $idUser, 'ESTADO' => 'EL', 'FECHA' => $nowStr];
- $statusHistoryStr = json_encode($statusHistoryArr);
- DB::table('S002V01TOTCO')->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->update([
- 'OTCO_ESOR' => 'EL',
- 'OTCO_HIES' => $statusHistoryStr,
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la orden de trabajo correctivo #$idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function approveWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => '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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }else if($order->OTCO_ESOR == 'EL'){
- return $this->responseController->makeResponse(true, 'La orden solicitada está eliminada.', [], 404);
- }else if($order->OTCO_ESOR != 'PE'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- $staffArr = json_decode($order->OTCO_PEIN, true);
- $audience = [];
- foreach($staffArr as $item){
- if($item['TYPE'] == 'EQ'){
- $employees = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_EQTR', '=', $item['ID']]
- ])->get()->all();
- foreach($employees as $employee){
- if(!in_array($employee->PERS_IDUS, $audience)){
- $audience[] = $employee->PERS_IDUS;
- }
- }
- }else if($item['TYPE'] == 'SU'){
- $employees = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPS', '=', $item['ID']]
- ])->get()->all();
- foreach($employees as $employee){
- if(!in_array($employee->PERS_IDUS, $audience)){
- $audience[] = $employee->PERS_IDUS;
- }
- }
- }else if($item['TYPE'] == 'EM'){
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $item['ID']]
- ])->first();
- if(!in_array($employee->PERS_IDUS, $audience)){
- $audience[] = $employee->PERS_IDUS;
- }
- }
- }
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "Se ha generado la orden de mantenimiento correctivo #$idOrder y requiere su atención.",
- [],
- $audience,
- $idUser,
- $form['linea'],
- $this->socketClient,
- $idOrder,
- 'Correctivo'
- );
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusHistoryArr[] = ['USUARIO' => $idUser, 'ESTADO' => 'VA', 'FECHA' => $nowStr];
- $statusHistoryStr = json_encode($statusHistoryArr);
- DB::table('S002V01TOTCO')->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->update([
- 'OTCO_ESOR' => 'VA',
- 'OTCO_HIES' => $statusHistoryStr,
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") validó la orden de trabajo correctivo #$idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function startWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => '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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }else if($order->OTCO_ESOR == 'EL'){
- return $this->responseController->makeResponse(true, 'La orden solicitada está eliminada.', [], 404);
- }else if($order->OTCO_ESOR != 'VA'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusHistoryArr[] = ['USUARIO' => $idUser, 'ESTADO' => 'EP', 'FECHA' => $nowStr];
- $statusHistoryStr = json_encode($statusHistoryArr);
- DB::table('S002V01TOTCO')->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->update([
- 'OTCO_ESOR' => 'EP',
- 'OTCO_HIES' => $statusHistoryStr,
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") inició la orden de trabajo correctivo #$idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateWorkOrderStatus(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'status' => 'required|string|in:RE,CE,CA',
- 'comments' => 'required|string|min:15'
- ]);
-
- 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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }else if($order->OTCO_ESOR == 'EL'){
- return $this->responseController->makeResponse(true, 'La orden solicitada está eliminada.', [], 404);
- }
-
- $status = $form['status'];
- switch($status){
- case 'RE':
- if($order->OTCO_ESOR != 'PE'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- break;
- case 'CE':
- if($order->OTCO_ESOR != 'EP' && $order->OTCO_ESOR != 'CP'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- break;
- case 'CA':
- if($order->OTCO_ESOR != 'VA'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- break;
- }
- $message = '';
- if($status == 'CE' && is_null($order->OTCO_ANCO)){
- $status = 'CP';
- $message = 'La orden no puede cerrarse complentamente hasta asignar el análisis de costos.';
- }else{
- $message = 'Actualización correcta.';
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $ftin = null;
- $dtin = null;
- if(($status == 'CE' || $status == 'CP') && is_null($order->OTCO_FTIN)){
- $ftin = $nowStr;
- $startDate = new Carbon($order->OTCO_FIFA);
- $diffInSecs = $now->diffInSeconds($startDate);
- $diffInMins = $this->functionsController->floatDiv($diffInSecs, 60);
- $dtin = $this->functionsController->floatDiv($diffInMins, 60);
- }else{
- $ftin = $order->OTCO_FTIN;
- $dtin = $order->OTCO_DTIN;
- }
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusHistoryArr[] = ['USUARIO' => $idUser, 'ESTADO' => $status, 'FECHA' => $nowStr];
- $statusHistoryStr = json_encode($statusHistoryArr);
- DB::table('S002V01TOTCO')->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->update([
- 'OTCO_ESOR' => $status,
- 'OTCO_COME' => $form['comments'],
- 'OTCO_HIES' => $statusHistoryStr,
- 'OTCO_FTIN' => $ftin,
- 'OTCO_DTIN' => $dtin,
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F04GEOT',
- 'S002V01P01GEOT',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el estado de la orden de trabajo correctivo #$idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, "EXITO: $message");
- }
- public function getWorkOrderClasifications($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);
- }
- $clasifications = DB::table('S002V01TOTCO')->select([
- DB::raw('DISTINCT(OTCO_CLAS) AS CLASIFICACION')
- ])->get()->all();
- $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,
- 'S002V01M09GMCO',
- 'S002V01F01GEOP',
- 'S002V01P01COOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las clasificaciones registradas.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $clasifications);
- }
- public function getResponsibleUsers($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);
- }
- $profiles = DB::table('S002V01TPERF')->where('PERF_NULI', '=', $line)->get()->all();
- $profilesWithAccess = [];
- foreach($profiles as $profile){
- $permissions = json_decode($profile->PERF_PERM, true);
- $permissionsArr = $permissions['permissions'];
- $correctiveMaintenanceFilt = array_filter($permissionsArr, function($v, $k) {
- return $v['id'] == 'S002V01M09GMCO';
- }, ARRAY_FILTER_USE_BOTH);
-
- $correctiveMaintenance = end($correctiveMaintenanceFilt);
- if(intval($correctiveMaintenance['access']) > 0){
- $submodules = $correctiveMaintenance['children'];
- $workOrdersFilt = array_filter($submodules, function($v, $k) {
- return $v['id'] == 'S002V01S01ORTR';
- }, ARRAY_FILTER_USE_BOTH);
- $workOrders = end($workOrdersFilt);
- if(intval($workOrders['access']) > 0){
- $functions = $workOrders['children'];
- $operationsManagementFilt = array_filter($functions, function($v, $k) {
- return $v['id'] == 'S002V01F01GEOP';
- }, ARRAY_FILTER_USE_BOTH);
- $operationsManagement = end($operationsManagementFilt);
- if(intval($operationsManagement['access']) > 0){
- $profilesWithAccess[] = $profile->PERF_IDPE;
- }
- }
- }
- }
- $usersWithAccess = [];
- foreach($profilesWithAccess as $idProfile){
- $users = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_PERF', '=', $idProfile],
- ['USUA_ESTA', '=', 'Activo']
- ])->get()->all();
- foreach($users as $user){
- $userName = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
- $usersWithAccess[] = [
- 'ID' => $this->encryptionController->encrypt($user->USUA_IDUS),
- 'NOMBRE' => $userName,
- ];
- }
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F01GEOP',
- 'S002V01P01COOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios con acceso a la gestión de las operaciones.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $usersWithAccess);
- }
- public function transferWorkOrder(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'id_new_user' => 'required|string',
- 'type' => 'required|string|in:U,S'
- ]);
-
- 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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
-
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no existe.', [], 404);
- }else if($order->OTCO_ESOR == 'EL'){
- return $this->responseController->makeResponse(true, 'La orden solicitada está eliminada.', [], 404);
- }else if($order->OTCO_ESOR != 'PE'){
- $status = $orderStates[$order->OTCO_ESOR];
- return $this->responseController->makeResponse(true, "La orden está $status.", [], 401);
- }
- if($order->OTCO_TURE == 'U' && $order->OTCO_IDUR != $idUser){
- return $this->responseController->makeResponse(true, "El usuario que realizó la solicitud no es el responsable de atenderla.", [], 401);
- }else if($order->OTCO_TURE == 'S'){
- $users = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_TICO', '=', 'Subcontratista'],
- ['PERS_IDPS', '=', $order->OTCO_IDUR],
- ])->get()->all();
- $enabledUsers = [];
- foreach($users as $user){
- $enabledUsers[] = $user->PERS_IDUS;
- }
- if(!in_array($idUser, $enabledUsers)){
- return $this->responseController->makeResponse(true, "El usuario que realizó la solicitud no es el responsable de atenderla.", [], 401);
- }
- }
- $audience = [];
- $idNewUser = $this->encryptionController->decrypt($form['id_new_user']);
- if(!$idNewUser){
- return $this->responseController->makeResponse(true, 'El ID del nuevo encargado no fue encriptado correctamente.', [], 400);
- }
- if($form['type'] == 'U'){
- $newUser = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idNewUser]
- ])->first();
-
- if(is_null($newUser)){
- return $this->responseController->makeResponse(true, 'El usuario seleccionado no existe.', [], 404);
- }
-
- $audience[] = $idNewUser;
- }else if($form['type'] == 'S'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $idNewUser],
- ['PESU_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, 'El subcontratista seleccionado no existe.', [], 404);
- }
-
- $users = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_TICO', '=', 'Subcontratista'],
- ['PERS_IDPS', '=', $idNewUser],
- ])->get()->all();
- foreach($users as $user){
- $audience[] = $user->PERS_IDUS;
- }
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->update([
- 'OTCO_IDUR' => $idNewUser,
- 'OTCO_TURE' => $form['type'],
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $nowStr
- ]);
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "Su usuario ha sido asignado como responsable de atender la orden de mantenimiento #$idOrder.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ], [
- 'BOTON' => 'Validar orden',
- 'FUNCION' => 'validateCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ], [
- 'BOTON' => 'Ir al módulo',
- 'FUNCION' => 'openModule',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
- ]],
- $audience,
- $idUser,
- $form['linea'],
- $this->socketClient,
- $idOrder,
- 'Correctivo'
- );
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F06TROT',
- '-',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") traspasó la orden de trabajo correctivo al usuario o subcontratista #$idNewUser.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerSecurityManagement(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'lada1' => 'required|string|max:8',
- 'phone1' => 'required|string|min:10|max:11',
- 'ext1' => 'string|max:5',
- 'lada2' =>'string|max:8',
- 'phone2' => 'string|min:10|max:11',
- 'ext2' => 'string|max:5',
- 'email' => 'required|string|max:150',
- 'id_manager' => '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);
- }
- $idManager = $this->encryptionController->decrypt($form['id_manager']);
- if(!$idManager){
- return $this->responseController->makeResponse(true, 'El ID del gerente no fue encriptado correctamente.', [], 400);
- }
- $manager = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idManager]
- ])->first();
-
- if(is_null($manager)){
- return $this->responseController->makeResponse(true, 'El usuario seleccionado como gerente no existe.', [], 404);
- }
- $email = $form['email'];
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
- return $this->responseController->makeResponse(true, 'El formato del correo electrónico enviado es inválido.', [], 400);
- }
- $emailVerified = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_COEL', '=', $email]
- ])->get()->all();
- if(count($emailVerified) > 0){
- return $this->responseController->makeResponse(true, 'El correo electrónico enviado ya ha sido registrado.', [], 400);
- }
- $lada1 = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_LADA', '=', $form['lada1']]
- ])->first();
-
- if(is_null($lada1)){
- return $this->responseController->makeResponse(true, 'La lada seleccionada para el teléfono principal es inválida.', [], 400);
- }else if(!$this->functionsController->validPhoneNumber($form['phone1'])){
- return $this->responseController->makeResponse(true, 'El número de teléfono principal es inválido.', [], 400);
- }else if(isset($form['ext1']) && !is_numeric($form['ext1'])){
- return $this->responseController->makeResponse(true, 'La extensión de teléfono principal es inválida.', [], 400);
- }
- $ext1 = isset($form['ext1']) ? $form['ext1']: null;
- $lad2 = null;
- $tel2 = null;
- $ext2 = null;
- if(isset($form['lada2']) || isset($form['phone2'])){
- if(!isset($form['lada2']) || !isset($form['phone2'])){
- if(!isset($form['lada2'])){
- return $this->responseController->makeResponse(true, 'La lada del teléfono secundario es obligatoria cuando se envía el teléfono o la extensión secundarios', [], 400);
- }
- if(!isset($form['phone2'])){
- return $this->responseController->makeResponse(true, 'El teléfono secundario es obligatorio cuando se envía la lada o la extensión secundarias', [], 400);
- }
- }
- $lada2 = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_LADA', '=', $form['lada2']]
- ])->first();
-
- if(is_null($lada2)){
- return $this->responseController->makeResponse(true, 'La lada seleccionada para el teléfono secundario es inválida.', [], 400);
- }else if(!$this->functionsController->validPhoneNumber($form['phone2'])){
- return $this->responseController->makeResponse(true, 'El número de teléfono secundario es inválido.', [], 400);
- }else if(isset($form['ext2']) && !is_numeric($form['ext2'])){
- return $this->responseController->makeResponse(true, 'La extensión de teléfono secundario es inválida.', [], 400);
- }
- $lad2 = $form['lada2'];
- $tel2 = $form['phone2'];
- $ext2 = isset($form['ext2']) ? $form['ext2'] : null;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idManagement = DB::table('S002V01TGESE')->insertGetId([
- 'GESE_NULI' => $form['linea'],
- 'GESE_LAD1' => $form['lada1'],
- 'GESE_TEL1' => $form['phone1'],
- 'GESE_EXT1' => $ext1,
- 'GESE_LAD2' => $lad2,
- 'GESE_TEL2' => $tel2,
- 'GESE_EXT2' => $ext2,
- 'GESE_COEL' => $email,
- 'GESE_GERE' => $idManager,
- 'GESE_USRE' => $idUser,
- 'GESE_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P02GSAU',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la gerencia de seguridad #$idManagement.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getSegurityManagements($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);
- }
- $securityManagements = DB::table('S002V01TGESE')->select([
- 'GESE_IDGS AS ID_GERENCIA_SEGURIDAD',
- 'GESE_LAD1 AS LADA_TELEFONO_PRINCIPAL',
- 'GESE_TEL1 AS TELEFONO_PRINCIPAL',
- 'GESE_EXT1 AS EXTENSION_TELEFONO_PRINCIPAL',
- 'GESE_LAD2 AS LADA_TELEFONO_SECUNDARIO',
- 'GESE_TEL2 AS TELEFONO_SECUNDARIO',
- 'GESE_EXT2 AS EXTENSION_TELEFONO_SECUNDARIO',
- 'GESE_COEL AS CORREO_GERENCIA',
- 'GESE_GERE AS GERENTE',
- 'GESE_ESTA AS ESTADO',
- 'GESE_USRE AS USUREG',
- 'GESE_FERE AS FECREG',
- 'GESE_USMO AS USUMOD',
- 'GESE_FEMO AS FECMOD'
- ])->where('GESE_NULI', '=', $line)->get()->all();
- foreach($securityManagements as $key=>$item){
- $workOrders = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $line],
- ['OTCO_GESE', '=', $item->ID_GERENCIA_SEGURIDAD]
- ])->get()->all();
-
- $item->NUMERO_ORDENES = count($workOrders);
- $item->ID_GERENCIA_SEGURIDAD = $this->encryptionController->encrypt($item->ID_GERENCIA_SEGURIDAD);
- $manager = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item->GERENTE]
- ])->first();
- $managerName = $this->functionsController->joinName($manager->USUA_NOMB, $manager->USUA_APPA, $manager->USUA_APMA);
- $item->GERENTE = $managerName . " (" . $item->GERENTE . ")";
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item->USUREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $item->USUREG = $usrRegName . " (" . $item->USUREG . ")";
- if(!is_null($item->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item->USUMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $item->USUMOD = $usrModName . " (" . $item->USUMOD . ")";
- }
- $securityManagements[$key] = $item;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P02GSAU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las gerencias de seguridad registradas.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $securityManagements);
- }
- public function getSecurityManagement($idManagement, $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);
- }
- $idManagement = $this->encryptionController->decrypt($idManagement);
- if(!$idManagement){
- return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
- }
- $management = DB::table('S002V01TGESE')->select([
- 'GESE_IDGS AS ID_GERENCIA_SEGURIDAD',
- 'GESE_LAD1 AS LADA_TELEFONO_PRINCIPAL',
- 'GESE_TEL1 AS TELEFONO_PRINCIPAL',
- 'GESE_EXT1 AS EXTENSION_TELEFONO_PRINCIPAL',
- 'GESE_LAD2 AS LADA_TELEFONO_SECUNDARIO',
- 'GESE_TEL2 AS TELEFONO_SECUNDARIO',
- 'GESE_EXT2 AS EXTENSION_TELEFONO_SECUNDARIO',
- 'GESE_COEL AS CORREO_GERENCIA',
- 'GESE_GERE AS GERENTE',
- 'GESE_ESTA AS ESTADO',
- 'GESE_USRE AS USUREG',
- 'GESE_FERE AS FECREG',
- 'GESE_USMO AS USUMOD',
- 'GESE_FEMO AS FECMOD'
- ])->where([
- ['GESE_NULI', '=', $line],
- ['GESE_IDGS', '=', $idManagement]
- ])->first();
- if(is_null($management)){
- return $this->responseController->makeResponse(true, 'La gerencia de seguridad consultada no está registrada.', [], 404);
- }
- $workOrders = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS ID_ORDEN'
- ])->where([
- ['OTCO_NULI', '=', $line],
- ['OTCO_GESE', '=', $idManagement]
- ])->get()->all();
- foreach($workOrders as $key=>$order){
- $order->ID_ORDEN = $this->encryptionController->encrypt($order->ID_ORDEN);
- $workOrders[$key] = $order;
- }
- $management->ORDENES_TRABAJO = $workOrders;
- $management->ID_GERENCIA_SEGURIDAD = $this->encryptionController->encrypt($management->ID_GERENCIA_SEGURIDAD);
- $manager = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $management->GERENTE]
- ])->first();
- $managerName = $this->functionsController->joinName($manager->USUA_NOMB, $manager->USUA_APPA, $manager->USUA_APMA);
- $management->GERENTE = $managerName . " (" . $management->GERENTE . ")";
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $management->USUREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $management->USUREG = $usrRegName . " (" . $management->USUREG . ")";
- if(!is_null($management->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $management->USUMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $management->USUMOD = $usrModName . " (" . $management->USUMOD . ")";
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P02GSAU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la gerencias de seguridad #$idManagement.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $management);
- }
- public function updateSecurityManagement(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'lada1' => 'required|string|max:8',
- 'phone1' => 'required|string|min:10|max:11',
- 'ext1' => 'string|max:5',
- 'lada2' =>'string|max:8',
- 'phone2' => 'string|min:10|max:11',
- 'ext2' => 'string|max:5',
- 'email' => 'required|string|max:150',
- 'id_manager' => 'required|string',
- 'id_management' => '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);
- }
- $idManagement = $this->encryptionController->decrypt($form['id_management']);
- if(!$idManagement){
- return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
- }
- $management = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->first();
- if(is_null($management)){
- return $this->responseController->makeResponse(true, 'La gerencia de seguridad consultada no está registrada.', [], 404);
- }
- $idManager = $this->encryptionController->decrypt($form['id_manager']);
- if(!$idManager){
- return $this->responseController->makeResponse(true, 'El ID del gerente no fue encriptado correctamente.', [], 400);
- }
- $manager = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idManager]
- ])->first();
-
- if(is_null($manager)){
- return $this->responseController->makeResponse(true, 'El usuario seleccionado como gerente no existe.', [], 404);
- }
- $email = $form['email'];
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
- return $this->responseController->makeResponse(true, 'El formato del correo electrónico enviado es inválido.', [], 400);
- }
- $emailVerified = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_COEL', '=', $email],
- ['GESE_IDGS', '!=', $idManagement]
- ])->get()->all();
- if(count($emailVerified) > 0){
- return $this->responseController->makeResponse(true, 'El correo electrónico enviado ya ha sido registrado.', [], 400);
- }
- $lada1 = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_LADA', '=', $form['lada1']]
- ])->first();
-
- if(is_null($lada1)){
- return $this->responseController->makeResponse(true, 'La lada seleccionada para el teléfono principal es inválida.', [], 400);
- }else if(!$this->functionsController->validPhoneNumber($form['phone1'])){
- return $this->responseController->makeResponse(true, 'El número de teléfono principal es inválido.', [], 400);
- }else if(isset($form['ext1']) && !is_numeric($form['ext1'])){
- return $this->responseController->makeResponse(true, 'La extensión de teléfono principal es inválida.', [], 400);
- }
- $ext1 = isset($form['ext1']) ? $form['ext1']: null;
- $lad2 = null;
- $tel2 = null;
- $ext2 = null;
- if(isset($form['lada2']) || isset($form['phone2'])){
- if(!isset($form['lada2']) || !isset($form['phone2'])){
- if(!isset($form['lada2'])){
- return $this->responseController->makeResponse(true, 'La lada del teléfono secundario es obligatoria cuando se envía el teléfono o la extensión secundarios', [], 400);
- }
- if(!isset($form['phone2'])){
- return $this->responseController->makeResponse(true, 'El teléfono secundario es obligatorio cuando se envía la lada o la extensión secundarias', [], 400);
- }
- }
- $lada2 = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_LADA', '=', $form['lada2']]
- ])->first();
-
- if(is_null($lada2)){
- return $this->responseController->makeResponse(true, 'La lada seleccionada para el teléfono secundario es inválida.', [], 400);
- }else if(!$this->functionsController->validPhoneNumber($form['phone2'])){
- return $this->responseController->makeResponse(true, 'El número de teléfono secundario es inválido.', [], 400);
- }else if(isset($form['ext2']) && !is_numeric($form['ext2'])){
- return $this->responseController->makeResponse(true, 'La extensión de teléfono secundario es inválida.', [], 400);
- }
- $lad2 = $form['lada2'];
- $tel2 = $form['phone2'];
- $ext2 = isset($form['ext2']) ? $form['ext2'] : null;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->update([
- 'GESE_LAD1' => $form['lada1'],
- 'GESE_TEL1' => $form['phone1'],
- 'GESE_EXT1' => $ext1,
- 'GESE_LAD2' => $lad2,
- 'GESE_TEL2' => $tel2,
- 'GESE_EXT2' => $ext2,
- 'GESE_COEL' => $email,
- 'GESE_GERE' => $idManager,
- 'GESE_USMO' => $idUser,
- 'GESE_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P02GSAU',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la gerencia de seguridad #$idManagement.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteSecurityManagement(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_management' => '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);
- }
- $idManagement = $this->encryptionController->decrypt($form['id_management']);
- if(!$idManagement){
- return $this->responseController->makeResponse(true, 'El ID de la gerencia de seguridad no está encriptado correctamente', [], 400);
- }
- $management = DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->first();
- if(is_null($management)){
- return $this->responseController->makeResponse(true, 'La gerencia de seguridad consultada no está registrada.', [], 404);
- }
- $workOrders = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS ID_ORDEN'
- ])->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_GESE', '=', $idManagement],
- ['OTCO_ESOR', '!=', 'EL'],
- ])->get()->all();
- if(count($workOrders) > 0){
- return $this->responseController->makeResponse(true, 'La gerencia no se puede eliminar porque tiene órdenes de trabajo relacionadas.', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGESE')->where([
- ['GESE_NULI', '=', $form['linea']],
- ['GESE_IDGS', '=', $idManagement]
- ])->update([
- 'GESE_ESTA' => 'Eliminado',
- 'GESE_USMO' => $idUser,
- 'GESE_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P02GSAU',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la gerencia de seguridad #$idManagement.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerBlock(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'blocked' => 'required|string',
- 'type' => 'required|string|in:USR,SUB'
- ]);
-
- 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);
- }
- $idBlocked = $this->encryptionController->decrypt($form['blocked']);
- if(!$idBlocked){
- return $this->responseController->makeResponse(true, 'El ID que desea bloquear no fue encriptado correctamente.', [], 400);
- }
- $blockedTypes = ['USR' => 'Empleado', 'SUB' => 'Subcontratista'];
- $blockedType = $blockedTypes[$form['type']];
- if($blockedType == 'Empleado'){
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_IDPE', '=', $idBlocked],
- ['PERS_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado que desea bloquear no está registrado.', [], 404);
- }
- }else{
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $idBlocked]
- ])->first();
-
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, 'El subcontratista que desea bloquear no está registrado.', [], 404);
- }
- }
- $checkStatus = DB::table('S002V01TBIBL')->where([
- ['BIBL_NULI', '=', $form['linea']],
- ['BIBL_BLOQ', '=', $idBlocked],
- ['BIBL_TIBL', '=', $blockedType],
- ['BIBL_ESTA', '=', 'Activo']
- ])->get()->all();
- if(count($checkStatus)){
- return $this->responseController->makeResponse(true, "El $blockedType que desea bloquear ya se encuentra bloqueado.", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TBIBL')->insert([
- 'BIBL_NULI' => $form['linea'],
- 'BIBL_BLOQ' => $idBlocked,
- 'BIBL_TIBL' => $blockedType,
- 'BIBL_USRE' => $idUser,
- 'BIBL_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P04REBL',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") bloqueó al $blockedType #$idBlocked.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getBlockRegisters($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);
- }
- $blockRegisters = DB::table('S002V01TBIBL')->select([
- 'BIBL_IDBL AS ID_BLOQUEO',
- 'BIBL_BLOQ AS BLOQUEADO',
- 'BIBL_TIBL AS TIPO_BLOQUEADO',
- 'BIBL_ESTA AS ESTADO',
- 'BIBL_USRE AS USUREG',
- 'BIBL_FERE AS FECREG',
- 'BIBL_USMO AS USUMOD',
- 'BIBL_FEMO AS FECMOD'
- ])->where('BIBL_NULI', '=', $line)->get()->all();
- foreach($blockRegisters as $key=>$register){
- $register->ID_BLOQUEO = $this->encryptionController->encrypt($register->ID_BLOQUEO);
- if($register->TIPO_BLOQUEADO == 'Subcontratista'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $register->BLOQUEADO]
- ])->first();
- $register->BLOQUEADO = $subcontratist->PESU_RASO . " (" . $subcontratist->PESU_REFI . ") (" . $register->BLOQUEADO . ")";
- }else{
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $register->BLOQUEADO]
- ])->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->first();
- $employeeName = $this->functionsController->joinName($employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA);
- $register->BLOQUEADO = $employeeName . " (" . $register->BLOQUEADO . ")";
- }
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $register->USUREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $register->USUREG = $usrRegName . " (" . $register->USUREG . ")";
- if(!is_null($register->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $register->USUMOD]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $register->USUMOD = $usrModName . " (" . $register->USUMOD . ")";
- }
- $blockRegisters[$key] = $register;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P03BLOQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los bloqueos registrados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $blockRegisters);
- }
- public function unblockRegister(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_register' => '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);
- }
- $idBlocked = $this->encryptionController->decrypt($form['id_register']);
- if(!$idBlocked){
- return $this->responseController->makeResponse(true, 'El ID del bloqueo no fue encriptado correctamente.', [], 400);
- }
- $register = DB::table('S002V01TBIBL')->where([
- ['BIBL_NULI', '=', $form['linea']],
- ['BIBL_IDBL', '=', $idBlocked]
- ])->first();
-
- if(is_null($register)){
- return $this->responseController->makeResponse(true, 'El bloqueo que desea revocar no está registrado.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TBIBL')->where([
- ['BIBL_NULI', '=', $form['linea']],
- ['BIBL_IDBL', '=', $idBlocked]
- ])->update([
- 'BIBL_ESTA' => 'Anulado',
- 'BIBL_USMO' => $idUser,
- 'BIBL_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F03GESE',
- 'S002V01P04REBL',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") anuló el bloqueo #$idBlocked.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getWorkOrderStatusHistory($idOrder, $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);
- }
- $idOrder = $this->encryptionController->decrypt($idOrder);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden solicitada no está encriptado correctamente', [], 400);
- }
- $order = DB::table('S002V01TOTCO')->select([
- 'OTCO_HIES AS HISTORIAL',
- ])->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $line]
- ])->first();
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden solicitada no está registrada.', [], 404);
- }
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
- $statusHistoryArr = json_decode($order->HISTORIAL, true);
- foreach($statusHistoryArr as $key=>$item){
- $item['ESTADO'] = $orderStates[$item['ESTADO']];
- $usrSta = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item['USUARIO']]
- ])->first();
- $usrStaName = $this->functionsController->joinName($usrSta->USUA_NOMB, $usrSta->USUA_APPA, $usrSta->USUA_APMA);
- $item['USUARIO'] = $usrStaName . " (" . $item['USUARIO'] . ")";
- $statusHistoryArr[$key] = $item;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F01GEOT',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el historial de estados de la orden #$idOrder de mantenimiento correctivo.",
- $idUser,
- $nowStr,
- 'S002V01S03PRIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $statusHistoryArr);
- }
- public function generateReport(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'report_type' => 'required|string|in:TODAS,MANUA,AUTOM,ESTAD',
- 'start_date' => 'date',
- 'end_date' => 'date',
- 'order_state' => 'required_if:report_type,=,ESTAD|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);
- }
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
- $ordersBuilder = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS ID_ORDEN',
- 'OTCO_IDUR AS USUARIO_RESPONSABLE',
- 'OTCO_TURE AS TIPO_USUARIO_RESPONSABLE',
- 'OTCO_DEIN AS DESCRIPCION',
- 'OTCO_EQIN AS EQUIPAMIENTO',
- 'OTCO_FIFA AS FECHA_REGISTRO_FALLA',
- 'OTCO_TESO AS TIEMPO_ESTIMADO',
- 'OTCO_CORE AS CONTADOR',
- 'OTCO_DRCO AS MEDIDA_REGISTRADA',
- 'OTCO_PRIO AS PRIORIDAD',
- 'OTCO_FTIN AS FECHA_FINALIZACION',
- 'OTCO_DTIN AS DURACION_TOTAL',
- 'OTCO_RHUT AS RECURSOS',
- 'OTCO_PEIN AS PERSONAL',
- 'OTCO_TIAC AS TIPO_ACTIVACION',
- 'OTCO_ANCO AS ANALISIS_COSTOS',
- 'OTCO_DORE AS DOCUMENTOS',
- 'OTCO_CLAS AS CLASIFICACION',
- 'OTCO_COME AS COMENTARIOS',
- 'OTCO_GESE AS GERENCIA_SGURIDAD',
- 'OTCO_HIES AS HISTORIAL_ESTADOS',
- 'OTCO_ESOR AS ESTADO',
- 'OTCO_USRE AS USUREG',
- 'OTCO_FERE AS FECREG',
- 'OTCO_USMO AS USUMOD',
- 'OTCO_FEMO AS FECMOD'
- ])->where('OTCO_NULI', '=', $form['linea']);
- if(isset($form['start_date'])){
- $ordersBuilder->where('OTCO_FERE', '>=', $form['start_date']);
- }
- if(isset($form['end_date'])){
- $ordersBuilder->where('OTCO_FERE', '<=', $form['end_date']);
- }
-
- $orderStates = [
- 'PE' => 'Pendiente', 'VA' => 'Validado', 'RE' => 'Rechazado',
- 'EP' => 'En progreso', 'CE' => 'Cerrado', 'CP' => 'Cerrado pendiente',
- 'CA' => 'Cancelado', 'EL' => 'Eliminado'
- ];
- if(isset($form['order_state']) && !array_key_exists($form['order_state'], $orderStates)){
- return $this->responseController->makeResponse(true, 'El estado solicitado para las órdenes de mantenimiento correctivo es inválido.', [], 400);
- }else if(isset($form['order_state']) && array_key_exists($form['order_state'], $orderStates)){
- $ordersBuilder->where('OTCO_ESOR', '=', $form['order_state']);
- }
- if($form['report_type'] == 'MANUA'){
- $ordersBuilder->where('OTCO_TIAC', '=', 'M');
- }
- if($form['report_type'] == 'AUTOM'){
- $ordersBuilder->where('OTCO_TIAC', '=', 'A');
- }
- $workOrders = $ordersBuilder->get()->all();
- foreach($workOrders as $order){
- $order->ID_ORDEN = "#" . $order->ID_ORDEN;
- if($order->TIPO_USUARIO_RESPONSABLE == 'S'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $order->USUARIO_RESPONSABLE]
- ])->first();
- $order->USUARIO_RESPONSABLE = $subcontratist->PESU_RASO . " (" . $subcontratist->PESU_REFI . ") (" . $subcontratist->PESU_IDPS . ")";
- $order->TIPO_USUARIO_RESPONSABLE = 'Subcontratista';
- }else if($order->TIPO_USUARIO_RESPONSABLE == 'U'){
- $usrResp = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $order->USUARIO_RESPONSABLE]
- ])->first();
-
- $nameUsrResp = $this->functionsController->joinName($usrResp->USUA_NOMB, $usrResp->USUA_APPA, $usrResp->USUA_APMA);
- $order->USUARIO_RESPONSABLE = $nameUsrResp . " (" . $order->USUARIO_RESPONSABLE . ")";
- $order->TIPO_USUARIO_RESPONSABLE = 'Empleado';
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $order->EQUIPAMIENTO]
- ])->first();
- $order->EQUIPAMIENTO = $order->EQUIPAMIENTO . ' - ' . $equipment->EQUI_TIPO . ' - ' . $equipment->EQUI_MODE . ' (' . $equipment->EQUI_IDEQ . ')';
- $order->FECHA_REGISTRO_FALLA = $this->functionsController->formatDateTime($order->FECHA_REGISTRO_FALLA);
- $order->TIEMPO_ESTIMADO = $order->TIEMPO_ESTIMADO . "h";
- $counterActivator = DB::table('S002V01TACTI')->where([
- ['ACTI_NULI', '=', $form['linea']],
- ['ACTI_CORE', '=', $order->CONTADOR]
- ])->first();
- $measureArr = json_decode($order->MEDIDA_REGISTRADA, true);
- $activationConfig = json_decode($counterActivator->ACTI_COAC, true);
- if($counterActivator->ACTI_TIAC == 'Medida' || $counterActivator->ACTI_TIAC == 'Valor'){
- $unit = DB::table('S002V01TLIME')->where([
- ['LIME_IDME', '=', $activationConfig['unit']],
- ['LIME_MAGN', '=', $activationConfig['magnitude']],
- ])->first();
- $order->MEDIDA_REGISTRADA = "Medida #" . $measureArr['ID_MEDIDA'] . ". Valor registrado: " . $measureArr['VALOR'] .
- ' ' . $unit->LIME_ACME . ". Fecha de registro: " . $this->functionsController->formatDateTime($measureArr['HORA_REGISTRO']) .
- ". Servicio web de recepción: " . $measureArr['URL_SERVICIO_WEB'] . " (" . $measureArr['ID_SERVICIO_WEB'] . ")";
- }else if($counterActivator->ACTI_TIAC == 'Sintoma'){
- $symptom = DB::table('S002V01TLISI')->where([
- ['LISI_IDSI', '=', $activationConfig['sign']],
- ['LISI_NULI', '=', $form['linea']]
- ])->first();
- $unit = DB::table('S002V01TLIME')->where([
- ['LIME_IDME', '=', $symptom->LISI_IDME],
- ['LIME_MAGN', '=', $activationConfig['magnitude']],
- ])->first();
- $order->MEDIDA_REGISTRADA = "Medida #" . $measureArr['ID_MEDIDA'] . ". Valor registrado: " . $measureArr['VALOR'] .
- ' ' . $unit->LIME_ACME . ". Fecha de registro: " . $this->functionsController->formatDateTime($measureArr['HORA_REGISTRO']) .
- ". Servicio web de recepción: " . $measureArr['URL_SERVICIO_WEB'] . " (" . $measureArr['ID_SERVICIO_WEB'] . ")";
- }else{
- $order->MEDIDA_REGISTRADA = 'No aplica';
- }
- $order->CONTADOR = "#" . $order->CONTADOR;
- $orderPriorities = $paramsArr['order_priorities'];
- $priorityFilt = array_filter($orderPriorities, function($v, $k) use($order) {
- return $v['value'] == $order->PRIORIDAD;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($priorityFilt) < 1){
- $order->PRIORIDAD = 'Desconocido';
- }else{
- $priority = end($priorityFilt);
- $order->PRIORIDAD = $priority['label'] . " (" . $order->PRIORIDAD . ")";
- }
- if(is_null($order->FECHA_FINALIZACION)) {
- $order->FECHA_FINALIZACION = '-';
- }else{
- $order->FECHA_FINALIZACION = $this->functionsController->formatDateTime($order->FECHA_FINALIZACION);
- }
- if(is_null($order->DURACION_TOTAL)) {
- $order->DURACION_TOTAL = '-';
- }else{
- $order->DURACION_TOTAL = $order->DURACION_TOTAL . "h";
- }
- $resourcesArr = json_decode($order->RECURSOS, true);
- if(count($resourcesArr) < 1){
- $order->RECURSOS = 'Ninguno';
- }else{
- //Pendiente procesar los recursos
- }
- $staffArr = json_decode($order->PERSONAL, true);
- $staffStr = "";
- foreach($staffArr as $item){
- if($item['TYPE'] == 'EQ'){
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $item['ID']],
- ['EQMA_NULI', '=', $form['linea']]
- ])->first();
- $staffStr .= "equipo de trabajo " . $workTeam->EQMA_NOMB . " (" . $item['ID'] . "), ";
- }else if($item['TYPE'] == 'SU'){
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $item['ID']],
- ['PESU_NULI', '=', $form['linea']]
- ])->first();
- $staffStr .= "subcontratista " . $subcontratist->PESU_RASO . " (" . $subcontratist->PESU_REFI . ") (" . $item['ID'] . "), ";
- }else if($item['TYPE'] == 'EM'){
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_IDPE', '=', $item['ID']],
- ['PERS_NULI', '=', $form['linea']]
- ])->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->first();
- $employeeName = $this->functionsController->joinName($employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA);
- $staffStr .= "empleado " . $employeeName . " (" . $item['ID'] . "), ";
- }
- }
- $staffStr = substr($staffStr, 0, -2);
- $staffStr = ucfirst($staffStr);
-
- $order->PERSONAL = $staffStr;
- $order->TIPO_ACTIVACION = $order->TIPO_ACTIVACION == 'M' ? 'Manual' : 'Automática';
- if(is_null($order->ANALISIS_COSTOS)){
- $order->ANALISIS_COSTOS = 'Sin asignar';
- }else{
- //Pendiente revisar el análisis de costos
- }
- $documentsArr = json_decode($order->DOCUMENTOS, true);
- $documentsStr = "";
- if(count($documentsArr) < 1){
- $documentsStr = 'Ninguno';
- }else{
- foreach($documentsArr as $document){
- $documentsStr .= $document . ", ";
- }
- $documentsStr = substr($documentsStr, 0, -2);
- }
- $order->DOCUMENTOS = $documentsStr;
- if(is_null($order->COMENTARIOS)){
- $order->COMENTARIOS = 'Sin comentarios';
- }
- $order->GERENCIA_SGURIDAD = "Gerencia #" . $order->GERENCIA_SGURIDAD;
- $statusHistoryArr = json_decode($order->HISTORIAL_ESTADOS, true);
- $statusHistoryStr = "";
- foreach($statusHistoryArr as $item){
- $statusHistoryStr .= $orderStates[$item['ESTADO']] . ' - ' . $this->functionsController->formatDateTime($item['FECHA']);
- $usrState = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $item['USUARIO']],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- $usrStateName = $this->functionsController->joinName($usrState->USUA_NOMB, $usrState->USUA_APPA, $usrState->USUA_APMA);
- $statusHistoryStr .= ' - ' . $usrStateName . ' (' . $item['USUARIO'] . '), ';
- }
- $statusHistoryStr = substr($statusHistoryStr, 0, -2);
- $order->HISTORIAL_ESTADOS = $statusHistoryStr;
- $order->ESTADO = $orderStates[$order->ESTADO];
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->USUREG],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $order->USUREG = $usrRegName . " (" . $order->USUREG . ")";
- $order->FECREG = $this->functionsController->formatDateTime($order->FECREG);
- if(!is_null($order->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $order->USUMOD],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $order->USUMOD = $usrModName . " (" . $order->USUMOD . ")";
- $order->FECMOD = $this->functionsController->formatDateTime($order->FECMOD);
- }else{
- $order->USUMOD = "-";
- $order->FECMOD = "-";
- }
- }
- $document = $this->reportWorkOrders($workOrders);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
-
- $dateTimeArr = explode(" ", $nowStr);
- $dateArr = explode("-", $dateTimeArr[0]);
- $year = substr($dateArr[0], 2);
- $como = 'GMCO';
- $cldo = 'IN';
- $fecr = $year . $dateArr[1] . $dateArr[2];
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['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_ordenes_mantenimiento_correctivo_$timestamp";
- $exte = "xlsx";
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['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 = $form['linea'] < 10 ? "0$form[linea]" : "$form[linea]";
- $filePath = 'C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\public_files\\';
- $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
-
- $tempFile = $filePath . $fileName;
- if(file_exists($tempFile)){
- unlink($tempFile);
- }
- $writer = IOFactory::createWriter($document, 'Xlsx');
- $writer->save($tempFile);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\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,
- ]);
- $idReport = DB::table('S002V01TIMCO')->insertGetId([
- 'IMCO_NULI' => $form['linea'],
- 'IMCO_TIIN' => $form['report_type'],
- 'IMCO_DORE' => $fileName,
- 'IMCO_USRE' => $idUser,
- 'IMCO_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02PRIN',
- 'S002V01P01REIN',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el informe #$idReport.",
- $idUser,
- $nowStr,
- 'S002V01S03PRIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.', ['report' => $this->encryptionController->encrypt($fileName)]);
- }
- private function reportWorkOrders($workOrders) : Spreadsheet {
- $spreadsheet = new Spreadsheet;
- $spreadsheet->getProperties()
- ->setCreator('STC')
- ->setTitle('Historial de órdenes de trabajo de mantenimiento correctivo.')
- ->setSubject('Historial documento')
- ->setKeywords('Historial Órdenes Mantenimiento Correctivo')
- ->setCategory('Historial archivo');
- $worksheet = $spreadsheet->getActiveSheet();
- $worksheet->setTitle('ÓRDENES DE MANT CORRECTIVO');
- $columns = ['# ORDEN', 'RESPONSABLE', 'TIPO DE USUARIO RESPONSABLE', 'DESCRIPCIÓN', 'EQUIPAMIENTO', 'FECHA Y HORA DE REGISTRO DE LA FALLA',
- 'TIEMPO ESTIMADO DE DURACIÓN DE LA INTERVENCIÓN', 'CONTADOR RELACIONADO', 'MEDIDA REGISTRADA AL MOMENTO DE LA FALLA', 'PRIORIDAD',
- 'FECHA DE FINALIZACIÓN DE LA INTERVENCIÓN', 'DURACIÓN TOTAL DE LA INTERVENCIÓN', 'CONSUMIBLES UTILIZADOS', 'PERSONAL INVOLUCRADO',
- 'TIPO DE ACTIVACIÓN', 'ANÁLISIS DE COSTOS', 'DOCUMENTOS REQUERIDOS', 'CLASIFICACIÓN', 'COMENTARIOS REALIZADOS DURANTE LA INTERVENCIÓN',
- 'GERENCIA DE SEGURIDAD RELACIONADA', 'HISTORIAL DE ESTADOS', 'ESTADO DE LA ORDEN', 'USUARIO DE REGISTRO', 'FECHA DE REGISTRO', 'USUARIO DE ACTIALIZACIÓN',
- 'FECHA DE ACTUALIZACIÓN'];
-
- $startRow = 2;
- $startCol = 2;
- $maxRow = $startRow + count($workOrders) + 1;
- $maxCol = $startCol + count($columns) - 1;
- for($row = $startRow; $row <= $maxRow; $row++){
- $startColStr = Coordinate::stringFromColumnIndex($startCol);
- $maxColStr = Coordinate::stringFromColumnIndex($maxCol);
- if($row == 2){
- $worksheet->mergeCells($startColStr . $row . ':' . $maxColStr . $row);
- $worksheet->setCellValue($startColStr . $row, 'INFORME DE ÓRDENES DE MANTENIMIENTO CORRECTIVO')->getStyle($startColStr . $row)->getFill()
- ->setFillType(Fill::FILL_SOLID)
- ->getStartColor()->setRGB('B7BCC4');
- $worksheet->getStyle($startColStr . $row)->getFont()->setBold(true);
- $worksheet->getStyle($startColStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }else if($row == 3){
- for($col = $startCol; $col <= $maxCol; $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $colInd = $col - 2;
- $column = $columns[$colInd];
- $worksheet->setCellValue($colStr . $row, $column);
- $worksheet->getStyle($colStr . $row)->getFont()->setBold(true);
- $worksheet->getStyle($colStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }
- }else if($row > 3){
- $rowInd = $row - 4;
- $order = (array) $workOrders[$rowInd];
- $keys = array_keys($order);
- for($col = $startCol; $col <= $maxCol; $col++){
- $colInd = $col - 2;
- $key = $keys[$colInd];
- $value = $order[$key];
- $colStr = Coordinate::stringFromColumnIndex($col);
- if($key == 'ID_ORDEN' || $key == 'TIEMPO_ESTIMADO' || $key == 'CONTADOR' ||
- $key == 'DURACION_TOTAL' || $key == 'GERENCIA_SGURIDAD'){
- $worksheet->getStyle($colStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- $worksheet->getColumnDimension($colStr)->setAutoSize(true);
- }else if($key == 'EQUIPAMIENTO' || $key == 'DESCRIPCION' || $key == 'MEDIDA_REGISTRADA' ||
- $key == 'PERSONAL' || $key == 'DOCUMENTOS' || $key == 'COMENTARIOS' || $key == 'HISTORIAL_ESTADOS'){
- $worksheet->getColumnDimension($colStr)->setWidth(48);
- $worksheet->getStyle($colStr . $row)->getAlignment()->setWrapText(true);
- }else{
- $worksheet->getColumnDimension($colStr)->setAutoSize(true);
- }
- $worksheet->getStyle($colStr . $row)->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
- $worksheet->setCellValue($colStr . $row, $value);
- }
- }
- }
- return $spreadsheet;
- }
- public function getReports($type, $startDate, $endDate, $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);
- }
- $reportsBuilder = DB::table('S002V01TIMCO')->select([
- 'IMCO_IDIN AS ID_INFORME',
- 'IMCO_TIIN AS TIPO_INFORME',
- 'IMCO_DORE AS DOCUMENTO',
- 'IMCO_USRE AS USUREG',
- 'IMCO_FERE AS FECREG'
- ])->where('IMCO_NULI', '=', $line);
- if($type != '-'){
- $validReports = ['TODAS','MANUA','AUTOM','ESTAD'];
- if(!in_array($type, $validReports)){
- return $this->responseController->makeResponse(true, "El tipo de reportes solicitado es inválido.", [], 400);
- }
- $reportsBuilder->where('IMCO_TIIN', '=', $type);
- }
- if($startDate != '-'){
- $startDateArr = explode('-', $startDate);
- if(count($startDateArr) != 3){
- return $this->responseController->makeResponse(true, 'La fecha de inicio tiene un formato inválido.', [], 400);
- }
-
- try{
- $startDateObj = new Carbon($startDate);
- }catch(InvalidFormatException $e){
- return $this->responseController->makeResponse(true, "La fecha de inicio tiene un formato inválido: " . $e->getMessage(), [], 400);
- }
-
- $startDate = $startDateObj->toDateTimeString();
- $reportsBuilder->where('IMCO_FERE', '>=', $startDate);
- }
- if($endDate != '-'){
- $endDateArr = explode('-', $endDate);
- if(count($endDateArr) != 3){
- return $this->responseController->makeResponse(true, 'La fecha final tiene un formato inválido.', [], 400);
- }
-
- try{
- $endDateObj = new Carbon($endDate);
-
- $endDateObj->addDay();
- $endDateObj->subSecond();
- }catch(InvalidFormatException $e){
- return $this->responseController->makeResponse(true, "La fecha final tiene un formato inválido: " . $e->getMessage(), [], 400);
- }
-
- $endDate = $endDateObj->toDateTimeString();
- $reportsBuilder->where('IMCO_FERE', '<=', $endDate);
- }
- $reports = $reportsBuilder->get()->all();
- foreach($reports as $key=>$report){
- $report->ID_INFORME = $this->encryptionController->encrypt($report->ID_INFORME);
- $report->DOCUMENTO = $this->encryptionController->encrypt($report->DOCUMENTO);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $report->USUREG],
- ['USUA_NULI', '=', $line]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $report->USUREG = $usrRegName . " (" . $report->USUREG . ")";
- $reports[$key] = $report;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F02PRIN',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los informes de tipo $type.",
- $idUser,
- $nowStr,
- 'S002V01S03PRIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $reports);
- }
- public function registerMaintnencePlan(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'equipment' => 'required|string',
- 'equipment_status' => 'required|string|in:DE,DP,EF',
- 'lru' => 'string',
- 'lru_status' => 'string|in:DE,DP,EF',
- 'description' => 'required|string|min:15',
- 'inm_time' => 'required|numeric',
- 'priority' => 'required|string',
- 'total_duration' => 'required|numeric',
- 'classification' => 'required|string|max:100',
- 'specialties' => 'required|json',
- 'specialties_conf' => 'required|json',
- 'resources' => 'required|json',
- 'attached' => 'required|json',
- 'symptom' => 'required|string',
- 'scada' => '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);
- }
- $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
- if(!$equipmentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_COEQ', '=', $equipmentCode],
- ['EQUI_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
- }
- $lrui = null;
- $eflr = null;
- if(isset($form['lru'])){
- $lruCode = $this->encryptionController->decrypt($form['lru']);
- if(!$lruCode){
- return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
- }
- $lru = DB::table('S002V01TEQUI')->where([
- ['EQUI_COEQ', '=', $lruCode],
- ['EQUI_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($lru)){
- return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
- }
- if(!isset($form['lru_status'])){
- return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
- }
- $lrui = $lruCode;
- $eflr = $form['lru_status'];
- }
- $priorityDec = $this->encryptionController->decrypt($form['priority']);
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
- $orderPriorities = $paramsArr['order_priorities'];
- $priorityFilt = array_filter($orderPriorities, function($v, $k) use($priorityDec) {
- return $v['value'] == $priorityDec;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($priorityFilt) < 1){
- return $this->responseController->makeResponse(true, 'La prioridad seleccionada es inválida.', [], 400);
- }
- //PENDINTE REVISAR RECURSOS CON STOCK
- $attachedArr = json_decode($form['attached'], true);
- $attachedArrFn = [];
- foreach($attachedArr as $key=>$attached){
- $idDec = $this->encryptionController->decrypt($attached['id']);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idDec],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $attachedArrFn[] = [
- 'ID' => $finalFile[1],
- 'TYPE' => $attached['type']
- ];
- }
- }
- $idSymptom = $this->encryptionController->decrypt($form['symptom']);
- if(!$idSymptom){
- return $this->responseController->makeResponse(true, 'El ID del síntoma no fue encriptado correctamente.', [], 400);
- }
- $symptom = DB::table('S002V01TLISI')->where([
- ['LISI_NULI', '=', $form['linea']],
- ['LISI_IDSI', '=', $idSymptom],
- ])->first();
-
- if(is_null($symptom)){
- return $this->responseController->makeResponse(true, 'El síntoma relacionado no existe.', [], 404);
- }
- $idSCADA = $this->encryptionController->decrypt($form['scada']);
- if(!$idSCADA){
- return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
- }
- $scada = DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $idSCADA]
- ])->first();
-
- if(is_null($scada)){
- return $this->responseController->makeResponse(true, 'El SCADA relacionado no existe.', [], 404);
- }
- //Una vez que se aprueban los datos se registra el contador relacionado
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idCounter = DB::table('S002V01TCONA')->insertGetId([
- 'CONA_NULI' => $form['linea'],
- 'CONA_INLE' => 5,
- 'CONA_UTIL' => 'min',
- 'CONA_TOIN' => 1,
- 'CONA_UTTI' => 'min',
- 'CONA_IDSC' => $idSCADA,
- 'CONA_COEQ' => is_null($lrui) ? $equipmentCode : $lrui,
- 'CONA_COVI' => '[]',
- 'CONA_USRE' => $idUser,
- 'CONA_FERE' => $nowStr
- ]);
- $repeatStartDate = new Carbon($now->toDateString());
- $repeatStart = str_replace(' ', 'T', $repeatStartDate->toDateTimeString());
- $repeatHourDate = new Carbon($nowStr);
- $hour = $repeatHourDate->hour;
- $hourStr = "";
- $minute = $repeatHourDate->minute;
- $minuteStr = "";
- if($minute > 0 && $minute <= 15){
- $minuteStr = "15";
- $hourStr = $hour < 10 ? "0$hour" : "$hour";
- }else if($minute > 15 && $minute <= 30){
- $minuteStr = "30";
- $hourStr = $hour < 10 ? "0$hour" : "$hour";
- }else if($minute > 30 && $minute <= 45){
- $minuteStr = "45";
- $hourStr = $hour < 10 ? "0$hour" : "$hour";
- }else{
- $minuteStr = "00";
- $hourAux = $hour + 1;
- $hourStr = $hourAux < 10 ? "0$hourAux" : "$hourAux";
- }
- $repeatHourStr = "$hourStr:$minuteStr:00";
- $symptomRepeat = [
- 'sign' => $idSymptom,
- 'color' => 'rgb(79, 195, 255)',
- 'repeat' => 'TD',
- 'startDate' => "$repeatStart.000Z",
- 'startHour' => $repeatHourStr,
- 'customRepeat' => '',
- ];
- //Se procede a crear un activador relacionado al contador nuevo
- $symptomRepeatStr = json_encode($symptomRepeat);
- $idActivator = DB::table('S002V01TACTI')->insertGetId([
- 'ACTI_NULI' => $form['linea'],
- 'ACTI_PRIO' => $priorityDec,
- 'ACTI_TIAC' => 'Sintoma',
- 'ACTI_COAC' => $symptomRepeatStr,
- 'ACTI_CORE' => $idCounter,
- 'ACTI_USRE' => $idUser,
- 'ACTI_FERE' => $nowStr,
- ]);
-
- $specialtiesArr = json_decode($form['specialties'], true);
- $specialtiesDec = [];
- foreach($specialtiesArr as $specialty){
- $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
- }
- $specialtiesStr = json_encode($specialtiesDec);
- //Una vez obtenido el ID del nuevo contador relacionado se ingresa el plan de mantenimiento
- $come = isset($form['comments']) ? $form['comments'] : null;
- $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
- $dore = json_encode($attachedArrFn);
-
- $idPlan = DB::table('S002V01TPMCO')->insertGetId([
- 'PMCO_NULI' => $form['linea'],
- 'PMCO_EQIN' => $equipmentCode,
- 'PMCO_LRUI' => $lrui,
- 'PMCO_EFEQ' => $form['equipment_status'],
- 'PMCO_EFLR' => $eflr,
- 'PMCO_DESC' => $form['description'],
- 'PMCO_TIES' => $form['inm_time'],
- 'PMCO_DTIN' => $form['total_duration'],
- 'PMCO_CLAS' => $form['classification'],
- 'PMCO_ESRE' => $specialtiesStr,
- 'PMCO_COES' => $form['specialties_conf'],
- 'PMCO_COME' => $come,
- 'PMCO_RECU' => $form['resources'],
- 'PMCO_DEAD' => $dead,
- 'PMCO_DORE' => $dore,
- 'PMCO_CORE' => $idCounter,
- 'PMCO_USRE' => $idUser,
- 'PMCO_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02PLAN',
- 'S002V01P01ASPL',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el plan de mantenimiento correctivo #$idPlan.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.', [
- 'PLAN' => $this->encryptionController->encrypt($idPlan),
- 'ACTIVADOR' => $this->encryptionController->encrypt($idActivator),
- 'CONTADOR' => $this->encryptionController->encrypt($idCounter),
- ]);
- }
- public function getMaintenancePlans($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);
- }
- $plansList = DB::table('S002V01TPMCO')->select([
- 'PMCO_IDPM AS ID_PLAN',
- 'PMCO_EQIN AS EQUIPAMIENTO',
- 'PMCO_LRUI AS LRU',
- 'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
- 'PMCO_DTIN AS DURACION_TOTAL',
- 'PMCO_CLAS AS CLASIFICACION',
- 'PMCO_CORE AS CONTADOR',
- 'ACTI_IDAC AS ACTIVADOR',
- 'ACTI_PRIO AS PRIORIDAD',
- 'PMCO_ESTA AS ESTADO',
- 'PMCO_USRE AS USRREG',
- 'PMCO_FERE AS FECREG',
- 'PMCO_USMO AS USRMOD',
- 'PMCO_FEMO AS FECMOD',
- ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')->get()->all();
- foreach($plansList as $key=>$plan){
- $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
- ])->first();
- $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
- $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
- if(!is_null($plan->LRU)){
- $lru = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $plan->LRU]
- ])->first();
- $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
- $plan->LRU = $this->encryptionController->encrypt($lruLabel);
- }
-
- $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
- $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
- $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $plan->USRREG],
- ['USUA_NULI', '=', '1'],
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
- if(!is_null($plan->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $plan->USRMOD],
- ['USUA_NULI', '=', '1'],
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $plan->USRMOD = $usrModName . " (" . $plan->USRMOD . ")";
- }
- $plansList[$key] = $plan;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F02PLAN',
- 'S002V01P01ASPL',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los planes de mantenimiento registrados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $plansList);
- }
- public function getMaintenancePlan($idPlan, $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);
- }
- $idPlan = $this->encryptionController->decrypt($idPlan);
- if(!$idPlan){
- return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no está encriptado correctamente.', [], 400);
- }
- $plan = DB::table('S002V01TPMCO')->select([
- 'PMCO_IDPM AS ID_PLAN',
- 'PMCO_EQIN AS EQUIPAMIENTO',
- 'PMCO_LRUI AS LRU',
- 'PMCO_EFEQ AS ESTADO_FUNCIONAMIENTO_EQUIPAMIENTO',
- 'PMCO_EFLR AS ESTADO_FUNCIONAMIENTO_LRU',
- 'PMCO_DESC AS DESCRIPCION',
- 'PMCO_TIES AS TIEMPO_INMOVILIZACION_ESTIMADO',
- 'PMCO_DTIN AS DURACION_TOTAL',
- 'PMCO_CLAS AS CLASIFICACION',
- 'PMCO_ESRE AS ESPECIALIDADES_REQUERIDAS',
- 'PMCO_COES AS CONFIGURACION_OPERARIOS',
- 'PMCO_COME AS COMENTARIOS',
- 'PMCO_RECU AS RECURSOS',
- 'PMCO_DEAD AS DETALLES_ADICIONALES',
- 'PMCO_DORE AS DOCUMENTOS_RELACIONADOS',
- 'PMCO_CORE AS CONTADOR',
- 'CONA_IDSC AS SCADA',
- 'ACTI_IDAC AS ACTIVADOR',
- 'ACTI_PRIO AS PRIORIDAD',
- 'ACTI_COAC AS SINTOMA',
- 'PMCO_ESTA AS ESTADO',
- 'PMCO_USRE AS USRREG',
- 'PMCO_FERE AS FECREG',
- 'PMCO_USMO AS USRMOD',
- 'PMCO_FEMO AS FECMOD',
- ])->where([
- ['PMCO_NULI', '=', $line],
- ['PMCO_IDPM', '=', $idPlan]
- ])->join('S002V01TACTI', 'ACTI_CORE', '=', 'PMCO_CORE')
- ->join('S002V01TCONA', 'CONA_IDCO', '=', 'PMCO_CORE')->first();
- if(is_null($plan)){
- return $this->responseController->makeResponse(true, 'El plan solicitado no existe.', [], 404);
- }
- $plan->ID_PLAN = $this->encryptionController->encrypt($plan->ID_PLAN);
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $plan->EQUIPAMIENTO]
- ])->first();
- $equipmentLabel = $plan->EQUIPAMIENTO . " - " . $equipment->EQUI_TIPO . " - " . $equipment->EQUI_MODE . " (" . $equipment->EQUI_IDEQ . ")";
- $plan->EQUIPAMIENTO = $this->encryptionController->encrypt($equipmentLabel);
- if(!is_null($plan->LRU)){
- $lru = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $plan->LRU]
- ])->first();
- $lruLabel = $plan->LRU . " - " . $lru->EQUI_TIPO . " - " . $lru->EQUI_MODE . " (" . $lru->EQUI_IDEQ . ")";
- $plan->LRU = $this->encryptionController->encrypt($lruLabel);
- }
- $documentsArr = json_decode($plan->DOCUMENTOS_RELACIONADOS, true);
- $documentsFn = [];
- foreach($documentsArr as $document){
- $documentCodeArr0 = explode('=', $document['ID']);
- $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
- $documentObj = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $documentCodeArr1[1]],
- ['AFAL_CLDO', '=', $documentCodeArr1[2]],
- ['AFAL_FECR', '=', $documentCodeArr1[3]],
- ['AFAL_NUSE', '=', $documentCodeArr1[4]],
- ['AFAL_NUVE', '=', $documentCodeArr0[1]],
- ])->first();
- $documentsFn[] = [
- 'id' => $this->encryptionController->encrypt($document['ID']),
- 'name' => $document['ID'],
- 'size' => $documentObj->AFAL_TAMA,
- 'type' => $document['TYPE']
- ];
- }
- $plan->DOCUMENTOS_RELACIONADOS = json_encode($documentsFn);
- $plan->CONTADOR = $this->encryptionController->encrypt($plan->CONTADOR);
- $plan->SCADA = $this->encryptionController->encrypt($plan->SCADA);
- $plan->ACTIVADOR = $this->encryptionController->encrypt($plan->ACTIVADOR);
- $plan->PRIORIDAD = $this->encryptionController->encrypt($plan->PRIORIDAD);
- $activationConfig = json_decode($plan->SINTOMA, true);
- $plan->SINTOMA = $this->encryptionController->encrypt($activationConfig['sign']);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $plan->USRREG]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $plan->USRREG = $usrRegName . " (" . $plan->USRREG . ")";
- if(!is_null($plan->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $plan->USRMOD]
- ])->first();
-
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $plan->USRMOD = $usrModName . " (" . $plan->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,
- 'S002V01M09GMCO',
- 'S002V01F02PLAN',
- 'S002V01P01ASPL',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el plan de mantenimiento #$idPlan.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $plan);
- }
- public function updateMaintenancePlan(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_plan' => 'required|string',
- 'equipment' => 'required|string',
- 'equipment_status' => 'required|string|in:DE,DP,EF',
- 'lru' => 'string',
- 'lru_status' => 'string|in:DE,DP,EF',
- 'description' => 'required|string|min:15',
- 'inm_time' => 'required|numeric',
- 'total_duration' => 'required|numeric',
- 'classification' => 'required|string|max:100',
- 'specialties' => 'required|json',
- 'specialties_conf' => 'required|json',
- 'resources' => 'required|json',
- 'attached' => '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);
- }
- $idPlan = $this->encryptionController->decrypt($form['id_plan']);
- if(!$idPlan){
- return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
- }
- $plan = DB::table('S002V01TPMCO')->where([
- ['PMCO_NULI', '=', $form['linea']],
- ['PMCO_IDPM', '=', $idPlan]
- ])->first();
-
- if(is_null($plan)){
- return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
- }else if($plan->PMCO_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
- }
- $equipmentCode = $this->encryptionController->decrypt($form['equipment']);
- if(!$equipmentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_COEQ', '=', $equipmentCode],
- ['EQUI_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento relacionado no existe.', [], 404);
- }
- $lrui = null;
- $eflr = null;
- if(isset($form['lru'])){
- $lruCode = $this->encryptionController->decrypt($form['lru']);
- if(!$lruCode){
- return $this->responseController->makeResponse(true, 'El código del LRU no fue encriptado correctamente.', [], 400);
- }
- $lru = DB::table('S002V01TEQUI')->where([
- ['EQUI_COEQ', '=', $lruCode],
- ['EQUI_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($lru)){
- return $this->responseController->makeResponse(true, 'El LRU relacionado no existe.', [], 404);
- }
- if(!isset($form['lru_status'])){
- return $this->responseController->makeResponse(true, 'El estado del lru es obligatorio cuando se envía el campo lru.', [], 400);
- }
- $lrui = $lruCode;
- $eflr = $form['lru_status'];
- }
- $planCounter = DB::table('S002V01TCONA')->where([
- ['CONA_NULI', '=', $form['linea']],
- ['CONA_IDCO', '=', $plan->PMCO_CORE]
- ])->first();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $counterEquipment = $planCounter->CONA_COEQ;
-
- if(is_null($lrui) && $counterEquipment != $equipmentCode){
- DB::table('S002V01TCONA')->where([
- ['CONA_NULI', '=', $form['linea']],
- ['CONA_IDCO', '=', $plan->PMCO_CORE]
- ])->update([
- 'CONA_COEQ' => $equipmentCode,
- 'CONA_USMO' => $idUser,
- 'CONA_FEMO' => $nowStr
- ]);
- }else if($lrui != $counterEquipment){
- DB::table('S002V01TCONA')->where([
- ['CONA_NULI', '=', $form['linea']],
- ['CONA_IDCO', '=', $plan->PMCO_CORE]
- ])->update([
- 'CONA_COEQ' => $lrui,
- 'CONA_USMO' => $idUser,
- 'CONA_FEMO' => $nowStr
- ]);
- }
-
- $specialtiesArr = json_decode($form['specialties'], true);
- if(count($specialtiesArr) == 0){
- return $this->responseController->makeResponse(true, 'El arreglo de especialidades está vacío.', [], 400);
- }
- $specialtiesDec = [];
- foreach($specialtiesArr as $specialty){
- $specialtiesDec[] = $this->encryptionController->decrypt($specialty);
- }
- $specialtiesStr = json_encode($specialtiesDec);
- $attachedArr = json_decode($form['attached'], true);
- if(count($attachedArr) == 0){
- return $this->responseController->makeResponse(true, 'El arreglo de documentos está vacío.', [], 400);
- }
- $attachedArrFn = [];
- foreach($attachedArr as $key=>$attached){
- $idDec = $this->encryptionController->decrypt($attached['id']);
- if(!$idDec){
- return $this->responseController->makeResponse(true, "El ID del documento en la posición $key no fue encriptado correctamente.", [], 400);
- }
- if($attached['isFinalFile']){
- $documentCodeArr0 = explode('=', $idDec);
- $documentCodeArr1 = explode('-', $documentCodeArr0[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['AFAL_COMO', '=', $documentCodeArr1[1]],
- ['AFAL_CLDO', '=', $documentCodeArr1[2]],
- ['AFAL_FECR', '=', $documentCodeArr1[3]],
- ['AFAL_NUSE', '=', $documentCodeArr1[4]],
- ['AFAL_NUVE', '=', $documentCodeArr0[1]],
- ])->first();
-
- if(is_null($file)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
-
- $attachedArrFn[] = [
- 'ID' => $idDec,
- 'TYPE' => $attached['type']
- ];
- }else{
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idDec],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El documento en la posición $key no existe.", [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El documento en la posición $key está eliminado.", [], 404);
- }
-
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GMCO', 'OR', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $attachedArrFn[] = [
- 'ID' => $finalFile[1],
- 'TYPE' => $attached['type']
- ];
- }
- }
- }
-
- $come = isset($form['comments']) ? $form['comments'] : null;
- $dead = isset($form['extra_details']) ? $form['extra_details'] : null;
- $dore = json_encode($attachedArrFn);
- DB::table('S002V01TPMCO')->where([
- ['PMCO_NULI', '=', $form['linea']],
- ['PMCO_IDPM', '=', $idPlan]
- ])->update([
- 'PMCO_EQIN' => $equipmentCode,
- 'PMCO_LRUI' => $lrui,
- 'PMCO_EFEQ' => $form['equipment_status'],
- 'PMCO_EFLR' => $eflr,
- 'PMCO_DESC' => $form['description'],
- 'PMCO_TIES' => $form['inm_time'],
- 'PMCO_DTIN' => $form['total_duration'],
- 'PMCO_CLAS' => $form['classification'],
- 'PMCO_ESRE' => $specialtiesStr,
- 'PMCO_COES' => $form['specialties_conf'],
- 'PMCO_COME' => $come,
- 'PMCO_RECU' => $form['resources'],
- 'PMCO_DEAD' => $dead,
- 'PMCO_DORE' => $dore,
- 'PMCO_USMO' => $idUser,
- 'PMCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02PLAN',
- 'S002V01P01ASPL',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el plan de mantenimiento correctivo #$idPlan.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteMaintenancePlan(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_plan' => '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);
- }
- $idPlan = $this->encryptionController->decrypt($form['id_plan']);
- if(!$idPlan){
- return $this->responseController->makeResponse(true, 'El ID del plan de mantenimiento no fue encriptado correctamente.', [], 400);
- }
- $plan = DB::table('S002V01TPMCO')->where([
- ['PMCO_NULI', '=', $form['linea']],
- ['PMCO_IDPM', '=', $idPlan]
- ])->first();
-
- if(is_null($plan)){
- return $this->responseController->makeResponse(true, 'El plan que desea modificar no existe.', [], 404);
- }else if($plan->PMCO_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El plan que desea modificar está eliminado.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPMCO')->where([
- ['PMCO_NULI', '=', $form['linea']],
- ['PMCO_IDPM', '=', $idPlan]
- ])->update([
- 'PMCO_ESTA' => 'Eliminado',
- 'PMCO_USMO' => $idUser,
- 'PMCO_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02PLAN',
- 'S002V01P01ASPL',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el plan de mantenimiento correctivo #$idPlan.",
- $idUser,
- $nowStr,
- 'S002V01S02GEME'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerWorkGroup(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'work_group_name' => 'required|string|max:100|min:8',
- 'related_teams' => 'required|json',
- 'specialty' => 'required|string|max:100|min:8',
- ]);
-
- 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);
- }
- $relatedTeamsArr = json_decode($form['related_teams'], true);
- if(count($relatedTeamsArr) < 2){
- return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
- }
- $relatedTeamsArrDec = [];
- foreach($relatedTeamsArr as $key=>$team){
- $itemDec = $this->encryptionController->decrypt($team);
- if(!$itemDec){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
- }
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_NULI', '=', $form['linea']],
- ['EQMA_IDEQ', '=', $itemDec]
- ])->first();
- if(is_null($workTeam)){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
- }else if($workTeam->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
- }
- $relatedTeamsArrDec[] = $itemDec;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $relatedTeamsStr = json_encode($relatedTeamsArrDec);
- $idWorkGroup = DB::table('S002V01TGMCO')->insertGetId([
- 'GMCO_NULI' => $form['linea'],
- 'GMCO_NGMC' => $form['work_group_name'],
- 'GMCO_EQRE' => $relatedTeamsStr,
- 'GMCO_ESPE' => $form['specialty'],
- 'GMCO_USRE' => $idUser,
- 'GMCO_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02AEMA',
- 'S002V01P01AEOP',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
- $idUser,
- $nowStr,
- 'S002V01S04FUFL'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getWorkGroups($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);
- }
- $workGroups = DB::table('S002V01TGMCO')->select([
- 'GMCO_IDGM AS ID_GRUPO',
- 'GMCO_NGMC AS NOMBRE_GRUPO',
- 'GMCO_ESPE AS ESPECIALIDAD',
- 'GMCO_ESTA AS ESTADO',
- 'GMCO_USRE AS USUREG',
- 'GMCO_FERE AS FECREG',
- 'GMCO_USMO AS USUMOD',
- 'GMCO_FEMO AS FECMOD'
- ])->where('GMCO_NULI', '=', $line)->get()->all();
- foreach($workGroups as $key=>$group){
- $group->ID_GRUPO = $this->encryptionController->encrypt($group->ID_GRUPO);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $group->USUREG],
- ['USUA_NULI', '=', $line]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $group->USUREG = $usrRegName . " (" . $group->USUREG . ')';
- if(!is_null($group->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $group->USUMOD],
- ['USUA_NULI', '=', $line]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $group->USUMOD = $usrModName . " (" . $group->USUMOD . ')';
- }
- $workGroups[$key] = $group;
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F02AEMA',
- 'S002V01P01AEOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los grupos de trabajo registrados.",
- $idUser,
- $nowStr,
- 'S002V01S04FUFL'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $workGroups);
- }
- public function getWorkGroup($idGroup, $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);
- }
- $idGroup = $this->encryptionController->decrypt($idGroup);
- if(!$idGroup){
- return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no está encriptado correctamente', [], 400);
- }
- $workGroup = DB::table('S002V01TGMCO')->select([
- 'GMCO_IDGM AS ID_GRUPO',
- 'GMCO_NGMC AS NOMBRE_GRUPO',
- 'GMCO_EQRE AS EQUIPOS_RELACIONADOS',
- 'GMCO_ESPE AS ESPECIALIDAD',
- 'GMCO_ESTA AS ESTADO',
- 'GMCO_USRE AS USUREG',
- 'GMCO_FERE AS FECREG',
- 'GMCO_USMO AS USUMOD',
- 'GMCO_FEMO AS FECMOD'
- ])->where([
- ['GMCO_IDGM', '=', $idGroup],
- ['GMCO_NULI', '=', $line]
- ])->first();
- if(is_null($workGroup)){
- return $this->responseController->makeResponse(true, 'El grupo de trabajo consultado no está registrado.', [], 404);
- }
- $workGroup->ID_GRUPO = $this->encryptionController->encrypt($workGroup->ID_GRUPO);
- $relatedTeamsArr = json_decode($workGroup->EQUIPOS_RELACIONADOS, true);
-
- $relatedTeams = [];
- foreach($relatedTeamsArr as $team){
- $teamInfo = DB::table('S002V01TEQMA')->where([
- ['EQMA_NULI', '=', $line],
- ['EQMA_IDEQ', '=', $team]
- ])->first();
- $relatedTeams[] = [
- 'ID_EQUIPO' => $this->encryptionController->encrypt($teamInfo->EQMA_IDEQ),
- 'NOMBRE_EQUIPO' => $teamInfo->EQMA_NOMB,
- 'ESPECIALIDAD' => $teamInfo->EQMA_ESPE
- ];
- }
- $workGroup->EQUIPOS_RELACIONADOS = json_encode($relatedTeams);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $workGroup->USUREG],
- ['USUA_NULI', '=', $line]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $workGroup->USUREG = $usrRegName . " (" . $workGroup->USUREG . ')';
- if(!is_null($workGroup->USUMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $workGroup->USUMOD],
- ['USUA_NULI', '=', $line]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $workGroup->USUMOD = $usrModName . " (" . $workGroup->USUMOD . ')';
- }
- $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,
- 'S002V01M09GMCO',
- 'S002V01F02AEMA',
- 'S002V01P01AEOP',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el grupo de trabajo " . $workGroup->NOMBRE_GRUPO . " ($idGroup).",
- $idUser,
- $nowStr,
- 'S002V01S04FUFL'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $workGroup);
- }
- public function updateWorkGroup(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_work_group' => 'required|string',
- 'work_group_name' => 'required|string|max:100|min:8',
- 'related_teams' => 'required|json',
- 'specialty' => 'required|string|max:100|min:8',
- ]);
-
- 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);
- }
- $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
- if(!$idWorkGroup){
- return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
- }
- $workGroup = DB::table('S002V01TGMCO')->where([
- ['GMCO_NULI', '=', $form['linea']],
- ['GMCO_IDGM', '=', $idWorkGroup]
- ])->first();
-
- if(is_null($workGroup)){
- return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
- }
- $relatedTeamsArr = json_decode($form['related_teams'], true);
- if(count($relatedTeamsArr) < 2){
- return $this->responseController->makeResponse(true, 'El arreglo de equipos relacionados debe contener al menos 2 elementos.', [], 400);
- }
- $relatedTeamsArrDec = [];
- foreach($relatedTeamsArr as $key=>$team){
- $itemDec = $this->encryptionController->decrypt($team);
- if(!$itemDec){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no fue encriptado correctamente.", [], 400);
- }
- $workTeam = DB::table('S002V01TEQMA')->where([
- ['EQMA_NULI', '=', $form['linea']],
- ['EQMA_IDEQ', '=', $itemDec]
- ])->first();
- if(is_null($workTeam)){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados no existe.", [], 404);
- }else if($workTeam->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posicion #$key del arreglo de equipos relacionados está eliminado.", [], 404);
- }
- $relatedTeamsArrDec[] = $itemDec;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $relatedTeamsStr = json_encode($relatedTeamsArrDec);
- DB::table('S002V01TGMCO')->where([
- ['GMCO_NULI', '=', $form['linea']],
- ['GMCO_IDGM', '=', $idWorkGroup]
- ])->update([
- 'GMCO_NGMC' => $form['work_group_name'],
- 'GMCO_EQRE' => $relatedTeamsStr,
- 'GMCO_ESPE' => $form['specialty'],
- 'GMCO_USMO' => $idUser,
- 'GMCO_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02AEMA',
- 'S002V01P01AEOP',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el grupo de trabajo $form[work_group_name] ($idWorkGroup).",
- $idUser,
- $nowStr,
- 'S002V01S04FUFL'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteWorkGroup(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_work_group' => '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);
- }
- $idWorkGroup = $this->encryptionController->decrypt($form['id_work_group']);
- if(!$idWorkGroup){
- return $this->responseController->makeResponse(true, 'El ID del grupo de trabajo no fue encriptado correctamente.', [], 400);
- }
- $workGroup = DB::table('S002V01TGMCO')->where([
- ['GMCO_NULI', '=', $form['linea']],
- ['GMCO_IDGM', '=', $idWorkGroup]
- ])->first();
-
- if(is_null($workGroup)){
- return $this->responseController->makeResponse(true, 'El grupo de trabajo solicitado no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGMCO')->where([
- ['GMCO_NULI', '=', $form['linea']],
- ['GMCO_IDGM', '=', $idWorkGroup]
- ])->update([
- 'GMCO_ESTA' => 'Eliminado',
- 'GMCO_USMO' => $idUser,
- 'GMCO_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F02AEMA',
- 'S002V01P01AEOP',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el grupo de trabajo #$idWorkGroup.",
- $idUser,
- $nowStr,
- 'S002V01S04FUFL'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- }
|