| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837 |
- <?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 Exception;
- use Illuminate\Validation\Rule;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Http\File;
- use Dompdf\Dompdf;
- 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 $templatesUbic;
- public function __construct()
- {
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->documentManagementController = new DocumentManagementController();
- $this->notificationsController = new NotificationsController();
- $this->templatesUbic = $this->functionsController->getBasePath() . "\storage\app\public\pdf_templates\\01_04_GMCO\\";
- }
- private function getSocketClient()
- {
- $url = 'http://localhost:3200';
- $socketClient = new Client(Client::engine(Client::CLIENT_4X, $url));
- $socketClient->initialize();
- $socketClient->of('/');
- return $socketClient;
- }
- 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);
- }
- $staff = [];
- foreach ($staffArr as $key => $specialty) {
- $specialtyDec = $this->encryptionController->decrypt($specialty['SPECIALTY']);
- if (!$specialtyDec) {
- return $this->responseController->makeResponse(true, "El código en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyDec]
- ])->first();
- if (is_null($specialtyObj)) {
- return $this->responseController->makeResponse(true, "El item en la posición $key del arreglo de especialidades no existe.", [], 404);
- }
- $staff[] = [
- 'ID' => $specialtyDec,
- 'CANT' => $specialty['CANT']
- ];
- }
- $staffStrFn = json_encode($staff);
- $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);
- }
- $resources = json_decode($form['resources'], true);
- if (empty($resources)) {
- return $this->responseController->makeResponse(true, 'El JSON de recursos tiene un formato inválido.', [], 400);
- }
- foreach ($resources as $key => $item) {
- if (!array_key_exists('ID', $item)) {
- return $this->responseController->makeResponse(true, "No se pudo encontrar el ID del elemento en la posición $key del arreglo de recursos.", [], 400);
- }
- if ($item['ID'] != 'SH') {
- $idItemDec = $this->encryptionController->decrypt($item['ID']);
- $resource = DB::table('S002V01TINST')->where([
- ['INST_NULI', '=', $form['linea']],
- ['INST_IDIS', '=', $idItemDec],
- ])->first();
- if (is_null($resource)) {
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de recursos no existe.", [], 404);
- }
- $item['ID'] = $idItemDec;
- }
- $resources[$key] = $item;
- }
- $rhut = json_encode($resources);
- $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' => $rhut,
- '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' => 'Asignar 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->getSocketClient(),
- $orderID,
- 'Correctivo'
- );
- $idOrderEnc = $this->encryptionController->encrypt($orderID);
- $socketData = ['idOrder' => $idOrderEnc];
- $this->getSocketClient()->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();
- if (!is_null($subcontratistResponsible)) {
- $order->ID_RESPONSABLE = $subcontratistResponsible->PESU_RASO . " (" . $subcontratistResponsible->PESU_REFI . ") (" . $order->ID_RESPONSABLE . ")";
- } else {
- $order->ID_RESPONSABLE = "N/D";
- }
- }
- $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_HIES AS HISTORIAL_ESTATUS',
- '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();
- if (!is_null($subcontratistResponsible)) {
- $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);
- if (!empty($measureArr)) {
- $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) {
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $val['ID']]
- ])->first();
- $val['ID'] = $this->encryptionController->encrypt($val['ID']);
- $val['NAME'] = $specialty->GEES_NOES;
- $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'
- ];
- $resources = json_decode($order->RECURSOS, true);
- foreach ($resources as $key => $resource) {
- if ($resource['ID'] != 'SH') {
- $resourceObj = DB::table('S002V01TINST')->where([
- ['INST_NULI', '=', $line],
- ['INST_IDIS', '=', $resource['ID']],
- ])->join('S002V01TSTAR', 'STAR_IDIS', '=', 'INST_IDIS')
- ->join('S002V01TUNID', 'UNID_IDUN', '=', 'STAR_IDUN')->first();
- if (!is_null($resourceObj)) {
- $resource['NAME'] = $resourceObj->INST_MODE;
- $resource['UNIT'] = $resourceObj->UNID_NOMB;
- }
- $resource['ID'] = $this->encryptionController->encrypt($resource['ID']);
- }
- $resources[$key] = $resource;
- }
- $order->RECURSOS = json_encode($resources);
- }
- public function getCostAnalysis($idOrder, $idUser, $line)
- {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if (!$idUser) {
- return $this->responseController->makeResponse(true, 'El ID del usuario 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 no está registrado.', [], 404);
- }
- $idOrder = $this->encryptionController->decrypt($idOrder);
- if (!$idOrder) {
- return $this->responseController->makeResponse(true, 'El ID de la orden no está encriptado correctamente', [], 400);
- }
- $order = DB::table('S002V01TOTCO')
- ->select(['OTCO_HIES', 'OTCO_RHUT', 'OTCO_ANCO'])
- ->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $line]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden no está registrada.', [], 404);
- }
- $historial = json_decode($order->OTCO_HIES, true);
- $recursos = json_decode($order->OTCO_RHUT, true);
- // Buscar usuarios participantes en estado VA
- $usuariosParticipantes = [];
- foreach ($historial as $estado) {
- if ($estado['ESTADO'] == 'VA' && isset($estado['ATENCION'])) {
- foreach ($estado['ATENCION'] as $atencion) {
- if ($atencion['RESPUESTA'] == 'A') {
- $usuario = DB::table('S002V01TUSUA')
- ->where([
- ['USUA_IDUS', '=', $atencion['ID']],
- ['USUA_NULI', '=', $line]
- ])->first();
- if ($usuario) {
- $usuariosParticipantes[] = [
- 'ID' => $atencion['ID'],
- 'NOMBRE' => $this->functionsController->joinName(
- $usuario->USUA_NOMB,
- $usuario->USUA_APPA,
- $usuario->USUA_APMA
- ),
- 'COSTO' => 0
- ];
- }
- }
- }
- break;
- }
- }
- // Procesar recursos
- $herramientas = [];
- $refacciones = [];
- $subtotalesHerramientas = [];
- $subtotalesRefacciones = [];
- foreach ($recursos as $recurso) {
- if ($recurso['ID'] != 'SH') {
- $stock = DB::table('S002V01TINST')
- ->select(['INST_IDIS', 'INST_MODE', 'INAR_COMO', 'INAR_PREC', 'CAMO_DESC'])
- ->join('S002V01TINAR', 'INST_ARTI', '=', 'INAR_IDIN')
- ->join('S002V01TCAMO', 'INAR_COMO', '=', 'CAMO_COMO')
- ->where([
- ['INST_IDIS', '=', $recurso['ID']],
- ['INST_NULI', '=', $line]
- ])->first();
- if ($stock) {
- $subtotal = $stock->INAR_PREC * $recurso['REQ'];
- $moneda = $stock->INAR_COMO;
- $item = [
- 'ID' => $recurso['ID'],
- 'NOMBRE' => $stock->INST_MODE,
- 'CANTIDAD' => $recurso['REQ'],
- 'PRECIO_UNITARIO' => $stock->INAR_PREC,
- 'SUBTOTAL' => $subtotal,
- 'MONEDA_SIMBOLO' => $moneda,
- 'MONEDA_NOMBRE' => $stock->CAMO_DESC
- ];
- if ($recurso['TYPE'] == 'T') {
- $herramientas[] = $item;
- if (!isset($subtotalesHerramientas[$moneda])) {
- $subtotalesHerramientas[$moneda] = 0;
- }
- $subtotalesHerramientas[$moneda] += $subtotal;
- } else {
- $refacciones[] = $item;
- if (!isset($subtotalesRefacciones[$moneda])) {
- $subtotalesRefacciones[$moneda] = 0;
- }
- $subtotalesRefacciones[$moneda] += $subtotal;
- }
- }
- }
- }
- // Convertir subtotales a arrays
- $subtotalHerramientasArray = [];
- foreach ($subtotalesHerramientas as $simbolo => $subtotal) {
- $subtotalHerramientasArray[] = ['SIMBOLO' => $simbolo, 'SUBTOTAL' => $subtotal];
- }
- $subtotalRefaccionesArray = [];
- foreach ($subtotalesRefacciones as $simbolo => $subtotal) {
- $subtotalRefaccionesArray[] = ['SIMBOLO' => $simbolo, 'SUBTOTAL' => $subtotal];
- }
- $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ó el análisis de costos de la orden $idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- // Verificar si ya existe análisis previo
- $tieneAnalisisPrevio = !is_null($order->OTCO_ANCO) && $order->OTCO_ANCO !== '';
- $analisisPrevio = null;
-
- if ($tieneAnalisisPrevio) {
- $analisisPrevio = json_decode($order->OTCO_ANCO, true);
- }
- return $this->responseController->makeResponse(false, 'EXITO.', [
- 'USUARIOS' => $usuariosParticipantes,
- 'HERRAMIENTAS' => $herramientas,
- 'REFACCIONES' => $refacciones,
- 'SUBTOTAL_HERRAMIENTAS' => $subtotalHerramientasArray,
- 'SUBTOTAL_REFACCIONES' => $subtotalRefaccionesArray,
- 'TIENE_ANALISIS_PREVIO' => $tieneAnalisisPrevio,
- 'ANALISIS_PREVIO' => $analisisPrevio
- ]);
- }
- public function saveCostAnalysis(Request $request) {
- DB::enableQueryLog();
-
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'COMMENTS' => 'string',
- 'USUARIOS' => 'required|array',
- 'HERRAMIENTAS' => 'required|array',
- 'REFACCIONES' => 'required|array',
- 'SUBTOTAL_USUARIOS' => 'required|array',
- 'SUBTOTAL_HERRAMIENTAS' => 'required|array',
- 'SUBTOTAL_REFACCIONES' => 'required|array',
- 'TOTAL' => 'required|array'
- ]);
- 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 no está registrado.', [], 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')
- ->select(['OTCO_IDOT', 'OTCO_ESOR'])
- ->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden no está registrada.', [], 404);
- }
- if ($order->OTCO_ESOR !== 'CP') {
- return $this->responseController->makeResponse(true, 'Solo se puede registrar análisis de costos en órdenes con estado "Cerrado pendiente".', [], 400);
- }
- $analisisCostos = [
- 'FECHA' => $this->functionsController->now()->toDateTimeString(),
- 'USUARIO' => $idUser,
- 'COMENTARIOS' => $form['COMMENTS'] ?? '',
- 'USUARIOS' => $form['USUARIOS'],
- 'HERRAMIENTAS' => $form['HERRAMIENTAS'],
- 'REFACCIONES' => $form['REFACCIONES'],
- 'SUBTOTAL_USUARIOS' => $form['SUBTOTAL_USUARIOS'],
- 'SUBTOTAL_HERRAMIENTAS' => $form['SUBTOTAL_HERRAMIENTAS'],
- 'SUBTOTAL_REFACCIONES' => $form['SUBTOTAL_REFACCIONES'],
- 'TOTAL' => $form['TOTAL']
- ];
- $updated = DB::table('S002V01TOTCO')
- ->where([
- ['OTCO_IDOT', '=', $idOrder],
- ['OTCO_NULI', '=', $form['linea']]
- ])
- ->update([
- 'OTCO_ANCO' => json_encode($analisisCostos),
- 'OTCO_USMO' => $idUser,
- 'OTCO_FEMO' => $this->functionsController->now()->toDateTimeString()
- ]);
- if (!$updated) {
- return $this->responseController->makeResponse(true, 'No se pudo guardar el análisis de costos.', [], 500);
- }
- $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(
- $form['linea'],
- 'S002V01M09GMCO',
- 'S002V01F01GEOP',
- 'S002V01P01COOP',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el análisis de costos de la orden $idOrder.",
- $idUser,
- $nowStr,
- 'S002V01S01ORTR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
-
- return $this->responseController->makeResponse(false, 'Análisis de costos guardado exitosamente.', []);
- }
- 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 => $specialty) {
- $specialtyDec = $this->encryptionController->decrypt($specialty['SPECIALTY']);
- if (!$specialtyDec) {
- return $this->responseController->makeResponse(true, "El código en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyDec]
- ])->first();
- if (is_null($specialtyObj)) {
- return $this->responseController->makeResponse(true, "El item en la posición $key del arreglo de especialidades no existe.", [], 404);
- }
- $staffArrFn[] = [
- 'ID' => $specialtyDec,
- 'CANT' => $specialty['CANT']
- ];
- }
- $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);
- }
- $resources = json_decode($form['resources'], true);
- if (empty($resources)) {
- return $this->responseController->makeResponse(true, 'El JSON de recursos tiene un formato inválido.', [], 400);
- }
- foreach ($resources as $key => $item) {
- if (!array_key_exists('ID', $item)) {
- return $this->responseController->makeResponse(true, "No se pudo encontrar el ID del elemento en la posición $key del arreglo de recursos.", [], 400);
- }
- if ($item['ID'] != 'SH') {
- $idItemDec = $this->encryptionController->decrypt($item['ID']);
- $resource = DB::table('S002V01TINST')->where([
- ['INST_NULI', '=', $form['linea']],
- ['INST_IDIS', '=', $idItemDec],
- ])->first();
- if (is_null($resource)) {
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de recursos no existe.", [], 404);
- }
- $item['ID'] = $idItemDec;
- }
- $resources[$key] = $item;
- }
- $rhut = json_encode($resources);
- $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' => $rhut,
- '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',
- 'config' => '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);
- }
- $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);
- }
- $staffConfigArr = json_decode($form['config'], true);
- $audience = [];
- foreach ($staffConfigArr as $key => $val) {
- if (!array_key_exists('SPECIALTY', $val) || !array_key_exists('STAFF', $val)) {
- return $this->responseController->makeResponse(true, "El item $key del arreglo de configuración de operarios tiene un formato inválido.", [], 400);
- }
- $specialtyDec = $this->encryptionController->decrypt($val['SPECIALTY']);
- if (!$specialtyDec) {
- return $this->responseController->makeResponse(true, "El identificador de la especialidad en el item $key del arreglo de configuración de operarios no fue encriptado correctamente.", [], 400);
- }
- if (gettype($val['STAFF']) != 'array') {
- return $this->responseController->makeResponse(true, "El contenedor de oerarios en el item $key del arreglo de configuración de operarios es inválido-.", [], 400);
- }
- foreach ($val['STAFF'] as $key0 => $val0) {
- if (!array_key_exists('ID', $val0) || !array_key_exists('TYPE', $val0)) {
- return $this->responseController->makeResponse(true, "El item $key del arreglo de configuración de operarios tiene un formato inválido.", [], 400);
- }
- $idDec = $this->encryptionController->decrypt($val0['ID']);
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idDec]
- ])->first();
- if (is_null($employee)) {
- return $this->responseController->makeResponse(true, "El perario $key0 de la especialidad $specialtyDec del arreglo de configuración de operarios tiene un formato inválido.", [], 404);
- }
- $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.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ], [
- 'BOTON' => 'Atender orden',
- 'FUNCION' => 'attendCorrectiveWorkOrder',
- '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->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusHistoryArr[] = ['USUARIO' => $idUser, 'ESTADO' => 'VA', 'FECHA' => $nowStr, 'PERSONAL' => $audience];
- $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 updateApprovedWorkOrder(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'config' => '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);
- }
- $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);
- } else if ($order->OTCO_ESOR == 'EL') {
- return $this->responseController->makeResponse(true, 'La orden solicitada está eliminada.', [], 404);
- } else if ($order->OTCO_ESOR != 'VA') {
- return $this->responseController->makeResponse(true, "La orden noo está validada.", [], 401);
- }
- $staffConfigArr = json_decode($form['config'], true);
- $audience = [];
- foreach ($staffConfigArr as $key => $val) {
- if (!array_key_exists('SPECIALTY', $val) || !array_key_exists('STAFF', $val)) {
- return $this->responseController->makeResponse(true, "El item $key del arreglo de configuración de operarios tiene un formato inválido.", [], 400);
- }
- $specialtyDec = $this->encryptionController->decrypt($val['SPECIALTY']);
- if (!$specialtyDec) {
- return $this->responseController->makeResponse(true, "El identificador de la especialidad en el item $key del arreglo de configuración de operarios no fue encriptado correctamente.", [], 400);
- }
- if (gettype($val['STAFF']) != 'array') {
- return $this->responseController->makeResponse(true, "El contenedor de oerarios en el item $key del arreglo de configuración de operarios es inválido-.", [], 400);
- }
- foreach ($val['STAFF'] as $key0 => $val0) {
- if (!array_key_exists('ID', $val0) || !array_key_exists('TYPE', $val0)) {
- return $this->responseController->makeResponse(true, "El item $key del arreglo de configuración de operarios tiene un formato inválido.", [], 400);
- }
- $idDec = $this->encryptionController->decrypt($val0['ID']);
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idDec]
- ])->first();
- if (is_null($employee)) {
- return $this->responseController->makeResponse(true, "El perario $key0 de la especialidad $specialtyDec del arreglo de configuración de operarios tiene un formato inválido.", [], 404);
- }
- $audience[] = $employee->PERS_IDUS;
- }
- }
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $statusApprovedFilt = array_filter($statusHistoryArr, function ($v, $k) {
- return $v['ESTADO'] == 'VA';
- }, ARRAY_FILTER_USE_BOTH);
- $keysFiltered = array_keys($statusApprovedFilt);
- $approvedKey = end($keysFiltered);
- $statusApproved = $statusApprovedFilt[$approvedKey];
- $staff = $statusApproved['PERSONAL'];
- $newAudience = [];
- foreach ($audience as $item) {
- if (!in_array($item, $staff)) {
- $newAudience[] = $item;
- $staff[] = $item;
- }
- }
- $statusApproved['PERSONAL'] = $staff;
- $statusHistoryArr[$approvedKey] = $statusApproved;
- $statusHistoryStr = json_encode($statusHistoryArr);
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "Se ha generado la orden de mantenimiento correctivo #$idOrder y requiere su atención.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ], [
- 'BOTON' => 'Atender orden',
- 'FUNCION' => 'attendCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ], [
- 'BOTON' => 'Ir al módulo',
- 'FUNCION' => 'openModule',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
- ]],
- $newAudience,
- $idUser,
- $form['linea'],
- $this->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- 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 . ") 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 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);
- } else if ($order->OTCO_IDUR != $idUser) {
- return $this->responseController->makeResponse(true, "El usuario que solicitó la acción no tiene los permisos necesarios.", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $validatedStatusFilt = array_filter($statusHistoryArr, function ($v, $k) {
- return $v['ESTADO'] == 'VA';
- }, ARRAY_FILTER_USE_BOTH);
- $validatedStatus = end($validatedStatusFilt);
- $audience = [];
- foreach ($validatedStatus['ATENCION'] as $item) {
- if ($item['RESPUESTA'] == 'A') $audience[] = $item['ID'];
- }
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "Inicio de la ejecución de la orden de mantenimiento #$idOrder.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- '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->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- $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;
- }
- if ($order->OTCO_ESOR == 'EP' && $status == 'CE') {
- $status = 'CP';
- }
- /*$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)){
- if ($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);
- $validatedStatusFilt = array_filter($statusHistoryArr, function ($v, $k) {
- return $v['ESTADO'] == 'VA';
- }, ARRAY_FILTER_USE_BOTH);
- $validatedStatus = end($validatedStatusFilt);
- $attendance = $validatedStatus['ATENCION'];
- $enabledUsersToClose = [];
- foreach ($attendance as $item) {
- if ($item['RESPUESTA'] == 'A') $enabledUsersToClose[] = $item['ID'];
- }
- if (!in_array($idUser, $enabledUsersToClose)) {
- return $this->responseController->makeResponse(true, 'El usuario que solicitó la acción no tiene los permisos necesarios.', [], 401);
- }
- $closeUserName = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $audience = [$order->OTCO_IDUR];
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "El usuario $closeUserName ($idUser) cerró la orden de mantenimiento #$idOrder con los siguientes comentarios: $form[comments].",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- '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->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- $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");
- }
- public function closeWorkOrder(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 ($idUser != $order->OTCO_IDUR) {
- return $this->responseController->makeResponse(true, 'El usuario que solicitó la acción no tiene los permisos necesarios.', [], 401);
- }
- $status = 'CE';
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $closeUserName = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $audience = [$order->OTCO_USRE];
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "El usuario $closeUserName ($idUser) validó el cierre la orden de mantenimiento #$idOrder.",
- [[
- 'BOTON' => 'Ver detalles',
- 'FUNCION' => 'openCorrectiveWorkOrderDetails',
- '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->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- $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_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 . ") 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");
- }
- 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->getSocketClient(),
- $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();
- if (!is_null($employee)) {
- $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();
- if (!is_null($usrReg)) {
- $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();
- if (!is_null($usrMod)) {
- $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($this->functionsController->getBasePath() . '\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($this->functionsController->getBasePath() . '\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 = $this->functionsController->getBasePath() . '\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 = $this->functionsController->getBasePath() . "\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($this->functionsController->getBasePath() . '\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($this->functionsController->getBasePath() . '\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();
- if (!is_null($teamInfo)) {
- $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.');
- }
- public function getNoMeasuresFormFields($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);
- }
- $noMeasuresFormFields = DB::table('S002V01TCAPE')->select([
- 'CAPE_VERS AS VERSION',
- 'CAPE_FEAC AS FECHA_ACTUALIZACION',
- 'CAPE_CAMP AS CAMPOS'
- ])->where([
- ['CAPE_NULI', '=', $line],
- ['CAPE_TIFO', '=', 'RSM']
- ])->orderBy('CAPE_VERS', 'desc')->first();
- if (is_null($noMeasuresFormFields)) {
- return $this->responseController->makeResponse(false, 'EXITO', []);
- }
- $fieldsArr = json_decode($noMeasuresFormFields->CAMPOS, true);
- foreach ($fieldsArr as $key => $field) {
- if (array_key_exists('fieldID', $field)) {
- $field['fieldID'] = $this->encryptionController->encrypt($field['fieldID']);
- }
- $fieldsArr[$key] = $field;
- }
- $noMeasuresFormFields->CAMPOS = $fieldsArr;
- return $this->responseController->makeResponse(false, 'EXITO', $noMeasuresFormFields);
- }
- public function saveNoMeasuresFormFields(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'form_fields' => '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);
- }
- $formFields = $this->encryptionController->decrypt($form['form_fields']);
- if (!$formFields) {
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $lastFormVersion = DB::table('S002V01TCAPE')->where([
- ['CAPE_NULI', '=', $form['linea']],
- ['CAPE_TIFO', '=', 'RSM']
- ])->orderBy('CAPE_VERS', 'desc')->first();
- $lastVersion = 0;
- if (is_null($lastFormVersion)) {
- $lastVersion = 1;
- } else {
- $lastVersion = intval($lastFormVersion->CAPE_VERS) + 1;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TCAPE')->insert([
- 'CAPE_NULI' => $form['linea'],
- 'CAPE_TIFO' => 'RSM',
- 'CAPE_VERS' => $lastVersion,
- 'CAPE_FEAC' => $nowStr,
- 'CAPE_USAC' => $idUser,
- 'CAPE_CAMP' => $formFields
- ]);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function saveNoMeasuresOrder(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'data' => '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);
- }
- $noMeasuresFormFields = DB::table('S002V01TCAPE')->select([
- 'CAPE_VERS AS VERSION',
- 'CAPE_FEAC AS FECHA_ACTUALIZACION',
- 'CAPE_CAMP AS CAMPOS'
- ])->where([
- ['CAPE_NULI', '=', $form['linea']],
- ['CAPE_TIFO', '=', 'RSM']
- ])->orderBy('CAPE_VERS', 'desc')->first();
- if (is_null($noMeasuresFormFields)) {
- return $this->responseController->makeResponse(true, 'No se encontró algún formulario registrado.', [], 404);
- }
- $noMeasuresFormFieldsArr = json_decode($noMeasuresFormFields->CAMPOS, true);
- $formData = $this->encryptionController->decrypt($form['data']);
- if (!$formData) {
- return $this->responseController->makeResponse(true, 'El formulario enviado no fue encriptado correctamente.', [], 400);
- }
- $formDataArr = json_decode($formData, true);
- if (is_null($formDataArr)) {
- return $this->responseController->makeResponse(true, 'El formulario enviado no tiene un formato válido.', [], 400);
- }
- $errorsArr = [];
- $formDataFn = [];
- foreach ($formDataArr as $control => $value) {
- $isEncrypted = $this->encryptionController->decrypt($value);
- if ($isEncrypted) {
- $value = $isEncrypted;
- }
- $controlFilt = array_filter($noMeasuresFormFieldsArr, function ($v, $k) use ($control) {
- return $v['fieldID'] == $control;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($controlFilt) > 0) {
- $controlObj = end($controlFilt);
- $controlValidators = json_decode($controlObj['validators'], true);
- if (in_array('CARE', $controlValidators)) {
- if ($value == null || is_null($value)) {
- $errorsArr[] = "El campo $controlObj[label] es obligatorio.";
- }
- }
- if (in_array('NUME', $controlValidators)) {
- $validNumber = $this->functionsController->validNumber($value, $controlObj['includeDecimal']);
- if (!$validNumber) {
- $errorsArr[] = "El campo $controlObj[label] tiene un valor inválido.";
- }
- }
- if (in_array('LOMI', $controlValidators)) {
- $minLengthNum = intval($controlObj['minLength']);
- if (strlen($value) < $minLengthNum) {
- $errorsArr[] = "El campo $controlObj[label] debe contener al menos $minLengthNum caracteres.";
- }
- }
- if (in_array('LOMA', $controlValidators)) {
- $maxLengthNum = intval($controlObj['maxLength']);
- if (strlen($value) > $maxLengthNum) {
- $errorsArr[] = "El campo $controlObj[label] puede contener hasta $maxLengthNum caracteres.";
- }
- }
- $selectorOptions = [];
- foreach ($controlObj['selectorOptions'] as $option) {
- if (array_key_exists('value', $option)) {
- $valueEnc = $this->encryptionController->decrypt($option['value']);
- if ($valueEnc) {
- $option['value'] = $valueEnc;
- }
- $selectorOptions[] = $option;
- }
- }
- if ($controlObj['fieldType'] == 'SE-4' && !$controlObj['isMultiple']) {
- $valueFilt = array_filter($selectorOptions, function ($v, $k) use ($value) {
- if (array_key_exists('value', $v) && $v['value'] == $value) return true;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($valueFilt) <= 0) {
- $errorsArr[] = "El calor del campo $controlObj[label] es inválido.";
- }
- }
- $formDataFn[$control] = $value;
- } else {
- return $this->responseController->makeResponse(true, "El control $control no existe en la versión " . $noMeasuresFormFields->CAMPOS . " del formulario de órdenes sin mediciones", [], 400);
- }
- }
- if (count($errorsArr) > 0) {
- return $this->responseController->makeResponse(true, 'Se encontraron uno o más errores.', $errorsArr, 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $formDataStrFn = json_encode($formDataFn);
- $idRegister = DB::table('S002V01TFCPE')->insertGetId([
- 'FCPE_NULI' => $form['linea'],
- 'FCPE_TIFO' => 'RSM',
- 'FCPE_VERS' => $noMeasuresFormFields->VERSION,
- 'FCPE_DATO' => $formDataStrFn,
- 'FCPE_FERE' => $nowStr,
- 'FCPE_USRE' => $idUser,
- ]);
- $idRegisterEnc = $this->encryptionController->encrypt($idRegister);
- return $this->responseController->makeResponse(false, 'EXITO', ['order' => $idRegisterEnc]);
- }
- public function getNoMeasuresOrders($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);
- }
- $noMeasuresOrders = DB::table('S002V01TFCPE')->select([
- 'FCPE_IDRE AS ID_REGISTRO',
- 'FCPE_VERS AS VERSION_FORMULARIO',
- 'FCPE_ESTA AS ESTATUS',
- 'FCPE_FERE AS FECHA_REGISTRO',
- DB::raw("CONCAT(USRE.USUA_NOMB, ' ', USRE.USUA_APPA, IF(ISNULL(USRE.USUA_APMA), '', ' '), IF(ISNULL(USRE.USUA_APMA), '', USRE.USUA_APMA), ' (', FCPE_USRE, ')') AS USUARIO_REGISTRO"),
- 'FCPE_FEAC AS FECHA_ACTUALIZACION',
- DB::raw("IF(ISNULL(USMO.USUA_NOMB), '-', CONCAT(USMO.USUA_NOMB, ' ', USMO.USUA_APPA, IF(ISNULL(USMO.USUA_APMA), '', ' '), IF(ISNULL(USMO.USUA_APMA), '', USMO.USUA_APMA), ' (', FCPE_USAC, ')')) AS USUARIO_ACTUALIZACION")
- ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'FCPE_USRE')
- ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'FCPE_USAC')
- ->orderBy('FCPE_IDRE', 'desc')->where([
- ['FCPE_NULI', '=', $line],
- ['FCPE_IOMC', '=', null]
- ])->get()->all();
- foreach ($noMeasuresOrders as $key => $order) {
- $order->ID_REGISTRO = $this->encryptionController->encrypt($order->ID_REGISTRO);
- $order->USUARIO_REGISTRO = $this->encryptionController->encrypt($order->USUARIO_REGISTRO);
- if (!is_null($order->USUARIO_ACTUALIZACION)) {
- $order->USUARIO_ACTUALIZACION = $this->encryptionController->encrypt($order->USUARIO_ACTUALIZACION);
- }
- $noMeasuresOrders[$key] = $order;
- }
- return $this->responseController->makeResponse(false, 'EXITO', $noMeasuresOrders);
- }
- public function getNoMeasuresOrder($idRegister, $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);
- }
- $idRegister = $this->encryptionController->decrypt($idRegister);
- if (!$idRegister) {
- return $this->responseController->makeResponse(true, 'El ID de la solicitud no fue encriptado correctamente.', [], 400);
- }
- $noMeasuresOrder = DB::table('S002V01TFCPE')->select([
- 'FCPE_IDRE AS ID_REGISTRO',
- 'FCPE_VERS AS VERSION_FORMULARIO',
- 'FCPE_DATO AS DATOS',
- 'FCPE_VAPO AS VALIDADO_POR',
- 'FCPE_EXPE AS EXPEDIENTE',
- 'FCPE_ESTA AS ESTATUS',
- 'FCPE_ACRE AS ACTIVIDADES',
- 'FCPE_EVCI AS EVIDENCIA',
- 'FCPE_FERE AS FECHA_REGISTRO',
- DB::raw("CONCAT(USRE.USUA_NOMB, ' ', USRE.USUA_APPA, IF(ISNULL(USRE.USUA_APMA), '', ' '), IF(ISNULL(USRE.USUA_APMA), '', USRE.USUA_APMA), ' (', FCPE_USRE, ')') AS USUARIO_REGISTRO"),
- 'FCPE_FEAC AS FECHA_ACTUALIZACION',
- DB::raw("IF(ISNULL(USMO.USUA_NOMB), '-', CONCAT(USMO.USUA_NOMB, ' ', USMO.USUA_APPA, IF(ISNULL(USMO.USUA_APMA), '', ' '), IF(ISNULL(USMO.USUA_APMA), '', USMO.USUA_APMA), ' (', FCPE_USAC, ')')) AS USUARIO_ACTUALIZACION")
- ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'FCPE_USRE')
- ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'FCPE_USAC')->where([
- ['FCPE_NULI', '=', $line],
- ['FCPE_TIFO', '=', 'RSM'],
- ['FCPE_IDRE', '=', $idRegister]
- ])->first();
- if (is_null($noMeasuresOrder)) {
- return $this->responseController->makeResponse(true, 'La solicitud la consultada no está registrada.', [], 404);
- }
- $noMeasuresOrder->ID_REGISTRO = $this->encryptionController->encrypt($noMeasuresOrder->ID_REGISTRO);
- $orderForm = DB::table('S002V01TCAPE')->select([
- 'CAPE_VERS AS VERSION',
- 'CAPE_FEAC AS FECHA_ACTUALIZACION',
- 'CAPE_CAMP AS CAMPOS'
- ])->where([
- ['CAPE_NULI', '=', $line],
- ['CAPE_TIFO', '=', 'RSM'],
- ['CAPE_VERS', '=', $noMeasuresOrder->VERSION_FORMULARIO],
- ])->first();
- if (is_null($orderForm)) {
- return $this->responseController->makeResponse(true, 'El formulario en el que se registró la orden solicitada no existe', [], 404);
- }
- $fieldsArr = json_decode($orderForm->CAMPOS, true);
- $dataArr = json_decode($noMeasuresOrder->DATOS, true);
- $dataArrFn = [];
- foreach ($dataArr as $key => $value) {
- $fieldFilt = array_filter($fieldsArr, function ($v, $k) use ($key) {
- $idNum = intval($v['fieldID']);
- return $idNum == $key;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($fieldFilt) > 0) {
- $field = end($fieldFilt);
- if ($field['fieldType'] == 'SE-4') {
- $selectorOptions = $field['selectorOptions'];
- foreach ($selectorOptions as $option) {
- if (array_key_exists('value', $option)) {
- $valueDec = $this->encryptionController->decrypt($option['value']);
- if ($valueDec == $value) {
- $value = $option['value'];
- }
- }
- }
- }
- }
- $dataArrFn[$key] = $value;
- }
- foreach ($fieldsArr as $key => $value) {
- if (array_key_exists('fieldID', $value)) {
- $value['fieldID'] = $this->encryptionController->encrypt($value['fieldID']);
- }
- $fieldsArr[$key] = $value;
- }
- $dataStr = json_encode($dataArrFn);
- $noMeasuresOrder->DATOS = $this->encryptionController->encrypt($dataStr);
- $orderForm->CAMPOS = $fieldsArr;
- if (!is_null($noMeasuresOrder->ACTIVIDADES)) {
- $activitiesArr = json_decode($noMeasuresOrder->ACTIVIDADES, true);
- foreach ($activitiesArr as $key => $activity) {
- $activity['id'] = $this->encryptionController->encrypt($activity['id']);
- $activitiesArr[$key] = $activity;
- }
- $noMeasuresOrder->ACTIVIDADES = $activitiesArr;
- }
- if (!is_null($noMeasuresOrder->EVIDENCIA)) {
- $evidenceArr = json_decode($noMeasuresOrder->EVIDENCIA, true);
- foreach ($evidenceArr as $key => $file) {
- $evidenceArr[$key] = $this->encryptionController->encrypt($file);
- }
- $noMeasuresOrder->EVIDENCIA = $evidenceArr;
- }
- return $this->responseController->makeResponse(false, 'EXITO', [
- 'DATOS' => $noMeasuresOrder,
- 'FORMULARIO' => $orderForm
- ]);
- }
- public function updateNoMeasuresOrder(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'data' => 'required|string',
- '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 solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- }
- $noMeasuresFormFields = DB::table('S002V01TCAPE')->select([
- 'CAPE_VERS AS VERSION',
- 'CAPE_FEAC AS FECHA_ACTUALIZACION',
- 'CAPE_CAMP AS CAMPOS'
- ])->where([
- ['CAPE_NULI', '=', $form['linea']],
- ['CAPE_TIFO', '=', 'RSM'],
- ['CAPE_VERS', '=', $order->FCPE_VERS]
- ])->orderBy('CAPE_VERS', 'desc')->first();
- if (is_null($noMeasuresFormFields)) {
- return $this->responseController->makeResponse(true, 'El formulario relacionado a la solicitud no existe.', [], 404);
- }
- $noMeasuresFormFieldsArr = json_decode($noMeasuresFormFields->CAMPOS, true);
- $formData = $this->encryptionController->decrypt($form['data']);
- if (!$formData) {
- return $this->responseController->makeResponse(true, 'El formulario enviado no fue encriptado correctamente.', [], 400);
- }
- $formDataArr = json_decode($formData, true);
- if (is_null($formDataArr)) {
- return $this->responseController->makeResponse(true, 'El formulario enviado no tiene un formato válido.', [], 400);
- }
- $errorsArr = [];
- $formDataFn = [];
- foreach ($formDataArr as $control => $value) {
- $isEncrypted = $this->encryptionController->decrypt($value);
- if ($isEncrypted) {
- $value = $isEncrypted;
- }
- $controlFilt = array_filter($noMeasuresFormFieldsArr, function ($v, $k) use ($control) {
- return $v['fieldID'] == $control;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($controlFilt) > 0) {
- $controlObj = end($controlFilt);
- $controlValidators = json_decode($controlObj['validators'], true);
- if (in_array('CARE', $controlValidators)) {
- if ($value == null || is_null($value)) {
- $errorsArr[] = "El campo $controlObj[label] es obligatorio.";
- }
- }
- if (in_array('NUME', $controlValidators)) {
- $validNumber = $this->functionsController->validNumber($value, $controlObj['includeDecimal']);
- if (!$validNumber) {
- $errorsArr[] = "El campo $controlObj[label] tiene un valor inválido.";
- }
- }
- if (in_array('LOMI', $controlValidators)) {
- $minLengthNum = intval($controlObj['minLength']);
- if (strlen($value) < $minLengthNum) {
- $errorsArr[] = "El campo $controlObj[label] debe contener al menos $minLengthNum caracteres.";
- }
- }
- if (in_array('LOMA', $controlValidators)) {
- $maxLengthNum = intval($controlObj['maxLength']);
- if (strlen($value) > $maxLengthNum) {
- $errorsArr[] = "El campo $controlObj[label] puede contener hasta $maxLengthNum caracteres.";
- }
- }
- $selectorOptions = [];
- foreach ($controlObj['selectorOptions'] as $option) {
- if (array_key_exists('value', $option)) {
- $valueEnc = $this->encryptionController->decrypt($option['value']);
- if ($valueEnc) {
- $option['value'] = $valueEnc;
- }
- $selectorOptions[] = $option;
- }
- }
- if ($controlObj['fieldType'] == 'SE-4' && !$controlObj['isMultiple']) {
- $valueFilt = array_filter($selectorOptions, function ($v, $k) use ($value) {
- if (array_key_exists('value', $v) && $v['value'] == $value) return true;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($valueFilt) <= 0) {
- $errorsArr[] = "El calor del campo $controlObj[label] es inválido.";
- }
- }
- $formDataFn[$control] = $value;
- } else {
- return $this->responseController->makeResponse(true, "El control $control no existe en la versión " . $noMeasuresFormFields->CAMPOS . " del formulario de órdenes sin mediciones", [], 400);
- }
- }
- if (count($errorsArr) > 0) {
- return $this->responseController->makeResponse(true, 'Se encontraron uno o más errores.', $errorsArr, 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $formDataStrFn = json_encode($formDataFn);
- DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->update([
- 'FCPE_DATO' => $formDataStrFn,
- 'FCPE_FEAC' => $nowStr,
- 'FCPE_USAC' => $idUser,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function deleteNoMeasuresOrder(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 solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- } else if ($order->FCPE_ESTA == 'EL') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada está eliminada.', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->update([
- 'FCPE_ESTA' => 'EL',
- 'FCPE_FEAC' => $nowStr,
- 'FCPE_USAC' => $idUser,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function noMeasuresOrderValidation(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'validated_by' => 'required|string',
- 'record' => 'required|string',
- 'validation' => 'required|string|in:Si,No'
- ]);
- 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 solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- } else if ($order->FCPE_ESTA != 'PE') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada no está pendiente.', [], 401);
- }
- $validationStatus = $form['validation'] == 'Si' ? 'VA' : 'NV';
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->update([
- 'FCPE_VAPO' => $form['validated_by'],
- 'FCPE_EXPE' => $form['record'],
- 'FCPE_ESTA' => $validationStatus,
- 'FCPE_FEAC' => $nowStr,
- 'FCPE_USAC' => $idUser,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function closeNoMeasuresOrder(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'evidence' => 'required|json',
- 'activities' => '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);
- }
- $idOrder = $this->encryptionController->decrypt($form['id_order']);
- if (!$idOrder) {
- return $this->responseController->makeResponse(true, 'El ID de la solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- } else if ($order->FCPE_ESTA != 'VA') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada no está validada.', [], 401);
- }
- $activitiesArr = json_decode($form['activities'], true);
- if (count($activitiesArr) <= 0) {
- return $this->responseController->makeResponse(true, 'El arreglo de actividades está vacío.', [], 400);
- }
- foreach ($activitiesArr as $key => $activity) {
- if (!array_key_exists('id', $activity)) {
- return $this->responseController->makeResponse(true, "El elemento $key de la lista de actividades tiene un formato inválido.", [], 400);
- }
- $activity['id'] = $this->encryptionController->decrypt($activity['id']);
- $activitiesArr[$key] = $activity;
- }
- $activitiesStr = json_encode($activitiesArr);
- $evidenceArr = json_decode($form['evidence'], true);
- if (count($evidenceArr) <= 0) {
- return $this->responseController->makeResponse(true, 'El arreglo de evidencias está vacío.', [], 400);
- }
- $evidenceArrFn = [];
- foreach ($evidenceArr 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 {
- $evidenceArrFn[] = $finalFile[1];
- }
- }
- $evidenceStr = json_encode($evidenceArrFn);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->update([
- 'FCPE_ESTA' => 'CE',
- 'FCPE_ACRE' => $activitiesStr,
- 'FCPE_EVCI' => $evidenceStr,
- 'FCPE_FEAC' => $nowStr,
- 'FCPE_USAC' => $idUser,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function closedNoMeasuresOrderValidation(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'validation' => 'required|string|in:Si,No',
- 'validated_by' => '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 solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- } else if ($order->FCPE_ESTA != 'CE') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada no está cerrada.', [], 401);
- }
- $validationStatus = $form['validation'] == 'Si' ? 'CV' : 'VA';
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->update([
- 'FCPE_CVPO' => $form['validated_by'],
- 'FCPE_ESTA' => $validationStatus,
- 'FCPE_FEAC' => $nowStr,
- 'FCPE_USAC' => $idUser,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function generateNoMeasuresReport(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'report_type' => 'required|string|in:RITR,RIIF,RAAV',
- 'report_data' => '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 solicitud seleccionada no fue encriptado correctamente.', [], 400);
- }
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- if (is_null($order)) {
- return $this->responseController->makeResponse(true, 'La orden que desea actualizar no existe.', [], 404);
- } else if ($order->FCPE_ESTA != 'CV') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada no está cerrada y validada.', [], 401);
- }
- $reportDataDec = $this->encryptionController->decrypt($form['report_data']);
- if (!$reportDataDec) {
- return $this->responseController->makeResponse(true, 'Los datos del reporte no fueron encriptados correctamente.', [], 400);
- }
- $reportDataArr = json_decode($reportDataDec, true);
- $html = '';
- $crrcLogo = file_get_contents($this->functionsController->getBasePath() . "\storage\app\public\global_resources\logo_crrc.webp");
- $ingeropLogo = file_get_contents($this->functionsController->getBasePath() . "\storage\app\public\global_resources\logo_ingerop.png");
- $stcLogo = file_get_contents($this->functionsController->getBasePath() . "\storage\app\public\global_resources\logo_stc.webp");
- $stcShortLogo = file_get_contents($this->functionsController->getBasePath() . "\storage\app\public\global_resources\logo_stc_small.png");
- $crrcLogoStr = "data:image/svg+xml;base64," . base64_encode($crrcLogo);
- $ingeropLogoStr = "data:image/svg+xml;base64," . base64_encode($ingeropLogo);
- $stcLogoStr = "data:image/svg+xml;base64," . base64_encode($stcLogo);
- $stcShortLogoStr = "data:image/svg+xml;base64," . base64_encode($stcShortLogo);
- $noar = '';
- if ($form['report_type'] == 'RITR') {
- $html = file_get_contents($this->templatesUbic . "01-GMCO-PL-010101-000001=01=PDF_REPORTE_KIZEO_01.html");
- $html = str_replace("%logo_crrc%", $crrcLogoStr, $html);
- $html = str_replace("%logo_stc%", $stcLogoStr, $html);
- $html = str_replace("%logo_ingerop%", $ingeropLogoStr, $html);
- $noar = "rep_int_trenes_mod_nm16_nm22_ord_$idOrder";
- } else if ($form['report_type'] == 'RIIF') {
- $html = file_get_contents($this->templatesUbic . "01-GMCO-PL-010101-000001=01=PDF_REPORTE_KIZEO_02.html");
- $html = str_replace("%logo_stc_small%", $stcShortLogoStr, $html);
- $html = str_replace("%logo_crrc%", $crrcLogoStr, $html);
- $noar = "rep_inc_inst_fija_ord_$idOrder";
- } else if ($form['report_type'] == 'RAAV') {
- $html = file_get_contents($this->templatesUbic . "01-GMCO-PL-010101-000001=01=PDF_REPORTE_KIZEO_03.html");
- $html = str_replace("%logo_crrc%", $crrcLogoStr, $html);
- $html = str_replace("%logo_stc%", $stcLogoStr, $html);
- $html = str_replace("%logo_ingerop%", $ingeropLogoStr, $html);
- $noar = "reg_aten_aver_ord_$idOrder";
- }
- if (strlen($html) <= 0) {
- return $this->responseController->makeResponse(true, 'No se encontró ninguna plantilla para el reporte solicitado.', [], 404);
- }
- foreach ($reportDataArr as $key => $val) {
- $keyInd = "##$key##";
- $val = is_null($val) ? ' ' : $val;
- $html = str_replace($keyInd, $val, $html);
- }
- $como = 'GMCO';
- $cldo = 'IN';
- $exte = "pdf";
- $line = intval($form['linea']) < 10 ? "0$form[linea]" : "$form[linea]";
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $nowArr = explode(" ", $nowStr);
- $dateArr = explode("-", $nowArr[0]);
- $year = substr($dateArr[0], 2);
- $fecr = $year . $dateArr[1] . $dateArr[2];
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ])->orderBy('AFAL_NUSE', 'desc')->first();
- $nuse = is_null($sec) ? "1" : "" . intval($sec->AFAL_NUSE) + 1 . "";
- for ($i = strlen($nuse); $i < 6; $i++) {
- $nuse = "0$nuse";
- }
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ['AFAL_NOAR', '=', $noar],
- ['AFAL_EXTE', '=', $exte],
- ])->orderBy('AFAL_NUVE', 'desc')->first();
- $nuve = is_null($ver) ? "1" : "" . intval($ver->AFAL_NUVE) + 1 . "";
- for ($i = strlen($nuve); $i < 2; $i++) {
- $nuve = "0$nuve";
- }
- $filePath = $this->functionsController->getBasePath() . '\public_files\\';
- $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
- $dompdf = new Dompdf();
- $dompdf->loadHtml($html);
- $dompdf->setPaper('A4', 'portrait');
- $dompdf->render();
- $output = $dompdf->output();
- $tempFile = $filePath . $fileName;
- if (!file_exists($tempFile)) {
- fopen($tempFile, 'w');
- }
- file_put_contents($tempFile, $output);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- $ubic = $this->functionsController->getBasePath() . "\sam\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- return $this->responseController->makeResponse(false, 'EXITO.', ['fileID' => $fileName]);
- }
- public function getWorkOrderStaff($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 relacionada no está encriptado correctamente', [], 400);
- }
- $workOrder = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $line],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
- if (is_null($workOrder)) {
- return $this->responseController->makeResponse(true, 'La orden relacionada no está registrada.', [], 404);
- }
- $staffArr = json_decode($workOrder->OTCO_PEIN, true);
- $staffArrFn = [];
- foreach ($staffArr as $val) {
- if (array_key_exists('TYPE', $val)) {
- if ($val['TYPE'] == 'EQ') {
- $workTeamStaff = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_EQTR', '=', $val['ID']]
- ])->get()->all();
- foreach ($workTeamStaff as $item) {
- $itemID = $item->PERS_IDPE;
- $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
- return $v['ID'] == $itemID;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($itemFilt) <= 0) {
- $staffArrFn[] = [
- 'ID' => $itemID,
- 'ID_USER' => $item->USUA_IDUS,
- 'NAME' => $this->functionsController->joinName($item->USUA_NOMB, $item->USUA_APPA, $item->USUA_APMA),
- 'TYPE' => $item->PERS_TICO,
- ];
- }
- }
- } else if ($val['TYPE'] == 'SU') {
- $subcontratistStaff = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPS', '=', $val['ID']]
- ])->get()->all();
- foreach ($subcontratistStaff as $item) {
- $itemID = $item->PERS_IDPE;
- $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
- return $v['ID'] == $itemID;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($itemFilt) <= 0) {
- $staffArrFn[] = [
- 'ID' => $itemID,
- 'ID_USER' => $item->USUA_IDUS,
- 'NAME' => $this->functionsController->joinName($item->USUA_NOMB, $item->USUA_APPA, $item->USUA_APMA),
- 'TYPE' => $item->PERS_TICO,
- ];
- }
- }
- } else if ($val['TYPE'] == 'EM') {
- $employee = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $val['ID']]
- ])->first();
- if (!is_null($employee)) {
- $itemID = $employee->PERS_IDPE;
- $itemFilt = array_filter($staffArrFn, function ($v, $k) use ($itemID) {
- return $v['ID'] == $itemID;
- }, ARRAY_FILTER_USE_BOTH);
- if (count($itemFilt) <= 0) {
- $staffArrFn[] = [
- 'ID' => $itemID,
- 'ID_USER' => $employee->USUA_IDUS,
- 'NAME' => $this->functionsController->joinName($employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA),
- 'TYPE' => $employee->PERS_TICO,
- ];
- }
- }
- }
- }
- }
- foreach ($staffArrFn as $key => $item) {
- $item['ID'] = $this->encryptionController->encrypt($item['ID']);
- $item['ID_USER'] = $this->encryptionController->encrypt($item['ID_USER']);
- $staffArrFn[$key] = $item;
- }
- return $this->responseController->makeResponse(false, 'EXITO', $staffArr);
- }
- public function getWorkOrderAttendance($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 relacionada no está encriptado correctamente', [], 400);
- }
- $workOrder = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $line],
- ['OTCO_IDOT', '=', $idOrder]
- ])->first();
- if (is_null($workOrder)) {
- return $this->responseController->makeResponse(true, 'La orden relacionada no está registrada.', [], 404);
- }
- $statusHistory = json_decode($workOrder->OTCO_HIES, true);
- $validatedHistoryFilt = array_filter($statusHistory, function ($v, $k) {
- return $v['ESTADO'] == 'VA';
- }, ARRAY_FILTER_USE_BOTH);
- if (empty($validatedHistoryFilt)) {
- return $this->responseController->makeResponse(true, 'La orden relacionada no está en el estado de validación', [], 404);
- }
- $validatedHistory = end($validatedHistoryFilt);
- $attendance = array_key_exists('ATENCION', $validatedHistory) ? $validatedHistory['ATENCION'] : [];
- $attendanceAux = [];
- foreach ($attendance as $item) {
- if ($item['RESPUESTA'] == 'A') {
- $attendanceAux[] = $item;
- }
- }
- return $this->responseController->makeResponse(false, 'EXITO', $attendanceAux);
- }
- public function setWorkOrderAttendance(Request $request)
- {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_order' => 'required|string',
- 'attendance' => 'required|string|in:A,R',
- 'data' => '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 solicitud seleccionada 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 que desea actualizar no existe.', [], 404);
- } else if ($order->OTCO_ESOR != 'VA') {
- return $this->responseController->makeResponse(true, 'La solicitud seleccionada no está validada.', [], 401);
- }
- if ($form['attendance'] == 'A' && !str_contains($form['data'], 'data:image/png')) {
- return $this->responseController->makeResponse(true, 'El archivo de la firma capturada es inválido.', [], 400);
- } else if ($form['attendance'] == 'R' && strlen($form['data']) < 10) {
- return $this->responseController->makeResponse(true, 'La cadena de comentarios tiene una longitud menor a 10 caracteres.', [], 400);
- }
- $userAttendance = ["ID" => $idUser, "RESPUESTA" => $form['attendance']];
- $signature = null;
- $comments = null;
- if ($form['attendance'] == 'A') {
- $filesPath = str_replace("app\\Http\\Controllers", "storage\\app\\files", __DIR__);
- if (!file_exists($filesPath)) {
- return $this->responseController->makeResponse(true, 'No se encontró la ubicación de almacenamiento de archivos.', [], 400);
- }
- generateSignatureFileName:
- $signatureFileName = $this->generateSignatureImageName();
- $signatureFileDir = $filesPath . "\\" . $signatureFileName;
- $signatureFileExists = file_exists($signatureFileDir);
- if ($signatureFileExists) goto generateSignatureFileName;
- $signatureFileData = str_replace("data:image/png;base64,", "", $form['data']);
- file_put_contents($signatureFileDir, base64_decode($signatureFileData));
- $now = $this->functionsController->now();
- $year = $now->year;
- $month = $now->month < 10 ? "0{$now->month}" : "0{$now->month}";
- $day = $now->day < 10 ? "0{$now->day}" : "{$now->day}";
- $fecr = substr("$year", -2) . $month . $day;
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_COMO', '=', "GMCO"],
- ['AFAL_CLDO', '=', "FO"],
- ['AFAL_NULI', '=', $form['linea']],
- ])->orderBy('AFAL_NUSE', 'desc')->first();
- $nuse = 1;
- if (!is_null($sec)) {
- $nuse = intval($sec->AFAL_NUSE) + 1;
- }
- $noar = "firma_conformidad_" . $idUser;
- $exte = "png";
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $form['linea']],
- ['AFAL_COMO', '=', "GMCO"],
- ['AFAL_CLDO', '=', "FO"],
- ['AFAL_NOAR', '=', $noar],
- ['AFAL_EXTE', '=', $exte],
- ])->orderBy('AFAL_NUVE', 'desc')->first();
- $nuve = 1;
- if (!is_null($ver)) {
- $nuve = intval($sec->AFAL_NUVE) + 1;
- }
- $tama = filesize($signatureFileDir);
- $code = intval($form['linea']) < 10 ? "0$form[linea]" : "$form[linea]";
- $code .= "-GMCO-FO-$fecr-";
- for ($i = strlen($nuse); $i < 6; $i++) {
- $code .= "0";
- }
- $code .= "$nuse=";
- $code .= $nuve < 10 ? "0$nuve=" : "$nuve=";
- $code .= "$noar.$exte";
- $usac = json_encode([$idUser]);
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $form['linea'],
- 'AFAL_COMO' => "GMCO",
- 'AFAL_CLDO' => "FO",
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $signatureFileDir,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr
- ]);
- $signature = $code;
- } else if ($form['attendance'] == 'R') {
- $comments = $form['data'];
- }
- if (!is_null($signature) || !is_null($comments)) {
- $userAttendance['FIRMA'] = $signature;
- $userAttendance['COMENTARIOS'] = $comments;
- $statusHistoryArr = json_decode($order->OTCO_HIES, true);
- $validatedHistoryFilt = array_filter($statusHistoryArr, function ($v, $k) {
- return $v['ESTADO'] == 'VA';
- }, ARRAY_FILTER_USE_BOTH);
- if (!empty($validatedHistoryFilt)) {
- $validatedHistory = end($validatedHistoryFilt);
- $validatedHistoryKeys = array_keys($validatedHistoryFilt);
- $validatedHistoryKey = end($validatedHistoryKeys);
- $attendance = array_key_exists('ATENCION', $validatedHistory) ? $validatedHistory['ATENCION'] : [];
- $attendance[] = $userAttendance;
- $validatedHistory['ATENCION'] = $attendance;
- $statusHistoryArr[$validatedHistoryKey] = $validatedHistory;
- }
- $statusHistoryStr = json_encode($statusHistoryArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder]
- ])->update([
- "OTCO_HIES" => $statusHistoryStr,
- "OTCO_USMO" => $idUser,
- "OTCO_FEMO" => $nowStr,
- ]);
- }
- $userName = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $action = $form['attendance'] == 'A' ? 'aceptó' : 'rechazó';
- $notificationActions = [];
- if ($form['attendance'] == 'A') {
- $notificationActions[] = [
- 'BOTON' => 'Revisar firma',
- 'FUNCION' => 'reviewSignatureInCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder), $this->encryptionController->encrypt($idUser)])
- ];
- } else if ($form['attendance'] == 'R') {
- $notificationActions[] = [
- 'BOTON' => 'Revisar comentarios',
- 'FUNCION' => 'reviewCommentsInCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder), $this->encryptionController->encrypt($idUser)])
- ];
- $notificationActions[] = [
- 'BOTON' => 'Reasignar orden',
- 'FUNCION' => 'revalidateCorrectiveWorkOrder',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt($idOrder)])
- ];
- }
- $notificationActions[] = [
- 'BOTON' => 'Ir al módulo',
- 'FUNCION' => 'openModule',
- 'PARAMETROS' => json_encode([$this->encryptionController->encrypt('GMCO/ORTR/GEOP')])
- ];
- $this->notificationsController->emitNotification(
- 'S002V01M09GMCO',
- "Orden de mantenimiento correctivo #$idOrder",
- "El usuario $userName ($idUser) $action atender la orden de mantenimiento #$idOrder.",
- $notificationActions,
- [$order->OTCO_IDUR],
- $idUser,
- $form['linea'],
- $this->getSocketClient(),
- $idOrder,
- 'Correctivo'
- );
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- private function generateSignatureImageName()
- {
- $upperLetters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
- $lowerLetters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
- $numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
- $fileName = "";
- for ($i = 0; $i < 40; $i++) {
- $charTypeSelector = rand(0, 2);
- $selectedChar = "";
- switch ($charTypeSelector) {
- case 0:
- $charSelector = rand(0, count($upperLetters) - 1);
- $selectedChar = $upperLetters[$charSelector];
- break;
- case 1:
- $charSelector = rand(0, count($lowerLetters) - 1);
- $selectedChar = $lowerLetters[$charSelector];
- break;
- case 2:
- $charSelector = rand(0, count($numbers) - 1);
- $selectedChar = $numbers[$charSelector];
- break;
- }
- $selectedChar = empty($selectedChar) ? 'A' : $selectedChar;
- $fileName .= $selectedChar;
- }
- return $fileName . '.png';
- }
- }
|