| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Database\Query\Builder;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Carbon;
- use Dompdf\Dompdf;
- use Illuminate\Database\Query\JoinClause;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Http\File;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\Style\Border;
- use PhpOffice\PhpSpreadsheet\Style\Color;
- use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
- use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
- class EquipmentManagementController extends Controller{
- private $responseController;
- private $encryptionController;
- private $functionsController;
- private $templatesUbic;
- private $documentManagementController;
- private $pccValidElements;
-
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->templatesUbic = $this->functionsController->getBasePath() . "\storage\app\public\pdf_templates\\01_05_GEEQ\\";
- $this->documentManagementController = new DocumentManagementController();
- $this->pccValidElements = [
- ['coord' => '0N', 'element' => 'PDC', 'code' => 'PDCXX'],
- ['coord' => '1F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '1I', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '1R', 'element' => 'SAP/IHM OA', 'code' => 'SAIOA'],
- ['coord' => '2F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '2I', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '2R', 'element' => 'PIU/DDP', 'code' => 'PIUDD'],
- ['coord' => '2V', 'element' => 'ODF', 'code' => 'ODFXX'],
- ['coord' => '3F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '3I', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '3Ñ', 'element' => 'SRV-COMMS PCC-A', 'code' => 'SRCPA'],
- ['coord' => '3R', 'element' => 'CCTV', 'code' => 'CCTVX'],
- ['coord' => '4F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '4I', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '4Ñ', 'element' => 'SRV-COMMS PCC-B', 'code' => 'SRCPB'],
- ['coord' => '4R', 'element' => 'LTE', 'code' => 'LTEXX'],
- ['coord' => '4V', 'element' => 'AC', 'code' => 'ACXXX'],
- ['coord' => '5Ñ', 'element' => 'SRV-COMMS PCC-C', 'code' => 'SRCPC'],
- ['coord' => '6F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '6I', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '6R', 'element' => 'TEL/GDA', 'code' => 'TELGD'],
- ['coord' => '6V', 'element' => 'AC', 'code' => 'ACXXX'],
- ['coord' => '7Ñ', 'element' => 'SCADA E&M', 'code' => 'SCAEM'],
- ['coord' => '7R', 'element' => 'CLK/CDA', 'code' => 'CLKCD'],
- ['coord' => '8B', 'element' => 'INTERRUPTOR ELECTROMAGNÉTICO 3x1600 AMP', 'code' => 'IE316'],
- ['coord' => '8R', 'element' => 'RMS', 'code' => 'RMSXX'],
- ['coord' => '9V', 'element' => 'LTE-B', 'code' => 'LTEBX'],
- ['coord' => '10B', 'element' => 'TRANSFORMADOR TIPO SECO 500 KVA', 'code' => 'TTS5K'],
- ['coord' => '11U', 'element' => 'ARMARIOS RECUPERACIÓN DE MANDO L1 A L6', 'code' => 'ARM16'],
- ['coord' => '11V', 'element' => 'ARMARIOS RECUPERACIÓN DE MANDO L1 A L6', 'code' => 'ARM16'],
- ['coord' => '11W', 'element' => 'MDF', 'code' => 'MDFXX'],
- ['coord' => '11Y', 'element' => 'ODF', 'code' => 'ODFXX'],
- ['coord' => '12F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '12J', 'element' => 'COBRE', 'code' => 'COBRE'],
- ['coord' => '12L', 'element' => 'COBRE', 'code' => 'COBRE'],
- ['coord' => '12M', 'element' => 'COBRE', 'code' => 'COBRE'],
- ['coord' => '12Ñ', 'element' => 'RED', 'code' => 'REDXX'],
- ['coord' => '12O', 'element' => 'RED', 'code' => 'REDXX'],
- ['coord' => '12Q', 'element' => 'RED', 'code' => 'REDXX'],
- ['coord' => '13B', 'element' => 'TABLERO A', 'code' => 'TABLA'],
- ['coord' => '14F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '15F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '15K', 'element' => 'CCTV L1 A L6', 'code' => 'CCT16'],
- ['coord' => '15Ñ', 'element' => 'RED C Y S L1 A L6', 'code' => 'RCS16'],
- ['coord' => '15W', 'element' => 'TRACCIÓN', 'code' => 'TRACC'],
- ['coord' => '16B', 'element' => 'TABLERO P', 'code' => 'TABLP'],
- ['coord' => '16F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '16K', 'element' => 'CCTV L1 A L6', 'code' => 'CCT16'],
- ['coord' => '16Ñ', 'element' => 'RED C Y S L1 A L6', 'code' => 'RCS16'],
- ['coord' => '16W', 'element' => 'TRACCIÓN', 'code' => 'TRACC'],
- ['coord' => '17W', 'element' => 'DISTRIBUCIÓN DE ENERGÍA L2', 'code' => 'DIEL2'],
- ['coord' => '19B', 'element' => 'TABLERO B', 'code' => 'TABLB'],
- ['coord' => '19K', 'element' => 'TELECOM L2', 'code' => 'TELL2'],
- ['coord' => '19Ñ', 'element' => 'SERVIDOR BASE DE DATOS L2', 'code' => 'SBDL2'],
- ['coord' => '19R', 'element' => 'SERVIDOR DE APLICACIONES L2', 'code' => 'SEAL2'],
- ['coord' => '19W', 'element' => 'DISTRIBUCIÓN DE ENERGÍA L3', 'code' => 'DIEL3'],
- ['coord' => '20F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '20K', 'element' => 'TELECOM L3', 'code' => 'TELL3'],
- ['coord' => '20Ñ', 'element' => 'SERVIDOR BASE DE DATOS L3', 'code' => 'SBDL3'],
- ['coord' => '20R', 'element' => 'SERVIDOR DE APLICACIONES L3', 'code' => 'SEAL3'],
- ['coord' => '20W', 'element' => 'DISTRIBUCIÓN DE ENERGÍA L4', 'code' => 'DIEL4'],
- ['coord' => '21B', 'element' => 'TRANSFORMADOR TIPO SECO 500 KVA', 'code' => 'TTS5K'],
- ['coord' => '21F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '22F', 'element' => 'UPS', 'code' => 'UPSXX'],
- ['coord' => '22K', 'element' => 'TELECOM L4', 'code' => 'TELL4'],
- ['coord' => '22Ñ', 'element' => 'SERVIDOR BASE DE DATOS L4', 'code' => 'SBDL4'],
- ['coord' => '22R', 'element' => 'SERVIDOR DE APLICACIONES L4', 'code' => 'SEAL4'],
- ['coord' => '22W', 'element' => 'DISTRIBUCIÓN DE ENERGÍA L5', 'code' => 'DIEL5'],
- ['coord' => '23F', 'element' => 'BAT', 'code' => 'BATXX'],
- ['coord' => '23K', 'element' => 'TELECOM L5', 'code' => 'TELL5'],
- ['coord' => '23Ñ', 'element' => 'SERVIDOR BASE DE DATOS L5', 'code' => 'SBDL5'],
- ['coord' => '23R', 'element' => 'SERVIDOR DE APLICACIONES L5', 'code' => 'SEAL5'],
- ['coord' => '24B', 'element' => 'INTERRUPTOR ELECTROMAGNÉTICO 3x1600 AMP', 'code' => 'IE316'],
- ['coord' => '24K', 'element' => 'TELECOM L6', 'code' => 'TELL6'],
- ['coord' => '24Ñ', 'element' => 'SERVIDOR BASE DE DATOS L6', 'code' => 'SBDL6'],
- ['coord' => '24R', 'element' => 'SERVIDOR DE APLICACIONES L6', 'code' => 'SEAL6'],
- ['coord' => '24W', 'element' => 'DISTRIBUCIÓN DE ENERGÍA L6', 'code' => 'DIEL6'],
- ];
- }
- public function registerFamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => 'required|string',
- 'family_name' => 'required|string|max:50',
- 'family_icon' => 'required|string|max:50',
- 'family_color' => 'required|string',
- 'custom_icon' => 'required|string|in:S,N',
- 'icon_file' => 'required_if:custom_icon,=,S|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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->get()->all();
- if(count($family) > 0){
- return $this->responseController->makeResponse(true, 'El código de la familia ya se encuentra registrado.', [], 401);
- }
- $aipe = null;
- if($form['custom_icon'] == 'S'){
- $tempFileID = $this->encryptionController->decrypt($form['icon_file']);
- if(!$tempFileID){
- return $this->responseController->makeResponse(true, 'El código del archivo temporal del icono personalizado no fue encriptado correctamente.', [], 400);
- }
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado no existe.', [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado está eliminado.', [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $aipe = $finalFile[1];
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFAMI')->insert([
- 'FAMI_NULI' => $form['linea'],
- 'FAMI_COFA' => $familyCode,
- 'FAMI_NOFA' => $form['family_name'],
- 'FAMI_ICON' => $form['family_icon'],
- 'FAMI_COLO' => $form['family_color'],
- 'FAMI_ICPE' => $form['custom_icon'],
- 'FAMI_AIPE' => $aipe,
- 'FAMI_USRE' => $idUser,
- 'FAMI_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P02REFA',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la familia $form[family_name].",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getFamilies($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);
- }
- $families = DB::table('S002V01TFAMI')->select([
- 'FAMI_COFA AS CODIGOFAMILIA',
- 'FAMI_NOFA AS NOMBREFAMILIA',
- 'FAMI_COLO AS COLORFAMILIA',
- 'FAMI_ICON AS ICONO',
- 'FAMI_ICPE AS ICONO_PERSONALIZADO',
- 'FAMI_AIPE AS ARCHIVO_ICONO',
- 'FAMI_ESTA AS ESTADO',
- 'FAMI_USRE AS USRREG',
- 'FAMI_FERE AS FECREG',
- 'FAMI_USMO AS USRMOD',
- 'FAMI_FEMO AS FECMOD'
- ])->where('FAMI_NULI', '=', $line)->get()->all();
- foreach($families as $key=>$val){
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->USRREG],
- ])->first();
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $val->USRREG = $nameReg . " (" . $val->USRREG . ")";
- if($val->USRMOD != null){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->USRMOD],
- ])->first();
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $val->USRMOD = $nameMod . " (" . $val->USRMOD . ")";
- }
- $subfamilies = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $val->CODIGOFAMILIA],
- ])->get()->all();
-
- $val->SUBFAMILIAS = count($subfamilies);
- $val->CODIGOFAMILIA = $this->encryptionController->encrypt($val->CODIGOFAMILIA);
-
- if(!is_null($val->ARCHIVO_ICONO)){
- $val->ARCHIVO_ICONO = $this->encryptionController->encrypt($val->ARCHIVO_ICONO);
- }
- $families[$key] = $val;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P01COFA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las familias registradas.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $families);
- }
- public function getFamily($familyCode, $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);
- }
- $familyCode = $this->encryptionController->decrypt($familyCode);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia seleccionada no está encriptado correctamente', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->select([
- 'FAMI_COFA AS CODIGO_FAMILIA',
- 'FAMI_NOFA AS NOMBRE_FAMILIA',
- 'FAMI_COLO AS COLOR_FAMILIA',
- 'FAMI_ICON AS ICONO',
- 'FAMI_ICPE AS ICONO_PERSONALIZADO',
- 'FAMI_AIPE AS ARCHIVO_ICONO',
- 'FAMI_ESTA AS ESTADO',
- 'FAMI_USRE AS USRREG',
- 'FAMI_FERE AS FECREG',
- 'FAMI_USMO AS USRMOD',
- 'FAMI_FEMO AS FECMOD',
- ])->where([
- ['FAMI_NULI', '=', $line],
- ['FAMI_COFA', '=', $familyCode]
- ])->first();
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia seleccionada no existe.', [], 404);
- }
- $family->CODIGO_FAMILIA = $this->encryptionController->encrypt($family->CODIGO_FAMILIA);
- if(!is_null($family->ARCHIVO_ICONO)){
- $family->ARCHIVO_ICONO = $this->encryptionController->encrypt($family->ARCHIVO_ICONO);
- }
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $family->USRREG],
- ])->first();
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $family->USRREG = $nameReg . " (" . $family->USRREG . ")";
- if($family->USRMOD != null){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $family->USRMOD],
- ])->first();
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $family->USRMOD = $nameMod . " (" . $family->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,
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P01COFA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $family);
- }
- public function updateFamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => 'required|string',
- 'family_icon' => 'required|string|max:50',
- 'family_color' => 'required|string',
- 'custom_icon' => 'required|string|in:S,N',
- 'icon_file' => 'required_if:custom_icon,=,S|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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia que desea actualizar no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia que desea actualizar está eliminada.', [], 404);
- }
- $aipe = null;
- if($form['custom_icon'] == 'S'){
- $tempFileID = $this->encryptionController->decrypt($form['icon_file']);
- if(!$tempFileID){
- return $this->responseController->makeResponse(true, 'El código del archivo temporal del icono personalizado no fue encriptado correctamente.', [], 400);
- }else if(str_contains($tempFileID, '=')){
- $aipe = $tempFileID;
- goto familyUpdate;
- }
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado no existe.', [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado está eliminado.', [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $aipe = $finalFile[1];
- }
-
- familyUpdate:
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->update([
- 'FAMI_NOFA' => $form['family_name'],
- 'FAMI_ICON' => $form['family_icon'],
- 'FAMI_ICPE' => $form['custom_icon'],
- 'FAMI_COLO' => $form['family_color'],
- 'FAMI_AIPE' => $aipe,
- 'FAMI_USMO' => $idUser,
- 'FAMI_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P02REFA',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteFamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => '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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia que desea eliminar no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia que desea eliminar está eliminada.', [], 404);
- }
-
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->update([
- 'FAMI_ESTA' => 'Eliminado',
- 'FAMI_USMO' => $idUser,
- 'FAMI_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P02REFA',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerSubfamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => 'required|string',
- 'subfamily_code' => 'required|string',
- 'subfamily_name' => 'required|string|max:60',
- 'subfamily_icon' => 'required|string|max:50',
- 'custom_icon' => 'required|string|in:S,N',
- 'icon_file' => 'required_if:custom_icon,=,S|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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia relacionada no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia relacionada no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia relacionada está eliminada.', [], 404);
- }
- $subfamilyCode = $this->encryptionController->decrypt($form['subfamily_code']);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'El código de la subfamilia no fue encriptado correctamente.', [], 400);
- }
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $form['linea']],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode],
- ])->get()->all();
- if(count($subfamily) > 0){
- return $this->responseController->makeResponse(true, 'El código de la subfamilia ya se encuentra registrado.', [], 401);
- }
- $aipe = null;
- if($form['custom_icon'] == 'S'){
- $tempFileID = $this->encryptionController->decrypt($form['icon_file']);
- if(!$tempFileID){
- return $this->responseController->makeResponse(true, 'El código del archivo temporal del icono personalizado no fue encriptado correctamente.', [], 400);
- }
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado no existe.', [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado está eliminado.', [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $aipe = $finalFile[1];
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TSUBF')->insert([
- 'SUBF_NULI' => $form['linea'],
- 'SUBF_COFA' => $familyCode,
- 'SUBF_COSU' => $subfamilyCode,
- 'SUBF_NOSU' => $form['subfamily_name'],
- 'SUBF_ICON' => $form['subfamily_icon'],
- 'SUBF_ICPE' => $form['custom_icon'],
- 'SUBF_AIPE' => $aipe,
- 'SUBF_USRE' => $idUser,
- 'SUBF_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P04RESU',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la subfamilia $form[subfamily_name].",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getSubfamilies($familyCode, $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);
- }
- $familyCode = $this->encryptionController->decrypt($familyCode);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia relacionada no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $line],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia relacionada no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia relacionada está eliminada.', [], 404);
- }
- $subfamilies = DB::table('S002V01TSUBF')->select([
- 'SUBF_COFA AS CODIGOFAMILIA',
- 'SUBF_COSU AS CODIGOSUBFAMILIA',
- 'SUBF_NOSU AS NOMBRESUBFAMILIA',
- 'SUBF_ICON AS ICONO',
- 'SUBF_ICPE AS ICONO_PERSONALIZADO',
- 'SUBF_AIPE AS ARCHIVO_ICONO',
- 'SUBF_ESTA AS ESTADO',
- 'SUBF_USRE AS USRREG',
- 'SUBF_FERE AS FECREG',
- 'SUBF_USMO AS USRMOD',
- 'SUBF_FEMO AS FECMOD'
- ])->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $familyCode],
- ])->get()->all();
- foreach($subfamilies as $key=>$val){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_ESEQ', '=', 'I'],
- ['EQUI_FAMI', '=', $familyCode],
- ['EQUI_SUBF', '=', $val->CODIGOSUBFAMILIA]
- ])->get()->all();
- $val->CODIGOFAMILIA = $this->encryptionController->encrypt($val->CODIGOFAMILIA);
- $val->CODIGOSUBFAMILIA = $this->encryptionController->encrypt($val->CODIGOSUBFAMILIA);
- if(!is_null($val->ARCHIVO_ICONO)){
- $val->ARCHIVO_ICONO = $this->encryptionController->encrypt($val->ARCHIVO_ICONO);
- }
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->USRREG],
- ])->first();
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $val->USRREG = $nameReg . " (" . $val->USRREG . ")";
- if($val->USRMOD != null){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->USRMOD],
- ])->first();
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $val->USRMOD = $nameMod . " (" . $val->USRMOD . ")";
- }
-
- $val->TIENE_HIJOS = count($children) > 0;
- $families[$key] = $val;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P03COSU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las subfamilias relacionadas a la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $subfamilies);
- }
- public function updateSubfamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => 'required|string',
- 'subfamily_code' => 'required|string',
- 'subfamily_name' => 'required|string|max:60',
- 'subfamily_icon' => 'required|string|max:50',
- 'custom_icon' => 'required|string|in:S,N',
- 'icon_file' => 'required_if:custom_icon,=,S|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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia relacionada no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia relacionada no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia relacionada está eliminada.', [], 404);
- }
- $subfamilyCode = $this->encryptionController->decrypt($form['subfamily_code']);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'El código de la subfamilia no fue encriptado correctamente.', [], 400);
- }
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $form['linea']],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode],
- ])->first();
-
- if(is_null($subfamily)){
- return $this->responseController->makeResponse(true, 'La subfamilia que desea actualizar no existe.', [], 404);
- }else if($subfamily->SUBF_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La subfamilia que desea actualizar está eliminada.', [], 404);
- }
- $aipe = null;
- if($form['custom_icon'] == 'S'){
- $tempFileID = $this->encryptionController->decrypt($form['icon_file']);
- if(!$tempFileID){
- return $this->responseController->makeResponse(true, 'El código del archivo temporal del icono personalizado no fue encriptado correctamente.', [], 400);
- }else if(str_contains($tempFileID, '=')){
- $aipe = $tempFileID;
- goto subfamilyUpdate;
- }
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado no existe.', [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo temporal del icono personalizado está eliminado.', [], 404);
- }
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $aipe = $finalFile[1];
- }
-
- subfamilyUpdate:
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TSUBF')->where([
- 'SUBF_NULI' => $form['linea'],
- 'SUBF_COFA' => $familyCode,
- 'SUBF_COSU' => $subfamilyCode,
- ])->update([
- 'SUBF_NOSU' => $form['subfamily_name'],
- 'SUBF_ICON' => $form['subfamily_icon'],
- 'SUBF_ICPE' => $form['custom_icon'],
- 'SUBF_AIPE' => $aipe,
- 'SUBF_USMO' => $idUser,
- 'SUBF_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P04RESU',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la subfamilia $subfamilyCode de la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteSubfamily(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'family_code' => 'required|string',
- 'subfamily_code' => '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);
- }
- $familyCode = $this->encryptionController->decrypt($form['family_code']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia relacionada no fue encriptado correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
-
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia relacionada no existe.', [], 404);
- }else if($family->FAMI_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La familia relacionada está eliminada.', [], 404);
- }
- $subfamilyCode = $this->encryptionController->decrypt($form['subfamily_code']);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'El código de la subfamilia no fue encriptado correctamente.', [], 400);
- }
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $form['linea']],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode],
- ])->first();
-
- if(is_null($subfamily)){
- return $this->responseController->makeResponse(true, 'La subfamilia que desea eliminar no existe.', [], 404);
- }else if($subfamily->SUBF_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La subfamilia que desea eliminar está eliminada.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TSUBF')->where([
- 'SUBF_NULI' => $form['linea'],
- 'SUBF_COFA' => $familyCode,
- 'SUBF_COSU' => $subfamilyCode,
- ])->update([
- 'SUBF_ESTA' => 'Eliminado',
- 'SUBF_USMO' => $idUser,
- 'SUBF_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F02DFSU',
- 'S002V01P04RESU',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la subfamilia $subfamilyCode de la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getLocations($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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $locationsEnc = file_get_contents($ubic . "locations.sam");
- $locationsDec = $this->encryptionController->decrypt($locationsEnc);
- $locationsArr = json_decode($locationsDec, true);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el arreglo de ubicaciones de la línea.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $locationsArr);
- }
- public function getOccupationAreas($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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $occupationAreasEnc = file_get_contents($ubic . "occupation-areas.sam");
- $occupationAreasDec = $this->encryptionController->decrypt($occupationAreasEnc);
- $occupationAreasArr = json_decode($occupationAreasDec, true);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las áreas de ocupación.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $occupationAreasArr);
- }
- public function registerOccupation(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'area' => 'required|string',
- 'description' => 'required|string|min:15|max:150',
- ]);
-
- 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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $occupationAreasEnc = file_get_contents($ubic . "occupation-areas.sam");
- $occupationAreasDec = $this->encryptionController->decrypt($occupationAreasEnc);
- $occupationAreasArr = json_decode($occupationAreasDec, true);
- $occupationAreasArrDec = [];
- foreach($occupationAreasArr as $area){
- $occupationAreasArrDec[] = [
- 'CODE' => $this->encryptionController->decrypt($area['CODE']),
- 'AREA' => $this->encryptionController->decrypt($area['AREA'])
- ];
- }
- $areaCode = $this->encryptionController->decrypt($form['area']);
- if(!$areaCode){
- return $this->responseController->makeResponse(true, 'El área de ocupación no fue encriptada correctamente.', [], 400);
- }
- $areaCodeExists = array_filter($occupationAreasArrDec, function($v, $k) use ($areaCode) {
- return $v['CODE'] == $areaCode;
- }, ARRAY_FILTER_USE_BOTH);
-
- if(count($areaCodeExists) < 1){
- return $this->responseController->makeResponse(true, 'El área de ocupación seleccionada no existe.', [], 400);
- }
-
- $areaName = end($areaCodeExists)['AREA'] . " ($areaCode)";
- $lastOccupationByArea = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $areaCode]
- ])->orderBy('OCUP_IDOC', 'desc')->first();
- $id = 0;
- if(is_null($lastOccupationByArea)){
- $id = 1;
- }else{
- $id = $lastOccupationByArea->OCUP_IDOC + 1;
- }
- if($id > 999){
- return $this->responseController->makeResponse(true, "El área $areaName llegó al límite de 999 elementos.", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOCUP')->insert([
- 'OCUP_NULI' => $form['linea'],
- 'OCUP_AREA' => $areaCode,
- 'OCUP_IDOC' => $id,
- 'OCUP_DESC' => $form['description'],
- 'OCUP_USRE' => $idUser,
- 'OCUP_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró una nueva ocupación para el área $areaName.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getOccupations($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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $occupationAreasEnc = file_get_contents($ubic . "occupation-areas.sam");
- $occupationAreasDec = $this->encryptionController->decrypt($occupationAreasEnc);
- $occupationAreasArr = json_decode($occupationAreasDec, true);
- $occupationAreasArrDec = [];
- foreach($occupationAreasArr as $area){
- $occupationAreasArrDec[] = [
- 'CODE' => $this->encryptionController->decrypt($area['CODE']),
- 'AREA' => $this->encryptionController->decrypt($area['AREA'])
- ];
- }
- $occupations = DB::table('S002V01TOCUP')->where('OCUP_NULI', '=', $line)->get()->all();
- $occupationsFn = [];
- foreach($occupations as $occupation){
- $areaInd = $occupation->OCUP_AREA;
- $areaStr = $areaInd < 10 ? "0$areaInd" : "$areaInd";
- $area = array_filter($occupationAreasArrDec, function($v, $k) use ($areaStr) {
- return $v['CODE'] == $areaStr;
- }, ARRAY_FILTER_USE_BOTH);
- $areaName = end($area)['AREA'] . " (" . end($area)['CODE'] . ")";
- $occupationInd = "" . $occupation->OCUP_IDOC . "";
- $occupationStr = "";
- for($i = strlen($occupationInd); $i < 3; $i++){
- $occupationStr .= '0';
- }
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $occupation->OCUP_USRE],
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA) . " (" . $occupation->OCUP_USRE . ")";
- $usrModName = null;
- if($occupation->OCUP_USMO != null){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $occupation->OCUP_USMO],
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA) . " (" . $occupation->OCUP_USMO . ")";
- }
- $occupationStr = $areaStr . $occupationStr . $occupationInd;
- $occupationsFn[] = [
- "NOMBREAREA" => $areaName,
- "OCUPACION" => $occupationStr,
- "DESCRIPCION" => $occupation->OCUP_DESC,
- "ESTADO" => $occupation->OCUP_ESTA,
- "USRREG" => $usrRegName,
- "FECREG" => $occupation->OCUP_FERE,
- "USRMOD" => $usrModName,
- "FECMOD" => $occupation->OCUP_FEMO,
- ];
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las ocupaciones registradas.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $occupationsFn);
- }
- public function updateOccupation(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'area' => 'required|string',
- 'occupation' => 'required|string',
- 'description' => 'required|string|min:15|max:150',
- ]);
-
- 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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $occupationAreasEnc = file_get_contents($ubic . "occupation-areas.sam");
- $occupationAreasDec = $this->encryptionController->decrypt($occupationAreasEnc);
- $occupationAreasArr = json_decode($occupationAreasDec, true);
- $occupationAreasArrDec = [];
- foreach($occupationAreasArr as $area){
- $occupationAreasArrDec[] = [
- 'CODE' => $this->encryptionController->decrypt($area['CODE']),
- 'AREA' => $this->encryptionController->decrypt($area['AREA'])
- ];
- }
- $areaCode = $this->encryptionController->decrypt($form['area']);
- if(!$areaCode){
- return $this->responseController->makeResponse(true, 'El área de ocupación no fue encriptada correctamente.', [], 400);
- }
- $areaCodeExists = array_filter($occupationAreasArrDec, function($v, $k) use ($areaCode) {
- return $v['CODE'] == $areaCode;
- }, ARRAY_FILTER_USE_BOTH);
-
- if(count($areaCodeExists) < 1){
- return $this->responseController->makeResponse(true, 'El área de ocupación relacionada no existe.', [], 400);
- }
- $occupation = $this->encryptionController->decrypt($form['occupation']);
- if(!$occupation){
- return $this->responseController->makeResponse(true, 'La ocupación no fue encriptada correctamente.', [], 400);
- }
- $occupationID = substr($occupation, 2);
- $occupationObj = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $areaCode],
- ['OCUP_IDOC', '=', $occupationID],
- ])->first();
-
- if(is_null($occupationObj)){
- return $this->responseController->makeResponse(true, 'La ocupación que desea actualizar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $areaCode],
- ['OCUP_IDOC', '=', $occupationID],
- ])->update([
- 'OCUP_DESC' => $form['description'],
- 'OCUP_USMO' => $idUser,
- 'OCUP_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la ocupación $occupation.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteOccupation(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'area' => 'required|string',
- 'occupation' => '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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $occupationAreasEnc = file_get_contents($ubic . "occupation-areas.sam");
- $occupationAreasDec = $this->encryptionController->decrypt($occupationAreasEnc);
- $occupationAreasArr = json_decode($occupationAreasDec, true);
- $occupationAreasArrDec = [];
- foreach($occupationAreasArr as $area){
- $occupationAreasArrDec[] = [
- 'CODE' => $this->encryptionController->decrypt($area['CODE']),
- 'AREA' => $this->encryptionController->decrypt($area['AREA'])
- ];
- }
- $areaCode = $this->encryptionController->decrypt($form['area']);
- if(!$areaCode){
- return $this->responseController->makeResponse(true, 'El área de ocupación no fue encriptada correctamente.', [], 400);
- }
- $areaCodeExists = array_filter($occupationAreasArrDec, function($v, $k) use ($areaCode) {
- return $v['CODE'] == $areaCode;
- }, ARRAY_FILTER_USE_BOTH);
-
- if(count($areaCodeExists) < 1){
- return $this->responseController->makeResponse(true, 'El área de ocupación relacionada no existe.', [], 400);
- }
- $occupation = $this->encryptionController->decrypt($form['occupation']);
- if(!$occupation){
- return $this->responseController->makeResponse(true, 'La ocupación no fue encriptada correctamente.', [], 400);
- }
- $occupationID = substr($occupation, 2);
- $occupationObj = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $areaCode],
- ['OCUP_IDOC', '=', $occupationID],
- ])->first();
-
- if(is_null($occupationObj)){
- return $this->responseController->makeResponse(true, 'La ocupación que desea eliminar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $areaCode],
- ['OCUP_IDOC', '=', $occupationID],
- ])->update([
- 'OCUP_ESTA' => 'Eliminado',
- 'OCUP_USMO' => $idUser,
- 'OCUP_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la ocupación $occupation.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function saveEquipmentPreCodified(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'hierarchy' => 'required|string|in:Padre,Hijo',
- 'parent_equipment' => 'required_if:hierarchy,=,Hijo|string',
- 'code_type' => 'required|integer|between:1,6',
- 'origin_location' => 'required|string',
- 'origin_level' => 'required|string',
- 'origin_occupation' => 'required|string',
- 'origin_element' => 'required_unless:code_type,4|string',
- 'origin_element_enc' => 'required_if:code_type,=,4|string',
- 'origin_coords' => 'required|string|min:7|max:7',
- 'origin_coords_plane' => 'string',
- 'family' => 'required|string',
- 'subfamily' => 'required|string',
- 'status' => 'required|string',
- 'equipment_type' => 'required|string|max:150',
- 'equipment_model' => 'required|string|max:75',
- 'images' => 'required|json',
- 'documents' => 'required|json',
- 'acquisition_date' => 'required|date',
- 'warranty_start_date' => 'required|date',
- 'warranty_end_date' => 'required|date',
- 'equipment_provider' => 'required|string',
- 'serial_number' => 'required|string|max:150',
- 'has_software' => 'required|string|in:Si,No',
- 'software_name' => 'required_if:has_software,=,Si|string|max:150',
- 'software_version' => 'required_if:has_software,=,Si|string|max:75',
- 'pre_generated_code' => 'required|string',
- 'pcc_intersection' => 'required_if:code_type,=,2|string|max:5',
- 'pcc_position' => 'required_if:code_type,=,2|string|max:2',
- 'origin_kilometer' => 'required_if:code_type,=,3|numeric',
- 'origin_code_type' => 'required_if:code_type,=,6|numeric|between:1,5',
- 'origin_kilometer' => 'required_if:origin_code_type,=,3|numeric',
- 'origin_code_part_used' => 'required_if:origin_code_type,=,4|string|in:O,D',
- 'train_area' => 'required_if:code_type,=,5|string',
- 'destiny_location' => 'required_if:code_type,=,3|string',
- 'destiny_level' => 'required_if:code_type,=,3|string',
- 'destiny_occupation' => 'required_if:code_type,=,3|string',
- 'destiny_element' => 'required_if:code_type,=,3|string|max:150',
- 'destiny_element' => 'required_if:code_type,=,6|string',
- 'destiny_element_enc' => 'required_if:code_type,=,4|string',
- 'destiny_kilometer' => 'required_if:code_type,=,3|string',
- 'destiny_location' => 'required_if:code_type,=,4|string',
- 'destiny_level' => 'required_if:code_type,=,4|string',
- 'destiny_occupation' => 'required_if:code_type,=,4|string',
- 'destiny_code_type' => 'required_if:code_type,=,6|numeric|between:1,5',
- 'destiny_kilometer' => 'required_if:destiny_code_type,=,3|numeric',
- 'destiny_code_part_used' => 'required_if:destiny_code_type,=,4|string|in:O,D',
- 'destiny_coords' => 'required_if:code_type,=,4|string',
- 'destiny_coords' => 'required_if:code_type,=,6|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);
- }
- $eqpa = null;
- if($form['hierarchy'] == 'Hijo'){
- $eqpa = $this->encryptionController->decrypt($form['parent_equipment']);
- if(!$eqpa){
- return $this->responseController->makeResponse(true, 'El ID del equipamiento padre no fue encriptado correctamente.', [], 400);
- }
- $parentEquipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $eqpa],
- ])->first();
-
- if(is_null($parentEquipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento padre no existe.', [], 404);
- }
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $locationsEnc = file_get_contents($ubic . "locations.sam");
- $locationsDec = $this->encryptionController->decrypt($locationsEnc);
- $locationsArr = json_decode($locationsDec, true);
- $locationsArrDec = [];
- foreach($locationsArr as $location){
- $locationStr = $this->encryptionController->decrypt($location['LOCATION']);
- $code = $this->encryptionController->decrypt($location['CODE']);
- $locationsArrDec[] = [
- 'LOCATION' => $locationStr,
- 'CODE' => $code
- ];
- }
- $originLocation = $this->encryptionController->decrypt($form['origin_location']);
- if(!$originLocation){
- return $this->responseController->makeResponse(true, 'La ubicación de origen no fue encriptada correctamente.', [], 400);
- }
- $originLocationFilt = array_filter($locationsArrDec, function($v, $k) use ($originLocation) {
- return $v['CODE'] == $originLocation;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($originLocationFilt) < 1){
- return $this->responseController->makeResponse(true, 'La ubicación de origen no se encuentra registrada en el sistema.', [], 404);
- }
- $destinyLocation = null;
- if(isset($form['destiny_location'])){
- $destinyLocation = $this->encryptionController->decrypt($form['destiny_location']);
- if(!$destinyLocation){
- return $this->responseController->makeResponse(true, 'La ubicación de destino no fue encriptada correctamente.', [], 400);
- }
- $destinyLocationFilt = array_filter($locationsArrDec, function($v, $k) use ($destinyLocation) {
- return $v['CODE'] == $destinyLocation;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($destinyLocationFilt) < 1){
- return $this->responseController->makeResponse(true, 'La ubicación de destino no se encuentra registrada en el sistema.', [], 404);
- }
- }
- $originLevel = $this->encryptionController->decrypt($form['origin_level']);
- if(!$originLevel){
- return $this->responseController->makeResponse(true, 'El nivel de origen no fue encriptado correctamente.', [], 400);
- }
- $supportedLevels = [];
- for($i = 5; $i > 0; $i--){
- $supportedLevels[] = "S0$i";
- }
- for($i = 0; $i <= 15; $i++){
- $tag = $i < 10 ? "P0$i" : "P$i";
- $supportedLevels[] = $tag;
- }
- if(!in_array($originLevel, $supportedLevels)){
- return $this->responseController->makeResponse(true, 'El nivel de origen seleccionado es inválido.', [], 400);
- }
- $destinyLevel = null;
- if(isset($form['destiny_level'])){
- $destinyLevel = $this->encryptionController->decrypt($form['destiny_level']);
- if(!in_array($destinyLevel, $supportedLevels)){
- return $this->responseController->makeResponse(true, 'El nivel de destino seleccionado es inválido.', [], 400);
- }
- }
- $originOccupationStr = $this->encryptionController->decrypt($form['origin_occupation']);
- if(!$originOccupationStr){
- return $this->responseController->makeResponse(true, 'La ocupación de origen no fue encriptada correctamente.', [], 400);
- }
- if($form['code_type'] == '5'){
- $trainOccupationsEnc = file_get_contents($ubic . "train-occupations.sam");
- $trainOccupationsDec = $this->encryptionController->decrypt($trainOccupationsEnc);
- $trainOccupationsArr = json_decode($trainOccupationsDec, true);
- foreach($trainOccupationsArr as $k0=>$v0){
- $trainOccupation = [];
- foreach($v0 as $k1=>$v1){
- $valDec = $this->encryptionController->decrypt($v1);
- $trainOccupation[$k1] = $valDec;
- }
- $trainOccupationsArr[$k0] = $trainOccupation;
- }
- $occupationFilt = array_filter($trainOccupationsArr, function($v, $k) use ($originOccupationStr) {
- return $v['CODE'] == $originOccupationStr;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($occupationFilt) < 1){
- return $this->responseController->makeResponse(true, 'La ocupación de origen seleccionada no existe.', [], 404);
- }
- }else{
- $originOccupationArea = substr($originOccupationStr, 0, 2);
- $originOccupationID = substr($originOccupationStr, 2);
- $originOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $originOccupationArea],
- ['OCUP_IDOC', '=', $originOccupationID]
- ])->first();
-
- if(is_null($originOccupation)){
- return $this->responseController->makeResponse(true, 'La ocupación de origen seleccionada no existe.', [], 404);
- }
- }
- $destinyOccupationStr = null;
- if(isset($form['destiny_occupation'])){
- $destinyOccupationStr = $this->encryptionController->decrypt($form['destiny_occupation']);
- if(!$destinyOccupationStr){
- return $this->responseController->makeResponse(true, 'La ocupación de destino no fue encriptada correctamente.', [], 400);
- }
- $destinyOccupationArea = substr($destinyOccupationStr, 0, 2);
- $destinyOccupationID = substr($destinyOccupationStr, 2);
- $destinyOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $destinyOccupationArea],
- ['OCUP_IDOC', '=', $destinyOccupationID]
- ])->first();
- if(is_null($destinyOccupation)){
- return $this->responseController->makeResponse(true, 'La ocupación de destino seleccionada no existe.', [], 404);
- }
- }
- $originCoords = null;
- $originCoordsPlaneID = null;
- $destinyCoords = null;
- $destinyCoordsPlaneID = null;
- if($form['code_type'] != '5' && $form['code_type'] != '2' && $form['code_type'] != '3'){
- if($form['code_type'] == '4'){
- $originElementCode = $this->encryptionController->decrypt($form['origin_element_enc']);
- if(!$originElementCode){
- return $this->responseController->makeResponse(true, 'El elemento de origen no fue encriptado correctamente.', [], 400);
- }
- $originElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $originElementCode],
- ])->first();
- if(is_null($originElement)){
- return $this->responseController->makeResponse(true, 'El elemento de origen no existe.', [], 404);
- }
- $originCoordsPlaneID = $originElement->EQUI_PCOR;
- $originCoords = $originElement->EQUI_COOR;
- $destinyElementCode = $this->encryptionController->decrypt($form['destiny_element_enc']);
- if(!$destinyElementCode){
- return $this->responseController->makeResponse(true, 'El elemento de destino no fue encriptado correctamente.', [], 400);
- }
- $destinyElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $destinyElementCode],
- ])->first();
- if(is_null($destinyElement)){
- return $this->responseController->makeResponse(true, 'El elemento de destino no existe.', [], 404);
- }
- $destinyCoordsPlaneID = $destinyElement->EQUI_PCOR;
- $destinyCoords = $destinyElement->EQUI_COOR;
- }else if($form['code_type'] == '6'){
- if($form['origin_code_type'] == '1'){
- $originCodeDec = $this->encryptionController->decrypt($form['origin_element']);
- if(!$originCodeDec){
- return $this->responseController->makeResponse(true, 'El código del elemento de origen no fue encriptado correctamente.', [], 400);
- }
-
- $originElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $originCodeDec]
- ])->first();
-
- if(is_null($originElement)){
- return $this->responseController->makeResponse(true, 'El elemento de origen no existe.', [], 404);
- }
- $originCoords = $originElement->EQUI_COOR;
- $originCoordsPlaneID = $originElement->EQUI_PCOR;
- }else if($form['origin_code_type'] == '4'){
- $originCodeDec = $this->encryptionController->decrypt($form['origin_element']);
- if(!$originCodeDec){
- return $this->responseController->makeResponse(true, 'El código del elemento de origen no fue encriptado correctamente.', [], 400);
- }
-
- $originElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $originCodeDec]
- ])->first();
-
- if(is_null($originElement)){
- return $this->responseController->makeResponse(true, 'El elemento de origen no existe.', [], 404);
- }
- $originCodeArr = explode('_', $originCodeDec);
- if(count($originCodeArr) != 2){
- return $this->responseController->makeResponse(true, 'El código del elemento de origen tiene un formato inválido.', [], 400);
- }
-
- $originCodeLBSArr = explode(':', $originCodeArr[0]);
- if(count($originCodeLBSArr) != 2){
- return $this->responseController->makeResponse(true, 'La ubicación LBS del elemento de origen tiene un formato inválido.', [], 400);
- }
- $codePartUsed = null;
- if($form['origin_code_part_used'] == 'O'){
- $codePartUsed = $originCodeLBSArr[0];
- $originCoords = $originElement->EQUI_COOR;
- $originCoordsPlaneID = $originElement->EQUI_PCOR;
- }else if($form['origin_code_part_used'] == 'D'){
- $codePartUsed = $originCodeLBSArr[1];
- $originCoords = $originElement->EQUI_CODE;
- $originCoordsPlaneID = $originElement->EQUI_PCDE;
- }
-
- if(is_null($codePartUsed)){
- return $this->responseController->makeResponse(true, 'La parte usada del código del elemento de origen no existe.', [], 404);
- }
- }
- if($form['destiny_code_type'] == '1'){
- $destinyElementDec = $this->encryptionController->decrypt($form['destiny_element']);
- if(!$destinyElementDec){
- return $this->responseController->makeResponse(true, 'El código del elemento de destino no fue encriptado correctamente.', [], 400);
- }
-
- $destinyElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $destinyElementDec]
- ])->first();
-
- if(is_null($destinyElement)){
- return $this->responseController->makeResponse(true, 'El elemento de destino no existe.', [], 404);
- }
- $destinyCoords = $destinyElement->EQUI_COOR;
- $destinyCoordsPlaneID = $destinyElement->EQUI_PCOR;
- }else if($form['destiny_code_type'] == '4'){
- $destinyCodeDec = $this->encryptionController->decrypt($form['destiny_element']);
- if(!$destinyCodeDec){
- return $this->responseController->makeResponse(true, 'El código del elemento de destino no fue encriptado correctamente.', [], 400);
- }
-
- $destinyElement = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $destinyCodeDec]
- ])->first();
-
- if(is_null($destinyElement)){
- return $this->responseController->makeResponse(true, 'El elemento de destino no existe.', [], 404);
- }
- $destinyCodeArr = explode('_', $destinyCodeDec);
- if(count($destinyCodeArr) != 2){
- return $this->responseController->makeResponse(true, 'El código del elemento de destino tiene un formato inválido.', [], 400);
- }
-
- $destinyCodeLBSArr = explode(':', $destinyCodeArr[0]);
- if(count($destinyCodeLBSArr) != 2){
- return $this->responseController->makeResponse(true, 'La ubicación LBS del elemento de destino tiene un formato inválido.', [], 400);
- }
- $codePartUsed = null;
- if($form['destiny_code_part_used'] == 'O'){
- $codePartUsed = $destinyCodeLBSArr[0];
- $destinyCoords = $destinyElement->EQUI_COOR;
- $destinyCoordsPlaneID = $destinyElement->EQUI_PCOR;
- }else if($form['destiny_code_part_used'] == 'D'){
- $codePartUsed = $destinyCodeLBSArr[1];
- $destinyCoords = $destinyElement->EQUI_CODE;
- $destinyCoordsPlaneID = $destinyElement->EQUI_PCDE;
- }
-
- if(is_null($codePartUsed)){
- return $this->responseController->makeResponse(true, 'La parte usada del código del elemento de origen no existe.', [], 404);
- }
- }
- }else{
- $originCoordsPlaneID = $this->encryptionController->decrypt($form['origin_coords_plane']);
- if(!$originCoordsPlaneID){
- return $this->responseController->makeResponse(true, 'El ID del plano seleccionado no fue encriptado correctamente.', [], 400);
- }
-
- $originCoordsPlane = DB::table('S002V01TGPES')->where([
- ['GPES_NULI', '=', $form['linea']],
- ['GPES_IDPL', '=', $originCoordsPlaneID]
- ])->first();
-
- if(is_null($originCoordsPlane)){
- return $this->responseController->makeResponse(true, 'El plano seleccionado no existe.', [], 404);
- }
-
- $originCoords = $form['origin_coords'];
- }
- }
- $familyCode = $this->encryptionController->decrypt($form['family']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'La familia del equipamiento no fue encriptada correctamente.', [], 400);
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode]
- ])->first();
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia seleccionada no existe.', [], 404);
- }
- $subfamilyCode = $this->encryptionController->decrypt($form['subfamily']);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'La subfamilia del equipamiento no fue encriptada correctamente.', [], 400);
- }
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $form['linea']],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode]
- ])->first();
- if(is_null($subfamily)){
- return $this->responseController->makeResponse(true, 'La subfamilia seleccionada no existe.', [], 404);
- }
- $validStatus = ["A", "S", "T", "I", "R", "D"];
- $status = $this->encryptionController->decrypt($form['status']);
- if(!$status){
- return $this->responseController->makeResponse(true, 'La estado del equipamiento no fue encriptado correctamente.', [], 400);
- }else if(!in_array($status, $validStatus)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado para el equipamiento es inválido.', [], 400);
- }
- $imagesArr = json_decode($form['images'], true);
- if(count($imagesArr) < 1){
- return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes está vacío.', [], 400);
- }
- $imagesGallery = [];
- foreach($imagesArr as $imageFile){
- if(!array_key_exists('type', $imageFile)){
- return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes tiene un formato inválido.', [], 400);
- }else if($imageFile['type'] == 'Nuevo'){
- $tempFileID = $this->encryptionController->decrypt($imageFile['id']);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $imagesGallery[] = $finalFile[1];
- }else{
- $fileID = $this->encryptionController->decrypt($imageFile['id']);
- $imagesGallery[] = $fileID;
- }
- }
- $imagesGalleryStr = json_encode($imagesGallery);
- $documentsArr = json_decode($form['documents'], true);
- if(count($documentsArr) < 1){
- return $this->responseController->makeResponse(true, 'El arreglo de documentos relacionados está vacío.', [], 400);
- }
- $documents = [];
- foreach($documentsArr as $documentFile){
- if(!array_key_exists('type', $documentFile)){
- return $this->responseController->makeResponse(true, 'El arreglo de documentos asociados tiene un formato inválido.', [], 400);
- }else if($documentFile['type'] == 'Nuevo'){
- $tempFileID = $this->encryptionController->decrypt($documentFile['id']);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'IN', $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- $documents[] = $finalFile[1];
- }else{
- $fileID = $this->encryptionController->decrypt($documentFile['id']);
- $documents[] = $fileID;
- }
- }
- $documentsStr = json_encode($documents);
- $acquisitionDate = new Carbon($form['acquisition_date']);
- $warrantyStartDate = new Carbon($form['warranty_start_date']);
- $warrantyEndDate = new Carbon($form['warranty_end_date']);
- if($warrantyStartDate->lt($acquisitionDate)){
- return $this->responseController->makeResponse(true, 'La fecha de inicio de la grantía no puede ser menor a la fecha de adquisición.', [], 400);
- }else if($warrantyEndDate->lte($acquisitionDate)){
- return $this->responseController->makeResponse(true, 'La fecha de término de la grantía no puede ser menor o igual a la fecha de inicio de la garantía.', [], 400);
- }
- $providerID = $this->encryptionController->decrypt($form['equipment_provider']);
- if(!$providerID){
- return $this->responseController->makeResponse(true, 'El proveedor del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $provider = DB::table('S002V01TPROV')->where([
- ['PROV_NUPR', '=', $providerID],
- ['PROV_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($provider)){
- return $this->responseController->makeResponse(true, 'La proveedor seleccionada no existe.', [], 404);
- }
- $serialNumer = $this->encryptionController->decrypt($form['serial_number']);
- if(!$serialNumer){
- return $this->responseController->makeResponse(true, 'El número de serie del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $serialNmberDB = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_NUSE', '=', $serialNumer]
- ])->first();
- if(!is_null($serialNmberDB)){
- $serialNumberStr = $serialNmberDB->EQUI_COEQ;
- return $this->responseController->makeResponse(true, "El número de serie enviado ya se encuentra relacionado al equipamiento $serialNumberStr.", [], 401);
- }
- $preCode = $this->encryptionController->decrypt($form['pre_generated_code']);
- if(!$preCode){
- return $this->responseController->makeResponse(true, 'El código pre generado no fue encriptado correctamente.', [], 400);
- }
- $elde = null;
- $destinyElementSecuence = null;
- $originElement = '';
- $originElementSecuence = null;
- $trainArea = null;
- if($form['code_type'] == '4'){
- $originElementDec = $this->encryptionController->decrypt($form['origin_element_enc']);
- if(!$originElementDec){
- return $this->responseController->makeResponse(true, 'El elemento de origen no fue encriptado correctamente.', [], 400);
- }
- $originElementObj = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $originElementDec]
- ])->first();
- if(is_null($originElementObj)){
- return $this->responseController->makeResponse(true, "El elemento de origen no existe.", [], 404);
- }
- $originElement = $originElementObj->EQUI_ELOR;
- $originElementSecuence = $originElementObj->EQUI_IDEQ;
- $destinyElementDec = $this->encryptionController->decrypt($form['destiny_element_enc']);
- if(!$destinyElementDec){
- return $this->responseController->makeResponse(true, 'El elemento de destino no fue encriptado correctamente.', [], 400);
- }
- $destinyElementObj = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $destinyElementDec]
- ])->first();
- if(is_null($destinyElementObj)){
- return $this->responseController->makeResponse(true, "El elemento de destino no existe.", [], 404);
- }
- $elde = $destinyElementObj->EQUI_ELOR;
- $destinyElementSecuence = $destinyElementObj->EQUI_IDEQ;
- }else if($form['code_type'] == '5'){
- $originElement = $this->encryptionController->decrypt($form['origin_element']);
- if(!$originElement){
- return $this->responseController->makeResponse(true, 'El elemento de origen no fue encriptado correctamente.', [], 400);
- }
- $trainElementsEnc = file_get_contents($ubic . "train-elements.sam");
- $trainElementsDec = $this->encryptionController->decrypt($trainElementsEnc);
- $trainElementsArr = json_decode($trainElementsDec, true);
- foreach($trainElementsArr as $k0=>$v0){
- $trainElement = [];
- foreach($v0 as $k1=>$v1){
- $valDec = $this->encryptionController->decrypt($v1);
- $trainElement[$k1] = $valDec;
- }
- $trainElementsArr[$k0] = $trainElement;
- }
- $trainElementFilt = array_filter($trainElementsArr, function($v, $k) use ($originElement) {
- return $v['CODE'] == $originElement;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($trainElementFilt) < 1){
- return $this->responseController->makeResponse(true, "El elemento de origen no existe.", [], 404);
- }
-
- $trainArea = $this->encryptionController->decrypt($form['train_area']);
- if(!$trainArea){
- return $this->responseController->makeResponse(true, 'El área del tren no fue encriptado correctamente.', [], 400);
- }
- $carAreasEnc = file_get_contents($ubic . "car-areas.sam");
- $carAreasDec = $this->encryptionController->decrypt($carAreasEnc);
- $carAreasArr = json_decode($carAreasDec, true);
- $carAreasArrDec = [];
-
- foreach($carAreasArr as $key=>$val){
- $keyDec = $this->encryptionController->decrypt($key);
- $carAreasArrDec[$keyDec] = $val;
- }
- $occupationAreasFilt = array_filter($carAreasArrDec, function($v, $k) use($originOccupationStr) {
- return $k == $originOccupationStr;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($occupationAreasFilt) < 1){
- return $this->responseController->makeResponse(true, "No se encontraron áreas relacionadas a la ocupación $originOccupationStr.", [], 404);
- }
- $occupationAreasArr = end($occupationAreasFilt);
- foreach($occupationAreasArr as $k0=>$v0){
- $occupationArea = [];
- foreach($v0 as $k1=>$v1){
- $valDec = $this->encryptionController->decrypt($v1);
- $occupationArea[$k1] = $valDec;
- }
- $occupationAreasArr[$k0] = $occupationArea;
- }
- $occupationAreaFilt = array_filter($occupationAreasArr, function($v, $k) use($trainArea) {
- return $v['CODE'] == $trainArea;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($occupationAreaFilt) < 1){
- return $this->responseController->makeResponse(true, "el área del tren seleccionada no existe.", [], 404);
- }
- }else{
- $originElement = $form['origin_element'];
- $elde = isset($form['destiny_element']) ? $form['destiny_element'] : null;
- }
- $ipcc = isset($form['pcc_intersection']) ? $form['pcc_intersection'] : null;
- $ppcc = isset($form['pcc_position']) ? $form['pcc_position'] : null;
- $kior = isset($form['origin_kilometer']) ? $form['origin_kilometer'] : null;
- $kide = isset($form['destiny_kilometer']) ? $form['destiny_kilometer'] : null;
- $tcor = null;
- $ceor = null;
- $tcde = null;
- $cede = null;
- if($form['code_type'] == '6'){
- if($form['origin_code_type'] == $form['destiny_code_type']){
- return $this->responseController->makeResponse(true, 'El tipo de código de origen no puede ser igual al tipo de código de destino.', [], 400);
- }
- $ceor = $this->encryptionController->decrypt($form['origin_element']);
- if(!$ceor){
- return $this->responseController->makeResponse(true, 'El código del elemento de origen no fue encriptado correctamente.', [], 400);
- }
- $tcor = $form['origin_code_type'];
- $originElementCodeArr0 = explode('_', $ceor);
- if($form['origin_code_type'] == '1'){
- $originPBSArr = explode('.', $originElementCodeArr0[0]);
- $originLocation = $originPBSArr[1];
- $originLevel = $originPBSArr[2];
- $originOccupationStr = $originPBSArr[3];
- $originElement = $originPBSArr[4];
- $originLBSArr = explode('.', $originElementCodeArr0[1]);
- $originLBSArr = array_reverse($originLBSArr);
- $originEquipment = explode('-', $originLBSArr[0]);
- $originElementSecuence = $originEquipment[2];
- }else if($form['origin_code_type'] == '2'){
- $originPBSArr = explode('.', $originElementCodeArr0[0]);
- $originLocation = $originPBSArr[1];
- $originLevel = $originPBSArr[2];
- $originOccupationStr = $originPBSArr[3];
- $originElement = $originPBSArr[4];
- $ipcc = $originPBSArr[5];
- $ppcc = $originPBSArr[6];
- $originLBSArr = explode('.', $originElementCodeArr0[1]);
- $originLBSArr = array_reverse($originLBSArr);
- $originEquipment = explode('-', $originLBSArr[0]);
- $originElementSecuence = $originEquipment[2];
- }else if($form['origin_code_type'] == '3'){
- $originElementCodeArr1 = explode(':', $originElementCodeArr0[0]);
- $originPBSArr = explode('.', $originElementCodeArr1[0]);
- $originLocation = $originPBSArr[1];
- $originLevel = $originPBSArr[2];
- $originOccupationStr = $originPBSArr[3];
- $originLBSArr = explode('.', $originElementCodeArr0[1]);
- $originLBSArr = array_reverse($originLBSArr);
- $originEquipment = explode('-', $originLBSArr[0]);
- $originElement = $originEquipment[0];
- $originKilometerArr = explode('.', $form['origin_kilometer']);
- $kior = implode(',', $originKilometerArr);
- }else if($form['origin_code_type'] == '4'){
- $originElementCodeArr1 = explode(':', $originElementCodeArr0[0]);
- $originLBSArr = $form['origin_code_part_used'] == 'O' ? explode('.', $originElementCodeArr1[0]) : explode('.', $originElementCodeArr1[1]);
- $originLBSArr = array_reverse($originLBSArr);
-
- $originElementSecuence = explode('+', $originLBSArr[0])[0];
- $originElement = $originLBSArr[1];
- $originLBSArr = array_reverse($originLBSArr);
- $originLocation = $form['origin_code_part_used'] == 'O' ? $originLBSArr[1] : $originLBSArr[0];
- $originLevel = $form['origin_code_part_used'] == 'O' ? $originLBSArr[2]: $originLBSArr[1];
- $originOccupationStr = $form['origin_code_part_used'] == 'O' ? $originLBSArr[3] : $originLBSArr[2];
- }else if($form['origin_code_type'] == '5'){
- $originPBSArr = explode('.', $originElementCodeArr0[0]);
- $originLocation = $originPBSArr[1];
- $originLevel = $originPBSArr[2];
- $originOccupationStr = $originPBSArr[3];
- $originElement = $originPBSArr[5];
- $trainArea = $originPBSArr[4];
- $originLBSArr = explode('.', $originElementCodeArr0[1]);
- $originLBSArr = array_reverse($originLBSArr);
- $originEquipment = explode('-', $originLBSArr[0]);
- $originElementSecuence = $originEquipment[2];
- }
- $cede = $this->encryptionController->decrypt($form['destiny_element']);
- if(!$cede){
- return $this->responseController->makeResponse(true, 'El código del elemento de destino no fue encriptado correctamente.', [], 400);
- }
- $tcde = $form['destiny_code_type'];
- $destinyElementCodeArr0 = explode('_', $cede);
- if($form['destiny_code_type'] == '1'){
- $destinyPBSArr = explode('.', $destinyElementCodeArr0[0]);
- $destinyLocation = $destinyPBSArr[1];
- $destinyLevel = $destinyPBSArr[2];
- $destinyOccupationStr = $destinyPBSArr[3];
- $elde = $destinyPBSArr[4];
- $destinyLBSArr = explode('.', $destinyElementCodeArr0[1]);
- $destinyLBSArr = array_reverse($destinyLBSArr);
- $destinyEquipment = explode('-', $destinyLBSArr[0]);
- $destinyElementSecuence = $destinyEquipment[2];
- }else if($form['destiny_code_type'] == '2'){
- $destinyPBSArr = explode('.', $destinyElementCodeArr0[0]);
- $destinyLocation = $destinyPBSArr[1];
- $destinyLevel = $destinyPBSArr[2];
- $destinyOccupationStr = $destinyPBSArr[3];
- $elde = $destinyPBSArr[4];
- $ipcc = $destinyPBSArr[5];
- $ppcc = $destinyPBSArr[6];
- $destinyLBSArr = explode('.', $destinyElementCodeArr0[1]);
- $destinyLBSArr = array_reverse($destinyLBSArr);
- $destinyEquipment = explode('-', $destinyLBSArr[0]);
- $destinyElementSecuence = $destinyEquipment[2];
- }else if($form['destiny_code_type'] == '3'){
- $destinyElementCodeArr1 = explode(':', $destinyElementCodeArr0[0]);
- $destinyPBSArr = explode('.', $destinyElementCodeArr1[1]);
- $destinyLocation = $destinyPBSArr[0];
- $destinyLevel = $destinyPBSArr[1];
- $destinyOccupationStr = $destinyPBSArr[2];
- $destinyBSArr = explode('.', $destinyElementCodeArr0[1]);
- $destinyBSArr = array_reverse($destinyBSArr);
- $destinyEquipment = explode('-', $destinyBSArr[0]);
- $elde = $destinyEquipment[0];
- $destinyKilometerArr = explode('.', $form['destiny_kilometer']);
- $kide = implode(',', $destinyKilometerArr);
- }else if($form['destiny_code_type'] == '4'){
- $destinyElementCodeArr1 = explode(':', $destinyElementCodeArr0[0]);
- $destinyLBSArr = $form['destiny_code_part_used'] == 'O' ? explode('.', $destinyElementCodeArr1[0]) : explode('.', $destinyElementCodeArr1[1]);
- $destinyLBSArr = array_reverse($destinyLBSArr);
-
- $destinyElementSecuence = explode('+', $destinyLBSArr[0])[0];
- $elde = $destinyLBSArr[1];
- $destinyLBSArr = array_reverse($destinyLBSArr);
- $destinyLocation = $form['destiny_code_part_used'] == 'O' ? $destinyLBSArr[1] : $destinyLBSArr[0];
- $destinyLevel = $form['destiny_code_part_used'] == 'O' ? $destinyLBSArr[2]: $destinyLBSArr[1];
- $destinyOccupationStr = $form['destiny_code_part_used'] == 'O' ? $destinyLBSArr[3] : $destinyLBSArr[2];
- }else if($form['destiny_code_type'] == '5'){
- $destinyPBSArr = explode('.', $destinyElementCodeArr0[0]);
- $destinyLocation = $destinyPBSArr[1];
- $destinyLevel = $destinyPBSArr[2];
- $destinyOccupationStr = $destinyPBSArr[3];
- $elde = $destinyPBSArr[5];
- $trainArea = $destinyPBSArr[4];
- $destinyBSArr = explode('.', $destinyElementCodeArr0[1]);
- $destinyBSArr = array_reverse($destinyBSArr);
- $destinyEquipment = explode('-', $destinyBSArr[0]);
- $destinyElementSecuence = $destinyEquipment[2];
- }
- }
- $codeVerified = $this->verifyPreCode([
- "line" => $form['linea'],
- "originLocation" => $originLocation,
- "originLevel" => $originLevel,
- "originOccupation" => $originOccupationStr,
- "originElement" => $originElement,
- "originCoords" => $originCoords,
- "family" => $familyCode,
- "subfamily" => $subfamilyCode,
- "status" => $status,
- "equipmentType" => $form['equipment_type'],
- "equipmentModel" => $form['equipment_model'],
- "equipmentID" => "XXXXX",
- "pccIntersection" => $ipcc,
- "pccPosition" => $ppcc,
- "originKilometers" => $kior,
- "destinyLocation" => $destinyLocation,
- "destinyLevel" => $destinyLevel,
- "destinyOccupation" => $destinyOccupationStr,
- "destinyElement" => $elde,
- "destinyKilometers" => $kide,
- "originElementSecuence" => $originElementSecuence,
- "destinyElementSecuence" => $destinyElementSecuence,
- "trainArea" => $trainArea,
- "originCodeType" => isset($form['origin_code_type']) ? $form['origin_code_type'] : null,
- "destinyCodeType" => isset($form['destiny_code_type']) ? $form['destiny_code_type'] : null,
- "destinyCoords" => $destinyCoords
- ], $form['code_type'], $form['hierarchy'], $eqpa);
- if($codeVerified != $preCode){
- return $this->responseController->makeResponse(true, 'El código generado no coincide con el código verificado a partir de la información del formulario.', [$preCode, $codeVerified], 400);
- }
- $deso = isset($form['software_name']) ? $form['software_name'] : null;
- $veso = isset($form['software_version']) ? $form['software_version'] : null;
- $additionalCodesDec = $this->encryptionController->decrypt($form['additional_codes']);
- if(!$additionalCodesDec){
- return $this->responseController->makeResponse(true, 'El arreglo de códigos adicionales no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPCEQ')->insert([
- 'PCEQ_NULI' => $form['linea'],
- 'PCEQ_CPGE' => $preCode,
- 'PCEQ_JERA' => $form['hierarchy'],
- 'PCEQ_EQPA' => $eqpa,
- 'PCEQ_TICO' => $form['code_type'],
- 'PCEQ_UBOR' => $originLocation,
- 'PCEQ_NIOR' => $originLevel,
- 'PCEQ_OCOR' => $originOccupationStr,
- 'PCEQ_ELOR' => $originElement,
- 'PCEQ_COOR' => $originCoords,
- 'PCEQ_PCOR' => $originCoordsPlaneID,
- 'PCEQ_FAMI' => $familyCode,
- 'PCEQ_SUBF' => $subfamilyCode,
- 'PCEQ_ESEQ' => $status,
- 'PCEQ_TIEQ' => $form['equipment_type'],
- 'PCEQ_MOEQ' => $form['equipment_model'],
- 'PCEQ_IPCC' => $ipcc,
- 'PCEQ_PPCC' => $ppcc,
- 'PCEQ_KIOR' => $kior,
- 'PCEQ_SEOR' => $originElementSecuence,
- 'PCEQ_ARTR' => $trainArea,
- 'PCEQ_TCOR' => $tcor,
- 'PCEQ_CEOR' => $ceor,
- 'PCEQ_UBDE' => $destinyLocation,
- 'PCEQ_NIDE' => $destinyLevel,
- 'PCEQ_OCDE' => $destinyOccupationStr,
- 'PCEQ_ELDE' => $elde,
- 'PCEQ_CODE' => $destinyCoords,
- 'PCEQ_PCDE' => $destinyCoordsPlaneID,
- 'PCEQ_KIDE' => $kide,
- 'PCEQ_SEDE' => $destinyElementSecuence,
- 'PCEQ_TCDE' => $tcde,
- 'PCEQ_CEDE' => $cede,
- 'PCEQ_FEAD' => $form['acquisition_date'],
- 'PCEQ_FIGA' => $form['warranty_start_date'],
- 'PCEQ_FTGA' => $form['warranty_end_date'],
- 'PCEQ_PREQ' => $providerID,
- 'PCEQ_NUSE' => $serialNumer,
- 'PCEQ_DESO' => $deso,
- 'PCEQ_VESO' => $veso,
- 'PCEQ_GAIM' => $imagesGalleryStr,
- 'PCEQ_DORE' => $documentsStr,
- 'PCEQ_OTCO' => $additionalCodesDec,
- 'PCEQ_USRE' => $idUser,
- 'PCEQ_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P11REEQ',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") solicitó el registro del equipamiento $preCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function saveEquipmentPreCodifiedStock(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'hierarchy' => 'required|string|in:Padre,Hijo',
- 'parent_equipment' => 'required_if:hierarchy,=,Hijo|string',
- 'code_type' => 'required|integer|between:1,7',
- 'origin_location' => 'required_unless:code_type,7|string|nullable',
- 'origin_level' => 'required_unless:code_type,7|string|nullable',
- 'origin_occupation' => 'required_unless:code_type,7|string|nullable',
- 'origin_element' => 'required_unless:code_type,7|string|max:150|nullable',
- 'family' => 'required|string',
- 'subfamily' => 'required|string',
- 'status' => 'required|string',
- 'equipment_type' => 'required|string|max:150',
- 'equipment_model' => 'required|string|max:75',
- 'images' => 'required|json',
- 'documents' => 'required|json',
- 'acquisition_date' => 'required|date',
- 'warranty_start_date' => 'required|date',
- 'warranty_end_date' => 'required|date',
- 'equipment_provider' => 'required|string',
- 'serial_number' => 'nullable|string',
- 'has_software' => 'required|string|in:Si,No',
- 'software_name' => 'required_if:has_software,=,Si|string|max:150',
- 'software_version' => 'required_if:has_software,=,Si|string|max:75',
- 'pre_generated_code' => 'required|string',
- 'pcc_intersection' => 'required_if:code_type,=,2|string|max:5',
- 'pcc_position' => 'required_if:code_type,=,2|string|max:2',
- 'origin_kilometer' => 'required_if:code_type,=,3|numeric',
- 'destiny_location' => 'required_if:code_type,=,3|string',
- 'destiny_level' => 'required_if:code_type,=,3|string',
- 'destiny_occupation' => 'required_if:code_type,=,3|string',
- 'destiny_element' => 'required_if:code_type,=,3|string|max:150',
- 'destiny_kilometer' => 'required_if:code_type,=,3|string',
- 'warehouse' => 'required_if:code_type,=,7|string',
- 'area' => 'required_if:code_type,=,7|string',
- 'level' => 'required_if:code_type,=,7|string',
- 'zone' => 'required_if:code_type,=,7|string',
- 'number_items' => 'required|integer',
- 'id_description' => '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();
-
- // Desencriptación del usuario
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- // Obtención del usuario
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
- // Verificación de la existencia del usuario
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idDescription = intval($form['id_description']);
- if($idDescription < 0){
- goto noDescription;
- }
- try {
- $infoAdquisition = (array) DB::table('S002V01TINAR')->select([
- 'DEAR_CAAR AS CANTIDAD_ARTICULOS',
- ])->where([
- ['INAR_IDIN', '=', $form['id_description']],
- ['INAR_NULI', '=', $form['linea']],
- ])->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
- ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')->first();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de la adquisición.', $th->getMessage(), 404);
- }
-
- if (empty($infoAdquisition)) {
- return $this->responseController->makeResponse(true, 'No existe la información de la adquisición.', [], 404);
- }
- noDescription:
- $infoAdquisition['CANTIDAD_ARTICULOS'] = $idDescription < 0 ? 1 : intval($infoAdquisition['CANTIDAD_ARTICULOS']);
- $form['number_items'] = intval($form['number_items']);
- $form['number_items'] = $infoAdquisition['CANTIDAD_ARTICULOS'] * $form['number_items'];
- // El código del equipo padre se inicializa
- $eqpa = null;
- // Si la jerarquía es de tipo "Hijo", Entonces
- if($form['hierarchy'] == 'Hijo'){
- // Se desencripta el código del equipamiento padre
- $eqpa = $this->encryptionController->decrypt($form['parent_equipment']);
- if(!$eqpa){
- return $this->responseController->makeResponse(true, 'El ID del equipamiento padre no fue encriptado correctamente.', [], 400);
- }
- // Se obtiene la información del equipo padre
- $parentEquipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $eqpa],
- ])->first();
- // Se verifica que el equipo padre exista
- if(is_null($parentEquipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento padre no existe.', [], 404);
- }
- }
-
- // Se obtiene la ubicación de las plantillas
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $locationsEnc = file_get_contents($ubic . "locations.sam");
- $locationsDec = $this->encryptionController->decrypt($locationsEnc);
- $locationsArr = json_decode($locationsDec, true);
- $locationsArrDec = [];
- foreach($locationsArr as $location){
- $locationStr = $this->encryptionController->decrypt($location['LOCATION']);
- $code = $this->encryptionController->decrypt($location['CODE']);
- $locationsArrDec[] = [
- 'LOCATION' => $locationStr,
- 'CODE' => $code
- ];
- }
- $originLocation = null;
- $originLevel = null;
- $originOccupationStr = null;
- $idWarehouse = null;
- $idArea = null;
- $idLevel = null;
- $idZone = null;
- if ($form['code_type'] !== '7') {
- // Se desencripta la ubicación de origen
- $originLocation = $this->encryptionController->decrypt($form['origin_location']);
- if(!$originLocation){
- return $this->responseController->makeResponse(true, 'La ubicación de origen no fue encriptada correctamente.', [], 400);
- }
- // Se verifica con la información del sistema
- $originLocationFilt = array_filter($locationsArrDec, function($v, $k) use ($originLocation) {
- return $v['CODE'] == $originLocation;
- }, ARRAY_FILTER_USE_BOTH);
- // Se verifica que la ubicacion exista en la información del sistema
- if(count($originLocationFilt) < 1){
- return $this->responseController->makeResponse(true, 'La ubicación de origen no se encuentra registrada en el sistema.', [], 404);
- }
- // Se desencripta el nivel del origen
- $originLevel = $this->encryptionController->decrypt($form['origin_level']);
- if(!$originLevel){
- return $this->responseController->makeResponse(true, 'El nivel de origen no fue encriptado correctamente.', [], 400);
- }
- // Se obtienen los niveles disponibles
- $supportedLevels = [];
- for($i = 5; $i > 0; $i--){
- $supportedLevels[] = "S0$i";
- }
- for($i = 0; $i <= 15; $i++){
- $tag = $i < 10 ? "P0$i" : "P$i";
- $supportedLevels[] = $tag;
- }
- // Se verifica que el origen sea válido
- if(!in_array($originLevel, $supportedLevels)){
- return $this->responseController->makeResponse(true, 'El nivel de origen seleccionado es inválido.', [], 400);
- }
- // Se desencripta la ocupación de orden
- $originOccupationStr = $this->encryptionController->decrypt($form['origin_occupation']);
- if(!$originOccupationStr){
- return $this->responseController->makeResponse(true, 'La ocupación de origen no fue encriptada correctamente.', [], 400);
- }
- // Se obtiene la información de la ocupación
- $originOccupationArea = substr($originOccupationStr, 0, 2);
- $originOccupationID = substr($originOccupationStr, 2);
- $originOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $form['linea']],
- ['OCUP_AREA', '=', $originOccupationArea],
- ['OCUP_IDOC', '=', $originOccupationID]
- ])->first();
- // Se verifica que exista la ocupació
- if(is_null($originOccupation)){
- return $this->responseController->makeResponse(true, 'La ocupación de origen seleccionada no existe.', [], 404);
- }
- } else {
- $form['origin_element'] = null;
- $idWarehouse = $this->encryptionController->decrypt($form['warehouse']);
- if ($idWarehouse === false) {
- return $this->responseController->makeResponse(true, 'El almacen no está encriptado correctamente.', [], 404);
- }
- $idArea = $this->encryptionController->decrypt($form['area']);
- if ($idArea === false) {
- return $this->responseController->makeResponse(true, 'El área no está encriptado correctamente.', [], 404);
- }
- $idLevel = $this->encryptionController->decrypt($form['level']);
- if ($idLevel === false) {
- return $this->responseController->makeResponse(true, 'El nivel no está encriptado correctamente.', [], 404);
- }
- $idZone = $this->encryptionController->decrypt($form['zone']);
- if ($idZone === false) {
- return $this->responseController->makeResponse(true, 'La zona no está encriptado correctamente.', [], 404);
- }
- try {
- $validateWarehouse = DB::table('S002V01TALMA')->where([
- ['ALMA_COAL', '=', $idWarehouse],
- ['ALMA_NULI', '=', $form['linea']]
- ])->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al validar el almacen.', [], 500);
- }
- if (!$validateWarehouse) {
- return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
- }
- try {
- $validateArea = DB::table('S002V01TAREA')->where([
- ['AREA_COAL', '=', $idWarehouse],
- ['AREA_COAR', '=', $idArea],
- ['AREA_NULI', '=', $form['linea']]
- ])->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al validar el almacen.', [], 500);
- }
- if (!$validateArea) {
- return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
- }
- try {
- $validateLevel = DB::table('S002V01TNIVE')->where([
- ['NIVE_COAL', '=', $idWarehouse],
- ['NIVE_COAR', '=', $idArea],
- ['NIVE_CONI', '=', $idLevel],
- ['NIVE_NULI', '=', $form['linea']]
- ])->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al validar el almacen.', [], 500);
- }
- if (!$validateLevel) {
- return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
- }
- try {
- $validateZone = DB::table('S002V01TZONA')->where([
- ['ZONA_COAL', '=', $idWarehouse],
- ['ZONA_COAR', '=', $idArea],
- ['ZONA_CONI', '=', $idLevel],
- ['ZONA_COZO', '=', $idZone],
- ['ZONA_NULI', '=', $form['linea']]
- ])->exists();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al validar el almacen.', [], 500);
- }
- if (!$validateZone) {
- return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
- }
- }
- // Se desencripta la familia
- $familyCode = $this->encryptionController->decrypt($form['family']);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'La familia del equipamiento no fue encriptada correctamente.', [], 400);
- }
- // Se obtienen los datos de la familia
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $form['linea']],
- ['FAMI_COFA', '=', $familyCode]
- ])->first();
- // Se verifica que la familia exista
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia seleccionada no existe.', [], 404);
- }
- // Se desencripta la subfamilia
- $subfamilyCode = $this->encryptionController->decrypt($form['subfamily']);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'La subfamilia del equipamiento no fue encriptada correctamente.', [], 400);
- }
- // Se obtienen los datos de la subfamilia
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $form['linea']],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode]
- ])->first();
- // Se verifica que la subfamilia exista
- if(is_null($subfamily)){
- return $this->responseController->makeResponse(true, 'La subfamilia seleccionada no existe.', [], 404);
- }
- // Se inicializa arreglo con los estados disponibles
- $validStatus = ["A", "S", "T", "I", "R", "D"];
- // Se desencripta el estado
- $status = $this->encryptionController->decrypt($form['status']);
- // Se verifica que el estado sea un valor válido
- if(!$status){
- return $this->responseController->makeResponse(true, 'La estado del equipamiento no fue encriptado correctamente.', [], 400);
- }else if(!in_array($status, $validStatus)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado para el equipamiento es inválido.', [], 400);
- }
- // Se obtiene el arreglo de las imagenes
- $imagesArr = json_decode($form['images'], true);
- // Se verifica que el arreglo contenga imagenes
- if(count($imagesArr) < 1){
- return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes está vacío.', [], 400);
- }
- $imagesGallery = [];
- // Se iteran las imagenes
- foreach($imagesArr as $imageFile){
- // Se verifica que tenga un formato correcto
- if(!array_key_exists('type', $imageFile)){
- return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes tiene un formato inválido.', [], 400);
- // Si la imagen es nueva, entonces...
- }else if($imageFile['type'] == 'Nuevo'){
- // Se obtiene el ID de la imagen
- $tempFileID = $this->encryptionController->decrypt($imageFile['id']);
- // Se obtiene la información registrada en la tabla de archivos temporales
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- // La imagen es colocada en su posición final
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'FO', $tempFile, $idUser);
- // Si ocurrió un error, entonces se manda el error
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- // La información es guardada en un arreglo
- $imagesGallery[] = $finalFile[1];
- }else{
- // Se desencripta el id de la imagen
- $fileID = $this->encryptionController->decrypt($imageFile['id']);
- // Es guardada en un arreglo
- $imagesGallery[] = $fileID;
- }
- }
- // El arreglo de las imagenes es pasada en formato string
- $imagesGalleryStr = json_encode($imagesGallery);
- // Se obtiene el arreglo de los documentos
- $documentsArr = json_decode($form['documents'], true);
- if(count($documentsArr) < 1){
- return $this->responseController->makeResponse(true, 'El arreglo de documentos relacionados está vacío.', [], 400);
- }
- $documents = [];
- // Se iteran los documentos
- foreach($documentsArr as $documentFile){
- // Se verifica que tenga un formato correcto
- if(!array_key_exists('type', $documentFile)){
- return $this->responseController->makeResponse(true, 'El arreglo de documentos asociados tiene un formato inválido.', [], 400);
- // Si el documento es nuevo, entonces...
- }else if($documentFile['type'] == 'Nuevo'){
- // Se obtiene el ID del documento
- $tempFileID = $this->encryptionController->decrypt($documentFile['id']);
- // Se obtiene la información registrada en la tabla de archivos temporales
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $tempFileID],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- // El documento es colocada en su posición final
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], 'GEEQ', 'IN', $tempFile, $idUser);
- // Si ocurrió un error, entonces se manda el error
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }
- // La información es guardada en un arreglo
- $documents[] = $finalFile[1];
- }else{
- // Se desencripta el id del documento
- $fileID = $this->encryptionController->decrypt($documentFile['id']);
- // Es guardada en un arreglo
- $documents[] = $fileID;
- }
- }
-
- // El arreglo de los documentos es pasada en formato string
- $documentsStr = json_encode($documents);
-
- // Se obtiene el formato de la fecha en formato manejable
- $acquisitionDate = new Carbon($form['acquisition_date']);
- $warrantyStartDate = new Carbon($form['warranty_start_date']);
- $warrantyEndDate = new Carbon($form['warranty_end_date']);
- // Se verifica que la fecha de inicio de la garantia sea menor a la fecha final de la garantia
- if($warrantyStartDate->lt($acquisitionDate)){
- return $this->responseController->makeResponse(true, 'La fecha de inicio de la grantía no puede ser menor a la fecha de adquisición.', [], 400);
- }else if($warrantyEndDate->lte($acquisitionDate)){
- return $this->responseController->makeResponse(true, 'La fecha de término de la grantía no puede ser menor o igual a la fecha de inicio de la garantía.', [], 400);
- }
- // Se desencripta el numero del proveedor
- $providerID = $this->encryptionController->decrypt($form['equipment_provider']);
- if(!$providerID){
- return $this->responseController->makeResponse(true, 'El proveedor del equipamiento no fue encriptado correctamente.', [], 400);
- }
- // Se obtiene la información del proveedor
- $provider = DB::table('S002V01TPROV')->where([
- ['PROV_NUPR', '=', $providerID],
- ['PROV_NULI', '=', $form['linea']]
- ])->first();
- // Se verifica que el proveedor exista
- if(is_null($provider)){
- return $this->responseController->makeResponse(true, 'La proveedor seleccionada no existe.', [], 404);
- }
- $arrSerialNumber = array();
- if ($form['serial_number'] !== '' && !is_null($form['serial_number'])) {
- // Se desencripta el número de serie
- $serialNumer = $this->encryptionController->decrypt($form['serial_number']);
- if(!$serialNumer){
- return $this->responseController->makeResponse(true, 'El número de serie del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $arrSerialNumber = explode(',', $serialNumer);
- if (count($arrSerialNumber) === 1 && intval($form['number_items']) > 1) {
- $arrSerialContinue = array();
- for ($item = 1; $item <= intval($form['number_items']); $item++) {
- $arrSerialContinue[] = "{$arrSerialNumber[0]}-$item";
- }
- $arrSerialNumber = $arrSerialContinue;
- } else {
- if (intval($form['number_items']) !== count($arrSerialNumber)) {
- return $this->responseController->makeResponse(true, 'La cantidad de número de series no corresponde con la cantidad de artículos a registrar.', [], 400);
- }
- foreach ($arrSerialNumber as $key => $serialNumber) {
- // Se obtiene la información del equipamiento por medio del número de serie
- $serialNmberDB = DB::table('S002V01TPCEQ')->where([
- ['PCEQ_NULI', '=', $form['linea']],
- ['PCEQ_NUSE', '=', $serialNumber]
- ])->first();
- // Se verifica que exista el código de serie
- if(!is_null($serialNmberDB)){
- $serialNumberStr = $serialNmberDB->PCEQ_CPGE;
- return $this->responseController->makeResponse(true, "El número de serie $serialNumber enviado ya se encuentra relacionado al equipamiento $serialNumberStr.", [], 401);
- }
- }
-
- $temp_array = array_unique($arrSerialNumber);
- $duplicates = sizeof($temp_array) != sizeof($arrSerialNumber);
- if ($duplicates) {
- return $this->responseController->makeResponse(true, 'Los número de serie no se pueden repetir.', [], 400);
- }
- }
- } else {
- try {
- $getEquipment = DB::table('S002V01TPCEQ')->select([
- 'PCEQ_NUSE AS NUMERO_SERIE'
- ])->where([
- ['PCEQ_NULI', '=', $form['linea']],
- ['PCEQ_NUSE', 'LIKE', '0-%']
- ])->get();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los artículos.', $th->getMessage(), 400);
- }
-
- $lastSerie = 0;
- if (count($getEquipment) > 0) {
- foreach ($getEquipment as $key => $equipment) {
- $serie = str_replace('0-', '', $equipment->NUMERO_SERIE);
- $serie = intval($serie);
- if (is_null($lastSerie)) {
- $lastSerie = $serie;
- } else if ($serie > $lastSerie) {
- $lastSerie = $serie;
- }
- }
- }
-
- for ($i=0; $i < $form['number_items']; $i++) {
- $lastSerie = $lastSerie + 1;
- $arrSerialNumber[] = '0-'.$lastSerie;
- }
- }
- if ( empty($arrSerialNumber) ) {
- return $this->responseController->makeResponse(true, 'No hay números de serie disponibles.', [], 400);
- }
-
- // Se desencripta el código pregenerado en Angular
- $preCode = $this->encryptionController->decrypt($form['pre_generated_code']);
- if(!$preCode){
- return $this->responseController->makeResponse(true, 'El código pre generado no fue encriptado correctamente.', [], 400);
- }
- $form['equipment_model'] = str_replace('-', '', $form['equipment_model']);
- $form['equipment_model'] = str_replace('.', '', $form['equipment_model']);
- $form['equipment_model'] = str_replace(',', '', $form['equipment_model']);
- $form['equipment_model'] = str_replace('_', '', $form['equipment_model']);
- $form['equipment_model'] = str_replace(':', '', $form['equipment_model']);
- // $form['equipment_model'] = str_replace(' ', '', $form['equipment_model']);
- $form['equipment_type'] = str_replace('-', '', $form['equipment_type']);
- $form['equipment_type'] = str_replace('.', '', $form['equipment_type']);
- $form['equipment_type'] = str_replace(',', '', $form['equipment_type']);
- $form['equipment_type'] = str_replace('_', '', $form['equipment_type']);
- $form['equipment_type'] = str_replace(':', '', $form['equipment_type']);
- // $form['equipment_type'] = str_replace(' ', '', $form['equipment_type']);
- // Se obtiene el código pregenerado en Laravel
- $codeVerified = $this->verifyPreCode([
- "line" => $form['linea'],
- "originLocation" => $originLocation,
- "originLevel" => $originLevel,
- "originOccupation" => $originOccupationStr,
- "originElement" => $form['origin_element'],
- "warehouse" => $idWarehouse,
- "area" => $idArea,
- "level" => $idLevel,
- "zone" => $idZone,
- "family" => $familyCode,
- "subfamily" => $subfamilyCode,
- "status" => $status,
- "equipmentType" => $form['equipment_type'],
- "equipmentModel" => $form['equipment_model'],
- "equipmentID" => "XXXXX",
- "pccIntersection" => null,
- "pccPosition" => null,
- "originKilometers" => null,
- "destinyLocation" => null,
- "destinyLevel" => null,
- "destinyOccupation" => null,
- "destinyElement" => null,
- "destinyKilometers" => null
- ], $form['code_type'], $form['hierarchy'], $eqpa);
- // Se verifica que el código pregenerado en Angular y el pregenerado en Laravel
- if($codeVerified != $preCode){
- return $this->responseController->makeResponse(true, 'El código generado no coincide con el código verificado a partir de la información del formulario.', [$codeVerified, $preCode], 400);
- }
- // Se verifica que la información del sfotware
- $deso = isset($form['software_name']) ? $form['software_name'] : null;
- $veso = isset($form['software_version']) ? $form['software_version'] : null;
- // Se obtiene la fecha actual
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $arrPreCodification = array();
- $numberItems = intval($form['number_items']);
- for ($i=0; $i < $numberItems; $i++) {
- // Se ingresa la información a la tabla de los precódigos de los equipamientos
- $idPreCodification = DB::table('S002V01TPCEQ')->insertGetId([
- 'PCEQ_NULI' => $form['linea'],
- 'PCEQ_CPGE' => $preCode,
- 'PCEQ_JERA' => $form['hierarchy'],
- 'PCEQ_EQPA' => $eqpa,
- 'PCEQ_TICO' => $form['code_type'],
- 'PCEQ_UBOR' => $originLocation,
- 'PCEQ_NIOR' => $originLevel,
- 'PCEQ_OCOR' => $originOccupationStr,
- 'PCEQ_ELOR' => $form['origin_element'],
- 'PCEQ_ALMA' => $idWarehouse,
- 'PCEQ_AREA' => $idArea,
- 'PCEQ_NIVE' => $idLevel,
- 'PCEQ_ZONA' => $idZone,
- 'PCEQ_FAMI' => $familyCode,
- 'PCEQ_SUBF' => $subfamilyCode,
- 'PCEQ_ESEQ' => $status,
- 'PCEQ_TIEQ' => $form['equipment_type'],
- 'PCEQ_MOEQ' => $form['equipment_model'],
- 'PCEQ_IPCC' => null,
- 'PCEQ_PPCC' => null,
- 'PCEQ_KIOR' => 0.0,
- 'PCEQ_UBDE' => '',
- 'PCEQ_NIDE' => '',
- 'PCEQ_OCDE' => '',
- 'PCEQ_ELDE' => '',
- 'PCEQ_KIDE' => 0.0,
- 'PCEQ_FEAD' => $form['acquisition_date'],
- 'PCEQ_FIGA' => $form['warranty_start_date'],
- 'PCEQ_FTGA' => $form['warranty_end_date'],
- 'PCEQ_PREQ' => $providerID,
- 'PCEQ_NUSE' => count($arrSerialNumber) === 1 ? $arrSerialNumber[0] : $arrSerialNumber[$i],
- 'PCEQ_DESO' => $deso,
- 'PCEQ_VESO' => $veso,
- 'PCEQ_GAIM' => $imagesGalleryStr,
- 'PCEQ_DORE' => $documentsStr,
- 'PCEQ_OTCO' => '[]',
- 'PCEQ_USRE' => $idUser,
- 'PCEQ_FERE' => $nowStr,
- ]);
- $idPreCodification = $this->encryptionController->encrypt($idPreCodification);
- $arrPreCodification[] = $idPreCodification;
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P11REEQ',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") solicitó el registro del equipamiento $preCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.', $arrPreCodification);
- }
- public function verifyPreCode(array $parameters, string $type, string $mode, string | null $parentCode = '') : string {
- $code = "";
- if($mode == 'Hijo'){
- $code .= $parentCode;
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code .= "." . $equipmentStr;
- }else{
- switch($type){
- case "1":
- //CASO 1: Codificación general
- $lbs = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement'];
- $lbsStr = "";
- foreach($lbs as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'originElement'){
- $val = $this->processElement($val, 'element');
- }
-
- $lbsStr .= $val . ".";
- }
- $lbsStr = substr($lbsStr, 0, -1);
- $coords = $parameters['originCoords'];
- $lbsStr = "$lbsStr+$coords";
-
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl != 'equipmentID'){
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
- }else{
- $val = 'XXXXXX';
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = $lbsStr . "_" . $pbsStr . "." . $equipmentStr;
- break;
- case "2":
- // CASO 2: Elemento en PCC
- $lbs = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'pccIntersection', 'pccPosition'];
- $lbsStr = "";
- foreach($lbs as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'originElement'){
- $elementArr = explode(' - ', $val);
- if(count($elementArr) > 1){
- $elementCode = $elementArr[1];
- $pccElementFilt = array_filter($this->pccValidElements, function($v, $k) use ($elementCode) {
- return $elementCode == $v['code'];
- }, ARRAY_FILTER_USE_BOTH);
- if(count($pccElementFilt) > 0){
- $pccElement = end($pccElementFilt);
- $val = $pccElement['code'];
- }
- }
- }
-
- $lbsStr .= $val . ".";
- }
-
- $lbsStr = substr($lbsStr, 0, -1);
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = $lbsStr . "_" . $pbsStr . "." . $equipmentStr;
- break;
- case "3":
- // CASO 3: Origen - destino para líneas y enlaces
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'originKilometers'];
- $lbsOriginTag = "";
- foreach($lbsOrigin as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'originElement'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'originKilometers'){
- $valArr = explode('.', $val);
- $val = implode(',', $valArr);
- }
-
- $lbsOriginTag .= $val . ".";
- }
-
- $lbsOriginTag = substr($lbsOriginTag, 0, -1);
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'destinyKilometers'];
- $lbsDestinyTag = "";
- foreach($lbsDestiny as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'destinyElement'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'destinyKilometers'){
- $valArr = explode('.', $val);
- $val = implode(',', $valArr);
- }
-
- $lbsDestinyTag .= $val . ".";
- }
-
- $lbsDestinyTag = substr($lbsDestinyTag, 0, -1);
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = "$lbsOriginTag:$lbsDestinyTag" . "_" . "$pbsStr.$equipmentStr";
- break;
- case "4":
- // CASO 4: Origen - destino para estaciones y edificios
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'originElementSecuence'];
- $lbsOriginTag = "";
- foreach($lbsOrigin as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'originElement'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'originElementSecuence'){
- $valStr = "$val";
- $valLength = strlen($valStr);
- $valStrAux = "";
- for($i = $valLength; $i < 6; $i++){
- $valStrAux .= "0";
- }
- $val = "$valStrAux$valStr";
- }
-
- $lbsOriginTag .= $val . ".";
- }
-
- $lbsOriginTag = substr($lbsOriginTag, 0, -1);
- $lbsOriginTag .= "+" . $parameters['originCoords'];
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'destinyElementSecuence'];
- $lbsDestinyTag = "";
- foreach($lbsDestiny as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'destinyElement'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'destinyElementSecuence'){
- $valStr = "$val";
- $valLength = strlen($valStr);
- $valStrAux = "";
- for($i = $valLength; $i < 6; $i++){
- $valStrAux .= "0";
- }
- $val = "$valStrAux$valStr";
- }
-
- $lbsDestinyTag .= $val . ".";
- }
-
- $lbsDestinyTag = substr($lbsDestinyTag, 0, -1);
- $lbsDestinyTag .= "+" . $parameters['destinyCoords'];
-
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = "$lbsOriginTag:$lbsDestinyTag" . "_" . "$pbsStr.$equipmentStr";
- break;
- case "5":
- // CASO 4: Tren
- $lbs = ['line', 'originLocation', 'originLevel', 'originOccupation', 'trainArea', 'originElement'];
- $lbsStr = "";
- foreach($lbs as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }
-
- $lbsStr .= $val . ".";
- }
-
- $lbsStr = substr($lbsStr, 0, -1);
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = $lbsStr . "_" . $pbsStr . "." . $equipmentStr;
- break;
- case "6":
- $lbsOrigin = [];
- if($parameters['originCodeType'] == '1'){
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'originElementSecuence'];
- }else if($parameters['originCodeType'] == '2'){
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'pccIntersection',
- 'pccPosition', 'originElementSecuence'];
- }else if($parameters['originCodeType'] == '3'){
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'originKilometers'];
- }else if($parameters['originCodeType'] == '4'){
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'originElement', 'originElementSecuence'];
- }else if($parameters['originCodeType'] == '5'){
- $lbsOrigin = ['line', 'originLocation', 'originLevel', 'originOccupation', 'trainArea', 'originElement', 'originElementSecuence'];
- }
- $lbsOriginTag = "";
- foreach($lbsOrigin as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'originElement' && $parameters['originCodeType'] != '5'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'originElementSecuence'){
- $valStr = "$val";
- $valLength = strlen($valStr);
- $valStrAux = "";
- for($i = $valLength; $i < 6; $i++){
- $valStrAux .= "0";
- }
- $val = "$valStrAux$valStr";
- }
-
- $lbsOriginTag .= $val . ".";
- }
-
- $lbsOriginTag = substr($lbsOriginTag, 0, -1);
- if($parameters['originCodeType'] == '1' || $parameters['originCodeType'] == '4'){
- $lbsOriginTag .= '+' . $parameters['originCoords'];
- }
- $lbsDestiny = [];
- if($parameters['destinyCodeType'] == '1'){
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'destinyElementSecuence'];
- }else if($parameters['destinyCodeType'] == '2'){
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'pccIntersection',
- 'pccPosition', 'destinyElementSecuence'];
- }else if($parameters['destinyCodeType'] == '3'){
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'destinyKilometers'];
- }else if($parameters['destinyCodeType'] == '4'){
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'destinyElement', 'destinyElementSecuence'];
- }else if($parameters['destinyCodeType'] == '5'){
- $lbsDestiny = ['destinyLocation', 'destinyLevel', 'destinyOccupation', 'trainArea', 'destinyElement', 'destinyElementSecuence'];
- }
- $lbsDestinyTag = "";
- foreach($lbsDestiny as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }else if($ctrl == 'destinyElement' && $parameters['destinyCodeType'] != '5'){
- $val = $this->processElement($val, 'element');
- }else if($ctrl == 'destinyElementSecuence'){
- $valStr = "$val";
- $valLength = strlen($valStr);
- $valStrAux = "";
- for($i = $valLength; $i < 6; $i++){
- $valStrAux .= "0";
- }
- $val = "$valStrAux$valStr";
- }
-
- $lbsDestinyTag .= $val . ".";
- }
-
- $lbsDestinyTag = substr($lbsDestinyTag, 0, -1);
- if($parameters['destinyCodeType'] == '1' || $parameters['destinyCodeType'] == '4'){
- $lbsDestinyTag .= '+' . $parameters['destinyCoords'];
- }
- $pbs = ['family', 'subfamily', 'status'];
- $pbsStr = "";
- foreach($pbs as $ctrl){
- $val = $parameters[$ctrl];
- $pbsStr .= $val . ".";
- }
-
- $pbsStr = substr($pbsStr, 0, -1);
- $equipment = ['equipmentType', 'equipmentModel', 'equipmentID'];
- $equipmentStr = "";
- foreach($equipment as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
-
- $equipmentStr .= $val . '-';
- }
-
- $equipmentStr = substr($equipmentStr, 0, -1);
- $code = "$lbsOriginTag:$lbsDestinyTag" . "_" . "$pbsStr.$equipmentStr";
- break;
- case "7":
- $siteTag = '';
- $site = ['line', 'area', 'level'];
- foreach($site as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'line'){
- $val = intval($val) < 10 ? "0$val" : "$val";
- }
- $siteTag .= $val.'.';
- }
- $siteTag = substr($siteTag, 0, -1);
- $areaTag = '';
- $area = ['warehouse', 'zone'];
- foreach($area as $ctrl){
- $val = $parameters[$ctrl];
- $areaTag .= $val.'.';
- }
- $areaTag = substr($areaTag, 0, -1);
- $technicalSpecificationTag = '';
- $technicalSpecification = ['family', 'subfamily', 'status'];
- foreach($technicalSpecification as $ctrl){
- $val = $parameters[$ctrl];
- $technicalSpecificationTag .= $val.'.';
- }
- $technicalSpecificationTag = substr($technicalSpecificationTag, 0, -1);
- $equipmentIdentifierTag = '';
- $equipmentIdentifier = ['equipmentType', 'equipmentModel', 'equipmentID'];
- foreach($equipmentIdentifier as $ctrl){
- $val = $parameters[$ctrl];
- if($ctrl == 'equipmentModel'){
- $val = $this->processElement($val, 'model');
- }else if($ctrl == 'equipmentType'){
- $val = $this->processElement($val, 'element');
- }
- $equipmentIdentifierTag .= $val.'-';
- }
- $equipmentIdentifierTag = substr($equipmentIdentifierTag, 0, -1);
-
- $code = $siteTag.'-'.$areaTag.'_'.$technicalSpecificationTag.'.'.$equipmentIdentifierTag;
- break;
- }
- }
- return $code;
- }
- private function processElement(string $value, string $type) : string {
- $value = strtoupper($value);
- $value = str_replace('-', '', $value);
- $value = str_replace('.', '', $value);
- $value = str_replace('_', '', $value);
- $value = str_replace(':', '', $value);
- $value = str_replace('.', '', $value);
- $value = str_replace(',', '', $value);
- $value = str_replace('+', '', $value);
- $validVal0 = $this->functionsController->unaccent($value);
- $validVal0 = strtoupper($validVal0);
- $validVal0 = str_replace('-', '', $validVal0);
- $CONNECTORS = ['DE', 'PARA', 'Y', 'O', 'DEL', 'EL', 'LA', 'LOS', 'POR', 'EN'];
- $valueArr1 = explode(' ', $validVal0);
- $validVal1 = [];
- foreach($valueArr1 as $word){
- if(!in_array($word, $CONNECTORS)){
- $validVal1[] = $word;
- }
- }
- if($type == 'model'){
- $modelStr = implode('', $validVal1);
- $model = substr($modelStr, -5);
- $modelFn = "";
- for($i = strlen($model); $i < 5; $i++){
- $modelFn .= 'X';
- }
- $modelFn = $modelFn . $model;
- return $modelFn;
- }
- $validLength = count($validVal1);
- $validVal2 = "";
- if($validLength < 1){
- return "ERROR";
- }else if($validLength == 1){
- if(strlen($validVal1[0]) < 5){
- $validVal2 = $validVal1[0];
- for($i = strlen($validVal1[0]); $i < 5; $i++){
- $validVal2 = "X$validVal2";
- }
- }else{
- $validVal2 = substr($validVal1[0], 0, 5);
- }
- }else if($validLength == 2){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = substr($validVal1[0], 0, 2);
- }
- $word2 = "";
- if(strlen($validVal1[1]) < 3){
- $word2 = $validVal1[1];
- for($i = strlen($validVal1[1]); $i < 3; $i++){
- $word2 = "X$word2";
- }
- }else{
- $word2 = substr($validVal1[1], 0, 3);
- }
- $validVal2 = $word1 . $word2;
- }else if($validLength == 3){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = substr($validVal1[0], 0, 2);
- }
-
- $word2 = substr($validVal1[1], 0, 1);
- $word3 = "";
- if(strlen($validVal1[2]) < 2){
- $word3 = "X$validVal1[2]";
- }else{
- $word3 = substr($validVal1[2], 0, 2);
- }
- $validVal2 = $word1 . $word2 . $word3;
- }else if($validLength == 4){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = substr($validVal1[0], 0, 2);
- }
-
- $word2 = substr($validVal1[1], 0, 1);
- $word3 = substr($validVal1[2], 0, 1);
- $word4 = substr($validVal1[3], 0, 1);
- $validVal2 = $word1 . $word2 . $word3 . $word4;
- }else if($validLength >= 5){
- $word1 = substr($validVal1[0], 0, 1);
- $word2 = substr($validVal1[1], 0, 1);
- $word3 = substr($validVal1[2], 0, 1);
- $word4 = substr($validVal1[3], 0, 1);
- $word5 = substr($validVal1[4], 0, 1);
- $validVal2 = $word1 . $word2 . $word3 . $word4 . $word5;
- }else{
- return "ERROR";
- }
- return $validVal2;
- }
- public function getTotalPendingEquipments($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);
- }
- $totalPendingEquipments = DB::table('S002V01TPCEQ')->select([
- DB::raw("COUNT(PCEQ_IDPR) AS PENDIENTES_TOTALES"),
- ])->where([
- ['PCEQ_NULI', '=', $line],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ])->first();
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el número total de equipamientos en revisión.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['TOTAL' => $totalPendingEquipments->PENDIENTES_TOTALES]);
- }
- public function getPendingEquipments($offset, $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);
- }
- $pendingEquipments = DB::table('S002V01TPCEQ')->select([
- 'PCEQ_IDPR AS IDREG',
- 'PCEQ_CPGE AS CODIGO',
- 'PCEQ_TICO AS TIPO_CODIGO',
- 'PCEQ_TIEQ AS TIPO_EQUIPAMIENTO',
- 'PCEQ_MOEQ AS MODELO_EQUIPAMIENTO',
- 'PCEQ_GAIM AS GALERIA_IMAGENES',
- 'PCEQ_ESRE AS ESTADO_REGISTRO',
- ])->where([
- ['PCEQ_NULI', '=', $line],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ])->offset($offset)->limit(15)->orderBy('PCEQ_IDPR', 'asc')->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($pendingEquipments as $key=>$equipment){
- $equipment->IDREG = $this->encryptionController->encrypt($equipment->IDREG);
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIPO_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->TIPO_EQUIPAMIENTO);
- $equipment->MODELO_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->MODELO_EQUIPAMIENTO);
-
- $pendingEquipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos en revisión.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $pendingEquipments);
- }
- public function getGroupedPendingEquipments($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);
- }
- $groupedPendingEquipments = DB::table('S002V01TPCEQ')->select([
- DB::raw("DISTINCT(PCEQ_CPGE) AS CODIGO"),
- 'PCEQ_TICO AS TIPO_CODIGO',
- 'PCEQ_TIEQ AS TIPO_EQUIPAMIENTO',
- 'PCEQ_MOEQ AS MODELO_EQUIPAMIENTO',
- 'PCEQ_GAIM AS GALERIA_IMAGENES',
- 'PCEQ_ESRE AS ESTADO_REGISTRO',
- ])->where([
- ['PCEQ_NULI', '=', $line],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ])->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($groupedPendingEquipments as $key=>$equipment){
- $equipmentsByCode = DB::table('S002V01TPCEQ')->select([
- DB::raw("COUNT(PCEQ_CPGE) AS TOTAL")
- ])->where([
- ['PCEQ_NULI', '=', $line],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ['PCEQ_CPGE', '=', $equipment->CODIGO]
- ])->first();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIPO_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->TIPO_EQUIPAMIENTO);
- $equipment->MODELO_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->MODELO_EQUIPAMIENTO);
- $equipment->TOTAL = $equipmentsByCode->TOTAL;
-
- $pendingEquipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos en revisión agrupados.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $pendingEquipments);
- }
- public function getPendigEquipment($idReg, $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);
- }
- $idReg = $this->encryptionController->decrypt($idReg);
- if(!$idReg){
- return $this->responseController->makeResponse(true, 'El ID del pre-registro no está encriptado correctamente', [], 400);
- }
- $pendingEquipment = DB::table('S002V01TPCEQ')->select([
- 'PCEQ_IDPR AS IDREG',
- 'PCEQ_CPGE AS CODIGO',
- 'PCEQ_JERA AS JERARQUIA',
- 'PCEQ_EQPA AS PADRE',
- 'PCEQ_TICO AS TIPO_CODIGO',
- 'PCEQ_UBOR AS UBICACION_ORIGEN',
- 'PCEQ_NIOR AS NIVEL_ORIGEN',
- 'PCEQ_OCOR AS OCUPACION_ORIGEN',
- 'PCEQ_ELOR AS ELEMENTO_ORIGEN',
- 'PCEQ_FAMI AS FAMILIA',
- 'PCEQ_SUBF AS SUBFAMILIA',
- 'PCEQ_ESEQ AS ESTADO_EQUIPAMIENTO',
- 'PCEQ_TIEQ AS TIPO_EQUIPAMIENTO',
- 'PCEQ_MOEQ AS MODELO_EQUIPAMIENTO',
- 'PCEQ_IPCC AS INTERSECCION_PCC',
- 'PCEQ_PPCC AS POSICION_PCC',
- 'PCEQ_KIOR AS KILOMETRO_ORIGEN',
- 'PCEQ_UBDE AS UBICACION_DESTINO',
- 'PCEQ_NIDE AS NIVEL_DESTINO',
- 'PCEQ_OCDE AS OCUPACION_DESTINO',
- 'PCEQ_ELDE AS ELEMENTO_DESTINO',
- 'PCEQ_KIDE AS KILOMETRO_DESTINO',
- 'PCEQ_FEAD AS FECHA_ADQUISICION',
- 'PCEQ_FIGA AS FECHA_INICIO_GARANTIA',
- 'PCEQ_FTGA AS FECHA_FIN_GARANTIA',
- 'PCEQ_PREQ AS PROVEEDOR',
- 'PCEQ_NUSE AS NUMERO_SERIAL',
- 'PCEQ_DESO AS DENOMINACION_SOFTWARE',
- 'PCEQ_VESO AS VERSION_SOFTWARE',
- 'PCEQ_GAIM AS GALERIA_IMAGENES',
- 'PCEQ_DORE AS DOCUMENTOS',
- 'PCEQ_ESRE AS ESTADO_REGISTRO',
- 'PCEQ_CORE AS COMENTARIOS_RECHAZO',
- 'PCEQ_COAC AS COMENTARIOS_ACEPTACION',
- 'PCEQ_USRE AS USUARIO_REGISTRO',
- 'PCEQ_FERE AS FECHA_REGISTRO',
- 'PCEQ_USMO AS USUARIO_MODIFICO',
- 'PCEQ_FEMO AS FECHA_MODIFICACION'
- ])->where([
- ['PCEQ_NULI', '=', $line],
- ['PCEQ_IDPR', '=', $idReg],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ])->first();
- if(is_null($pendingEquipment)){
- return $this->responseController->makeResponse(true, 'El pre-registro solicitado no existe', [], 404);
- }
- $pendingEquipment->IDREG = $this->encryptionController->encrypt($pendingEquipment->IDREG);
- $pendingEquipment->CODIGO = $this->encryptionController->encrypt($pendingEquipment->CODIGO);
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $locationsEnc = file_get_contents($ubic . "locations.sam");
- $locationsDec = $this->encryptionController->decrypt($locationsEnc);
- $locationsArr = json_decode($locationsDec, true);
- $locationsArrDec = [];
- foreach($locationsArr as $location){
- $locationStr = $this->encryptionController->decrypt($location['LOCATION']);
- $code = $this->encryptionController->decrypt($location['CODE']);
- $locationsArrDec[] = [
- 'LOCATION' => $locationStr,
- 'CODE' => $code
- ];
- }
- $originLocation = $pendingEquipment->UBICACION_ORIGEN;
- $originLocationFilt = array_filter($locationsArrDec, function ($v, $k) use ($originLocation) {
- return $v['CODE'] == $originLocation;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($originLocationFilt) > 0){
- $pendingEquipment->UBICACION_ORIGEN = end($originLocationFilt)['LOCATION'] . " (" . $pendingEquipment->UBICACION_ORIGEN . ")";
- }
- $levelsArr = [];
- for($i = 5; $i > 0; $i--){
- $levelsArr[] = [
- 'LEVEL' => "Subterráneo S0$i",
- 'CODE' => "S0$i",
- ];
- }
- for($i = 0; $i <= 15; $i++){
- $code = $i < 10 ? "P0$i" : "P$i";
- $level = $i == 0 ? "Planta baja P00" : "Piso $code";
- $levelsArr[] = [
- 'LEVEL' => $level,
- 'CODE' => $code,
- ];
- }
- $originLevel = $pendingEquipment->NIVEL_ORIGEN;
- $originLevelFilt = array_filter($levelsArr, function ($v, $k) use ($originLevel) {
- return $v['CODE'] == $originLevel;
- }, ARRAY_FILTER_USE_BOTH);
- if(count($originLevelFilt) > 0){
- $pendingEquipment->NIVEL_ORIGEN = end($originLevelFilt)['LEVEL'] . " (" . $pendingEquipment->NIVEL_ORIGEN . ")";
- }
- $originOccupationStr = $pendingEquipment->OCUPACION_ORIGEN;
- $originOccupationArea = substr($originOccupationStr, 0, 2);
- $originOccupationID = substr($originOccupationStr, 2);
- $originOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $line],
- ['OCUP_AREA', '=', $originOccupationArea],
- ['OCUP_IDOC', '=', $originOccupationID]
- ])->first();
- if(!is_null($originOccupation)){
- $pendingEquipment->OCUPACION_ORIGEN = $originOccupation->OCUP_DESC . " (" . $originOccupationStr . ")";
- }
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $line],
- ['FAMI_COFA', '=', $pendingEquipment->FAMILIA],
- ])->first();
-
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $pendingEquipment->FAMILIA],
- ['SUBF_COSU', '=', $pendingEquipment->SUBFAMILIA],
- ])->first();
- $pendingEquipment->FAMILIA = $family->FAMI_NOFA . " (" . $pendingEquipment->FAMILIA . ")";
- $pendingEquipment->SUBFAMILIA = $subfamily->SUBF_NOSU . " (" . $pendingEquipment->SUBFAMILIA . ")";
- $validStatus = ["A" => "Adquisición", "S" => "Stock", "T" => "Traslado", "I" => "Instalación", "R" => "Reparación", "D" => "Disposición"];
- $pendingEquipment->ESTADO_EQUIPAMIENTO = $validStatus[$pendingEquipment->ESTADO_EQUIPAMIENTO] . " (" . $pendingEquipment->ESTADO_EQUIPAMIENTO . ")";
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- $imagesGalleryArr = json_decode($pendingEquipment->GALERIA_IMAGENES);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
-
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $documentsArr = json_decode($pendingEquipment->DOCUMENTOS);
- $documentsFn = [];
- foreach($documentsArr as $document){
- $codeArr = explode('=',$document);
- $codeArr0 = explode('-', $codeArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['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 archivo $document no está registrado.", [], 404);
- }
- $documentsFn[] = [
- 'id' => $this->encryptionController->encrypt($document),
- 'name' => $document,
- 'size' => $file->AFAL_TAMA
- ];
- }
- $pendingEquipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $pendingEquipment->DOCUMENTOS = json_encode($documentsFn);
- $pendingEquipment->PROVEEDOR = $this->encryptionController->encrypt($pendingEquipment->PROVEEDOR);
- $pendingEquipment->NUMERO_SERIAL = $this->encryptionController->encrypt($pendingEquipment->NUMERO_SERIAL);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $pendingEquipment->USUARIO_REGISTRO]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $pendingEquipment->USUARIO_REGISTRO = $usrRegName . " (" . $pendingEquipment->USUARIO_REGISTRO . ")";
- if(!is_null($pendingEquipment->USUARIO_MODIFICO)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $pendingEquipment->USUARIO_MODIFICO]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $pendingEquipment->USUARIO_MODIFICO = $usrModName . " (" . $pendingEquipment->USUARIO_MODIFICO . ")";
- }
- $pendingEquipment->TIPO_EQUIPAMIENTO = $this->encryptionController->encrypt($pendingEquipment->TIPO_EQUIPAMIENTO);
- $pendingEquipment->MODELO_EQUIPAMIENTO = $this->encryptionController->encrypt($pendingEquipment->MODELO_EQUIPAMIENTO);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el equipamiento pre codificado $idReg.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $pendingEquipment);
- }
- public function changePreCodedEquipmentStatus(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_reg' => 'required|string',
- 'status' => 'required|string|in:Aprobado,Rechazado',
- '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);
- }
- $idReg = $this->encryptionController->decrypt($form['id_reg']);
- if(!$idReg){
- return $this->responseController->makeResponse(true, 'El ID del pre-registro no está encriptado correctamente', [], 400);
- }
- $pendingEquipment = DB::table('S002V01TPCEQ')->where([
- ['PCEQ_NULI', '=', $form['linea']],
- ['PCEQ_IDPR', '=', $idReg],
- ])->first();
- if(is_null($pendingEquipment)){
- return $this->responseController->makeResponse(true, 'El pre-registro solicitado no existe.', [], 404);
- }else if($pendingEquipment->PCEQ_ESRE == 'Rechazado'){
- return $this->responseController->makeResponse(true, 'El pre-registro se encuentra rechazado.', [], 400);
- }else if($pendingEquipment->PCEQ_ESRE == 'Aprobado'){
- return $this->responseController->makeResponse(true, 'El pre-registro se encuentra aprobado.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- if($form['status'] == 'Rechazado'){
- DB::table('S002V01TPCEQ')->where([
- ['PCEQ_IDPR', '=', $idReg],
- ['PCEQ_NULI', '=', $form['linea']],
- ])->update([
- 'PCEQ_ESRE' => $form['status'],
- 'PCEQ_CORE' => $form['comments'],
- 'PCEQ_USMO' => $idUser,
- 'PCEQ_FEMO' => $nowStr,
- ]);
- }else{
- //PASO 1: SE BUSCA EL ÚLTIMO ID DEL EQUIPAMIENTO
- $lastID = DB::table('S002V01TEQUI')->select([
- 'EQUI_IDEQ AS LAST_ID'
- ])->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_FAMI', '=', $pendingEquipment->PCEQ_FAMI],
- ['EQUI_SUBF', '=', $pendingEquipment->PCEQ_SUBF],
- ['EQUI_TIPO', '=', $pendingEquipment->PCEQ_TIEQ],
- ['EQUI_MODE', '=', $pendingEquipment->PCEQ_MOEQ],
- ])->orderBy('EQUI_IDEQ', 'desc')->first();
- //PASO 2: SE DEFINE EL ID DEL NUEVO EQUIPAMIENTO
- $IDNum = is_null($lastID) ? 1 : $lastID->LAST_ID + 1;
- //PASO 3: SE DEFINE UN ESPACIO PARA RETORNAR EL PROCESO
- doAgain:
- //PASO 4: SE RELLENA EL ID CON CEROS A LA IZQUIERDA PARA DARLE EL FORMATO DE LA CODIFICACIÓN
- $IDStr = "$IDNum";
- for($i = strlen($IDStr); $i < 6; $i++){
- $IDStr = "0$IDStr";
- }
- //PASO 5: SE INTEGRA EL ID AL CÓDIGO PRE-GENERADO
- $preCodeArr = explode('_', $pendingEquipment->PCEQ_CPGE);
- $previewPBS = $preCodeArr[1];
- $previewPBSArr = explode('-', $previewPBS);
- $previewPBSArr = array_reverse($previewPBSArr);
- $previewPBSArr[0] = $IDStr;
- $previewPBSArr = array_reverse($previewPBSArr);
- $previewPBS = implode('-', $previewPBSArr);
- //PASO 6: SE BUSCA SI EL CÓDIGO ESTÁ REGISTRADO EN ALGÚN EQUIPAMIENTO O EN EL HISTORIAL DE CÓDIGOS DE ALGÚN EQUIPAMIENTO
- $previewCode = $preCodeArr[0] . "_" . $previewPBS;
- $registeredCode = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $previewCode]
- ])->first();
- $codeInHistory = DB::table('S002V01TEQUI')
- ->where('EQUI_NULI', '=', $form['linea'])
- ->whereJsonContains('EQUI_HICO->CODIGO', $previewCode)->first();
- //PASO 7: VERIFICAR QUE EL CÓDIGO NO EXISTA, SI EXISTE SE REALIZA NUEVAMENTE EL PROCESO AUMENTANDO EN 1 EL ID
- if(!is_null($registeredCode) || !is_null($codeInHistory)){
- $IDNum++;
- goto doAgain;
- }
- //PASO 8: REALIZAR EL REGISTRO DEL EQUIPAMIENTO
- $hico = json_encode([
- [
- 'CODIGO' => $previewCode,
- 'PADRE' => $pendingEquipment->PCEQ_EQPA,
- 'FECHA' => $nowStr,
- ]
- ]);
- DB::table('S002V01TEQUI')->insert([
- 'EQUI_NULI' => $form['linea'],
- 'EQUI_FAMI' => $pendingEquipment->PCEQ_FAMI,
- 'EQUI_SUBF' => $pendingEquipment->PCEQ_SUBF,
- 'EQUI_TIPO' => $pendingEquipment->PCEQ_TIEQ,
- 'EQUI_MODE' => $pendingEquipment->PCEQ_MOEQ,
- 'EQUI_IDEQ' => $IDNum,
- 'EQUI_ESEQ' => $pendingEquipment->PCEQ_ESEQ,
- 'EQUI_COEQ' => $previewCode,
- 'EQUI_JERA' => $pendingEquipment->PCEQ_JERA,
- 'EQUI_EQPA' => $pendingEquipment->PCEQ_EQPA,
- 'EQUI_TICO' => $pendingEquipment->PCEQ_TICO,
- 'EQUI_UBOR' => $pendingEquipment->PCEQ_UBOR,
- 'EQUI_NIOR' => $pendingEquipment->PCEQ_NIOR,
- 'EQUI_OCOR' => $pendingEquipment->PCEQ_OCOR,
- 'EQUI_ELOR' => $pendingEquipment->PCEQ_ELOR,
- 'EQUI_COOR' => $pendingEquipment->PCEQ_COOR,
- 'EQUI_PCOR' => $pendingEquipment->PCEQ_PCOR,
- 'EQUI_ALMA' => $pendingEquipment->PCEQ_ALMA,
- 'EQUI_AREA' => $pendingEquipment->PCEQ_AREA,
- 'EQUI_NIVE' => $pendingEquipment->PCEQ_NIVE,
- 'EQUI_ZONA' => $pendingEquipment->PCEQ_ZONA,
- 'EQUI_IPCC' => $pendingEquipment->PCEQ_IPCC,
- 'EQUI_PPCC' => $pendingEquipment->PCEQ_PPCC,
- 'EQUI_KIOR' => $pendingEquipment->PCEQ_KIOR,
- 'EQUI_SEOR' => $pendingEquipment->PCEQ_SEOR,
- 'EQUI_ARTR' => $pendingEquipment->PCEQ_ARTR,
- 'EQUI_TCOR' => $pendingEquipment->PCEQ_TCOR,
- 'EQUI_CEOR' => $pendingEquipment->PCEQ_CEOR,
- 'EQUI_UBDE' => $pendingEquipment->PCEQ_UBDE,
- 'EQUI_NIDE' => $pendingEquipment->PCEQ_NIDE,
- 'EQUI_OCDE' => $pendingEquipment->PCEQ_OCDE,
- 'EQUI_ELDE' => $pendingEquipment->PCEQ_ELDE,
- 'EQUI_CODE' => $pendingEquipment->PCEQ_CODE,
- 'EQUI_PCDE' => $pendingEquipment->PCEQ_PCDE,
- 'EQUI_KIDE' => $pendingEquipment->PCEQ_KIDE,
- 'EQUI_SEDE' => $pendingEquipment->PCEQ_SEDE,
- 'EQUI_TCDE' => $pendingEquipment->PCEQ_TCDE,
- 'EQUI_CEDE' => $pendingEquipment->PCEQ_CEDE,
- 'EQUI_FEAD' => $pendingEquipment->PCEQ_FEAD,
- 'EQUI_FIGA' => $pendingEquipment->PCEQ_FIGA,
- 'EQUI_FTGA' => $pendingEquipment->PCEQ_FTGA,
- 'EQUI_PREQ' => $pendingEquipment->PCEQ_PREQ,
- 'EQUI_NUSE' => $pendingEquipment->PCEQ_NUSE,
- 'EQUI_DESO' => $pendingEquipment->PCEQ_DESO,
- 'EQUI_VESO' => $pendingEquipment->PCEQ_VESO,
- 'EQUI_HICO' => $hico,
- 'EQUI_GAIM' => $pendingEquipment->PCEQ_GAIM,
- 'EQUI_DORE' => $pendingEquipment->PCEQ_DORE,
- 'EQUI_OTCO' => $pendingEquipment->PCEQ_OTCO,
- 'EQUI_USRE' => $idUser,
- 'EQUI_FERE' => $nowStr,
- ]);
- DB::table('S002V01TPCEQ')->where([
- ['PCEQ_IDPR', '=', $idReg],
- ['PCEQ_NULI', '=', $form['linea']],
- ])->update([
- 'PCEQ_ESRE' => $form['status'],
- 'PCEQ_COAC' => $form['comments'],
- 'PCEQ_USMO' => $idUser,
- 'PCEQ_FEMO' => $nowStr,
- ]);
- if ($pendingEquipment->PCEQ_TICO === '7') {
- try {
- $star = (array) DB::table('S002V01TSTAR')
- ->where('STAR_IDPC', '=', $pendingEquipment->PCEQ_IDPR)
- ->where('STAR_ESTA', '=', 'Pendiente')
- ->where('STAR_NULI', '=', $form['linea'])
- ->first();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los artículos en Stock.', [], 500);
- }
- if ( !empty($star) && !is_null($star) ) {
- try {
- $validateUpdate = DB::table('S002V01TSTAR')
- ->where('STAR_IDPC', '=', $pendingEquipment->PCEQ_IDPR)
- ->where('STAR_ESTA', '=', 'Pendiente')
- ->where('STAR_NULI', '=', $form['linea'])
- ->update([
- 'STAR_ESTA' => 'Activo',
- 'STAR_USMO' => $idUser,
- 'STAR_FEMO' => $nowStr,
- 'STAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un al actualizar el stock.', [], 500);
- }
- if (!$validateUpdate) {
- return $this->responseController->makeResponse(true, 'No se pudo actualizar la información en stock.', [], 500);
- }
- try {
- $validateUpdate = DB::table('S002V01TUBAR')
- ->where('UBAR_IDST', '=', $star['STAR_IDST'])
- ->where('UBAR_ESTA', '=', 'Pendiente')
- ->where('UBAR_NULI', '=', $form['linea'])
- ->update([
- 'UBAR_COUB' => $previewCode,
- 'UBAR_ESTA' => 'Activo',
- 'UBAR_USMO' => $idUser,
- 'UBAR_FEMO' => $nowStr,
- 'UBAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un al actualizar el stock.', [], 500);
- }
- if (!$validateUpdate) {
- return $this->responseController->makeResponse(true, 'No se pudo actualizar la información en stock.', [], 500);
- }
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P11REEQ',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió el estado del pre-registro $idReg a $form[status].",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function changePreCodedEquipmentStatusByGroup(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'code' => 'required|string',
- 'status' => 'required|string|in:Aprobado,Rechazado',
- '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);
- }
- $preCode = $this->encryptionController->decrypt($form['code']);
- if(!$preCode){
- return $this->responseController->makeResponse(true, 'El código del pre-registro no está encriptado correctamente', [], 400);
- }
- $pendingEquipments = DB::table('S002V01TPCEQ')->where([
- ['PCEQ_NULI', '=', $form['linea']],
- ['PCEQ_CPGE', '=', $preCode],
- ['PCEQ_ESRE', '=', 'Revisión'],
- ])->get()->all();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- if($form['status'] == 'Rechazado'){
- DB::table('S002V01TPCEQ')->where([
- ['PCEQ_NULI', '=', $form['linea']],
- ['PCEQ_CPGE', '=', $preCode],
- ])->update([
- 'PCEQ_ESRE' => 'Rechazado',
- 'PCEQ_CORE' => $form['comments'],
- 'PCEQ_USMO' => $idUser,
- 'PCEQ_FEMO' => $nowStr,
- ]);
- }else{
- foreach($pendingEquipments as $pendingEquipment){
- //PASO 1: SE BUSCA EL ÚLTIMO ID DEL EQUIPAMIENTO
- $lastID = DB::table('S002V01TEQUI')->select([
- 'EQUI_IDEQ AS LAST_ID'
- ])->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_FAMI', '=', $pendingEquipment->PCEQ_FAMI],
- ['EQUI_SUBF', '=', $pendingEquipment->PCEQ_SUBF],
- ['EQUI_TIPO', '=', $pendingEquipment->PCEQ_TIEQ],
- ['EQUI_MODE', '=', $pendingEquipment->PCEQ_MOEQ],
- ])->orderBy('EQUI_IDEQ', 'asc')->first();
- //PASO 2: SE DEFINE EL ID DEL NUEVO EQUIPAMIENTO
- $IDNum = is_null($lastID) ? 1 : $lastID->LAST_ID + 1;
- //PASO 3: SE DEFINE UN ESPACIO PARA RETORNAR EL PROCESO
- doAgainGroup:
- //PASO 4: SE RELLENA EL ID CON CEROS A LA IZQUIERDA PARA DARLE EL FORMATO DE LA CODIFICACIÓN
- $IDStr = "$IDNum";
- for($i = strlen($IDStr); $i < 6; $i++){
- $IDStr = "0$IDStr";
- }
- //PASO 5: SE INTEGRA EL ID AL CÓDIGO PRE-GENERADO
- $preCodeArr = explode('_', $pendingEquipment->PCEQ_CPGE);
- $previewPBS = $preCodeArr[1];
- $previewPBSArr = explode('-', $previewPBS);
- $previewPBSArr = array_reverse($previewPBSArr);
- $previewPBSArr[0] = $IDStr;
- $previewPBSArr = array_reverse($previewPBSArr);
- $previewPBS = implode('-', $previewPBSArr);
- //PASO 6: SE BUSCA SI EL CÓDIGO ESTÁ REGISTRADO EN ALGÚN EQUIPAMIENTO O EN EL HISTORIAL DE CÓDIGOS DE ALGÚN EQUIPAMIENTO
- $previewCode = $preCodeArr[0] . "_" . $previewPBS;
- $registeredCode = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $previewCode]
- ])->first();
- $codeInHistory = DB::table('S002V01TEQUI')
- ->where('EQUI_NULI', '=', $form['linea'])
- ->whereJsonContains('EQUI_HICO->CODIGO', $previewCode)->first();
- //PASO 7: VERIFICAR QUE EL CÓDIGO NO EXISTA, SI EXISTE SE REALIZA NUEVAMENTE EL PROCESO AUMENTANDO EN 1 EL ID
- if(!is_null($registeredCode) || !is_null($codeInHistory)){
- $IDNum++;
- goto doAgainGroup;
- }
- //PASO 8: REALIZAR EL REGISTRO DEL EQUIPAMIENTO
- $hico = json_encode([
- [
- 'CODIGO' => $previewCode,
- 'PADRE' => $pendingEquipment->PCEQ_EQPA,
- 'FECHA' => $nowStr
- ]
- ]);
- DB::table('S002V01TEQUI')->insert([
- 'EQUI_NULI' => $form['linea'],
- 'EQUI_FAMI' => $pendingEquipment->PCEQ_FAMI,
- 'EQUI_SUBF' => $pendingEquipment->PCEQ_SUBF,
- 'EQUI_TIPO' => $pendingEquipment->PCEQ_TIEQ,
- 'EQUI_MODE' => $pendingEquipment->PCEQ_MOEQ,
- 'EQUI_IDEQ' => $IDNum,
- 'EQUI_ESEQ' => $pendingEquipment->PCEQ_ESEQ,
- 'EQUI_COEQ' => $previewCode,
- 'EQUI_JERA' => $pendingEquipment->PCEQ_JERA,
- 'EQUI_EQPA' => $pendingEquipment->PCEQ_EQPA,
- 'EQUI_TICO' => $pendingEquipment->PCEQ_TICO,
- 'EQUI_UBOR' => $pendingEquipment->PCEQ_UBOR,
- 'EQUI_NIOR' => $pendingEquipment->PCEQ_NIOR,
- 'EQUI_OCOR' => $pendingEquipment->PCEQ_OCOR,
- 'EQUI_ELOR' => $pendingEquipment->PCEQ_ELOR,
- 'EQUI_COOR' => $pendingEquipment->PCEQ_COOR,
- 'EQUI_PCOR' => $pendingEquipment->PCEQ_PCOR,
- 'EQUI_ALMA' => $pendingEquipment->PCEQ_ALMA,
- 'EQUI_AREA' => $pendingEquipment->PCEQ_AREA,
- 'EQUI_NIVE' => $pendingEquipment->PCEQ_NIVE,
- 'EQUI_ZONA' => $pendingEquipment->PCEQ_ZONA,
- 'EQUI_IPCC' => $pendingEquipment->PCEQ_IPCC,
- 'EQUI_PPCC' => $pendingEquipment->PCEQ_PPCC,
- 'EQUI_KIOR' => $pendingEquipment->PCEQ_KIOR,
- 'EQUI_SEOR' => $pendingEquipment->PCEQ_SEOR,
- 'EQUI_ARTR' => $pendingEquipment->PCEQ_ARTR,
- 'EQUI_TCOR' => $pendingEquipment->PCEQ_TCOR,
- 'EQUI_CEOR' => $pendingEquipment->PCEQ_CEOR,
- 'EQUI_UBDE' => $pendingEquipment->PCEQ_UBDE,
- 'EQUI_NIDE' => $pendingEquipment->PCEQ_NIDE,
- 'EQUI_OCDE' => $pendingEquipment->PCEQ_OCDE,
- 'EQUI_ELDE' => $pendingEquipment->PCEQ_ELDE,
- 'EQUI_CODE' => $pendingEquipment->PCEQ_CODE,
- 'EQUI_PCDE' => $pendingEquipment->PCEQ_PCDE,
- 'EQUI_KIDE' => $pendingEquipment->PCEQ_KIDE,
- 'EQUI_SEDE' => $pendingEquipment->PCEQ_SEDE,
- 'EQUI_TCDE' => $pendingEquipment->PCEQ_TCDE,
- 'EQUI_CEDE' => $pendingEquipment->PCEQ_CEDE,
- 'EQUI_FEAD' => $pendingEquipment->PCEQ_FEAD,
- 'EQUI_FIGA' => $pendingEquipment->PCEQ_FIGA,
- 'EQUI_FTGA' => $pendingEquipment->PCEQ_FTGA,
- 'EQUI_PREQ' => $pendingEquipment->PCEQ_PREQ,
- 'EQUI_NUSE' => $pendingEquipment->PCEQ_NUSE,
- 'EQUI_DESO' => $pendingEquipment->PCEQ_DESO,
- 'EQUI_VESO' => $pendingEquipment->PCEQ_VESO,
- 'EQUI_HICO' => $hico,
- 'EQUI_GAIM' => $pendingEquipment->PCEQ_GAIM,
- 'EQUI_DORE' => $pendingEquipment->PCEQ_DORE,
- 'EQUI_OTCO' => $pendingEquipment->PCEQ_OTCO,
- 'EQUI_USRE' => $idUser,
- 'EQUI_FERE' => $nowStr,
- ]);
-
- DB::table('S002V01TPCEQ')->where([
- ['PCEQ_IDPR', '=', $pendingEquipment->PCEQ_IDPR],
- ['PCEQ_NULI', '=', $form['linea']],
- ])->update([
- 'PCEQ_ESRE' => $form['status'],
- 'PCEQ_COAC' => $form['comments'],
- 'PCEQ_USMO' => $idUser,
- 'PCEQ_FEMO' => $nowStr,
- ]);
- if ($pendingEquipment->PCEQ_TICO === '7') {
- try {
- $star = (array) DB::table('S002V01TSTAR')->where([
- ['STAR_IDPC', '=', $pendingEquipment->PCEQ_IDPR],
- ['STAR_ESTA', '=', 'Pendiente'],
- ['STAR_NULI', '=', $form['linea']]
- ])->first();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los artículos en Stock.', [], 500);
- }
- if ( !empty($star) && !is_null($star) ) {
- try {
- $validateUpdate = DB::table('S002V01TSTAR')->where([
- ['STAR_IDPC', '=', $pendingEquipment->PCEQ_IDPR],
- ['STAR_ESTA', '=', 'Pendiente'],
- ['STAR_NULI', '=', $form['linea']]
- ])->update([
- 'STAR_ESTA' => 'Activo',
- 'STAR_USMO' => $idUser,
- 'STAR_FEMO' => $nowStr,
- 'STAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un al actualizar el stock.', [], 500);
- }
- if (!$validateUpdate) {
- return $this->responseController->makeResponse(true, 'No se pudo actualizar la información en stock.', [], 500);
- }
- try {
- $validateUpdate = DB::table('S002V01TUBAR')->where([
- ['UBAR_IDST', '=', $star['STAR_IDST']],
- ['UBAR_ESTA', '=', 'Pendiente'],
- ['UBAR_NULI', '=', $form['linea']]
- ])->update([
- 'UBAR_COUB' => $previewCode,
- 'UBAR_ESTA' => 'Activo',
- 'UBAR_USMO' => $idUser,
- 'UBAR_FEMO' => $nowStr,
- 'UBAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un al actualizar el stock.', [], 500);
- }
- if (!$validateUpdate) {
- return $this->responseController->makeResponse(true, 'No se pudo actualizar la información en stock.', [], 500);
- }
- }
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P11REEQ',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió el estado del grupo de pre-registro $preCode a $form[status].",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getEquipments($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);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where('EQUI_NULI', '=', $line)->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos registrados.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getFilteredEquipments($search, $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);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where('EQUI_NULI', '=', $line)
- ->where('EQUI_ESEQ', '=', 'I')
- ->where(function(Builder $query) use($search) {
- $query->where('EQUI_TIPO', 'like', "%$search%")
- ->orWhere('EQUI_MODE', 'like', "%$search%")
- ->orWhere('EQUI_IDEQ', 'like', "%$search%")
- ->orWhere('EQUI_COEQ', 'like', "%$search%");
- })->limit(50)->orderBy('EQUI_FEMO', 'desc')
- ->orderBy('EQUI_FERE', 'desc')->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos registrados.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getFilteredEquipmentChildren($search, $parent, $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);
- }
- $parent = $this->encryptionController->decrypt($parent);
- if(!$parent){
- return $this->responseController->makeResponse(true, 'El código del equipamiento relacionado no está encriptado correctamente', [], 400);
- }
- $parentObj = DB::table('S002V01TEQUI')->where([
- ['EQUI_COEQ', '=', $parent],
- ['EQUI_NULI', '=', $line]
- ])->first();
- if(is_null($parentObj)){
- return $this->responseController->makeResponse(true, 'El equipo relacionado no está registrado', [], 404);
- }
- $search = 'dell';
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_ESEQ', '=', 'I'],
- ['EQUI_JERA', '=', 'Hijo'],
- ['EQUI_EQPA', '=', $parent]
- ])->where(function(Builder $query) use($search) {
- $query->where('EQUI_TIPO', 'like', "%$search%")
- ->orWhere('EQUI_MODE', 'like', "%$search%")
- ->orWhere('EQUI_IDEQ', 'like', "%$search%")
- ->orWhere('EQUI_COEQ', 'like', "%$search%");
- })->limit(50)->orderBy('EQUI_FEMO', 'desc')
- ->orderBy('EQUI_FERE', 'desc')->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos registrados.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentsBySubfamily($familyCode, $subfamilyCode, $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);
- }
- $familyCode = $this->encryptionController->decrypt($familyCode);
- if(!$familyCode){
- return $this->responseController->makeResponse(true, 'El código de la familia no está encriptado correctamente', [], 400);
- }
-
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $line],
- ['FAMI_COFA', '=', $familyCode],
- ])->first();
- if(is_null($family)){
- return $this->responseController->makeResponse(true, 'La familia relacionada no está registrada.', [], 404);
- }
- $subfamilyCode = $this->encryptionController->decrypt($subfamilyCode);
- if(!$subfamilyCode){
- return $this->responseController->makeResponse(true, 'El código de la subfamilia no está encriptado correctamente', [], 400);
- }
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $familyCode],
- ['SUBF_COSU', '=', $subfamilyCode],
- ])->first();
- if(is_null($subfamily)){
- return $this->responseController->makeResponse(true, 'La subfamilia relacionada no está registrada.', [], 404);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_FAMI', '=', $familyCode],
- ['EQUI_SUBF', '=', $subfamilyCode],
- ['EQUI_JERA', '=', 'Padre']
- ])->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos relacionados a la subfamilia $subfamilyCode de la familia $familyCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentsByParent($parentCode, $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);
- }
- $parentCode = $this->encryptionController->decrypt($parentCode);
- if(!$parentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento padre no está encriptado correctamente', [], 400);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_JERA', '=', 'Hijo'],
- ['EQUI_EQPA', '=', $parentCode],
- ])->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P02DEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos relacionados al equipamiento $parentCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentHasChildren($parentCode, $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);
- }
- $parentCode = $this->encryptionController->decrypt($parentCode);
- if(!$parentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento padre no está encriptado correctamente', [], 400);
- }
- $hasChildren = DB::table('S002V01TEQUI')->select([
- DB::raw("COUNT(*) AS HIJOS")
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_JERA', '=', 'Hijo'],
- ['EQUI_EQPA', '=', $parentCode],
- ])->first();
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P02DEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos relacionados al equipamiento $parentCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['TIENE_HIJOS' => intval($hasChildren->HIJOS) > 0 ? 'S' : 'N']);
- }
- public function getEquipmentDetails($equipmentCode, $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);
- }
- $equipmentCode = $this->encryptionController->decrypt($equipmentCode);
- if(!$equipmentCode){
- return $this->responseController->makeResponse(true, 'El código del equipamiento no está encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->select([
- DB::raw("CONCAT(FAMI_NOFA, ' (', EQUI_FAMI, ')') AS FAMILIA"),
- DB::raw("CONCAT(SUBF_NOSU, ' (', EQUI_SUBF, ')') AS SUBFAMILIA"),
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'EQUI_ESEQ AS ESTADO',
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_JERA AS JERARQUIA',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_UBOR AS UBICACION_ORIGEN',
- 'EQUI_NIOR AS NIVEL_ORIGEN',
- 'EQUI_OCOR AS OCUPACION_ORIGEN',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_IPCC AS INTERSECCION_PCC',
- 'EQUI_PPCC AS POSICION_PCC',
- 'EQUI_KIOR AS KILOMETRO_ORIGEN',
- 'EQUI_SEOR AS SECUENCIA_ELEMENTO_ORIGEN',//
- 'EQUI_ARTR AS AREA_TREN',//
- 'EQUI_TCOR AS TIPO_CODIFICACION_ORIGEN',//
- 'EQUI_CEOR AS CODIGO_ELEMENTO_ORIGEN',//
- 'EQUI_UBDE AS UBICACION_DESTINO',
- 'EQUI_NIDE AS NIVEL_DESTINO',
- 'EQUI_OCDE AS OCUPACION_DESTINO',
- 'EQUI_ELDE AS ELEMENTO_DESTINO',
- 'EQUI_KIDE AS KILOMETRO_DESTINO',
- 'EQUI_SEDE AS SECUENCIA_ELEMENTO_DESTINO',//
- 'EQUI_TCDE AS TIPO_CODIFICACION_DESTINO',//
- 'EQUI_CEDE AS CODIGO_ELEMENTO_DESTINO',//
- 'EQUI_CRSE AS NIVEL_CRITICIDAD',//
- 'EQUI_FEAD AS FECHA_ADQUISICION',
- 'EQUI_FIGA AS FECHA_INICIO_GARANTIA',
- 'EQUI_FTGA AS FECHA_TERMINO_GARANTIA',
- 'EQUI_PREQ AS PROVEEDOR',
- 'EQUI_NUSE AS NUMERO_SERIAL',
- 'EQUI_DESO AS DENOMINACION_SOFTWARE',
- 'EQUI_VESO AS VERSION_SOFTWARE',
- 'EQUI_HICO AS HISTORIAL_CODIGOS',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_DORE AS DOCUMENTOS',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_USRE AS USUARIO_REGISTRO',
- 'EQUI_FERE AS FECHA_REGISTRO',
- 'EQUI_USMO AS USUARIO_MODIFICACION',
- 'EQUI_FEMO AS FECHA_MODIFICACION',
- ])->join('S002V01TFAMI', 'FAMI_COFA', '=', 'EQUI_FAMI')
- ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'EQUI_SUBF')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $equipmentCode],
- ])->first();
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento solicitado no existe.', [], 404);
- }
- $equipment->ID_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->ID_EQUIPAMIENTO);
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $locationsEnc = file_get_contents($ubic . "locations.sam");
- $locationsDec = $this->encryptionController->decrypt($locationsEnc);
- $locationsArr = json_decode($locationsDec, true);
- $locationsArrDec = [];
- foreach($locationsArr as $location){
- $locationStr = $this->encryptionController->decrypt($location['LOCATION']);
- $code = $this->encryptionController->decrypt($location['CODE']);
- $locationsArrDec[] = [
- 'LOCATION' => $locationStr,
- 'CODE' => $code
- ];
- }
- $originLocation = $equipment->UBICACION_ORIGEN;
- $originLocationFilt = array_filter($locationsArrDec, function ($v, $k) use ($originLocation) {
- return $v['CODE'] == $originLocation;
- }, ARRAY_FILTER_USE_BOTH);
- if(end($originLocationFilt)){
- $equipment->UBICACION_ORIGEN = end($originLocationFilt)['LOCATION'] . " (" . $equipment->UBICACION_ORIGEN . ")";
- }else{
- $equipment->UBICACION_ORIGEN = '-';
- }
- if(!is_null($equipment->UBICACION_DESTINO) && $equipment->UBICACION_DESTINO != ''){
- $destinyLocation = $equipment->UBICACION_DESTINO;
- $destinyLocationFilt = array_filter($locationsArrDec, function ($v, $k) use ($destinyLocation) {
- return $v['CODE'] == $destinyLocation;
- }, ARRAY_FILTER_USE_BOTH);
- $equipment->UBICACION_DESTINO = end($destinyLocationFilt)['LOCATION'] . " (" . $equipment->UBICACION_DESTINO . ")";
- }
- $levelsArr = [];
- for($i = 5; $i > 0; $i--){
- $levelsArr[] = [
- 'LEVEL' => "Subterráneo S0$i",
- 'CODE' => "S0$i",
- ];
- }
- if($equipment->TIPO_CODIGO == '3'){
- $levelsArr = [
- ['CODE' => 'S05', 'LEVEL' => 'Nivel debajo de vía'],
- ['CODE' => 'S04', 'LEVEL' => 'Nivel vía'],
- ['CODE' => 'S03', 'LEVEL' => 'Nivel túnel'],
- ['CODE' => 'S02', 'LEVEL' => 'Nivel techo - túnel'],
- ['CODE' => 'S01', 'LEVEL' => 'Nivel sobre túnel'],
- ];
- }
- for($i = 0; $i <= 15; $i++){
- $code = $i < 10 ? "P0$i" : "P$i";
- $level = $i == 0 ? "Planta baja P00" : "Piso $code";
- $levelsArr[] = [
- 'LEVEL' => $level,
- 'CODE' => $code,
- ];
- }
- $originLevel = $equipment->NIVEL_ORIGEN;
- $originLevelFilt = array_filter($levelsArr, function ($v, $k) use ($originLevel) {
- return $v['CODE'] == $originLevel;
- }, ARRAY_FILTER_USE_BOTH);
- if(end($originLevelFilt)){
- $equipment->NIVEL_ORIGEN = end($originLevelFilt)['LEVEL'] . " (" . $equipment->NIVEL_ORIGEN . ")";
- }else{
- $equipment->NIVEL_ORIGEN = '-';
- }
- if(!is_null($equipment->NIVEL_DESTINO) && $equipment->NIVEL_DESTINO != ''){
- $destinyLevel = $equipment->NIVEL_DESTINO;
- $destinyLevelFilt = array_filter($levelsArr, function ($v, $k) use ($destinyLevel) {
- return $v['CODE'] == $destinyLevel;
- }, ARRAY_FILTER_USE_BOTH);
- $equipment->NIVEL_DESTINO = end($destinyLevelFilt)['LEVEL'] . " (" . $equipment->NIVEL_DESTINO . ")";
- }
- if($equipment->TIPO_CODIGO == '5'){
- $trainOccupationsEnc = file_get_contents($ubic . "train-occupations.sam");
- $trainOccupationsDec = $this->encryptionController->decrypt($trainOccupationsEnc);
- $trainOccupationsArr = json_decode($trainOccupationsDec, true);
- $trainOccupationsArrDec = [];
- foreach($trainOccupationsArr as $k0=>$v0){
- $trainOccupation = [];
- foreach($v0 as $k1=>$v1){
- $valDec = $this->encryptionController->decrypt($v1);
- $trainOccupation[$k1] = $valDec;
- }
- $trainOccupationsArrDec[$k0] = $trainOccupation;
- }
- $originOccupation = $equipment->OCUPACION_ORIGEN;
- $trainOccupationFilt = array_filter($trainOccupationsArrDec, function($v, $k) use($originOccupation){
- return $v['CODE'] == $originOccupation;
- }, ARRAY_FILTER_USE_BOTH);
- $trainOccupation = end($trainOccupationFilt);
- $equipment->OCUPACION_ORIGEN = $trainOccupation['CAR'] . " (" . $trainOccupation['CODE'] . ")";
- $trainElementsEnc = file_get_contents($ubic . "train-elements.sam");
- $trainElementsDec = $this->encryptionController->decrypt($trainElementsEnc);
- $trainElementsArr = json_decode($trainElementsDec, true);
- $trainElementsArrDec = [];
- foreach($trainElementsArr as $k0=>$v0){
- $trainElement = [];
- foreach($v0 as $k1=>$v1){
- $valDec = $this->encryptionController->decrypt($v1);
- $trainElement[$k1] = $valDec;
- }
- $trainElementsArrDec[$k0] = $trainElement;
- }
- $originElement = $equipment->ELEMENTO_ORIGEN;
- $trainElementFilt = array_filter($trainElementsArrDec, function($v, $k) use($originElement){
- return $v['CODE'] == $originElement;
- }, ARRAY_FILTER_USE_BOTH);
- $trainElement = end($trainElementFilt);
- $equipment->ELEMENTO_ORIGEN = $trainElement['ELEMENT'] . " (" . $trainElement['CODE'] . ")";
- $carAreasEnc = file_get_contents($ubic . "car-areas.sam");
- $carAreasDec = $this->encryptionController->decrypt($carAreasEnc);
- $carAreasArr = json_decode($carAreasDec, true);
- $carAreasArrDec = [];
- foreach($carAreasArr as $k0=>$v0){
- $keyDec = $this->encryptionController->decrypt($k0);
- if($keyDec == $trainOccupation['CODE']){
- foreach($v0 as $k1=>$v1){
- $carArea = [];
- foreach($v1 as $k2=>$v2){
- $valDec = $this->encryptionController->decrypt($v2);
- $carArea[$k2] = $valDec;
- }
- $carAreasArrDec[$k1] = $carArea;
- }
- }
- }
- $trainArea = $equipment->AREA_TREN;
- $carAreaFilt = array_filter($carAreasArrDec, function($v, $k) use($trainArea){
- return $v['CODE'] == $trainArea;
- }, ARRAY_FILTER_USE_BOTH);
- $carArea = end($carAreaFilt);
- $equipment->AREA_TREN = $carArea['AREA'] . " (" . $carArea['CODE'] . ")";
- }else{
- $originOccupationStr = $equipment->OCUPACION_ORIGEN;
- $originOccupationArea = substr($originOccupationStr, 0, 2);
- $originOccupationID = substr($originOccupationStr, 2);
- $originOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $line],
- ['OCUP_AREA', '=', $originOccupationArea],
- ['OCUP_IDOC', '=', $originOccupationID]
- ])->first();
- if(!is_null($originOccupation)){
- $equipment->OCUPACION_ORIGEN = $originOccupation->OCUP_DESC . " (" . $originOccupationStr . ")";
- }else{
- $equipment->OCUPACION_ORIGEN = '-';
- }
- if(!is_null($equipment->OCUPACION_DESTINO) && $equipment->OCUPACION_DESTINO != ''){
- $destinyOccupationStr = $equipment->OCUPACION_DESTINO;
- $destinyOccupationArea = substr($destinyOccupationStr, 0, 2);
- $destinyOccupationID = substr($destinyOccupationStr, 2);
- $destinyOccupation = DB::table('S002V01TOCUP')->where([
- ['OCUP_NULI', '=', $line],
- ['OCUP_AREA', '=', $destinyOccupationArea],
- ['OCUP_IDOC', '=', $destinyOccupationID]
- ])->first();
- $equipment->OCUPACION_DESTINO = $destinyOccupation->OCUP_DESC . " (" . $destinyOccupationStr . ")";
- }
- }
- if(!is_null($equipment->SECUENCIA_ELEMENTO_ORIGEN)){
- $equipment->SECUENCIA_ELEMENTO_ORIGEN = $this->encryptionController->encrypt($equipment->SECUENCIA_ELEMENTO_ORIGEN);
- }
- if(!is_null($equipment->SECUENCIA_ELEMENTO_DESTINO)){
- $equipment->SECUENCIA_ELEMENTO_DESTINO = $this->encryptionController->encrypt($equipment->SECUENCIA_ELEMENTO_DESTINO);
- }
- if(!is_null($equipment->CODIGO_ELEMENTO_ORIGEN)){
- $equipment->CODIGO_ELEMENTO_ORIGEN = $this->encryptionController->encrypt($equipment->CODIGO_ELEMENTO_ORIGEN);
- }
- if(!is_null($equipment->CODIGO_ELEMENTO_DESTINO)){
- $equipment->CODIGO_ELEMENTO_DESTINO = $this->encryptionController->encrypt($equipment->CODIGO_ELEMENTO_DESTINO);
- }
- $validStatus = ["A" => "Adquisición", "S" => "Stock", "T" => "Traslado", "I" => "Instalación", "R" => "Reparación", "D" => "Disposición"];
- $equipment->ESTADO = $validStatus[$equipment->ESTADO] . " (" . $equipment->ESTADO . ")";
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $documentsArr = json_decode($equipment->DOCUMENTOS);
- $documentsFn = [];
- foreach($documentsArr as $document){
- $codeArr = explode('=',$document);
- $codeArr0 = explode('-', $codeArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['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 archivo $document no está registrado.", [], 404);
- }
- $documentsFn[] = [
- 'id' => $this->encryptionController->encrypt($document),
- 'name' => $document,
- 'size' => $file->AFAL_TAMA
- ];
- }
- if(!is_null($equipment->NIVEL_CRITICIDAD)){
- $equipment->NIVEL_CRITICIDAD = $this->encryptionController->encrypt($equipment->NIVEL_CRITICIDAD);
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->DOCUMENTOS = json_encode($documentsFn);
- $provider = DB::table('S002V01TPROV')->where([
- ['PROV_NULI', '=', $line],
- ['PROV_NUPR', '=', $equipment->PROVEEDOR],
- ])->first();
-
- $equipment->PROVEEDOR = $provider->PROV_NOCO . " (" . $equipment->PROVEEDOR . ")";
- $equipment->NUMERO_SERIAL = $this->encryptionController->encrypt($equipment->NUMERO_SERIAL);
- $codesHistory = json_decode($equipment->HISTORIAL_CODIGOS, true);
- $codesHistoryFn = [];
- foreach($codesHistory as $code){
- $code['CODIGO'] = $this->encryptionController->encrypt($code['CODIGO']);
- if(isset($code['PADRE'])){
- $code['PADRE'] = $this->encryptionController->encrypt($code['PADRE']);
- }
-
- $codesHistoryFn[] = $code;
- }
- $equipment->HISTORIAL_CODIGOS = json_encode($codesHistoryFn);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $equipment->USUARIO_REGISTRO]
- ])->first();
- $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $equipment->USUARIO_REGISTRO = $usrRegName . " (" . $equipment->USUARIO_REGISTRO . ")";
- if(!is_null($equipment->USUARIO_MODIFICACION)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $equipment->USUARIO_MODIFICACION]
- ])->first();
- $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $equipment->USUARIO_MODIFICACION = $usrModName . " (" . $equipment->USUARIO_MODIFICACION . ")";
- }
- $equipment->TIPO_EQUIPAMIENTO = $this->encryptionController->encrypt($equipment->TIPO_EQUIPAMIENTO);
- $equipment->MODELO = $this->encryptionController->encrypt($equipment->MODELO);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el equipamiento $equipmentCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipment);
- }
- public function getTrainOccupations($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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $trainOccupationsEnc = file_get_contents($ubic . "train-occupations.sam");
- $trainOccupationsDec = $this->encryptionController->decrypt($trainOccupationsEnc);
- $trainOccupationsArr = json_decode($trainOccupationsDec, true);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las ocupaciones de tren.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $trainOccupationsArr);
- }
- public function getTrainAreas($trainOccupation, $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);
- }
- $trainOccupation = $this->encryptionController->decrypt($trainOccupation);
- if(!$trainOccupation){
- return $this->responseController->makeResponse(true, 'La ocupación no fue encriptada correctamente.', [], 400);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $carAreasEnc = file_get_contents($ubic . "car-areas.sam");
- $carAreasDec = $this->encryptionController->decrypt($carAreasEnc);
- $carAreasArr = json_decode($carAreasDec, true);
- $carAreasArrDec = [];
- foreach($carAreasArr as $key=>$val){
- $keyDec = $this->encryptionController->decrypt($key);
- $carAreasArrDec[$keyDec] = $val;
- }
- if(!array_key_exists($trainOccupation, $carAreasArrDec)){
- return $this->responseController->makeResponse(true, "La ocupación $trainOccupation no existe.", [], 404);
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las áreas de la ocupación $trainOccupation de tren.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $carAreasArrDec[$trainOccupation]);
- }
- public function getTrainElements($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);
- }
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $trainElementsEnc = file_get_contents($ubic . "train-elements.sam");
- $trainElementsDec = $this->encryptionController->decrypt($trainElementsEnc);
- $trainElementsArr = json_decode($trainElementsDec, true);
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los elementos de tren.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $trainElementsArr);
- }
- public function getEquipmentsByCodeType($codeType, $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);
- }
- $codeType = $this->encryptionController->decrypt($codeType);
- if(!$codeType){
- return $this->responseController->makeResponse(true, 'El tipo de código seleccionado no está encriptado correctamente', [], 400);
- }
- $codeTypeArr = explode('|', $codeType);
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where('EQUI_NULI', '=', $line)->where(function(Builder $query) use($codeTypeArr) {
- foreach($codeTypeArr as $codeTypeStr){
- $query->orWhere('EQUI_TICO', '=', $codeTypeStr);
- }
- })->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P01MEEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos con tipo de código #$codeType.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function generateGraphicArborescence(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'equipment_code' => 'required|string',
- 'equipment_arborescence' => '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);
- }
- $equipmentCodeDec = $this->encryptionController->decrypt($form['equipment_code']);
- if(!$equipmentCodeDec){
- return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $equipmentCodeDec]
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento solicitado no existe.', [], 404);
- }
- $arborescenceDec = $this->encryptionController->decrypt($form['equipment_arborescence']);
- if(!$arborescenceDec){
- return $this->responseController->makeResponse(true, 'El arreglo de la arborescencia no fue encriptado correctamente.', [], 400);
- }
- $materialIcons = [];
- $iconsLocation = $this->templatesUbic;
- $iconsLocation = str_replace("pdf_templates\\01_05_GEEQ\\", "global_resources\\mat_icons_png", $iconsLocation);
- if(!file_exists($iconsLocation)){
- return $this->responseController->makeResponse(true, 'No se pudo obtener la lista de iconos.', [], 404);
- }
- $iconsList = scandir($iconsLocation);
- foreach($iconsList as $category){
- if($category != '.' && $category != '..'){
- $categoryIcons = scandir("$iconsLocation\\$category");
- foreach($categoryIcons as $icon){
- if($icon != '.' && $icon != '..'){
- if(file_exists("$iconsLocation\\$category\\$icon\\materialicons\\48dp\\2x")){
- $imgFiles = scandir("$iconsLocation\\$category\\$icon\\materialicons\\48dp\\2x");
- if(count($imgFiles) == 3){
- foreach($imgFiles as $imgStr){
- if($imgStr != '.' && $imgStr != '..'){
- $materialIcons[] = [
- 'category' => $category,
- 'icon' => $icon,
- 'iconRoute' => "$iconsLocation\\$category\\$icon\\materialicons\\48dp\\2x\\$imgStr"
- ];
- }
- }
- }
- }
- }
- }
- }
- }
- $html = file_get_contents($this->templatesUbic . "01-GEEQ-PL-010101-000001=01=PDF_ARBORESCENCIA.html");
- $arborescenceArr = json_decode($arborescenceDec, true);
- $tableBody = "";
- foreach($arborescenceArr as $level=>$item){
- $levelIndex = $level + 1;
- if(!array_key_exists('label', $item) || !array_key_exists('graph', $item)){
- return $this->responseController->makeResponse(true, "El elemento del nivel $levelIndex de la arborescencia tiene un formato inválido.", [], 404);
- }
- if($levelIndex == 1){
- $logo = file_get_contents($this->functionsController->getBasePath() ."\storage\app\public\global_resources\sam-short-logo.png");
- $logoStr = "data:image/svg+xml;base64," . base64_encode($logo);
- $tableBody .= "
- <tr>
- <td class=\"td-label\">Línea 1</td>
- <td style=\"padding: 8px; text-align:center;\">
- <img src=\"$logoStr\" width=\"256px\">
- </td>
- </tr>
- ";
- }else if($levelIndex > 1 && $levelIndex <= 3){
- $graphArr = json_decode($item['graph'], true);
- if($graphArr['customIcon'] == 'N'){
- $iconName = $graphArr['icon'];
- $iconFilt = array_filter($materialIcons, function($v, $k) use ($iconName) {
- return $v['icon'] == $iconName;
- }, ARRAY_FILTER_USE_BOTH);
- $iconObj = end($iconFilt);
- $imageContent = file_get_contents($iconObj['iconRoute']);
- $imageContentStr = "data:image/svg+xml;base64," . base64_encode($imageContent);
- $tableBody .= "
- <tr>
- <td class=\"td-label\">$item[label]</td>
- <td style=\"padding: 8px; text-align:center;\">
- <img src=\"$imageContentStr\" width=\"128px\" height=\"128px\" style=\"opacity:0.6;\">
- </td>
- </tr>
- ";
- }
- }else{
- $graphLocation = str_replace('http://git.ittec.mx/', '', $item['graph']);
- $graphLocation = str_replace('/', "\\", $graphLocation);
- $publicImagesLocation = str_replace('sam\storage\app\public\pdf_templates\01_05_GEEQ\\', '', $this->templatesUbic);
- $graphLocation = $publicImagesLocation . $graphLocation;
- if(file_exists($graphLocation)){
- $graphSize = getimagesize($graphLocation);
- $graphWidth = $graphSize[0];
- $graphHeight = $graphSize[1];
- $graphSizeStr = '';
- if($graphWidth > $graphHeight){
- $widthZoom = round($this->functionsController->floatDiv($graphWidth, 272));
- $widthZoom = $widthZoom <= 0 ? 1 : $widthZoom;
- $graphWidth = round($this->functionsController->floatDiv($graphWidth, $widthZoom));
- $graphHeight = round($this->functionsController->floatDiv($graphHeight, $widthZoom));
- $graphSizeStr = "width=\"" . $graphWidth . "px\" height=\"" . $graphHeight . "px\"";
- }else if($graphWidth < $graphHeight){
- $heightZoom = round($this->functionsController->floatDiv($graphHeight, 272));
- $heightZoom = $heightZoom <= 0 ? 1 : $heightZoom;
- $graphWidth = round($this->functionsController->floatDiv($graphWidth, $heightZoom));
- $graphHeight = round($this->functionsController->floatDiv($graphHeight, $heightZoom));
- $graphSizeStr = "width=\"" . $graphWidth . "px\" height=\"" . $graphHeight . "px\"";
- }else{
- $widthZoom = round($this->functionsController->floatDiv($graphWidth, 272));
- $widthZoom = $widthZoom <= 0 ? 1 : $widthZoom;
- $heightZoom = round($this->functionsController->floatDiv($graphHeight, 272));
- $heightZoom = $heightZoom <= 0 ? 1 : $heightZoom;
-
- $graphWidth = round($this->functionsController->floatDiv($graphWidth, $widthZoom));
- $graphHeight = round($this->functionsController->floatDiv($graphHeight, $heightZoom));
- $graphSizeStr = "width=\"" . $graphWidth . "px\" height=\"" . $graphHeight . "px\"";
- }
- $labelArr = explode(' - ', $item['label']);
- $graphContent = file_get_contents($graphLocation);
- $graphContentStr ="data:image/svg+xml;base64," . base64_encode($graphContent);
- $tableBody .= "
- <tr>
- <td class=\"td-label\">
- <b>Código: </b>$labelArr[0]<br><br>
- <b>Descripción: </b>$labelArr[1] - $labelArr[2]
- </td>
- <td style=\"padding: 8px; text-align:center;\">
- <img src=\"$graphContentStr\" $graphSizeStr>
- </td>
- </tr>
- ";
- }
- }
- }
- $html = str_replace('%tableBody%', $tableBody, $html);
- $elementCodeArr0 = explode('_', $equipmentCodeDec);
- $elementCodeStr0 = end($elementCodeArr0);
- $elementCodeArr1 = explode('.', $elementCodeStr0);
- $elementCodeStr = end($elementCodeArr1);
- $como = 'GEEQ';
- $cldo = 'IN';
- $noar = "arborescencia_$elementCodeStr";
- $exte = "pdf";
- $line = intval($form['linea']);
- $line = $line < 10 ? "0$line" : "$line";
- $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() ."\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") generó el archivo de arborescencia del equipamiento $equipmentCodeDec.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['fileID' => $this->encryptionController->encrypt($fileName)]);
- }
- public function updateSecurityCriticality(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'equipment_code' => 'required|string',
- 'criticality' => '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);
- }
- $equipmentCodeDec = $this->encryptionController->decrypt($form['equipment_code']);
- if(!$equipmentCodeDec){
- return $this->responseController->makeResponse(true, 'El código del equipamiento no fue encriptado correctamente.', [], 400);
- }
- $equipment = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $equipmentCodeDec]
- ])->first();
-
- if(is_null($equipment)){
- return $this->responseController->makeResponse(true, 'El equipamiento solicitado no existe.', [], 404);
- }
- $criticality = $this->encryptionController->decrypt($form['criticality']);
- if(!$criticality){
- return $this->responseController->makeResponse(true, 'La criticidad seleccionada no fue encriptada correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $form['linea']],
- ['EQUI_COEQ', '=', $equipmentCodeDec]
- ])->update([
- 'EQUI_CRSE' => $criticality,
- 'EQUI_USMO' => $idUser,
- 'EQUI_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M07GEEQ',
- 'S002V01F03GCSE',
- 'S002V01P01GECR',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la criticidad de seguridad del equipamiento $equipmentCodeDec.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function generateEquipmentFile(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'file_type' => 'required|string|in:PDF,XLS',
- 'file_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);
- }
- $fileData = $this->encryptionController->decrypt($form['file_data']);
- if(!$fileData){
- return $this->responseController->makeResponse(true, 'La información del equipamiento no fue encriptada correctamente.', [], 400);
- }
- $fileDataArr = json_decode($fileData, true);
- $spreadsheet = $this->generateEquipmentDataSheet($fileDataArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
-
- $dateTimeArr = explode(" ", $nowStr);
- $dateArr = explode("-", $dateTimeArr[0]);
- $year = substr($dateArr[0], 2);
- $como = 'GEEQ';
- $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;
- }
- $equipmentCode = $fileDataArr['CODIGO'];
- $equipmentCodeArr0 = explode('_', $equipmentCode);
- $equipmentCodeArr1 = explode('.', $equipmentCodeArr0[1]);
- $equipmentCodeArr1 = array_reverse($equipmentCodeArr1);
- $timestamp = $now->timestamp;
- $noar = "ficha_descriptiva_$equipmentCodeArr1[0]_$timestamp";
- $exte = $form['file_type'] == 'XLS' ? "xlsx": 'pdf';
- $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);
- }
- if($form['file_type'] == 'XLS'){
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
- }else{
- $writer = new Mpdf($spreadsheet);
- $writer->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
- }
- $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,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- '-',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") generó la ficha descriptiva del equipamiento #$equipmentCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['fileID' => $this->encryptionController->encrypt($fileName)]);
- }
- private function generateEquipmentDataSheet($equipmentInfo) : Spreadsheet {
- $spreadsheet = new Spreadsheet;
- $spreadsheet->getProperties()
- ->setCreator('STC')
- ->setTitle('Ficha descriptiva de equipamiento.')
- ->setSubject('Ficha equipamiento')
- ->setKeywords('Ficha Técnica Equipamiento')
- ->setCategory('Fichas técnicas');
- $worksheet = $spreadsheet->getActiveSheet();
- $worksheet->setTitle('FICHA DESCRIPTIVA');
- $worksheet->mergeCells('B2:M2');
- $worksheet->setCellValue('B2', $equipmentInfo['CODIGO'])->getStyle('B2')->getFill()
- ->setFillType(Fill::FILL_SOLID)
- ->getStartColor()->setRGB('B7BCC4');
- $worksheet->getStyle('B2')->getFont()->setBold(true);
- $worksheet->getStyle('B2')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- $worksheet->getColumnDimension('B')->setWidth(16);
- $worksheet->getColumnDimension('C')->setWidth(16);
- $worksheet->getColumnDimension('D')->setWidth(16);
- $worksheet->getColumnDimension('E')->setWidth(16);
- $worksheet->getColumnDimension('F')->setWidth(16);
- $worksheet->getColumnDimension('G')->setWidth(16);
- $worksheet->getColumnDimension('H')->setWidth(16);
- $worksheet->getColumnDimension('I')->setWidth(16);
- $worksheet->getColumnDimension('J')->setWidth(16);
- $worksheet->getColumnDimension('K')->setWidth(16);
- $worksheet->getColumnDimension('L')->setWidth(16);
- $worksheet->getColumnDimension('M')->setWidth(16);
- /*INICIO COLUMNA 1*/
- $worksheet->mergeCells('B3:E3');
- $worksheet->setCellValue('B3', "Tipo: $equipmentInfo[TIPO_EQUIPAMIENTO]");
- $worksheet->mergeCells('F3:I3');
- $worksheet->setCellValue('F3', "Modelo: $equipmentInfo[MODELO]");
- $worksheet->mergeCells('J3:M3');
- $worksheet->setCellValue('J3', "ID: $equipmentInfo[ID_EQUIPAMIENTO]");
- /*FIN COLUMNA 1*/
- /*INICIO COLUMNA 2*/
- $worksheet->mergeCells('B4:E4');
- $worksheet->setCellValue('B4', "Familia: $equipmentInfo[FAMILIA]");
- $worksheet->mergeCells('F4:I4');
- $worksheet->setCellValue('F4', "Subfamilia: $equipmentInfo[SUBFAMILIA]");
- $worksheet->mergeCells('J4:M4');
- $worksheet->setCellValue('J4', "Estado: $equipmentInfo[ESTADO]");
- /*FIN COLUMNA 2*/
- /*INICIO COLUMNA 3*/
- $worksheet->mergeCells('B5:E5');
- $worksheet->setCellValue('B5', "Jerarquía: $equipmentInfo[JERARQUIA]");
- $parentCode = is_null($equipmentInfo['EQUIPO_PADRE']) ? '-' : $equipmentInfo['EQUIPO_PADRE'];
- $worksheet->mergeCells('F5:M5');
- $worksheet->setCellValue('F5', "Equipo padre: $parentCode");
- /*FIN COLUMNA 3*/
- /*INICIO COLUMNA 4*/
- $worksheet->mergeCells('B6:D6');
- $worksheet->setCellValue('B6', "Tipo de codificación: $equipmentInfo[TIPO_CODIGO]");
- $worksheet->mergeCells('E6:G6');
- $worksheet->setCellValue('E6', "Ubicación de origen: $equipmentInfo[UBICACION_ORIGEN]");
- $worksheet->mergeCells('H6:J6');
- $worksheet->setCellValue('H6', "Nivel de origen: $equipmentInfo[NIVEL_ORIGEN]");
- $worksheet->mergeCells('K6:M6');
- $worksheet->setCellValue('K6', "Ocupación de origen: $equipmentInfo[OCUPACION_ORIGEN]");
- /*FIN COLUMNA 4*/
- /*INICIO COLUMNA 5*/
- $worksheet->mergeCells('B7:D7');
- $worksheet->setCellValue('B7', "Elemento de origen: $equipmentInfo[ELEMENTO_ORIGEN]");
- $pccIntersection = is_null($equipmentInfo['INTERSECCION_PCC']) ? 'No aplica' : $equipmentInfo['INTERSECCION_PCC'];
- $worksheet->mergeCells('E7:G7');
- $worksheet->setCellValue('E7', "Intersección en PCC: $pccIntersection");
- $pccPosition = is_null($equipmentInfo['POSICION_PCC']) ? 'No aplica' : $equipmentInfo['POSICION_PCC'];
- $worksheet->mergeCells('H7:J7');
- $worksheet->setCellValue('H7', "Posición en PCC: $pccPosition");
- $pccPosition = is_null($equipmentInfo['KILOMETRO_ORIGEN']) ? 'No aplica' : $equipmentInfo['KILOMETRO_ORIGEN'];
- $worksheet->mergeCells('K7:M7');
- $worksheet->setCellValue('K7', "Kilómetro de origen: $pccPosition");
- /*FIN COLUMNA 5*/
- /*INICIO COLUMNA 6*/
- $trainArea = is_null($equipmentInfo['AREA_TREN']) ? 'No aplica' : $equipmentInfo['AREA_TREN'];
- $worksheet->mergeCells('B8:D8');
- $worksheet->setCellValue('B8', "Área del tren: $trainArea");
- $originElementSecuence = is_null($equipmentInfo['SECUENCIA_ELEMENTO_ORIGEN']) ? 'No aplica' : $equipmentInfo['SECUENCIA_ELEMENTO_ORIGEN'];
- $worksheet->mergeCells('E8:G8');
- $worksheet->setCellValue('E8', "Secuencia del elemento de origen: $originElementSecuence");
- $originCodificationType = is_null($equipmentInfo['TIPO_CODIFICACION_ORIGEN']) ? 'No aplica' : $equipmentInfo['TIPO_CODIFICACION_ORIGEN'];
- $worksheet->mergeCells('H8:J8');
- $worksheet->setCellValue('H8', "Tipo de codificación de origen: $originCodificationType");
- $originElementCode = is_null($equipmentInfo['CODIGO_ELEMENTO_ORIGEN']) ? 'No aplica' : $equipmentInfo['CODIGO_ELEMENTO_ORIGEN'];
- $worksheet->mergeCells('K8:M8');
- $worksheet->setCellValue('K8', "Código del elemento de origen: $originElementCode");
- /*FIN COLUMNA 6*/
- /*INICIO COLUMNA 7*/
- $destinyLocation = is_null($equipmentInfo['UBICACION_DESTINO']) ? 'No aplica' : $equipmentInfo['UBICACION_DESTINO'];
- $worksheet->mergeCells('B9:D9');
- $worksheet->setCellValue('B9', "Ubicación de destino: $destinyLocation");
- $destinyLevel = is_null($equipmentInfo['NIVEL_DESTINO']) ? 'No aplica' : $equipmentInfo['NIVEL_DESTINO'];
- $worksheet->mergeCells('E9:G9');
- $worksheet->setCellValue('E9', "Nivel de destino: $destinyLevel");
- $destinyOccupation = is_null($equipmentInfo['OCUPACION_DESTINO']) ? 'No aplica' : $equipmentInfo['OCUPACION_DESTINO'];
- $worksheet->mergeCells('H9:J9');
- $worksheet->setCellValue('H9', "Ocupación de destino: $destinyOccupation");
- $destinyElement = is_null($equipmentInfo['ELEMENTO_DESTINO']) ? 'No aplica' : $equipmentInfo['ELEMENTO_DESTINO'];
- $worksheet->mergeCells('K9:M9');
- $worksheet->setCellValue('K9', "Elemento de destino: $destinyElement");
- /*FIN COLUMNA 7*/
- /*INICIO COLUMNA 8*/
- $destinyKilometer = is_null($equipmentInfo['KILOMETRO_DESTINO']) ? 'No aplica' : $equipmentInfo['KILOMETRO_DESTINO'];
- $worksheet->mergeCells('B10:D10');
- $worksheet->setCellValue('B10', "Kilómetro de destino: $destinyKilometer");
- $destinyElementSecuence = is_null($equipmentInfo['SECUENCIA_ELEMENTO_DESTINO']) ? 'No aplica' : $equipmentInfo['SECUENCIA_ELEMENTO_DESTINO'];
- $worksheet->mergeCells('E10:G10');
- $worksheet->setCellValue('E10', "Secuencia del elemento de destino: $destinyElementSecuence");
- $destinyCodificationType = is_null($equipmentInfo['TIPO_CODIFICACION_DESTINO']) ? 'No aplica' : $equipmentInfo['TIPO_CODIFICACION_DESTINO'];
- $worksheet->mergeCells('H10:J10');
- $worksheet->setCellValue('H10', "Tipo de codificación de destino: $destinyCodificationType");
- $destinyElementCode = is_null($equipmentInfo['CODIGO_ELEMENTO_DESTINO']) ? 'No aplica' : $equipmentInfo['CODIGO_ELEMENTO_DESTINO'];
- $worksheet->mergeCells('K10:M10');
- $worksheet->setCellValue('K10', "Código del elemento de destino: $destinyElementCode");
- /*FIN COLUMNA 8*/
- /*INICIO COLUMNA 9*/
- $criticalityLevel = !isset($equipmentInfo['NIVEL_CRITICIDAD_OBJ']) ? 'No configurado' : $equipmentInfo['NIVEL_CRITICIDAD_OBJ']['label'];
- $worksheet->mergeCells('B11:D11');
- $worksheet->setCellValue('B11', "Nivel de criticidad de seguridad: $criticalityLevel");
- $worksheet->mergeCells('E11:G11');
- $worksheet->setCellValue('E11', "Fecha de adquisición: $equipmentInfo[FECHA_ADQUISICION]");
- $worksheet->mergeCells('H11:J11');
- $worksheet->setCellValue('H11', "Fecha de inicio de la garantía: $equipmentInfo[FECHA_INICIO_GARANTIA]");
- $worksheet->mergeCells('K11:M11');
- $worksheet->setCellValue('K11', "Fecha de término de la garantía: $equipmentInfo[FECHA_TERMINO_GARANTIA]");
- /*FIN COLUMNA 9*/
- /*INICIO COLUMNA 10*/
- $worksheet->mergeCells('B12:D12');
- $worksheet->setCellValue('B12', "Proveedor: $equipmentInfo[PROVEEDOR]");
- $requiredSoftware = is_null($equipmentInfo['TIPO_CODIFICACION_DESTINO']) ? 'Ningúno' : $equipmentInfo['TIPO_CODIFICACION_DESTINO'];
- $worksheet->mergeCells('E12:G12');
- $worksheet->setCellValue('E12', "Software requerido: $requiredSoftware");
- $softwareVersion = is_null($equipmentInfo['VERSION_SOFTWARE']) ? 'No aplica' : $equipmentInfo['VERSION_SOFTWARE'];
- $worksheet->mergeCells('H12:J12');
- $worksheet->setCellValue('H12', "Versión del software: $softwareVersion");
- $worksheet->mergeCells('K12:M12');
- $worksheet->setCellValue('K12', "Estado de funcionamiento: $equipmentInfo[ESTADO_FUNCIONAMIENTO]");
- /*FIN COLUMNA 10*/
- /*INICIO COLUMNA 11*/
- $worksheet->mergeCells('B13:G13');
- $worksheet->setCellValue('B13', "Usuario que registró: $equipmentInfo[USUARIO_REGISTRO]");
- $worksheet->mergeCells('H13:M13');
- $worksheet->setCellValue('H13', "Fecha de registro: $equipmentInfo[FECHA_REGISTRO]");
- /*FIN COLUMNA 11*/
- /*INICIO COLUMNA 12*/
- $usrMod = is_null($equipmentInfo['USUARIO_MODIFICACION']) ? '-' : $equipmentInfo['USUARIO_MODIFICACION'];
- $worksheet->mergeCells('B14:G14');
- $worksheet->setCellValue('B14', "Usuario que modificó: $usrMod");
- $fecMod = is_null($equipmentInfo['FECHA_MODIFICACION']) ? '-' : $equipmentInfo['FECHA_MODIFICACION'];
- $worksheet->mergeCells('H14:M14');
- $worksheet->setCellValue('H14', "Fecha última modificación: $fecMod");
- /*FIN COLUMNA 12*/
- $startRow = 2;
- $startCol = 2;
- $maxRow = $startRow + 12;
- $maxCol = $startCol + 11;
- for($row = $startRow; $row <= $maxRow; $row++){
- for($col = $startCol; $col <= $maxCol; $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $worksheet->getStyle($colStr . $row)->getBorders()->getOutline()->setBorderStyle(Border::BORDER_THIN)->setColor(new Color('55000000'));
- }
- }
- return $spreadsheet;
- }
- public function getEquipmentTypes($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);
- }
- $equipmentTypes = DB::table('S002V01TEQUI')->select([
- DB::raw('COUNT(*) AS CANTIDAD_EQUIPAMIENTOS'),
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- ])->groupBy('EQUI_TIPO')->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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P12GCTE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la cantidad de equipamientos por tipo.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipmentTypes);
- }
- public function getEquipmentsByType($equipmentType, $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);
- }
- $equipmentType = urldecode($equipmentType);
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_TIPO', '=', $equipmentType],
- ])->get()->all();
- $idUserEnc = $this->encryptionController->encrypt($idUser);
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $imagesGalleryArr = json_decode($equipment->GALERIA_IMAGENES, true);
- $imagesGalleryFn = [];
- foreach($imagesGalleryArr as $imageCode){
- $imageCodeEnc = $this->encryptionController->encrypt($imageCode);
- $publicUri = $this->documentManagementController->privateGetPublicDocumentURL(
- $imageCodeEnc,
- $idUserEnc,
- $line
- );
- if($publicUri['error']){
- return $this->responseController->makeresponse(true, $publicUri['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($publicUri['response']['public_uri']);
- $imagesGalleryFn[] = $uriEnc;
- }
- }
- $equipment->GALERIA_IMAGENES = json_encode($imagesGalleryFn);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P12GCTE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos de tipo $equipmentType.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentsByKilometer($startPK, $endPK, $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);
- }
- $startPK = $this->functionsController->floatAdd(floatval($startPK), 0.1);
- $endPK = floatVal($endPK);
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- 'EQUI_KIOR AS KILOMETRO_ORIGEN',
- 'EQUI_KIDE AS KILOMETRO_DESTINO',
- 'EQUI_NIOR AS NIVEL_ORIGEN',
- 'EQUI_NIDE AS NIVEL_DESTINO',
- ])->where('EQUI_NULI', '=', $line)
- ->where(function(Builder $query) use($endPK, $startPK) {
- $query->where([
- ['EQUI_KIOR', '>', $endPK],
- ['EQUI_KIOR', '<', $startPK],
- ])->orWhere([
- ['EQUI_KIDE', '>', $endPK],
- ['EQUI_KIDE', '<', $startPK],
- ]);
- })->get()->all();
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $equipment->GALERIA_IMAGENES = $this->encryptionController->encrypt($equipment->GALERIA_IMAGENES);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P13LOEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos entre los kilómetros $startPK y $endPK.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentsByTrainArea($car, $area, $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);
- }
- $car = $this->encryptionController->decrypt($car);
- if(!$car){
- return $this->responseController->makeResponse(true, 'El código del coche no está encriptado correctamente', [], 400);
- }
- $area = $this->encryptionController->decrypt($area);
- if(!$area){
- return $this->responseController->makeResponse(true, 'El código del área no está encriptado correctamente', [], 400);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_OCOR', '=', $car],
- ['EQUI_ARTR', '=', $area]
- ])->get()->all();
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $equipment->GALERIA_IMAGENES = $this->encryptionController->encrypt($equipment->GALERIA_IMAGENES);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P13LOEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos del área $area en el coche $car.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getEquipmentsByPCCIntersection($intersection, $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);
- }
- $intersection = $this->encryptionController->decrypt($intersection);
- if(!$intersection){
- return $this->responseController->makeResponse(true, 'La interección no está encriptada correctamente', [], 400);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_IPCC', '=', $intersection],
- ])->orWhere([
- ['EQUI_ELOR', 'LIKE', "%$element%"],
- ['EQUI_ELDE', 'LIKE', "%$element%"],
- ])->get()->all();
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $equipment->GALERIA_IMAGENES = $this->encryptionController->encrypt($equipment->GALERIA_IMAGENES);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P13LOEQ',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipamientos de la intersección $intersection del PCC",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- public function getArborescenceByDate($date, $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);
- }
- $dateArr = explode('-', $date);
- if(count($dateArr) != 3){
- return $this->responseController->makeResponse(true, 'La fecha enviada no tiene un formato correcto YYYY-MM-DD.', [], 400);
- }
- $validDate = checkdate(intval($dateArr[1]), intval($dateArr[2]), intval($dateArr[0]));
- if(!$validDate){
- return $this->responseController->makeResponse(true, 'La fecha enviada es inválida.', [], 400);
- }
- $searchDate = new Carbon($date);
- //CONSTRUCCIÓN DE LA ARBORESCENCIA
- //Paso 1: Consultar las familias
- $families = DB::table('S002V01TFAMI')->select([
- 'FAMI_COFA AS CODIGO_FAMILIA',
- 'FAMI_NOFA AS NOMBRE_FAMILIA',
- ])->where([
- ['FAMI_ESTA', '=', 'Activo'],
- ['FAMI_NULI', '=', $line]
- ])->get()->all();
- $familyArborescenceArr = [];
- foreach($families as $family){
- //Paso 2: Consultar las subfamilias de cada familia
- $subfamilies = DB::table('S002V01TSUBF')->select([
- 'SUBF_COSU AS CODIGO_SUBFAMILIA',
- 'SUBF_NOSU AS NOMBRE_SUBFAMILIA',
- ])->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $family->CODIGO_FAMILIA],
- ['SUBF_ESTA', '=', 'Activo']
- ])->get()->all();
- $subfamilyArborescenceArr = [];
- foreach($subfamilies as $subfamily){
- //Paso 3: Consultar los equipamientos padre
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO_EQUIPAMIENTO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'EQUI_HICO AS HISTORIAL_CODIGOS'
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_FAMI', '=', $family->CODIGO_FAMILIA],
- ['EQUI_SUBF', '=', $subfamily->CODIGO_SUBFAMILIA],
- ['EQUI_JERA', '=', 'Padre'],
- ])->get()->all();
- $equipmentArborescenceArr = [];
- foreach($equipments as $equipment){
- $codesHistory = json_decode($equipment->HISTORIAL_CODIGOS, true);
- $codeFilt = array_filter($codesHistory, function($v, $k) use ($searchDate){
- $codeDate = new Carbon($v['FECHA']);
- return $codeDate->lte($searchDate);
- }, ARRAY_FILTER_USE_BOTH);
- if(count($codeFilt) > 0){
- $lastCode = end($codeFilt);
- $children = $this->getEquipmentChildren(
- $lastCode['CODIGO'],
- $line,
- $family,
- $subfamily,
- $searchDate
- );
-
- $equipmentElement = $lastCode['CODIGO'] . ' - ' . $equipment->TIPO_EQUIPAMIENTO . ' - ' . $equipment->MODELO_EQUIPAMIENTO . ' (' . $equipment->ID_EQUIPAMIENTO . ')';
- $equipmentArborescenceArr[] = [
- 'ELEMENTO' => $this->encryptionController->encrypt($equipmentElement),
- 'HIJOS' => $children,
- ];
- }
- }
- $subfamilyElement = $subfamily->NOMBRE_SUBFAMILIA . ' (' . $subfamily->CODIGO_SUBFAMILIA . ')';
- $subfamilyArborescenceArr[] = [
- 'ELEMENTO' => $this->encryptionController->encrypt($subfamilyElement),
- 'HIJOS' => $equipmentArborescenceArr,
- ];
- }
- $familyElement = $family->NOMBRE_FAMILIA . ' (' . $family->CODIGO_FAMILIA . ')';
- $familyArborescenceArr[] = [
- 'ELEMENTO' => $this->encryptionController->encrypt($familyElement),
- 'HIJOS' => $subfamilyArborescenceArr,
- ];
- }
- $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,
- 'S002V01M07GEEQ',
- 'S002V01F01ADEQ',
- 'S002V01P14VAFD',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la arborescencia en la fecha $date",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $familyArborescenceArr);
- }
- private function getEquipmentChildren($equipmentCode, $line, $family, $subfamily, $searchDate) {
- $children = DB::table('S002V01TEQUI')->select([
- 'EQUI_TIPO AS TIPO_EQUIPAMIENTO',
- 'EQUI_MODE AS MODELO_EQUIPAMIENTO',
- 'EQUI_IDEQ AS ID_EQUIPAMIENTO',
- 'EQUI_HICO AS HISTORIAL_CODIGOS'
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_FAMI', '=', $family->CODIGO_FAMILIA],
- ['EQUI_SUBF', '=', $subfamily->CODIGO_SUBFAMILIA],
- ['EQUI_JERA', '=', 'Hijo'],
- ])->whereRaw("JSON_SEARCH(
- EQUI_HICO, 'one', ?, NULL, '$[*].PADRE'
- )", [$equipmentCode])->get()->all();
- $childrenFn = [];
- foreach($children as $child){
- $codesHistory = json_decode($child->HISTORIAL_CODIGOS, true);
- $codeFilt = array_filter($codesHistory, function($v, $k) use ($searchDate){
- $codeDate = new Carbon($v['FECHA']);
- return $codeDate->lte($searchDate);
- }, ARRAY_FILTER_USE_BOTH);
- if(count($codeFilt) > 0){
- $lastCode = end($codeFilt);
- $children = $this->getEquipmentChildren(
- $lastCode['CODIGO'],
- $line,
- $family,
- $subfamily,
- $searchDate
- );
-
- $childElement = $lastCode['CODIGO'] . ' - ' . $child->TIPO_EQUIPAMIENTO . ' - ' . $child->MODELO_EQUIPAMIENTO . ' (' . $child->ID_EQUIPAMIENTO . ')';
- $childrenFn[] = [
- 'ELEMENTO' => $this->encryptionController->encrypt($childElement),
- 'HIJOS' => $children,
- ];
- }
- }
- return $childrenFn;
- }
- public function processExcelEquipmnts(Request $request) {
- DB::enableQueryLog();
- if(!$request->hasFile('file')){
- return $this->responseController->makeResponse(true, "No se envió ningún archivo.", [], 400);
- }
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer'
- ]);
- 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 del usuario que realizó la petición no fue encriptado correctamente", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $originalFileName = $request->file('file')->getClientOriginalName();
- $extension = $request->file('file')->extension();
- $size = $request->file('file')->getSize();
- $extArr = explode(".", $originalFileName);
- $extArr = array_reverse($extArr);
- $extStr = $extArr[0];
- $isValid = $this->functionsController->checkFileSize($extStr, $size);
- if($isValid){
- $dir = str_replace("app\\Http\\Controllers", "storage\\app", __DIR__);
- $tmpPath = $request->file('file')->store('tempFiles');
- $tmpPath = str_replace("/", "\\", $tmpPath);
- $location = "$dir\\$tmpPath";
- $spreadsheet = IOFactory::load($location);
- $worksheets = $spreadsheet->getSheetNames();
- $html = "";
- $cont = 1;
- if(in_array("CODIFICACIÓN FINAL", $worksheets)){
- $worksheet = $spreadsheet->getSheetByName("CODIFICACIÓN FINAL");
- $maxRow = $worksheet->getHighestRow();
- $html .= "<table>";
- for($i = 0; $i < 100; $i++){
- for($row = 6; $row <= $maxRow; $row++){
- $html .= "<tr>";
- for($col = 2; $col <= 26; $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $value = $worksheet->getCell($colStr . $row)->getCalculatedValue();
-
- if($col == 2){
- $html .= "<td>" . $cont . "</td>";
- }
- $html .= "<td>" . $value . "</td>";
- }
- $html .= "</tr>";
- $cont++;
- }
- }
- $html .= "</table>";
- }
- $test = fopen($dir . "\\test.html", "w");
- fwrite($test, $html);
- fclose($test);
- echo "FIN";
- /*
- $nowStr = Carbon::now('America/Mexico_city')->toDateTimeString();
- $fileID = DB::table('S002V01TARTE')->insertGetId([
- 'ARTE_NULI' => $form['linea'],
- 'ARTE_NOAR' => $originalFileName,
- 'ARTE_EXTE' => $extension,
- 'ARTE_TAMA' => $size,
- 'ARTE_UBTE' => $location,
- 'ARTE_USRE' => $idUser,
- 'ARTE_FERE' => $nowStr
- ]);
-
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M04GDEL',
- 'S002V01F01ADDO',
- 'S002V01P05REDO',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") subió de manera temporal el archivo $originalFileName.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
-
- return $this->responseController->makeresponse(false, "EXITO", [
- 'idArchivo' => $this->encryptionController->encrypt($fileID),
- ]);*/
- }else{
- return $this->responseController->makeResponse(true, "El archivo enviado tiene una extensión no soportada o sobrepasa el límite de peso de su categoría.", [], 400);
- }
- }
- public function getPCCEquipments($idUser, $line) {
- $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);
- }
- $planeEquipments = DB::table('S002V01TEQUI')->select([
- DB::raw("DISTINCT(EQUI_FAMI) AS FAMILIA"),
- DB::raw("CONCAT(
- IF(ISNULL(EQUI_IPCC), '-', EQUI_IPCC),
- '|',
- FAMI_COLO,
- '|',
- FAMI_NOFA
- ) AS COLOR_COORDENADAS"),
- ])->join('S002V01TFAMI', 'FAMI_COFA', '=', 'EQUI_FAMI')->where(function(Builder $query) {
- $query->where('EQUI_TICO', '=', '2')->orWhere('EQUI_TCOR', '=', '2')->orWhere('EQUI_TCDE', '=', '2');
- })->where('EQUI_NULI', '=', $line)->get()->all();
- return $this->responseController->makeResponse(false, 'EXITO', $planeEquipments);
- }
- public function getTrainEquipments($trainCar, $idUser, $line) {
- $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);
- }
- $trainCar = $this->encryptionController->decrypt($trainCar);
- if(!$trainCar){
- return $this->responseController->makeResponse(true, 'El código del vagón seleccionado no está encriptado correctamente', [], 400);
- }
- $trainEquipments = DB::table('S002V01TEQUI')->select([
- DB::raw("DISTINCT(EQUI_FAMI) AS FAMILIA"),
- DB::raw("CONCAT(
- IF(ISNULL(EQUI_ARTR), '-', EQUI_ARTR),
- '|',
- FAMI_COLO,
- '|',
- FAMI_NOFA
- ) AS COLOR_COORDENADAS"),
- ])->join('S002V01TFAMI', 'FAMI_COFA', '=', 'EQUI_FAMI')->where(function(Builder $query) {
- $query->where('EQUI_TICO', '=', '5')->orWhere('EQUI_TCOR', '=', '5')->orWhere('EQUI_TCDE', '=', '5');
- })->where(function(Builder $query) use ($trainCar) {
- $query->where('EQUI_OCOR', '=', $trainCar)->orWhere('EQUI_OCDE', '=', $trainCar);
- })->where('EQUI_NULI', '=', $line)->get()->all();
- return $this->responseController->makeResponse(false, 'EXITO', $trainEquipments);
- }
- public function getViaEquipments($idUser, $line) {
- $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);
- }
- $startKM = 0;
- $endKM = 17.7;
- $equipmentsFN = [];
- while($startKM < $endKM){
- $maxKM = $this->functionsController->floatAdd($startKM, 0.1);
- $viaEquipments = DB::table('S002V01TEQUI')->select([
- DB::raw("DISTINCT(EQUI_FAMI) AS FAMILIA"),
- DB::raw("CONCAT(
- IF(ISNULL(EQUI_KIOR), '-', EQUI_KIOR),
- '|',
- IF(ISNULL(EQUI_KIDE), '-', EQUI_KIDE),
- '|',
- FAMI_COLO,
- '|',
- FAMI_NOFA
- ) AS COLOR_COORDENADAS"),
- ])->join('S002V01TFAMI', 'FAMI_COFA', '=', 'EQUI_FAMI')->where(function(Builder $query) {
- $query->where('EQUI_TICO', '=', '3')->orWhere('EQUI_TCOR', '=', '3')->orWhere('EQUI_TCDE', '=', '3');
- })->where(function(Builder $query) use ($startKM, $maxKM) {
- $query->whereBetween('EQUI_KIOR', [$startKM, $maxKM])->orWhereBetween('EQUI_KIDE', [$startKM, $maxKM]);
- })->where('EQUI_NULI', '=', $line)->get()->all();
- foreach($viaEquipments as $equipment){
- $coordsArr = explode('|', $equipment->COLOR_COORDENADAS);
- $min = $this->functionsController->validNumber($coordsArr[0], true) ? floatval($coordsArr[0]) : null;
- $max = $this->functionsController->validNumber($coordsArr[1], true) ? floatval($coordsArr[1]) : null;
- if($min >= $startKM && $min <= $maxKM){
- $coordsStr = $min . '|-|' . $coordsArr[2] . '|' . $coordsArr[3];
- $equipment->COLOR_COORDENADAS = $coordsStr;
- }else if($max >= $startKM && $max <= $maxKM){
- $coordsStr = '-|' . $max . '|' . $coordsArr[2] . '|' . $coordsArr[3];
- $equipment->COLOR_COORDENADAS = $coordsStr;
- }
- $equipmentsFN[] = $equipment;
- }
- $startKM = $maxKM;
- }
- return $this->responseController->makeResponse(false, 'EXITO', $equipmentsFN);
- }
- public function getStationEquipments($idPlane, $coords, $idUser, $line) {
- $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);
- }
- $idPlane = $this->encryptionController->decrypt($idPlane);
- if(!$idPlane){
- return $this->responseController->makeResponse(true, 'El ID del plano solicitado no está encriptado correctamente', [], 400);
- }
- $plane = DB::table('S002V01TGPES')->where([
- ['GPES_IDPL', '=', $idPlane],
- ['GPES_NULI', '=', $line]
- ])->first();
- if(is_null($plane)){
- return $this->responseController->makeResponse(true, 'El plano relacionado no está registrado', [], 404);
- }
- $coords = $this->encryptionController->decrypt($coords);
- if(!$coords){
- return $this->responseController->makeResponse(true, 'Las coordenadas de ubicación no están encriptadas correctamente', [], 400);
- }
- $equipments = DB::table('S002V01TEQUI')->select([
- 'EQUI_COEQ AS CODIGO',
- 'EQUI_TIPO AS TIPO',
- 'EQUI_MODE AS MODELO',
- 'EQUI_IDEQ AS ID_EQUIPO',
- 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
- 'EQUI_GAIM AS GALERIA_IMAGENES',
- 'EQUI_ELOR AS ELEMENTO_ORIGEN',
- 'EQUI_TICO AS TIPO_CODIGO',
- 'EQUI_EQPA AS EQUIPO_PADRE',
- ])->where(function(Builder $query) {
- $query->where('EQUI_TICO', '=', '4')->orWhere('EQUI_TCOR', '=', '4')->orWhere('EQUI_TCDE', '=', '4');
- })->where(function(Builder $query) use ($idPlane, $coords) {
- $query->where([
- ['EQUI_COOR', '=', $coords],
- ['EQUI_PCOR', '=', $idPlane],
- ])->orWhere([
- ['EQUI_CODE', '=', $coords],
- ['EQUI_PCDE', '=', $idPlane],
- ]);
- })->where('EQUI_NULI', '=', $line)->get()->all();
- foreach($equipments as $key=>$equipment){
- $children = DB::table('S002V01TEQUI')->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_EQPA', '=', $equipment->CODIGO],
- ])->get()->all();
- $equipment->CODIGO = $this->encryptionController->encrypt($equipment->CODIGO);
- $equipment->ID_EQUIPO = $this->encryptionController->encrypt($equipment->ID_EQUIPO);
- $equipment->EQUIPO_PADRE = is_null($equipment->EQUIPO_PADRE) ? null : $this->encryptionController->encrypt($equipment->EQUIPO_PADRE);
- $equipment->GALERIA_IMAGENES = $this->encryptionController->encrypt($equipment->GALERIA_IMAGENES);
- $equipment->TIENE_HIJOS = count($children) > 0 ? 'Si' : 'No';
- $equipments[$key] = $equipment;
- }
- return $this->responseController->makeResponse(false, 'EXITO.', $equipments);
- }
- }
|