| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Carbon;
- use Dompdf\Dompdf;
- 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();
- if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
- $this->templatesUbic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\public\pdf_templates\\01_05_GEEQ\\";
- } else {
- $this->templatesUbic = "C:\inetpub\wwwroot\sam\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:25',
- '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_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_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_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_name' => 'required|string|max:50',
- 'family_icon' => 'required|string|max:25',
- '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_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:50',
- 'subfamily_icon' => 'required|string|max:25',
- '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){
- $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 . ")";
- }
-
- $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:50',
- 'subfamily_icon' => 'required|string|max:25',
- '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',
- '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',
- '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',
- ]);
-
- 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);
- }
- }
- $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]);
- $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];
- $originElementSecuence = $originEquipment[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]);
- $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];
- $destinyElementSecuence = $destinyEquipment[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,
- "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,
- ], $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;
- $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_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_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_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',
- ]);
-
- 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);
- }
- // 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.', [$equipment_type, $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_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);
- $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 "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);
- $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);
- $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);
- $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);
- $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);
- $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++){
- if($type == 'model'){
- $validVal2 = "X$validVal2";
- }else{
- $validVal2 = $validVal2 . "X";
- }
- }
- }else{
- $validVal2 = substr($validVal1[0], 0, 5);
- }
- }else if($validLength == 2){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- if($type == 'model'){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = $validVal1[0] . "X";
- }
- }else{
- $word1 = substr($validVal1[0], 0, 2);
- }
- $word2 = "";
- if(strlen($validVal1[1]) < 3){
- $word2 = $validVal1[1];
- for($i = strlen($validVal1[1]); $i < 3; $i++){
- if($type == 'model'){
- $word2 = "X$word2";
- }else{
- $word2 = $word2 . "X";
- }
- }
- }else{
- $word2 = substr($validVal1[1], 0, 3);
- }
- $validVal2 = $word1 . $word2;
- }else if($validLength == 3){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- if($type == 'model'){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = $validVal1[0] . "X";
- }
- }else{
- $word1 = substr($validVal1[0], 0, 2);
- }
-
- $word2 = substr($validVal1[1], 0, 1);
- $word3 = "";
- if(strlen($validVal1[2]) < 2){
- if($type == 'model'){
- $word3 = "X$validVal1[2]";
- }else{
- $word3 = $validVal1[2] . "X";
- }
- }else{
- $word3 = substr($validVal1[2], 0, 2);
- }
- $validVal2 = $word1 . $word2 . $word3;
- }else if($validLength == 4){
- $word1 = "";
- if(strlen($validVal1[0]) < 2){
- if($type == 'model'){
- $word1 = "X$validVal1[0]";
- }else{
- $word1 = $validVal1[0] . "X";
- }
- }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 getPendigEquipments($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'],
- ])->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 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);
- $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);
- $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();
- $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', '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
- 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
- ]
- ]);
- 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', '=', $idReg],
- ['PCEQ_NULI', '=', $form['linea']],
- ])->update([
- 'PCEQ_ESRE' => $form['status'],
- 'PCEQ_CORE' => $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 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 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){
- $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);
- $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
- );
- $response = json_decode($publicUri->original, true);
- if($response['error']){
- return $this->responseController->makeresponse(true, $response['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($response['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([
- 'EQUI_FAMI AS FAMILIA',
- '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',
- ])->where([
- ['EQUI_NULI', '=', $line],
- ['EQUI_COEQ', '=', $equipmentCode],
- ])->first();
- $family = DB::table('S002V01TFAMI')->where([
- ['FAMI_NULI', '=', $line],
- ['FAMI_COFA', '=', $equipment->FAMILIA]
- ])->first();
- $subfamily = DB::table('S002V01TSUBF')->where([
- ['SUBF_NULI', '=', $line],
- ['SUBF_COFA', '=', $equipment->FAMILIA],
- ['SUBF_COSU', '=', $equipment->SUBFAMILIA]
- ])->first();
- $ubic = $this->templatesUbic;
- $ubic = str_replace("pdf_templates\\01_05_GEEQ", "global_resources", $ubic);
- $equipment->FAMILIA = $family->FAMI_NOFA . " (" . $equipment->FAMILIA . ")";
- $equipment->SUBFAMILIA = $subfamily->SUBF_NOSU . " (" . $equipment->SUBFAMILIA . ")";
- $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);
- $equipment->UBICACION_ORIGEN = end($originLocationFilt)['LOCATION'] . " (" . $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",
- ];
- }
- 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);
- $equipment->NIVEL_ORIGEN = end($originLevelFilt)['LEVEL'] . " (" . $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();
- $equipment->OCUPACION_ORIGEN = $originOccupation->OCUP_DESC . " (" . $originOccupationStr . ")";
- 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);
- }
- $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_TICO', '=', $codeType],
- ])->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
- );
- $response = json_decode($publicUri->original, true);
- if($response['error']){
- return $this->responseController->makeresponse(true, $response['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($response['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("C:\inetpub\wwwroot\sam\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 = 'C:\inetpub\wwwroot\sam\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 = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '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 = 'C:\inetpub\wwwroot\sam\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 = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- '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
- );
- $response = json_decode($publicUri->original, true);
- if($response['error']){
- return $this->responseController->makeresponse(true, $response['msg'], [], 500);
- }else{
- $uriEnc = $this->encryptionController->encrypt($response['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 = floatval($startPK);
- $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'
- ])->where('EQUI_NULI', '=', $line)
- ->whereBetween('EQUI_KIOR', [$startPK, $endPK])
- ->orWhereBetween('EQUI_KIDE', [$startPK, $endPK])->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, $element, $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);
- }
- $element = $this->encryptionController->decrypt($element);
- if(!$element){
- return $this->responseController->makeResponse(true, 'El elemento de la intersección 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_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;
- }
- }
|