| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292 |
- <?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' => 'required|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')
- ->where([
- ['INAR_IDIN', '=', $form['id_description']],
- ['INAR_NULI', '=', $form['linea']],
- ])
- ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
- ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
- ->first([
- 'DEAR_CAAR AS CANTIDAD_ARTICULOS',
- ]);
- } 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)
- ->where('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)
- ->where('AREA_COAR', '=', $idArea)
- ->where('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)
- ->where('NIVE_COAR', '=', $idArea)
- ->where('NIVE_CONI', '=', $idLevel)
- ->where('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)
- ->where('ZONA_COAR', '=', $idArea)
- ->where('ZONA_CONI', '=', $idLevel)
- ->where('ZONA_COZO', '=', $idZone)
- ->where('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')
- ->where('PCEQ_NULI', '=', $form['linea'])
- ->where('PCEQ_NUSE', 'LIKE', '0-%')
- ->get(['PCEQ_NUSE AS NUMERO_SERIE']);
- } 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;
- }
- }
- $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_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_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_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)
- ->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 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 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 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);
- }
- }
|