| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Carbon;
- use Illuminate\Database\Query\JoinClause;
- use PhpOffice\PhpSpreadsheet\Reader\Exception as ExcelException;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Shared\Date;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use Jenssegers\Agent\Agent;
- use Firebase\JWT\JWT;
- use Firebase\JWT\Key;
- use Exception;
- class SystemAdministratorController extends Controller{
- private $responseController;
- private $encryptionController;
- private $functionsController;
- private $documentManagementController;
- private $resourcesController;
- private $publicKey = "zOgD0uF22+xg37nTmA+bg/6/E80BJYeHeByGpeTrNFw=";
- private $secretKey = "ydl27x22cNsNY0z6o3Fr6XZoUvsX0QMZx6MaiwN+KCnM6APS4Xbb7GDfudOYD5uD/r8TzQElh4d4HIal5Os0XA==";
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->resourcesController = new ResourcesController();
- $this->documentManagementController = new DocumentManagementController();
- }
- public function getLastConnections($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 petición no existe.', [], 404);
- }
- $lastConnections = DB::table('S002V01TUSUA')->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')->select(
- 'USUA_IDUS AS IDUSUARIO',
- 'BIAC_FECO AS ULCON'
- )->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,
- 'S002V01M01ADSI',
- 'S002V01F01MAUS',
- 'S002V01P02HICO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las últimas conexiones de los demás usuarios.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $lastConnections);
- }
- public function setLastConnection(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id' => 'required|string',
- 'linea' => 'required|integer',
- 'latitude' => 'required|numeric|between:-90,90',
- 'longitude' => 'required|numeric|between:-180,180',
- 'accuracy' => 'required|numeric|between:0,1000000',
- 'city' => 'string|max:100',
- 'state' => 'string|max:100',
- 'country' => 'required|string|max:50',
- ]);
- 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']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "La ID del usuario no está 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);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $ipv = $request->ip();
- $v4 = filter_var($ipv, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? true : false;
- $state = isset($login['state']) ? $login['state'] : '-';
- //Se obtiene el dispositivo utilizado
- $agent = new Agent();
- $device = 'Desconocido';
- if($agent->isDesktop()) $device = 'PC';
- else if($agent->device()) $device = $agent->device();
- //Se obtiene el SO utilizado y la versión del mismo
- $platform = $agent->platform() ? $agent->platform() : 'Desconocido';
- $version = 'N/A';
- if($platform != 'Desconocido') $version = $agent->version($platform);
- //Se obtiene el navegador web utilizado
- $browser = $agent->browser() ? $agent->browser() : 'Desconocido';
-
- $idLastConn = DB::table('S002V01TBIAC')->insertGetId([
- 'BIAC_NULI' => $form['linea'],
- 'BIAC_IDUS' => $idUser,
- 'BIAC_FECO' => $nowStr,
- 'BIAC_IPV4' => $v4 ? $ipv : null,
- 'BIAC_IPV6' => !$v4 ? $ipv : null,
- 'BIAC_LATI' => $form['latitude'],
- 'BIAC_LONG' => $form['longitude'],
- 'BIAC_PREC' => $form['accuracy'],
- 'BIAC_CIUD' => $form['city'],
- 'BIAC_ESTA' => $state,
- 'BIAC_PAIS' => $form['country'],
- 'BIAC_DISP' => $device,
- 'BIAC_SIOP' => $platform,
- 'BIAC_VSOP' => $version,
- 'BIAC_NAVE' => $browser,
- ]);
- DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update(['USUA_ULCO' => $idLastConn]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F01MAUS',
- 'S002V01P01MOCO',
- 'Registró',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró su última conexión al sistema.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
- }
- public function getCatalogues($idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
- $catalogues = DB::table('S002V01TCATA')->select(
- 'CATA_IDCA AS IDCATALOGO',
- 'CATA_TICA AS TIPOCATALOGO',
- 'CATA_VERS AS VERSION',
- 'CATA_ARRE AS ADJUNTOS',
- 'CATA_USRE AS USUARIOREGISTRO',
- 'CATA_FERE AS FECHAREGISTRO',
- )->where([
- ['CATA_NULI', '=', $line],
- ['CATA_ESTA', '=', 'Activo']
- ])->get()->all();
- $cataloguesF = [];
- foreach($catalogues as $catalogue){
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $catalogue->USUARIOREGISTRO],
- ])->first();
- $idReg = $catalogue->USUARIOREGISTRO;
- $catalogue->USUARIOREGISTRO = $this->functionsController->joinName(
- $usrReg->USUA_NOMB,
- $usrReg->USUA_APPA,
- $usrReg->USUA_APMA
- ) . " ($idReg)";
- $cataloguesF[] = $catalogue;
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los catálogos registrados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $cataloguesF);
- }
- public function getUserConnections($id, $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 petición no existe.', [], 404);
- }
- $id = $this->encryptionController->decrypt($id);
- if(!$id){
- return $this->responseController->makeResponse(true, "El ID del usuario que desea consultar no está encriptado correctamente.", [], 400);
- }
- $usrCons = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $id]
- ])->first();
-
- if(is_null($usrCons)){
- return $this->responseController->makeResponse(true, 'El usuario consultado no existe.', [], 404);
- }
- $connections = DB::table('S002V01TBIAC')->select(
- 'BIAC_IPV4 AS IP4',
- 'BIAC_IPV6 AS IP6',
- 'BIAC_FECO AS FECHA',
- 'BIAC_LATI AS LATITUD',
- 'BIAC_LONG AS LONGITUD',
- 'BIAC_PREC AS PRECISION',
- 'BIAC_CIUD AS CIUDAD',
- 'BIAC_ESTA AS ESTADO',
- 'BIAC_PAIS AS PAIS',
- 'BIAC_DISP AS DISPOSITIVO',
- 'BIAC_SIOP AS SITEMAOPERATIVO',
- 'BIAC_VSOP AS VERSIONSO',
- 'BIAC_NAVE AS NAVEGADOR',
- )->where([
- ['BIAC_IDUS', '=', $id],
- ['BIAC_NULI', '=', $line]
- ])->orderBy('BIAC_FECO', 'desc')->get()->all();
- $responseArr = [
- 'NOMBRE' => $usrCons->USUA_NOMB,
- 'APPAT' => $usrCons->USUA_APPA,
- 'APMAT' => $usrCons->USUA_APMA,
- 'ULTCON' => $usrCons->USUA_ULCO,
- 'HISTORIAL' => $connections
- ];
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameCons = $this->functionsController->joinName($usrCons->USUA_NOMB, $usrCons->USUA_APPA, $usrCons->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F01MAUS',
- 'S002V01P02HICO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las conexiones del usuario $nameCons ($id).",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, "EXITO", $responseArr);
- }
- public function getLastActions($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
-
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID el usuario que realizó la petición no está encriptado correctamente.", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $lastActions = DB::table('S002V01TUSUA')->leftJoin('S002V01TACCI', 'USUA_ULAC', '=', 'ACCI_IDAC')->select(
- 'USUA_IDUS AS IDUSUARIO',
- 'USUA_NOMB AS NOMBRE',
- 'USUA_APPA AS APEPAT',
- 'USUA_APMA AS APEMAT',
- 'ACCI_IDMO AS IDMODULO',
- 'ACCI_IDSM AS IDSUBMODULO',
- 'ACCI_IDFU AS IDFUNCION',
- 'ACCI_IDPA AS IDPANTALLA',
- 'ACCI_TIAC AS TIPOACCION',
- 'ACCI_DESC AS DESCRIPCION',
- 'ACCI_FEAC AS FECHAACCION',
- )->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,
- 'S002V01M01ADSI',
- 'S002V01F02SAUS',
- 'S002V01P01MOAC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las últimas acciónes realizadas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $lastActions);
- }
- public function getUserActions($id, $idUser, $line){
- DB::enableQueryLog();
- $id = $this->encryptionController->decrypt($id);
- if(!$id){
- return $this->responseController->makeResponse(true, 'El ID del usuario que desea consultar no está encriptado correctamente.', [], 400);
- }
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $userInfo = DB::table('S002V01TUSUA')->select(
- 'USUA_IDUS AS IDUSUARIO',
- 'USUA_NOMB AS NOMBRE',
- 'USUA_APPA AS APEPAT',
- 'USUA_APMA AS APEMAT'
- )->where([
- ['USUA_IDUS', '=', $id],
- ['USUA_NULI', '=', $line],
- ])->get()->first();
- if(is_null($userInfo)){
- return $this->responseController->makeResponse(true, 'El usuario solicitado no existe.', [], 404);
- }
- $actions = DB::table('S002V01TACCI')->select(
- 'MODU_NOMO AS MODULO',
- 'SUBM_NOMB AS SUBMODULO',
- 'FUNC_NOMB AS FUNCION',
- 'PANT_NOMB AS PANTALLA',
- 'ACCI_TIAC AS TIPOACCION',
- 'ACCI_DESC AS DESCRIPCION',
- 'ACCI_FEAC AS FECHA',
- )->leftJoin('S002V01TMODU', 'ACCI_IDMO', '=', 'MODU_IDMO')
- ->leftJoin('S002V01TSUBM', 'ACCI_IDSM', '=', 'SUBM_IDSM')
- ->leftJoin('S002V01TPANT', 'ACCI_IDPA', '=', 'PANT_IDPA')
- ->leftJoin('S002V01TFUNC', 'ACCI_IDFU', '=', 'FUNC_IDFU')->where([
- ['ACCI_IDUS', '=', $id],
- ['ACCI_NULI', '=', $line],
- ])->orderBy('ACCI_FEAC', 'desc')->get()->all();
- $userInfo->HISTORIAL = $actions;
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameCons = $this->functionsController->joinName($userInfo->NOMBRE, $userInfo->APEPAT, $userInfo->APEMAT);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F02SAUS',
- 'S002V01P02HIAC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las acciones del usuario $nameCons (" . $userInfo->IDUSUARIO . ")",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $userInfo);
- }
- public function readCatalogue($id, $idUser, $line){
- DB::enableQueryLog();
- $id = $this->encryptionController->decrypt($id);
- if(!$id){
- return $this->responseController->makeResponse(true, "El ID del catálogo no fue encriptado correctamente");
- }
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario no fue encriptado correctamente");
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
- $idArr = explode("-", $id);
- $idArr2 = explode("=", end($idArr));
- $catalogue = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $idArr[0]],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr2[0]],
- ['AFAL_NUVE', '=', $idArr2[1]],
- ])->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'El catálogo solicitado no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $response = [
- "IDCATALOGO" => $this->encryptionController->encrypt($id),
- "EXTENSION" => $catalogue->AFAL_EXTE,
- "FECHA" => $now->timestamp
- ];
-
- copy($catalogue->AFAL_UBIC, 'C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public_files\\' . $id);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo $id.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, "EXITO", $response);
- }
- public function getAdvices($idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $advices = DB::table('S002V01TAVIS')->select(
- 'AVIS_IDAV AS IDAVISO',
- 'AVIS_TIAV AS TITULO',
- 'AVIS_CADU AS CADUCIDAD',
- DB::raw("IF(
- AVIS_ESTA != 'Activo',
- AVIS_ESTA,
- IF(
- NOW() > AVIS_CADU,
- 'Caducado',
- AVIS_ESTA
- )
- ) AS ESTATUS"),
- )->orderBy('AVIS_IDAV', 'asc')->get()->all();
- foreach($advices as $key=>$advice){
- $advice->IDAVISO = $this->encryptionController->encrypt($advice->IDAVISO);
- $advices[$key] = $advice;
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F03CRAV',
- 'S002V01P01HIAV',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los avisos registrados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $advices);
- }
- public function getAdvice($idAdvice, $idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
-
- $idAdvice = $this->encryptionController->decrypt($idAdvice);
- if(!$idAdvice){
- return $this->responseController->makeResponse(true, 'El ID del aviso que consultó no está encriptado correctamente.', [], 400);
- }
- $advice = DB::table('S002V01TAVIS')->select([
- 'AVIS_IDAV AS IDAVISO',
- 'AVIS_TIAV AS TITULO',
- 'AVIS_COAV AS CONTENIDO',
- 'AVIS_CADU AS CADUCIDAD',
- 'AVIS_ALAV AS AUDIENCIA',
- 'AVIS_ADJU AS ADJUNTOS',
- DB::raw("IF(
- AVIS_ESTA != 'Activo',
- AVIS_ESTA,
- IF(
- NOW() > AVIS_CADU,
- 'Caducado',
- AVIS_ESTA
- )
- ) AS ESTADO"),
- 'AVIS_FERE AS FECREG',
- DB::raw("CONCAT(USRE.USUA_NOMB, ' ', USRE.USUA_APPA, IF(ISNULL(USRE.USUA_APMA), '', ' '), IF(ISNULL(USRE.USUA_APMA), '', USRE.USUA_APMA), ' (', AVIS_USRE, ')') AS USRREG"),
- 'AVIS_FEMO AS FECMOD',
- DB::raw("IF(ISNULL(USMO.USUA_NOMB), null, CONCAT(USMO.USUA_NOMB, ' ', USMO.USUA_APPA, IF(ISNULL(USMO.USUA_APMA), '', ' '), IF(ISNULL(USMO.USUA_APMA), '', USMO.USUA_APMA), ' (', AVIS_USMO, ')')) AS USRMOD")
- ])->where([
- ['AVIS_NULI', '=', $line],
- ['AVIS_IDAV', '=', $idAdvice]
- ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'AVIS_USRE')
- ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'AVIS_USMO')->first();
- if(is_null($advice)){
- return $this->responseController->makeResponse(true, 'El aviso consultado no existe.', [], 404);
- }else if($advice->ESTADO != 'Activo'){
- return $this->responseController->makeResponse(true, 'El aviso consultado no está disponible.', [], 401);
- }
- $caduStr = $advice->CADUCIDAD;
- $caduObj = new Carbon($caduStr);
- $now = $this->functionsController->now();
-
- if($now->gt($caduObj)){
- return $this->responseController->makeResponse(true, 'El aviso consultado está caducado.', [], 401);
- }
- $attachedArr = json_decode($advice->ADJUNTOS, true);
- $attachedF = [];
- foreach($attachedArr as $fileCode){
- $nameArr = explode('=', $fileCode);
- $idArr = explode('-', $nameArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $idArr[0]],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $nameArr[1]],
- ])->first();
- $attachedF[] = [
- 'id' => $this->encryptionController->encrypt($fileCode),
- 'name' => $file->AFAL_NOAR . '.' . $file->AFAL_EXTE,
- 'size' => $file->AFAL_TAMA
- ];
- }
- $audienceArr = json_decode($advice->AUDIENCIA, true);
- foreach($audienceArr as $key=>$item){
- $itemName = '';
- if($item['type'] == 'user'){
- $user = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item['id']]
- ])->first();
- $itemName = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
- }else{
- $profile = DB::table('S002V01TPERF')->where([
- ['PERF_NULI', '=', $line],
- ['PERF_IDPE', '=', $item['id']]
- ])->first();
- $itemName = $profile->PERF_NOPE;
- }
- $item['name'] = $itemName;
- $item['id'] = $this->encryptionController->encrypt($item['id']);
- $audienceArr[$key] = $item;
- }
- $advice->AUDIENCIA = json_encode($audienceArr);
- $advice->ADJUNTOS = json_encode($attachedF);
- $advice->IDAVISO = $this->encryptionController->encrypt($advice->IDAVISO);
- $actions = DB::getQueryLog();
- $nowStr = $now->toDateTimeString();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F03CRAV',
- 'S002V01P01HIAV',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el aviso " . $advice->TITULO . " ($idAdvice).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $advice);
- }
- public function publishAdvice(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'titulo' => 'required|string|max:100',
- 'caducidad' => 'required|date_format:Y-m-d H:i:s',
- 'contenido' => 'required|string',
- 'audiencia' => 'required|json',
- 'archivos' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $advice = $request->all();
- $idUser = $this->encryptionController->decrypt($advice['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la petición no fue encriptado correctamente", [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $advice['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $audienceArr = json_decode($advice['audiencia'], true);
- $audienceArrFn = [];
- foreach($audienceArr as $key=>$item){
- $itemArr = explode('-', $item);
- if(count($itemArr) != 2){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de audiencia tiene un formáto inválido.", [], 400);
- }
- $idElementDec = $this->encryptionController->decrypt($itemArr[1]);
- if(!$idElementDec){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de audiencia no fue encriptado correctamente.", [], 400);
- }
- $element = null;
- if($itemArr[0] == 'prof'){
- $element = DB::table('S002V01TPERF')->where([
- ['PERF_NULI', '=', $advice['linea']],
- ['PERF_IDPE', '=', $idElementDec]
- ])->first();
- }else{
- $element = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $advice['linea']],
- ['USUA_IDUS', '=', $idElementDec]
- ])->first();
- }
- if(is_null($element)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key no existe.", [], 404);
- }
- $audienceArrFn[] = [
- 'type' => $itemArr[0],
- 'id' => $idElementDec
- ];
- }
- $audienceStr = json_encode($audienceArrFn);
- $filesArr = json_decode($advice['archivos'], true);
- $attachedArr = [];
- foreach($filesArr as $key=>$file){
- $idFileDec = $this->encryptionController->decrypt($file['id']);
- if(!$idFileDec){
- return $this->responseController->makeResponse(true, "El ID del archivo en la posición $key del arreglo de adjuntos no fue encriptado correctamente.", [], 400);
- }
- $document = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idFileDec],
- ['ARTE_NULI', '=', $advice['linea']]
- ])->first();
- if(is_null($document)){
- return $this->responseController->makeResponse(true, "El archivo en la posición $key del arreglo de adjuntos no existe.", [], 404);
- }else if($document->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El archivo en la posición $key del arreglo de adjuntos está eliminado.", [], 404);
- }
- $fileRes = $this->documentManagementController->moveFinalFile(
- $advice['linea'],
- 'ADSI',
- 'AV',
- $document,
- $idUser
- );
- if(!$fileRes[0]){
- return $this->responseController->makeResponse(true, "El archivo en la posición $key no pudo ser procesado: $fileRes[1].", [], 400);
- }
- $attachedArr[] = $fileRes[1];
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $attachedStr = json_encode($attachedArr);
- $idav = DB::table('S002V01TAVIS')->insertGetId([
- 'AVIS_NULI' => $advice['linea'],
- 'AVIS_TIAV' => $advice['titulo'],
- 'AVIS_COAV' => $advice['contenido'],
- 'AVIS_ALAV' => $audienceStr,
- 'AVIS_ADJU' => $attachedStr,
- 'AVIS_CADU' => $advice['caducidad'],
- 'AVIS_FERE' => $nowStr,
- 'AVIS_USRE' => $idUser
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $advice['linea'],
- 'S002V01M01ADSI',
- 'S002V01F03CRAV',
- 'S002V01P02CNAV',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró un nuevo aviso.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $advice['linea']);
- return $this->responseController->makeresponse(false, "EXITO", ['idav' => $this->encryptionController->encrypt($idav)]);
- }
- public function updateAdvice(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'id_advice' =>'required|string',
- 'linea' => 'required|integer',
- 'titulo' => 'required|string|max:100',
- 'caducidad' => 'required|date_format:Y-m-d H:i:s',
- 'contenido' => 'required|string',
- 'audiencia' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
-
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idAdvice = $this->encryptionController->decrypt($form['id_advice']);
- if(!$idAdvice){
- return $this->responseController->makeResponse(true, "El ID del aviso no fue encriptado correctamente.", [], 401);
- }
- $advice = DB::table('S002V01TAVIS')->where([
- ['AVIS_NULI', '=', $form['linea']],
- ['AVIS_IDAV', '=', $idAdvice]
- ])->first();
- if(is_null($advice)){
- return $this->responseController->makeResponse(true, 'El aviso seleccionado no está registrado', [], 404);
- }
- $audienceArr = json_decode($form['audiencia'], true);
- $audienceArrFn = [];
- foreach($audienceArr as $key=>$item){
- $itemArr = explode('-', $item);
- if(count($itemArr) != 2){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de audiencia tiene un formáto inválido.", [], 400);
- }
- $idElementDec = $this->encryptionController->decrypt($itemArr[1]);
- if(!$idElementDec){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de audiencia no fue encriptado correctamente.", [], 400);
- }
- $element = null;
- if($itemArr[0] == 'prof'){
- $element = DB::table('S002V01TPERF')->where([
- ['PERF_NULI', '=', $form['linea']],
- ['PERF_IDPE', '=', $idElementDec]
- ])->first();
- }else{
- $element = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idElementDec]
- ])->first();
- }
- if(is_null($element)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key no existe.", [], 404);
- }
- $audienceArrFn[] = [
- 'type' => $itemArr[0],
- 'id' => $idElementDec
- ];
- }
- $audienceStr = json_encode($audienceArrFn);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAVIS')->where([
- ['AVIS_NULI', '=', $form['linea']],
- ['AVIS_IDAV', '=', $idAdvice]
- ])->update([
- 'AVIS_TIAV' => $form['titulo'],
- 'AVIS_COAV' => $form['contenido'],
- 'AVIS_ALAV' => $audienceStr,
- 'AVIS_CADU' => $form['caducidad'],
- 'AVIS_FEMO' => $nowStr,
- 'AVIS_USMO' => $idUser,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F03CRAV',
- 'S002V01P03EDAV',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el aviso $idAdvice.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeresponse(false, "EXITO");
- }
- public function deleteAdvice(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'id_advice' =>'required|string',
- 'linea' => 'required|integer',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $advice = $request->all();
- $idAdvice = $this->encryptionController->decrypt($advice['id_advice']);
- if(!$idAdvice){
- return $this->responseController->makeResponse(true, "El ID del aviso no fue encriptado correctamente.", [], 401);
- }
- $idUser = $this->encryptionController->decrypt($advice['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $advice['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAVIS')->where([
- ['AVIS_NULI', '=', $advice['linea']],
- ['AVIS_IDAV', '=', $idAdvice]
- ])->update([
- 'AVIS_ESTA' => 'Eliminado',
- 'AVIS_FEMO' => $nowStr,
- 'AVIS_USMO' => $idUser,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $advice['linea'],
- 'S002V01M01ADSI',
- 'S002V01F03CRAV',
- 'S002V01P01HIAV',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el aviso $idAdvice.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $advice['linea']);
- return $this->responseController->makeresponse(false, "EXITO");
- }
- public function getTwoStepsAuthUsers($idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $usersAuth = DB::table('S002V01TUSUA')->select([
- 'USUA_IDUS',
- 'USUA_NOMB',
- 'USUA_APPA',
- 'USUA_APMA',
- 'USUA_FADO',
- ])->where('USUA_NULI', '=', $line)->get()->all();
- $arrAuth = [];
- foreach($usersAuth as $user){
- $name = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
- $authEnabled = $user->USUA_FADO == 'Si';
- $arrAuth[] = [
- 'IDUSUARIO' => $this->encryptionController->encrypt($user->USUA_IDUS),
- 'NOMBREUSUARIO' => $name,
- 'AUTHENABLED' => $authEnabled
- ];
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P03ADPA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las autenticaciones en dos pasos de los usuarios.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $arrAuth);
- }
- public function setTwoStepsAuth(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'factor_doble' => 'required|in:Si,No',
- 'usuario' => 'required|string',
- 'linea' => 'required|integer',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idChange = $this->encryptionController->decrypt($form['usuario']);
- if(!$idChange){
- return $this->responseController->makeResponse(true, "El ID del usuario que desea modificar no fue encriptado correctamente.", [], 401);
- }
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idChange],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($usrMod)){
- return $this->responseController->makeResponse(true, 'El usuario que desea actualizar no está registrado', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idChange],
- ['USUA_NULI', '=', $form['linea']]
- ])->update([
- 'USUA_FADO' => $form['factor_doble'],
- 'USUA_USMO' => $idUser,
- 'USUA_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P03ADPA',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió el factor de dos pasos del usuario $nameMod ($idChange).",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeresponse(false, "EXITO");
- }
- public function getPasswordFormat($idUser, $line){
- DB::enableQueryLog();
-
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
- $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
- $politicsStr = file_get_contents($politicsInfoRoute);
- $politicsArr = json_decode($politicsStr, true);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $passwordFormat = $politicsArr['password_format'];
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P01PACO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el formato de las contraseñas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['password_format' => $passwordFormat]);
- }
- public function savePasswordFormat(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'min_length' => 'required|integer|between:8,30',
- 'upper_enabled' => 'required|boolean',
- 'min_upper' => 'required|integer|between:1,10',
- 'number_enabled' => 'required|boolean',
- 'min_number' => 'required|integer|between:1,10',
- 'chars_enabled' => 'required|boolean',
- 'min_chars' => 'required|integer|between:1,10',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- if(!$filePoliticsExists){
- return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
- }
- $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- $politicsArr = json_decode($politicsStr, true);
- $passwordFormat = $politicsArr['password_format'];
- $formatBKP = $politicsStr;
-
- $passwordFormat['min_length'] = intval($info['min_length']);
- $passwordFormat['upper_enabled'] = intval($info['upper_enabled']) == 1;
- $passwordFormat['min_upper'] = intval($info['min_upper']);
- $passwordFormat['number_enabled'] = intval($info['number_enabled']) == 1;
- $passwordFormat['min_number'] = intval($info['min_number']);
- $passwordFormat['chars_enabled'] = intval($info['chars_enabled']) == 1;
- $passwordFormat['min_chars'] = intval($info['min_chars']);
- $politicsArr['password_format'] = $passwordFormat;
- $finalStr = json_encode($politicsArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAPSE')->insert([
- 'APSE_NULI' => $info['linea'],
- 'APSE_USMO' => $idUser,
- 'APSE_FEMO' => $nowStr,
- 'APSE_VAAN' => $formatBKP,
- 'APSE_VAAC' => $finalStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P01PACO',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el formato de las contraseñas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getSessionsDuration($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
- $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
- $politicsStr = file_get_contents($politicsInfoRoute);
- $politicsArr = json_decode($politicsStr, true);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $sessionsDuration = $politicsArr['sessions_duration'];
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P02DUSE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración de duración de sesiones.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['sessions_duration' => $sessionsDuration]);
- }
- public function saveSessionsDuration(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'days' => 'required|integer|max:30',
- 'hours' => 'required|integer|max:23',
- 'minutes' => 'required|integer|max:59',
- 'seconds' => 'required|integer|max:59',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- if(!$filePoliticsExists){
- return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
- }
- $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- $politicsArr = json_decode($politicsStr, true);
- $sessionsDuration = $politicsArr['sessions_duration'];
- $formatBKP = $politicsStr;
- $sessionsDuration['days'] = intval($info['days']);
- $sessionsDuration['hours'] = intval($info['hours']);
- $sessionsDuration['minutes'] = intval($info['minutes']);
- $sessionsDuration['seconds'] = intval($info['seconds']);
- $politicsArr['sessions_duration'] = $sessionsDuration;
- $finalStr = json_encode($politicsArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAPSE')->insert([
- 'APSE_NULI' => $info['linea'],
- 'APSE_USMO' => $idUser,
- 'APSE_FEMO' => $nowStr,
- 'APSE_VAAN' => $formatBKP,
- 'APSE_VAAC' => $finalStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P02DUSE',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la duración de las sesiones.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getActiveSessionsNumber($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
- $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
- $politicsStr = file_get_contents($politicsInfoRoute);
- $politicsArr = json_decode($politicsStr, true);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $activeSessionsNumber = $politicsArr['active_sessions_number'];
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P04NSAC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración del número de sesiones activas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['active_sessions_number' => $activeSessionsNumber]);
- }
- public function saveActiveSessionsNumber(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'sessions' => 'required|integer|between:1,5',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- if(!$filePoliticsExists){
- return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
- }
- $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
- $politicsArr = json_decode($politicsStr, true);
- $formatBKP = $politicsStr;
-
- $politicsArr['active_sessions_number'] = intval($info['sessions']);
- $finalStr = json_encode($politicsArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TAPSE')->insert([
- 'APSE_NULI' => $info['linea'],
- 'APSE_USMO' => $idUser,
- 'APSE_FEMO' => $nowStr,
- 'APSE_VAAN' => $formatBKP,
- 'APSE_VAAC' => $finalStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- 'S002V01M01ADSI',
- 'S002V01F04POSE',
- 'S002V01P04NSAC',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el número de sesiones activas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function activateMaintenanceMode(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'motivos' => 'required|string',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
-
- $maintenanceModeExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- if(!$maintenanceModeExists){
- return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
- }
-
- $maintenanceStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- $maintenanceArr = json_decode($maintenanceStr, true);
- if($maintenanceArr['activated']){
- return $this->responseController->makeResponse(true, 'El modo mantenimiento ya se encuentra activado', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idMant = DB::table('S002V01THMSA')->insertGetId([
- 'HMSA_NULI' => $info['linea'],
- 'HMSA_USAC' => $idUser,
- 'HMSA_FEAC' => $nowStr,
- 'HMSA_MOAC' => $info['motivos']
- ]);
- $maintenanceArr['activated'] = true;
- $maintenanceArr['last_activation_id'] = $idMant;
- $finalStr = json_encode($maintenanceArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- 'S002V01M01ADSI',
- 'S002V01F05MOMA',
- 'S002V01P01AMMA',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") activó el modo mantenimiento",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deactivateMaintenanceMode(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'justificacion' => 'required|string',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $info = $request->all();
- $idUser = $this->encryptionController->decrypt($info['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $info['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $maintenanceModeExists = file_exists('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- if(!$maintenanceModeExists){
- return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
- }
- $maintenanceStr = file_get_contents('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- $maintenanceArr = json_decode($maintenanceStr, true);
- if(!$maintenanceArr['activated']){
- return $this->responseController->makeResponse(true, 'El modo mantenimiento ya se encuentra desactivado', [], 401);
- }
- $maintenanceDB = DB::table('S002V01THMSA')->where([
- ['HMSA_IDAC', '=', $maintenanceArr['last_activation_id']],
- ['HMSA_NULI', '=', $info['linea']],
- ])->first();
- if(!is_null($maintenanceDB->HMSA_USDE)){
- $maintenanceArr['activated'] = false;
- $finalStr = json_encode($maintenanceArr);
- file_put_contents('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
- return $this->responseController->makeResponse(true, 'El modo mantenimiento ya fue desactivado en la base de datos.', [], 500);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01THMSA')->where([
- ['HMSA_IDAC', '=', $maintenanceArr['last_activation_id']],
- ['HMSA_NULI', '=', $info['linea']],
- ])->update([
- 'HMSA_USDE' => $idUser,
- 'HMSA_FEDE' => $nowStr,
- 'HMSA_JUDE' => $info['justificacion']
- ]);
-
- $maintenanceArr['activated'] = false;
- $finalStr = json_encode($maintenanceArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $info['linea'],
- 'S002V01M01ADSI',
- 'S002V01F05MOMA',
- 'S002V01P01AMMA',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") desactivó el modo mantenimiento",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getMaintenanceHistory($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $history = DB::table('S002V01THMSA')->where('HMSA_NULI', '=', $line)->get()->all();
- $historyF = array();
- foreach($history as $val){
- $activationDate = new Carbon($val->HMSA_FEAC, 'America/Mexico_city');
- $deactivationDate = new Carbon($val->HMSA_FEDE, 'America/Mexico_city');
- $diffDays = $deactivationDate->diffInDays($activationDate);
- $activationDate->addDays($diffDays);
- $diffHours = $deactivationDate->diffInHours($activationDate);
- $activationDate->addHours($diffHours);
-
- $diffMinutes = $deactivationDate->diffInMinutes($activationDate);
- $activationDate->addMinutes($diffMinutes);
-
- $diffSeconds = $deactivationDate->diffInSeconds($activationDate);
- $duration = "";
- if($diffDays > 0) $duration .= "$diffDays días, ";
- if($diffHours > 0) $duration .= "$diffHours horas, ";
- if($diffMinutes > 0) $duration .= "$diffMinutes minutos, ";
- if($diffSeconds > 0) $duration .= "$diffSeconds segundos, ";
- $duration = substr($duration, 0, -2);
- $usac = DB::table('S002V01TUSUA')->select([
- 'USUA_NOMB', 'USUA_APPA', 'USUA_APMA'
- ])->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->HMSA_USAC]
- ])->first();
- $nomUSAC = $this->functionsController->joinName($usac->USUA_NOMB, $usac->USUA_APPA, $usac->USUA_APMA);
- $usde = DB::table('S002V01TUSUA')->select([
- 'USUA_NOMB', 'USUA_APPA', 'USUA_APMA'
- ])->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $val->HMSA_USDE]
- ])->first();
- $nomUSDE = $this->functionsController->joinName($usde->USUA_NOMB, $usde->USUA_APPA, $usde->USUA_APMA);
- $historyF[] = [
- "IDACTIVACION" => $val->HMSA_IDAC,
- "LINEA" => $val->HMSA_NULI,
- "USUARIOACTIVO" => $nomUSAC . " (" . $val->HMSA_USAC . ")",
- "FECHAACTIVACION" => $val->HMSA_FEAC,
- "MOTIVOS" => $val->HMSA_MOAC,
- "USUARIODESACTIVO" => $nomUSDE . " (" . $val->HMSA_USDE . ")",
- "FECHADESACTIVACION" => $val->HMSA_FEDE,
- "JUSTIFICACION" => $val->HMSA_JUDE,
- "DURACION" => $duration
- ];
- }
- $now = $this->functionsController->now();
- $actions = DB::getQueryLog();
- $nowStr = $now->toDateTimeString();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F05MOMA',
- 'S002V01P02HIMA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el historial de mantenimientos.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $historyF);
- }
- public function getMaintenanceStatus($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $maintenanceModeExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- if(!$maintenanceModeExists){
- return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
- }
- $maintenanceStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
- $maintenanceArr = json_decode($maintenanceStr, 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,
- 'S002V01M01ADSI',
- 'S002V01F05MOMA',
- 'S002V01P02HIMA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el estado actual del modo mantenimiento.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['activated' => $maintenanceArr['activated']]);
- }
- public function getEmailServers($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $emailServers = DB::table('S002V01TSCEL')->where('SCEL_NULI', '=', $line)->orderBy('SCEL_PRIO')->get()->all();
- $serversArr = [];
- foreach($emailServers as $server){
- $usal = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $server->SCEL_USAL],
- ['USUA_NULI', '=', $line],
- ])->first();
- $usalName = $this->functionsController->joinName($usal->USUA_NOMB, $usal->USUA_APPA, $usal->USUA_APMA);
-
- $usmo = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $server->SCEL_USMO],
- ['USUA_NULI', '=', $line],
- ])->first();
- $usmoName = is_null($usmo) ? '-' : $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA);
- $serversArr[] = [
- 'USUARIO' => $server->SCEL_USUA,
- 'HOST' => $server->SCEL_HOST,
- 'PRIORIDAD' => $server->SCEL_PRIO,
- 'USRREG' => "$usalName (" . $server->SCEL_USAL . ")",
- 'FECREG' => $server->SCEL_FEAL,
- 'USRMOD' => is_null($usmo) ? $usmoName : "$usalName (" . $server->SCEL_USMO . ")",
- 'FECMOD' => is_null($server->SCEL_FEMO) ? '-' : $server->SCEL_FEMO,
- 'ESTADO' => $server->SCEL_ESCO,
- ];
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los servidores de correo electrónico registrados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $serversArr);
- }
- public function registerEmailServer(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'user' => 'required|string|max:50',
- 'host' => 'required|string|max:50',
- 'priority' => 'required|integer|between:1,100',
- 'smtpsec' => 'string|max:50',
- 'port' => 'required|string|max:10',
- 'password' => 'required|string|max:2000',
- 'timeout' => 'required|string|max:3',
- 'smtpaut' => 'required|string|max:2',
- 'portals' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $smtpsec = isset($form['smtpsec']) ? $form['smtpsec'] : null;
- DB::table('S002V01TSCEL')->insert([
- 'SCEL_NULI' => $form['linea'],
- 'SCEL_USUA' => $form['user'],
- 'SCEL_HOST' => $form['host'],
- 'SCEL_PRIO' => $form['priority'],
- 'SCEL_SESM' => $smtpsec,
- 'SCEL_PUER' => $form['port'],
- 'SCEL_CONT' => $form['password'],
- 'SCEL_TIES' => $form['timeout'],
- 'SCEL_AUSM' => $form['smtpaut'],
- 'SCEL_ADPO' => $form['portals'],
- 'SCEL_USAL' => $idUser,
- 'SCEL_FEAL' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el servidor $form[host]",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getEmailServer($host, $user, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $host = $this->encryptionController->decrypt($host);
- if(!$host){
- return $this->responseController->makeResponse(true, 'El HOST del servidor no está encriptado correctamente.', [], 400);
- }
- $user = $this->encryptionController->decrypt($user);
- if(!$user){
- return $this->responseController->makeResponse(true, 'El USUARIO del servidor no está encriptado correctamente.', [], 400);
- }
- $server = DB::table('S002V01TSCEL')->select([
- 'SCEL_USUA AS USUARIO',
- 'SCEL_HOST AS HOST',
- 'SCEL_PRIO AS PRIORIDAD',
- 'SCEL_SESM AS SEGSMTP',
- 'SCEL_PUER AS PUERTO',
- 'SCEL_CONT AS CONTRASENA',
- 'SCEL_TIES AS TIEMPOESPERA',
- 'SCEL_AUSM AS AUTSMTP',
- 'SCEL_ADPO AS PORTALES'
- ])->where([
- ['SCEL_NULI', '=', $line],
- ['SCEL_USUA', '=', $user],
- ['SCEL_HOST', '=', $host],
- ])->first();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el servidor $host.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $server);
- }
- public function updateEmailServer(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'user' => 'required|string|max:50',
- 'host' => 'required|string|max:50',
- 'priority' => 'required|integer|between:1,100',
- 'smtpsec' => 'string|max:50',
- 'port' => 'required|string|max:10',
- 'password' => 'required|string|max:2000',
- 'timeout' => 'required|string|max:3',
- 'smtpaut' => 'required|string|max:2',
- 'portals' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $server = DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->first();
-
- if(is_null($server)){
- return $this->responseController->makeResponse(true, 'El servidor que desea modificar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $smtpsec = isset($form['smtpsec']) ? $form['smtpsec'] : null;
- DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->update([
- 'SCEL_PRIO' => $form['priority'],
- 'SCEL_SESM' => $smtpsec,
- 'SCEL_PUER' => $form['port'],
- 'SCEL_CONT' => $form['password'],
- 'SCEL_TIES' => $form['timeout'],
- 'SCEL_AUSM' => $form['smtpaut'],
- 'SCEL_ADPO' => $form['portals'],
- 'SCEL_USMO' => $idUser,
- 'SCEL_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servidor $form[host]",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteEmailServer(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'user' => 'required|string|max:50',
- 'host' => 'required|string|max:50'
- ]);
- 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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $server = DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->first();
-
- if(is_null($server)){
- return $this->responseController->makeResponse(true, 'El servidor que desea eliminar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->update([
- 'SCEL_ESCO' => 'Eliminado',
- 'SCEL_USMO' => $idUser,
- 'SCEL_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el servidor $form[host]",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deactivateEmailServer(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'user' => 'required|string|max:50',
- 'host' => 'required|string|max:50',
- 'state' => 'required|string|in:Activo,Inactivo',
- ]);
- 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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $server = DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->first();
-
- if(is_null($server)){
- return $this->responseController->makeResponse(true, 'El servidor que desea modificar no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TSCEL')->where([
- ['SCEL_NULI', '=', $form['linea']],
- ['SCEL_USUA', '=', $form['user']],
- ['SCEL_HOST', '=', $form['host']],
- ])->update([
- 'SCEL_ESCO' => $form['state'],
- 'SCEL_USMO' => $idUser,
- 'SCEL_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F07CCEL',
- 'S002V01P01CNSC',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió el estado del servidor $form[host]",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerEmailTemplate(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'module' => 'required|string|max:25',
- 'submodule' => 'string|max:25',
- 'function' => 'required|string|max:25',
- 'screen' => 'required|string|max:25',
- 'subject' => 'required|string|max:50',
- 'body' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $module = DB::table('S002V01TMODU')->where([
- ['MODU_IDMO', '=', $form['module']],
- ['MODU_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($module)){
- return $this->responseController->makeResponse(true, 'El módulo seleccionado no existe.', [], 404);
- }
- $hasSubmodule = isset($form['submodule']);
- if($hasSubmodule){
- $submodule = DB::table('S002V01TSUBM')->where([
- ['SUBM_IDSM', '=', $form['submodule']],
- ['SUBM_IDMO', '=', $form['module']],
- ['SUBM_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($submodule)){
- return $this->responseController->makeResponse(true, 'El submódulo seleccionado no existe.', [], 404);
- }
- }
- $submodule = $hasSubmodule ? $form['submodule'] : null;
- $function = DB::table('S002V01TFUNC')->where([
- ['FUNC_NULI', '=', $form['linea']],
- ['FUNC_IDFU', '=', $form['function']],
- ['FUNC_IDMO', '=', $form['module']],
- ['FUNC_IDSM', '=', $submodule],
- ])->first();
-
- if(is_null($function)){
- return $this->responseController->makeResponse(true, 'La función seleccionada no existe.', [], 404);
- }
- $screen = DB::table('S002V01TPANT')->where([
- ['PANT_NULI', '=', $form['linea']],
- ['PANT_IDPA', '=', $form['screen']],
- ['PANT_IDFU', '=', $form['function']],
- ])->first();
-
- if(is_null($screen)){
- return $this->responseController->makeResponse(true, 'La pantalla seleccionada no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idPlan = DB::table('S002V01TPCEL')->insertGetId([
- 'PCEL_NULI' => $form['linea'],
- 'PCEL_IDMO' => $form['module'],
- 'PCEL_IDSM' => $submodule,
- 'PCEL_IDFU' => $form['function'],
- 'PCEL_IDPA' => $form['screen'],
- 'PCEL_ASCO' => $form['subject'],
- 'PCEL_CUCO' => $form['body'],
- 'PCEL_USRE' => $idUser,
- 'PCEL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F08CPCE',
- 'S002V01P02NPEP',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la plantilla $form[subject] ($idPlan)",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getEmailTemplates($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $emailTemplates = DB::table('S002V01TPCEL')->select([
- 'PCEL_IDPL AS IDPLANTILLA',
- 'PCEL_NULI AS LINEA',
- 'MODU_NOMO AS NOMBREMODULO',
- 'SUBM_NOMB AS NOMBRESUBMODULO',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'PANT_NOMB AS NOMBREPANTALLA',
- 'PCEL_ASCO AS ASUNTO',
- 'PCEL_CUCO AS CUERPO',
- 'PCEL_ESTA AS ESTADO',
- 'PCEL_USRE AS USUARIOREGISTRA',
- 'PCEL_FERE AS FECHAREGISTRO',
- 'PCEL_USMO AS USUARIOMODIFICA',
- 'PCEL_FEMO AS FECHAMODIFICACION'
- ])->join('S002V01TMODU', 'MODU_IDMO', '=', 'PCEL_IDMO')
- ->leftJoin('S002V01TSUBM', 'SUBM_IDSM', '=', 'PCEL_IDSM')
- ->join('S002V01TFUNC', 'FUNC_IDFU', '=', 'PCEL_IDFU')
- ->join('S002V01TPANT', 'PANT_IDPA', '=', 'PCEL_IDPA')->where([
- ['PCEL_NULI', '=', $line]
- ])->orderBy('PCEL_IDPL', 'asc')->get()->all();
- $emailTemplatesF = [];
- foreach($emailTemplates as $template){
- $usrTemplate = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $template->USUARIOREGISTRA],
- ])->first();
- $idus = $template->USUARIOREGISTRA;
- $template->USUARIOREGISTRA = $this->functionsController->joinName(
- $usrTemplate->USUA_NOMB,
- $usrTemplate->USUA_APPA,
- $usrTemplate->USUA_APMA
- ) . " ($idus)";
- if(!is_null($template->USUARIOMODIFICA)){
- $usrTemplate = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $template->USUARIOMODIFICA],
- ])->first();
-
- $idus = $template->USUARIOMODIFICA;
- $template->USUARIOMODIFICA = $this->functionsController->joinName(
- $usrTemplate->USUA_NOMB,
- $usrTemplate->USUA_APPA,
- $usrTemplate->USUA_APMA
- ) . " ($idus)";
- }
-
- $emailTemplatesF[] = $template;
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F09MACS',
- 'S002V01P01HIPL',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las plantillas de correo electrónico registradas.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $emailTemplatesF);
- }
- public function getEmailTemplate($id, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
- $id = $this->encryptionController->decrypt($id);
- if(!$id){
- return $this->responseController->makeResponse(true, 'El ID de la plantilla consultada no está encriptado correctamente.', [], 400);
- }
- $emailTemplate = DB::table('S002V01TPCEL')->select([
- 'PCEL_IDPL AS IDPLANTILLA',
- 'PCEL_IDMO AS MODULO',
- 'PCEL_IDSM AS SUBMODULO',
- 'PCEL_IDFU AS FUNCION',
- 'PCEL_IDPA AS PANTALLA',
- 'PCEL_ASCO AS ASUNTO',
- 'PCEL_CUCO AS CUERPO'
- ])->where([
- ['PCEL_IDPL', '=', $id],
- ['PCEL_NULI', '=', $line],
- ])->first();
- if(is_null($emailTemplate)){
- return $this->responseController->makeResponse(true, 'La plantilla solicitada 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,
- 'S002V01M01ADSI',
- 'S002V01F09MACS',
- 'S002V01P01HIPL',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la plantilla " . $emailTemplate->ASUNTO . " ($id).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $emailTemplate);
- }
- public function updateEmailTemplate(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_template' => 'required|string',
- 'module' => 'required|string|max:25',
- 'submodule' => 'string|max:25',
- 'function' => 'required|string|max:25',
- 'screen' => 'required|string|max:25',
- 'subject' => 'required|string|max:50',
- 'body' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
-
- $idTemplate = $this->encryptionController->decrypt($form['id_template']);
- if(!$idTemplate){
- return $this->responseController->makeResponse(true, 'El ID de la plantilla no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $submodule = isset($form['submodule']) ? $form['submodule'] : null;
- DB::table('S002V01TPCEL')->where([
- ['PCEL_NULI', '=', $form['linea']],
- ['PCEL_IDPL', '=', $idTemplate]
- ])->update([
- 'PCEL_IDMO' => $form['module'],
- 'PCEL_IDSM' => $submodule,
- 'PCEL_IDFU' => $form['function'],
- 'PCEL_IDPA' => $form['screen'],
- 'PCEL_ASCO' => $form['subject'],
- 'PCEL_CUCO' => $form['body'],
- 'PCEL_USMO' => $idUser,
- 'PCEL_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F08CPCE',
- 'S002V01P02NPEP',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la plantilla $form[subject] ($idTemplate)",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteEmailTemplate(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_template' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
-
- $idTemplate = $this->encryptionController->decrypt($form['id_template']);
- if(!$idTemplate){
- return $this->responseController->makeResponse(true, 'El ID de la plantilla no fue encriptado correctamente.', [], 400);
- }
-
- $template = DB::table('S002V01TPCEL')->where([
- ['PCEL_IDPL', '=', $idTemplate],
- ['PCEL_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($template)){
- return $this->responseController->makeResponse(true, 'La plantilla solicitada no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPCEL')->where([
- ['PCEL_IDPL', '=', $idTemplate],
- ['PCEL_NULI', '=', $form['linea']]
- ])->update([
- 'PCEL_ESTA' => 'Eliminado',
- 'PCEL_USMO' => $idUser,
- 'PCEL_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F08CPCE',
- 'S002V01P01HIPL',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la plantilla ($idTemplate)",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function saveCatalogue(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'tipo' => 'required|string|max:35',
- 'adjuntos' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
-
- $allowedFiles = ["Colonias", "Códigos postales", "Estados", "Localidades", "Municipios", "Países", "Régimen fiscal", "Monedas", "General"];
- if(!in_array($form['tipo'], $allowedFiles)){
- return $this->responseController->makeResponse(true, "El tipo de catálogo no está soportado.", [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $attachedFiles = json_decode($form['adjuntos'], true);
- $attachedArr = [];
- foreach($attachedFiles as $file){
- $idFile = $file['id'];
- $idFile = $this->encryptionController->decrypt($idFile);
- if(!$idFile){
- return $this->responseController->makeResponse(true, "El ID del archivo $file[name] no fue encriptado correctamente", [], 400);
- }
- $fileObj = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idFile],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($fileObj)){
- return $this->responseController->makeResponse(true, "El ID del archivo $file[name] no existe", [], 404);
- }else if($fileObj->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El archivo $file[name] está eliminado", [], 404);
- }
- $fileRes = $this->documentManagementController->moveFinalFile(
- $form['linea'],
- 'ADSI',
- 'CA',
- $fileObj,
- $idUser
- );
- if(!$fileRes[0]){
- return $this->responseController->makeResponse(true, "El archivo no pudo guardarse: $fileRes[1]", [], 500);
- }
-
- $attachedArr[] = $this->encryptionController->encrypt($fileRes[1]);
- DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $idFile],
- ['ARTE_NULI', '=', $form['linea']],
- ])->update([
- 'ARTE_ESTA' => 'Eliminado',
- 'ARTE_USMO' => $idUser,
- 'ARTE_FEMO' => $nowStr
- ]);
- }
- $lastVersionObj = DB::table('S002V01TCATA')->where([
- ['CATA_NULI', '=', $form['linea']],
- ['CATA_TICA', '=', $form['tipo']]
- ])->orderBy('CATA_IDCA', 'desc')->first();
- $lastVersion = 0;
- if(is_null($lastVersionObj)){
- $lastVersion = 1;
- }else{
- DB::table('S002V01TCATA')->where([
- ['CATA_NULI', '=', $form['linea']],
- ['CATA_IDCA', '=', $lastVersionObj->CATA_IDCA],
- ])->update([
- 'CATA_ESTA' => 'Obsoleto',
- ]);
- $lastVersion = intval($lastVersionObj->CATA_VERS) + 1;
- }
- $attachedStr = json_encode($attachedArr);
- DB::table('S002V01TCATA')->insert([
- 'CATA_NULI' => $form['linea'],
- 'CATA_TICA' => $form['tipo'],
- 'CATA_VERS' => $lastVersion,
- 'CATA_ARRE' => $attachedStr,
- 'CATA_USRE' => $idUser,
- 'CATA_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P02NUCA',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró un nuevo catálogo.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeresponse(false, "EXITO");
- }
- public function getCatalogueHistory($type, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
- $types = ['Colonias', 'Códigos postales', 'Estados', 'Localidades', 'Municipios', 'Países', 'Monedas', 'Régimen fiscal'];
- if(!in_array($type, $types)){
- return $this->responseController->makeResponse(true, 'El tipo de catálogo no está soportado.', [], 404);
- }
- $catalogueHistory = DB::table('S002V01TCATA')->select([
- 'CATA_IDCA AS IDCATALOGO',
- 'CATA_VERS AS VERSION',
- 'CATA_ARRE AS ARCHIVO',
- 'CATA_ESTA AS ESTADO',
- 'CATA_USRE AS USUARIOREGISTRA',
- 'CATA_FERE AS FECHAREGISTRO',
- ])->where([
- ['CATA_NULI', '=', $line],
- ['CATA_TICA', '=', $type],
- ])->get()->all();
- $cont = 0;
- foreach($catalogueHistory as $reg){
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $reg->USUARIOREGISTRA]
- ])->first();
- $catalogueHistory[$cont]->USUARIOREGISTRA = $this->functionsController->joinName(
- $usrReg->USUA_NOMB,
- $usrReg->USUA_APPA,
- $usrReg->USUA_APMA,
- ) . " (" . $reg->USUARIOREGISTRA . ")";
- $cont++;
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el historial de catálogos $type.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $catalogueHistory);
- }
- public function getMaterialIcons($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
- }
- $iconsStr = file_get_contents("C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\storage\\app\\files\\icons.json");
- $iconsArr = json_decode($iconsStr, true);
- $icons = $iconsArr['icons'];
- $iconsF = [];
- foreach($icons as $icon){
- if(!array_key_exists($icon['name'], $iconsF)){
- $iconsF[$icon['name']] = [
- 'name' => $icon['name'],
- 'categorie' => $icon['categories'],
- ];
- }
- }
- $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,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los íconos de Material.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', array_values($iconsF));
- }
- public function getOrderPriorities($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta 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);
- }
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
- $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,
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P08EPOT',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración de las prioridades de las órdenes de trabajo.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['order_priorities' => $paramsArr['order_priorities']]);
- }
- public function updateOrderPriorities(Request $request){
- DB::enableQueryLog();
-
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'priorities' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
- $newPriorities = json_decode($form['priorities'], true);
- if(empty($newPriorities)){
- return $this->responseController->makeResponse(true, 'El arreglo de prioridades enviado está vacío', [], 400);
- }
- $paramsArr['order_priorities'] = $newPriorities;
- $paramsStr = json_encode($paramsArr);
- file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json', $paramsStr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P08EPOT',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la configuración de las prioridades de las órdenes de trabajo.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getLoginImages($idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
- $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,
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P04EILO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las imágenes de la pantalla del inicio de sesión.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ['login_params' => $paramsArr['login_params']]);
- }
- public function saveLoginImage(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'tipo' => 'required|string|in:image,background',
- 'archivo' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- if(!$systemParamsExists){
- return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
- }
- $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
- $paramsArr = json_decode($paramsStr, true);
-
- $actualImage = $paramsArr["login_params"]["login_$form[tipo]"];
- $replaceImage = $this->encryptionController->decrypt($form['archivo']);
- if(!$replaceImage){
- return $this->responseController->makeResponse(true, 'El ID de la imágen enviada no fue encriptado correctamente.', [], 500);
- }
- $imageObj = DB::table('S002V01TARTE')->where([
- ['ARTE_IDAR', '=', $replaceImage],
- ['ARTE_NULI', '=', $form['linea']]
- ])->first();
- $ubiImgTmp = $imageObj->ARTE_UBTE;
- if(!file_exists($ubiImgTmp)){
- return $this->responseController->makeResponse(true, 'El archivo de la imagen enviada no existe.', [], 500);
- }
- $ubiImgAct = "C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public\\assets\\$actualImage";
- if(!file_exists($ubiImgAct)){
- return $this->responseController->makeResponse(true, 'La imagen actual no existe.', [], 500);
- }
- $now = $this->functionsController->now();
- $timestamp = $now->timestamp;
- rename($ubiImgAct, "C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public\\assets\\UPDATED_$timestamp.png");
- copy($ubiImgTmp, $ubiImgAct);
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P04EILO',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió la apariencia del login.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateModuleIcons(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'module_icons' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $moduleIconsStr = $form['module_icons'];
- $moduleIconsDec = $this->encryptionController->decrypt($moduleIconsStr);
- if(!$moduleIconsDec){
- return $this->responseController->makeResponse(true, 'El arreglo de módulos no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $moduleIconsArr = json_decode($moduleIconsDec, true);
- foreach($moduleIconsArr as $modIcon){
- DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $form['linea']],
- ['MODU_IDMO', '=', $modIcon['IDMODULO']]
- ])->update([
- 'MODU_ICON' => $modIcon['ICONOMODULO'],
- 'MODU_USMO' => $idUser,
- 'MODU_FEMO' => $nowStr,
- ]);
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P05EIMO',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de los módulos.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateSubmoduleIcons(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'submodule_icons' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $submoduleIconsDec = $this->encryptionController->decrypt($form['submodule_icons']);
- if(!$submoduleIconsDec){
- return $this->responseController->makeResponse(true, 'El arreglo de submódulos no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $submodulesArr = json_decode($submoduleIconsDec, true);
- foreach($submodulesArr as $module=>$submodules){
- foreach($submodules as $submodule){
- DB::table('S002V01TSUBM')->where([
- ['SUBM_NULI', '=', $form['linea']],
- ['SUBM_IDSM', '=', $submodule['IDSUBMODULO']],
- ['SUBM_IDMO', '=', $module],
- ])->update([
- 'SUBM_ICON' => $submodule['ICONOSUBMODULO'],
- 'SUBM_USMO' => $idUser,
- 'SUBM_FEMO' => $nowStr,
- ]);
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P06EISU',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de los submódulos.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateFunctionIcons(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'module_functions_icons' => 'required|string',
- 'submodule_functions_icons' => '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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $moduleFunctionIconsDec = $this->encryptionController->decrypt($form['module_functions_icons']);
- if(!$moduleFunctionIconsDec){
- return $this->responseController->makeResponse(true, 'El arreglo de funciones por módulo no fue encriptado correctamente.', [], 400);
- }
- $submoduleFunctionIconsDec = $this->encryptionController->decrypt($form['submodule_functions_icons']);
- if(!$submoduleFunctionIconsDec){
- return $this->responseController->makeResponse(true, 'El arreglo de funciones por submódulo no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $moduleFunctionIconsArr = json_decode($moduleFunctionIconsDec, true);
- foreach($moduleFunctionIconsArr as $module=>$functions){
- foreach($functions as $function){
- DB::table('S002V01TFUNC')->where([
- ['FUNC_NULI', '=', $form['linea']],
- ['FUNC_IDFU', '=', $function['IDFUNCION']],
- ['FUNC_IDMO', '=', $module],
- ['FUNC_IDSM', '=', null],
- ])->update([
- 'FUNC_ICON' => $function['ICONOFUNCION'],
- 'FUNC_USMO' => $idUser,
- 'FUNC_FEMO' => $nowStr,
- ]);
- }
- }
- $submoduleFunctionIconsArr = json_decode($submoduleFunctionIconsDec, true);
- foreach($submoduleFunctionIconsArr as $module=>$submodules){
- foreach($submodules as $submodule=>$functions){
- foreach($functions as $function){
- DB::table('S002V01TFUNC')->where([
- ['FUNC_NULI', '=', $form['linea']],
- ['FUNC_IDFU', '=', $function['IDFUNCION']],
- ['FUNC_IDMO', '=', $module],
- ['FUNC_IDSM', '=', $submodule],
- ])->update([
- 'FUNC_ICON' => $function['ICONOFUNCION'],
- 'FUNC_USMO' => $idUser,
- 'FUNC_FEMO' => $nowStr,
- ]);
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F11PASI',
- 'S002V01P07EIFU',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de las funciones.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getModuleFunctions($idMod, $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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El ID del módulo no fue encriptado correctamente', [], 400);
- }
- $mod = DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idMod]
- ])->first();
- if(is_null($mod)){
- return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
- }
- $functions = DB::table('S002V01TFUNC')->where([
- ['FUNC_NULI', '=', $line],
- ['FUNC_IDMO', '=', $idMod],
- ['FUNC_IDSM', '=', null],
- ])->select([
- 'FUNC_IDFU AS IDFUNCION',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'FUNC_ICON AS ICONOFUNCION'
- ])->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,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las funciones del módulo '" . $mod->MODU_NOMO . "'.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $functions);
- }
- public function registerSCADA(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'scada_name' => 'required|string|max:100',
- ]);
- 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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLISC')->insert([
- 'LISC_NULI' => $form['linea'],
- 'LISC_NOSC' => $form['scada_name'],
- 'LISC_USRE' => $idUser,
- 'LISC_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P02RESC',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el SCADA $form[scada_name].",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getSCADAList($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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $list = DB::table('S002V01TLISC')->select([
- 'LISC_IDSC AS IDSCADA',
- 'LISC_NOSC AS NOMBRESCADA',
- 'LISC_ESTA AS ESTATUS',
- 'LISC_USRE AS USUARIOREGISTRO',
- 'LISC_FERE AS FECHAREGISTRO',
- 'LISC_USMO AS USUARIOMODIFICO',
- 'LISC_FEMO AS FECHAMODIFICACION',
- ])->where([
- ['LISC_NULI', '=', $line],
- ['LISC_ESTA', '=', 'Activo'],
- ])->get()->all();
- foreach($list as $item){
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item->USUARIOREGISTRO],
- ])->first();
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA) . " (" . $item->USUARIOREGISTRO . ")";
- $item->USUARIOREGISTRO = $nameReg;
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $item->USUARIOMODIFICO],
- ])->first();
- if(!is_null($usrMod)){
- $nameMod = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA) . " (" . $item->USUARIOMODIFICO . ")";
- $item->USUARIOMODIFICO = $nameMod;
- }
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P01ADSC',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los SCADA registrados en el sistema.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $list);
- }
- public function updateSCADA(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'id_scada' => 'required|string',
- 'linea' => 'required|integer',
- 'scada_name' => 'required|string|max:100',
- ]);
- 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);
- }
- $idSCADA = $this->encryptionController->decrypt($form['id_scada']);
- if(!$idSCADA){
- return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
- }
- $scada = DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $idSCADA],
- ])->first();
-
- if(is_null($scada)){
- return $this->responseController->makeResponse(true, 'El SCADA solicitado no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $idSCADA],
- ])->update([
- 'LISC_NOSC' => $form['scada_name'],
- 'LISC_USMO' => $idUser,
- 'LISC_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P02RESC',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el SCADA $form[scada_name] ($idSCADA).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function deleteSCADA(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'id_scada' => 'required|string',
- 'linea' => 'required|integer',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSCADA = $this->encryptionController->decrypt($form['id_scada']);
- if(!$idSCADA){
- return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
- }
- $scada = DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $idSCADA],
- ])->first();
-
- if(is_null($scada)){
- return $this->responseController->makeResponse(true, 'El SCADA solicitado no existe.', [], 404);
- }
- $tokensSCADA = DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $idSCADA],
- ])->get()->all();
- if(!empty($tokensSCADA)){
- return $this->responseController->makeResponse(true, 'No se pudo eliminar el SCADA porque tiene tokens asignados.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $idSCADA],
- ])->update([
- 'LISC_ESTA' => 'Eliminado',
- 'LISC_USMO' => $idUser,
- 'LISC_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P01ADSC',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el SCADA " . $scada->LISC_NOSC . " ($idSCADA).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function generateSCADAtoken(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'id_scada' => 'required|string',
- 'linea' => 'required|integer',
- 'descripcion' => '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 del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
-
- $id = $this->encryptionController->decrypt($form['id_scada']);
- if(!$id){
- return $this->responseController->makeResponse(true, 'El ID del SCADA no está encriptado correctamente', [], 400);
- }
- $scada = DB::table('S002V01TLISC')->where([
- ['LISC_NULI', '=', $form['linea']],
- ['LISC_IDSC', '=', $id],
- ])->first();
- if(is_null($scada)){
- return $this->responseController->makeResponse(true, 'El SCADA consultado no existe', [], 404);
- }
- $now = $this->functionsController->now();
- $iat = $now->timestamp;
- $cad = $now->addYear()->timestamp;
- $payload = [
- "iss" => $scada->LISC_IDSC,
- "aud" => "dominio.syp.mx",
- "iat" => $iat,
- "cad" => $cad
- ];
- $token = JWT::encode($payload, $this->secretKey, 'EdDSA');
- $nowStr = $now->subYear()->toDateTimeString();
- DB::table('S002V01TTASW')->insert([
- 'TASW_NULI' => $form['linea'],
- 'TASW_IDSC' => $scada->LISC_IDSC,
- 'TASW_TOKE' => $token,
- 'TASW_DETO' => $form['descripcion'],
- 'TASW_TIMO' => "PRUEBA",
- 'TASW_USRE' => $idUser,
- 'TASW_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P04GETO',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró y asignó el token \"$token\" al SCADA \"" . $scada->LISC_NOSC . " ($id)\".",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.', ['token' => $token]);
- }
- public function getGeneratedTokens($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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $tokens = DB::table('S002V01TTASW')->join('S002V01TLISC', 'LISC_IDSC', '=', 'TASW_IDSC')->select([
- 'LISC_NOSC AS NOMBRESCADA',
- 'TASW_DETO AS DESCRIPCION',
- 'TASW_ESTA AS ESTATUS',
- 'TASW_USRE AS USUARIOREGISTRO',
- 'TASW_FERE AS FECHAREGISTRO',
- 'TASW_USMO AS USUARIOMODIFICACION',
- 'TASW_FEMO AS FECHAMODIFICACION',
- 'TASW_IDSC AS IDSCADA',
- 'TASW_TOKE AS TOKEN'
- ])->where([
- ['TASW_NULI', '=', $line],
- ['LISC_ESTA', '=', 'Activo'],
- ])->get()->all();
- foreach($tokens as $token){
- $usre = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $token->USUARIOREGISTRO]
- ])->first();
- $usreName = $this->functionsController->joinName($usre->USUA_NOMB, $usre->USUA_APPA, $usre->USUA_APMA) . " (" . $token->USUARIOREGISTRO . ")";
- $token->USUARIOREGISTRO = $usreName;
-
- $usmo = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $token->USUARIOMODIFICACION]
- ])->first();
- if(!is_null($usmo)){
- $usmoName = $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA) . " (" . $token->USUARIOMODIFICACION . ")";
- $token->USUARIOMODIFICACION = $usmoName;
- }
- $keyStr = $token->IDSCADA . "|" . $token->TOKEN;
- $keyEnc = $this->encryptionController->encrypt($keyStr);
- unset($token->IDSCADA);
- unset($token->TOKEN);
-
- $token->KEY = $keyEnc;
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P03ADTO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los tokens generados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $tokens);
- }
- public function revokeToken(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'token_key' => 'required|string',
- 'linea' => 'required|integer',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $form['linea']]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $tokenKey = $this->encryptionController->decrypt($form['token_key']);
- if(!$tokenKey){
- return $this->responseController->makeResponse(true, 'La llave del token solicitado no fue encriptado correctamente.', [], 400);
- }
- $keyArr = explode("|", $tokenKey);
- $token = DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $keyArr[0]],
- ['TASW_TOKE', '=', $keyArr[1]]
- ])->first();
- if(is_null($token)){
- return $this->responseController->makeResponse(true, 'El token solicitado no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $keyArr[0]],
- ['TASW_TOKE', '=', $keyArr[1]]
- ])->update([
- 'TASW_ESTA' => 'Revocado',
- 'TASW_USMO' => $idUser,
- 'TASW_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P03ADTO',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") revocó el token \"$keyArr[1]\".",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function registerWebService(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'url' => 'required|string|max:250',
- 'description' => 'required|string|max:100',
- ]);
- 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);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idWebService = DB::table('S002V01TLSWE')->insertGetId([
- 'LSWE_NULI' => $form['linea'],
- 'LSWE_URLX' => $form['url'],
- 'LSWE_DESC' => $form['description'],
- 'LSWE_USRE' => $idUser,
- 'LSWE_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P07RESW',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el servicio web $form[url] ($idWebService).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getWebServices($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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $webServices = DB::table('S002V01TLSWE')->where([
- ['LSWE_NULI', '=', $line]
- ])->select([
- 'LSWE_IDSW AS IDSERVICIO',
- 'LSWE_URLX AS URL',
- 'LSWE_DESC AS DESCRIPCION',
- 'LSWE_ESTA AS ESTADO',
- 'LSWE_USRE AS USUREG',
- 'LSWE_FERE AS FECREG',
- 'LSWE_USMO AS USUMOD',
- 'LSWE_FEMO AS FECMOD'
- ])->get()->all();
- foreach($webServices as $webService){
- $usre = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $webService->USUREG],
- ])->first();
- $usreName = $this->functionsController->joinName($usre->USUA_NOMB, $usre->USUA_APPA, $usre->USUA_APMA) . " (" . $webService->USUREG . ")";
- $webService->USUREG = $usreName;
- $usmo = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $webService->USUMOD],
- ])->first();
- if(!is_null($usmo)){
- $usmoName = $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA) . " (" . $webService->USUMOD . ")";
- $webService->USUMOD = $usmoName;
- }
- $vinculos = DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $line],
- ['TASW_IDSW', '=', $webService->IDSERVICIO],
- ])->get()->all();
- $webService->VINCULOS = count($vinculos);
- }
- $now = $this->functionsController->now();
- $actions = DB::getQueryLog();
- $nowStr = $now->toDateTimeString();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P06LSWE',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los servicios web almacenados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $webServices);
- }
- public function getRoutedTokens($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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $list = DB::table('S002V01TTASW')
- ->join('S002V01TLISC', 'LISC_IDSC', '=', 'TASW_IDSC')
- ->leftJoin('S002V01TLSWE', 'LSWE_IDSW', '=', 'TASW_IDSW')
- ->where([
- ['TASW_NULI', '=', $line],
- ['TASW_ESTA', '!=', 'Revocado'],
- ])->get()->all();
- $arrList = [];
- foreach($list as $val){
- $key = $this->encryptionController->encrypt($val->TASW_IDSC . "|" . $val->TASW_TOKE);
- $arrList[] = [
- 'SCADA' => $val->LISC_NOSC . " (" . $val->LISC_IDSC . ")",
- 'DESCRIPCIONSC' => $val->TASW_DETO,
- 'SERVICIOWEB' => is_null($val->LSWE_IDSW) ? 'No asignado' : $val->LSWE_URLX . " (" . $val->LSWE_IDSW . ")",
- 'DESCRIPCIONSW' => $val->LSWE_DESC,
- 'ESTADO' => $val->TASW_ESTA,
- "KEY" => $key
- ];
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P05ESSW',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el enrutamiento de los SCADA a los servicios web.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $arrList);
- }
- public function changeTokenAccess(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'estado' => 'required|string|in:Activo,Inactivo',
- 'key' => '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);
- }
- $keyStr = $this->encryptionController->decrypt($form['key']);
- if(!$keyStr){
- return $this->responseController->makeResponse(true, 'La llave del token no fue encriptada correctamente.', [], 400);
- }
- $keyArr = explode('|', $keyStr);
- if(count($keyArr) != 2){
- return $this->responseController->makeResponse(true, 'La llave del token no tiene un formato correcto.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $keyArr[0]],
- ['TASW_TOKE', '=', $keyArr[1]],
- ])->update([
- 'TASW_ESTA' => $form['estado'],
- 'TASW_TIMO' => 'Cambio de estado del token',
- 'TASW_USMO' => $idUser,
- 'TASW_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P05ESSW',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el estado de un token.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function changeWebService(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'key' => 'required|string',
- 'id_web_service' => '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);
- }
-
- $keyToken = $this->encryptionController->decrypt($form['key']);
- if(!$keyToken){
- return $this->responseController->makeResponse(true, 'La llave del token no está encriptada correctamente.', [], 400);
- }
- $keyArr = explode('|', $keyToken);
- $token = DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $keyArr[0]],
- ['TASW_TOKE', '=', $keyArr[1]],
- ])->first();
- if(is_null($token)){
- return $this->responseController->makeResponse(true, 'El token solicitado no existe.', [], 404);
- }
- $idWS = $this->encryptionController->decrypt($form['id_web_service']);
- if(!$idWS){
- return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
- }
- $webService = DB::table('S002V01TLSWE')->where([
- ['LSWE_NULI', '=', $form['linea']],
- ['LSWE_IDSW', '=', $idWS]
- ])->first();
-
- if(is_null($webService)){
- return $this->responseController->makeResponse(true, 'El servicio web solicitado no existe', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TTASW')->where([
- ['TASW_NULI', '=', $form['linea']],
- ['TASW_IDSC', '=', $keyArr[0]],
- ['TASW_TOKE', '=', $keyArr[1]],
- ])->update([
- 'TASW_IDSW' => $idWS,
- 'TASW_TIMO' => 'Cambio de servicio web',
- 'TASW_USMO' => $idUser,
- 'TASW_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P05ESSW',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servicio web de un SCADA.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateWebService(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_web_service' => 'required|string',
- 'url' => 'required|string|max:250',
- 'description' => 'required|string|max:100',
- ]);
- 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);
- }
- $idWS = $this->encryptionController->decrypt($form['id_web_service']);
- if(!$idWS){
- return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now ->toDateTimeString();
- DB::table('S002V01TLSWE')->where([
- ['LSWE_IDSW', '=', $idWS],
- ['LSWE_NULI', '=', $form['linea']]
- ])->update([
- 'LSWE_URLX' => $form['url'],
- 'LSWE_DESC' => $form['description'],
- 'LSWE_USMO' => $idUser,
- 'LSWE_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P07RESW',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servicio web $form[url] ($idWS).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function changeWSstatus(Request $request){
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_web_service' => 'required|string',
- 'status' => 'required|string|in:Activo,Inactivo',
- ]);
- 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);
- }
- $idWS = $this->encryptionController->decrypt($form['id_web_service']);
- if(!$idWS){
- return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
- }
- $webService = DB::table('S002V01TLSWE')->where([
- ['LSWE_NULI', '=', $form['linea']],
- ['LSWE_IDSW', '=', $idWS]
- ])->first();
-
- if(is_null($webService)){
- return $this->responseController->makeResponse(true, 'El servicio web solicitado no existe.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TLSWE')->where([
- ['LSWE_NULI', '=', $form['linea']],
- ['LSWE_IDSW', '=', $idWS],
- ])->update([
- 'LSWE_ESTA' => $form['status'],
- 'LSWE_USMO' => $idUser,
- 'LSWE_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F06ASWA',
- 'S002V01P07RESW',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el estado servicio web de un SCADA.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getBackupsList($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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $backups = DB::table('S002V01TRESP')->select([
- 'RESP_IDRE AS IDRESPALDO',
- 'RESP_FERE AS FECHARESPALDO',
- 'RESP_ESTA AS ESTADO',
- 'RESP_LORE AS LOG',
- ])->where('RESP_NULI', '=', $line)->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,
- 'S002V01M01ADSI',
- 'S002V01F12GERE',
- 'S002V01P01HRES',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la lista de respaldos.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $backups);
- }
- public function getSubmoduleFunctions($idMod, $idSub, $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_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idMod = $this->encryptionController->decrypt($idMod);
- if(!$idMod){
- return $this->responseController->makeResponse(true, 'El ID del módulo no está encriptado correctamente', [], 400);
- }
- $mod = DB::table('S002V01TMODU')->where([
- ['MODU_NULI', '=', $line],
- ['MODU_IDMO', '=', $idMod]
- ])->first();
- if(is_null($mod)){
- return $this->responseController->makeResponse(true, 'El módulo enviado no existe', [], 404);
- }
- $idSub = $this->encryptionController->decrypt($idSub);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El ID del submódulo no está encriptado correctamente', [], 400);
- }
- $sub = DB::table('S002V01TSUBM')->where([
- ['SUBM_NULI', '=', $line],
- ['SUBM_IDSM', '=', $idSub],
- ['SUBM_IDMO', '=', $idMod],
- ])->first();
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El submódulo enviado no existe', [], 404);
- }
- $functions = DB::table('S002V01TFUNC')->select([
- 'FUNC_IDFU AS IDFUNCION',
- 'FUNC_NOMB AS NOMBREFUNCION',
- 'FUNC_ICON AS ICONOFUNCION',
- ])->where([
- ['FUNC_NULI', '=', $line],
- ['FUNC_IDMO', '=', $idMod],
- ['FUNC_IDSM', '=', $idSub],
- ])->get()->all();
- foreach($functions as $function){
- $screens = DB::table('S002V01TPANT')->where([
- ['PANT_NULI', '=', $line],
- ['PANT_IDFU', '=', $function->IDFUNCION],
- ])->get()->all();
- $function->HASSCREENS = count($screens) > 0;
- }
- $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,
- '-',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las funciones del submódulo " . $sub->SUBM_NOMB . " ($idSub).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $functions);
- }
- public function getTaxInformation($line){
- try {
- $getTaxInformation = DB::table('S002V01TINFI')
- ->where('INFI_NULI','=',$line)
- ->where('INFI_ESTA','=','Activo')
- ->first([
- 'INFI_IDIN',
- 'INFI_NOFI',
- 'INFI_XRFC',
- 'INFI_COEL',
- 'INFI_CORF',
- 'INFI_LAD1',
- 'INFI_TEL1',
- 'INFI_LAD2',
- 'INFI_TEL2',
- 'INFI_COPO',
- 'INFI_TIVI',
- 'INFI_VIAL',
- 'INFI_ENCA',
- 'INFI_YCAL',
- 'INFI_NUEX',
- 'INFI_NUIN',
- 'INFI_COLO',
- 'INFI_LOCA',
- 'INFI_MUNI',
- 'INFI_ENFE',
- 'INFI_PAIS',
- 'INFI_USRE',
- 'INFI_FERE',
- 'INFI_USMO',
- 'INFI_FEMO',
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_GET_TAX_INFORMATION000: Ocurrió un error al obtener la información fiscal.", [], 401);
- }
- return $this->responseController->makeResponse(false, 'EXITO', $getTaxInformation);
- }
- public function getCountriesList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Países'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de paises', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_Pais', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Pais.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Pais'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $countries = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $countryKey = $worksheet->getCell("A$row")->getValue();
- $countryName = $worksheet->getCell("B$row")->getValue();
- $countryInfo = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $line],
- ['PAIS_IDPA', '=', $countryKey],
- ])->first();
- $countries[] = [
- 'COUNTRY_ID' => $countryKey,
- 'NAME' => $countryName,
- 'LADA' => is_null($countryInfo) ? null : $countryInfo->PAIS_LADA,
- 'NOMECLARUTA_ISO2' => is_null($countryInfo) ? null : $countryInfo->PAIS_NOME
- ];
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Países.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $countries);
- }
- public function saveCatalogueConfig(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'catalogue_type' => 'required|string',
- 'config' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
-
- $allowedFiles = ["Colonias", "Códigos postales", "Estados", "Localidades", "Municipios", "Países", "Monedas", "Régimen fiscal"];
- if(!in_array($form['catalogue_type'], $allowedFiles)){
- return $this->responseController->makeResponse(true, "El tipo de catálogo no está soportado.", [], 400);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', $form['catalogue_type']],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $form['linea']],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, "Aún no se ha registrado ningún catálogo de $form[catalogue_type]", [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- switch($form['catalogue_type']){
- case "Países":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $val['COUNTRY_ID']],
- ])->first();
- if(is_null($val['COUNTRY_ID'])) continue;
- if(is_null($country)){
- DB::table('S002V01TPAIS')->insert([
- 'PAIS_NULI' => $form['linea'],
- 'PAIS_IDPA' => $val['COUNTRY_ID'],
- 'PAIS_NOMB' => $val['NAME'],
- 'PAIS_NOME' => $val['NOMECLARUTA_ISO2'],
- 'PAIS_LADA' => $val['LADA'],
- 'PAIS_USRE' => $idUser,
- 'PAIS_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $val['COUNTRY_ID']],
- ])->update([
- 'PAIS_NOME' => $val['NOMECLARUTA_ISO2'],
- 'PAIS_LADA' => $val['LADA'],
- 'PAIS_USMO' => $idUser,
- 'PAIS_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Códigos postales":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $zipCode = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $val['CODIGO_POSTAL']],
- ['COPO_COES', '=', $val['ESTADO']],
- ])->first();
- if(is_null($val['CODIGO_POSTAL'])) continue;
- if(is_null($zipCode)){
- DB::table('S002V01TCOPO')->insert([
- 'COPO_NULI' => $form['linea'],
- 'COPO_COPO' => $val['CODIGO_POSTAL'],
- 'COPO_COES' => $val['ESTADO'],
- 'COPO_COMU' => $val['MUNICIPIO'],
- 'COPO_COLO' => $val['LOCALIDAD'],
- 'COPO_USRE' => $idUser,
- 'COPO_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $val['CODIGO_POSTAL']],
- ['COPO_COES', '=', $val['ESTADO']],
- ])->update([
- 'COPO_COMU' => $val['MUNICIPIO'],
- 'COPO_COLO' => $val['LOCALIDAD'],
- 'COPO_USMO' => $idUser,
- 'COPO_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Estados":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $val['STATE_KEY']],
- ['ESTA_COPA', '=', $val['COUNTRY_KEY']],
- ])->first();
- if(is_null($val['STATE_KEY'])) continue;
- if(is_null($state)){
- DB::table('S002V01TESTA')->insert([
- 'ESTA_NULI' => $form['linea'],
- 'ESTA_COES' => $val['STATE_KEY'],
- 'ESTA_COPA' => $val['COUNTRY_KEY'],
- 'ESTA_NOES' => $val['STATE_NAME'],
- 'ESTA_USRE' => $idUser,
- 'ESTA_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $val['STATE_KEY']],
- ['ESTA_COPA', '=', $val['COUNTRY_KEY']],
- ])->update([
- 'ESTA_NOES' => $val['STATE_NAME'],
- 'ESTA_USMO' => $idUser,
- 'ESTA_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Municipios":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $val['CITY_KEY']],
- ['MUNI_COES', '=', $val['STATE_KEY']],
- ])->first();
- if(is_null($val['CITY_KEY'])) continue;
- if(is_null($city)){
- DB::table('S002V01TMUNI')->insert([
- 'MUNI_NULI' => $form['linea'],
- 'MUNI_COMU' => $val['CITY_KEY'],
- 'MUNI_COES' => $val['STATE_KEY'],
- 'MUNI_NOMU' => $val['CITY_NAME'],
- 'MUNI_USRE' => $idUser,
- 'MUNI_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $val['CITY_KEY']],
- ['MUNI_COES', '=', $val['STATE_KEY']],
- ])->update([
- 'MUNI_NOMU' => $val['CITY_NAME'],
- 'MUNI_USMO' => $idUser,
- 'MUNI_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Localidades":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $val['TOWN_KEY']],
- ['LOCA_COES', '=', $val['STATE_KEY']],
- ])->first();
- if(is_null($val['TOWN_KEY'])) continue;
- if(is_null($town)){
- DB::table('S002V01TLOCA')->insert([
- 'LOCA_NULI' => $form['linea'],
- 'LOCA_COLO' => $val['TOWN_KEY'],
- 'LOCA_COES' => $val['STATE_KEY'],
- 'LOCA_NOLO' => $val['TOWN_NAME'],
- 'LOCA_USRE' => $idUser,
- 'LOCA_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $val['TOWN_KEY']],
- ['LOCA_COES', '=', $val['CITY_NAME']],
- ])->update([
- 'LOCA_NOLO' => $val['CITY_NAME'],
- 'LOCA_USMO' => $idUser,
- 'LOCA_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Colonias":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $town = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $val['SETTING_KEY']],
- ['COLO_COPO', '=', $val['CODIGO_POSTAL']],
- ])->first();
- if(is_null($val['SETTING_KEY'])) continue;
- if(is_null($town)){
- DB::table('S002V01TCOLO')->insert([
- 'COLO_NULI' => $form['linea'],
- 'COLO_COCO' => $val['SETTING_KEY'],
- 'COLO_COPO' => $val['CODIGO_POSTAL'],
- 'COLO_NOCO' => $val['SETTING_NAME'],
- 'COLO_USRE' => $idUser,
- 'COLO_FERE' => $nowStr,
- ]);
- }else{
- DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $val['SETTING_KEY']],
- ['COLO_COPO', '=', $val['CODIGO_POSTAL']],
- ])->update([
- 'COLO_NOCO' => $val['SETTING_NAME'],
- 'COLO_USMO' => $idUser,
- 'COLO_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- case "Monedas":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $camo = DB::table('S002V01TCAMO')->where([
- ['CAMO_NULI', '=', $form['linea']],
- ['CAMO_COMO', '=', $val['COIN']],
- ['CAMO_DESC', '=', $val['DESCRIPTION']],
- ])->first();
- if(is_null($val['COIN'])) continue;
- if(is_null($camo)){
- DB::table('S002V01TCAMO')->insert([
- 'CAMO_COMO' => $val['COIN'],
- 'CAMO_NULI' => $form['linea'],
- 'CAMO_DESC' => $val['DESCRIPTION'],
- 'CAMO_USRE' => $idUser,
- 'CAMO_FERE' => $nowStr,
- 'CAMO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- }else{
- DB::table('S002V01TCAMO')->where([
- ['CAMO_NULI', '=', $form['linea']],
- ['CAMO_COMO', '=', $val['COIN']],
- ])->update([
- 'CAMO_DESC' => $val['DESCRIPTION'],
- 'CAMO_USMO' => $idUser,
- 'CAMO_FEMO' => $nowStr,
- 'CAMO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- }
- }
- break;
- case "Régimen fiscal":
- $configArr = json_decode($form['config'], true);
- foreach($configArr as $val){
- $taxRegime = DB::table('S002V01TREFI')->where([
- ['REFI_NULI', '=', $form['linea']],
- ['REFI_CRFI', '=', $val['TAX_REGIME_KEY']],
- ])->first();
- if(is_null($val['TAX_REGIME_KEY'])) continue;
- if(is_null($taxRegime)){
- DB::table('S002V01TREFI')->insert([
- 'REFI_NULI' => $form['linea'],
- 'REFI_CRFI' => $val['TAX_REGIME_KEY'],
- 'REFI_DRFI' => $val['TAX_REGIME_DESC'],
- 'REFI_APFI' => $val['APPLY_PHISIC'],
- 'REFI_APMO' => $val['APPLY_MORAL'],
- 'REFI_FERE' => $nowStr,
- 'REFI_USRE' => $idUser,
- ]);
- }else{
- DB::table('S002V01TREFI')->where([
- ['REFI_NULI', '=', $form['linea']],
- ['REFI_CRFI', '=', $val['TAX_REGIME_KEY']],
- ])->update([
- 'REFI_DRFI' => $val['TAX_REGIME_DESC'],
- 'REFI_APFI' => $val['APPLY_PHISIC'],
- 'REFI_APMO' => $val['APPLY_MORAL'],
- 'REFI_USMO' => $idUser,
- 'REFI_FEMO' => $nowStr,
- ]);
- }
- }
- break;
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P02NUCA',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el catálogo $form[catalogue_type].",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeresponse(false, "EXITO");
- }
- public function getZipCodes($idUser, $line){
- ini_set("display_errors", 1);
- ini_set("memory_limit", "-1");
- 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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Códigos postales'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de códigos postales', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de códigos postales no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales no existe en el almacenamiento final.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- $zipCodes = [];
- foreach($sheetNames as $name){
- if(!str_contains($name, 'c_CodigoPostal')){
- return $this->responseController->makeResponse(true, "La hoja $name no pertenece al catálogo de códigos postales.", [], 400);
- }
- $worksheet = $spreadsheet->getSheetByName($name);
- $fileValidatorCell = $worksheet->getCell('A6')->getValue();
- if($fileValidatorCell != 'c_CodigoPostal'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $maxRow = $worksheet->getHighestRow();
- for($row = 8; $row <= $maxRow; $row++){
- $zipCode = $worksheet->getCell("A$row")->getValue();
- if($zipCode == null) continue;
- $state = $worksheet->getCell("B$row")->getValue();
- $city = $worksheet->getCell("C$row")->getValue();
- $town = $worksheet->getCell("D$row")->getValue();
- if(is_null($state)) continue;
-
- $endDateNum = $worksheet->getCell("G$row")->getValue();
- if(is_null($endDateNum)){
- $zipCodes[] = [
- 'CODIGO_POSTAL' => $zipCode,
- 'ESTADO' => $state,
- 'MUNICIPIO' => $city,
- 'LOCALIDAD' => $town,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $zipCodes[] = [
- 'CODIGO_POSTAL' => $zipCode,
- 'ESTADO' => $state,
- 'MUNICIPIO' => $city,
- 'LOCALIDAD' => $town,
- ];
- }
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Códigos postales.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $zipCodes);
- }
- public function getZipCodesTotal($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);
- }
- $totalZipCodes = DB::table('S002V01TCOPO')->select(DB::raw('count(*) as total_zip_codes'))->where(
- 'COPO_NULI', '=', $line
- )->first();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el total de Códigos postales.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', ["TOTAL_ZIP_CODES" => $totalZipCodes->total_zip_codes]);
- }
- public function getZipCodesPage($limit, $offset, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $limit = intval($limit);
- $offset = intval($offset);
- $zipCodesPaginated = DB::table('S002V01TCOPO')->select([
- 'COPO_COPO AS CODIGO_POSTAL',
- 'COPO_COES AS ESTADO',
- 'COPO_COMU AS MUNICIPIO',
- 'COPO_COLO AS LOCALIDAD',
- ])->where([
- ['COPO_NULI', '=', $line],
- ['COPO_ESTA', '=', 'Activo']
- ])->offset($offset)->limit($limit)->orderBy('COPO_COES', 'ASC')->orderBy('COPO_COPO', 'ASC')->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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó $limit registros desde el $offset del catálogo de Códigos postales.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $zipCodesPaginated);
- }
- public function getAddressByZipCode($zipCode, $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);
- }
- $zipCode = $this->encryptionController->decrypt($zipCode);
- if(!$zipCode){
- return $this->responseController->makeResponse(true, 'El código postal enviado no está encriptado correctamente', [], 400);
- }
- $code = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $line],
- ['COPO_COPO', '=', $zipCode]
- ])->first();
- if(is_null($code)){
- return $this->responseController->makeResponse(true, "El código postal $zipCode no está registrado.", [], 404);
- }else if($code->COPO_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El código postal $zipCode está eliminado.", [], 404);
- }
- $address = DB::table('S002V01TCOPO')->select([
- 'COPO_COPO AS CODIGO_POSTAL',
- 'COPO_COES AS CODIGO_ESTADO',
- 'ESTA_NOES AS NOMBRE_ESTADO',
- 'COPO_COMU AS CODIGO_MUNICIPIO',
- 'MUNI_NOMU AS NOMBRE_MUNICIPIO',
- 'COPO_COLO AS CODIGO_LOCALIDAD',
- 'LOCA_NOLO AS NOMBRE_LOCALIDAD'
- ])->where([
- ['COPO_NULI', '=', $line],
- ['COPO_COPO', '=', $zipCode]
- ])->join('S002V01TESTA', 'COPO_COES', '=', 'ESTA_COES')
- ->leftJoin('S002V01TMUNI', function(JoinClause $join) {
- $join->on('COPO_COMU', '=', 'MUNI_COMU')
- ->on('COPO_COES', '=', 'MUNI_COES');
- })->leftJoin('S002V01TLOCA', function(JoinClause $join) {
- $join->on('COPO_COLO', '=', 'LOCA_COLO')
- ->on('COPO_COES', '=', 'LOCA_COES');
- })->first();
- $settings = DB::table('S002V01TCOLO')->select([
- 'COLO_COCO AS CODIGO_COLONIA',
- 'COLO_NOCO AS NOMBRE_COLONIA'
- ])->where([
- ['COLO_NULI', '=', $line],
- ['COLO_COPO', '=', $zipCode],
- ])->get()->all();
- $address->COLONIAS = $settings;
- $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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P02NUCA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó la dirección del código postal $zipCode.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeresponse(false, "EXITO", $address);
- }
- public function getStatesList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Estados'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_Estado', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Estado.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Estado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $states = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $stateKey = $worksheet->getCell("A$row")->getValue();
- $countryKey = $worksheet->getCell("B$row")->getValue();
- $stateName = $worksheet->getCell("C$row")->getValue();
- $endDateNum = $worksheet->getCell("E$row")->getValue();
- if(is_null($endDateNum)){
- $states[] = [
- 'STATE_KEY' => $stateKey,
- 'COUNTRY_KEY' => $countryKey,
- 'STATE_NAME' => $stateName,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $states[] = [
- 'STATE_KEY' => $stateKey,
- 'COUNTRY_KEY' => $countryKey,
- 'STATE_NAME' => $stateName,
- ];
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Estados.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $states);
- }
- public function getCitiesList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Municipios'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_Municipio', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Municipio.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Municipio'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $cities = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $cityKey = $worksheet->getCell("A$row")->getValue();
- $stateKey = $worksheet->getCell("B$row")->getValue();
- $cityName = $worksheet->getCell("C$row")->getValue();
- $endDateNum = $worksheet->getCell("E$row")->getValue();
- if(is_null($endDateNum)){
- $cities[] = [
- 'CITY_KEY' => $cityKey,
- 'STATE_KEY' => $stateKey,
- 'CITY_NAME' => $cityName,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $cities[] = [
- 'CITY_KEY' => $cityKey,
- 'STATE_KEY' => $stateKey,
- 'CITY_NAME' => $cityName,
- ];
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Municipios.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $cities);
- }
- public function getTownsList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Localidades'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_Localidad', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Localidad.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Localidad'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $towns = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $townKey = $worksheet->getCell("A$row")->getValue();
- $stateKey = $worksheet->getCell("B$row")->getValue();
- $townName = $worksheet->getCell("C$row")->getValue();
- $endDateNum = $worksheet->getCell("E$row")->getValue();
- if(is_null($endDateNum)){
- $towns[] = [
- 'TOWN_KEY' => $townKey,
- 'STATE_KEY' => $stateKey,
- 'TOWN_NAME' => $townName,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $towns[] = [
- 'TOWN_KEY' => $townKey,
- 'STATE_KEY' => $stateKey,
- 'TOWN_NAME' => $townName,
- ];
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Localidades.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $towns);
- }
- public function getCoinsList($idUser, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($idUser, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $user],
- ])->first();
- try {
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Monedas'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los catálogos de monedas.', $th->getMessage(), 500);
- }
-
- if (is_null($catalogue)) {
- return $this->responseController->makeResponse(true, 'No se pudo obtener los catálogos de monedas.', [], 500);
- }
-
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_Moneda', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Moneda.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Moneda'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $towns = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $coinKey = $worksheet->getCell("A$row")->getValue();
- $descriptionKey = $worksheet->getCell("B$row")->getValue();
- $endDateNum = $worksheet->getCell("F$row")->getValue();
- if(is_null($endDateNum)){
- $towns[] = [
- 'COIN' => $coinKey,
- 'DESCRIPTION' => $descriptionKey,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $towns[] = [
- 'COIN' => $coinKey,
- 'DESCRIPTION' => $descriptionKey,
- ];
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Monedas.",
- $user,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $user, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $towns);
- }
- public function getSettingsList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Colonias'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- $settings = [];
- foreach($sheetNames as $name){
- if(!str_contains($name, 'c_Colonia')){
- return $this->responseController->makeResponse(true, "La hoja $name no pertenece al catálogo de colonias.", [], 400);
- }
- $worksheet = $spreadsheet->getSheetByName($name);
- $fileValidatorCell = $worksheet->getCell('A5')->getValue();
- if($fileValidatorCell != 'c_Colonia'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $maxRow = $worksheet->getHighestRow();
- for($row = 6; $row <= $maxRow; $row++){
- $settingKey = $worksheet->getCell("A$row")->getValue();
- if($settingKey == null) continue;
- $zipCode = $worksheet->getCell("B$row")->getValue();
- $settingName = $worksheet->getCell("C$row")->getValue();
- if(is_null($zipCode)) continue;
- $settings[] = [
- 'SETTING_KEY' => $settingKey,
- 'CODIGO_POSTAL' => $zipCode,
- 'SETTING_NAME' => $settingName,
- ];
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Colonias.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $settings);
- }
- public function getTaxRegimeList($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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'Régimen fiscal'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
- }
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- if(!in_array('c_RegimenFiscal', $sheetNames)){
- return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_RegimenFiscal.', [], 400);
- }
- $worksheet = $spreadsheet->getActiveSheet();
- $fileValidatorCell = $worksheet->getCell('A6')->getValue();
- if($fileValidatorCell != 'c_RegimenFiscal'){
- return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $taxRegime = [];
- $maxRow = $worksheet->getHighestRow();
- for($row = 7; $row <= $maxRow; $row++){
- $taxRegimeKey = $worksheet->getCell("A$row")->getValue();
- $taxRegimeDesc = $worksheet->getCell("B$row")->getValue();
- $applyPhisic = $worksheet->getCell("C$row")->getValue();
- $applyMoral = $worksheet->getCell("D$row")->getValue();
- $endDateNum = $worksheet->getCell("F$row")->getValue();
- if(is_null($endDateNum)){
- $taxRegime[] = [
- 'TAX_REGIME_KEY' => $taxRegimeKey,
- 'TAX_REGIME_DESC' => $taxRegimeDesc,
- 'APPLY_PHISIC' => $applyPhisic,
- 'APPLY_MORAL' => $applyMoral,
- ];
- }else{
- $endDateStr = Date::excelToTimestamp($endDateNum);
- $endDateObj = Carbon::createFromTimestamp($endDateStr);
- if($endDateObj->gte($now)){
- $taxRegime[] = [
- 'TAX_REGIME_KEY' => $taxRegimeKey,
- 'TAX_REGIME_DESC' => $taxRegimeDesc,
- 'APPLY_PHISIC' => $applyPhisic,
- 'APPLY_MORAL' => $applyMoral,
- ];
- }
- }
- }
-
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Régimen fiscal.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $taxRegime);
- }
- public function getStatesByCountryCode($countryCode, $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);
- }
- $countryCode = $this->encryptionController->decrypt($countryCode);
- if(!$countryCode){
- return $this->responseController->makeResponse(true, 'El código del país seleccionado no está encriptado correctamente', [], 400);
- }
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $line],
- ['PAIS_IDPA', '=', $countryCode]
- ])->first();
- if(is_null($country)){
- return $this->responseController->makeResponse(true, 'El país seleccionado no está registrado', [], 404);
- }
- $relatedStates = DB::table('S002V01TESTA')->select([
- 'ESTA_COES AS CODIGOESTADO',
- 'ESTA_NOES AS NOMBREESTADO'
- ])->where([
- ['ESTA_COPA', '=', $countryCode],
- ['ESTA_NULI', '=', $line],
- ])->orderBy('ESTA_COES', 'asc')->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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los estados relacionados al país " . $country->PAIS_NOMB . " ($countryCode).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $relatedStates);
- }
- public function getCitiesByStateCode($stateCode, $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);
- }
- $stateCode = $this->encryptionController->decrypt($stateCode);
- if(!$stateCode){
- return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
- }
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $line],
- ['ESTA_COES', '=', $stateCode]
- ])->first();
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
- }
- $relatedCities = DB::table('S002V01TMUNI')->select([
- 'MUNI_COMU AS CODIGOMUNICIPIO',
- 'MUNI_NOMU AS NOMBREMUNICIPIO'
- ])->where([
- ['MUNI_COES', '=', $stateCode],
- ['MUNI_NULI', '=', $line],
- ])->orderBy('MUNI_COMU', 'asc')->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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los municipios relacionados al estado " . $state->ESTA_NOES . " ($stateCode).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $relatedCities);
- }
- public function getTowns($stateCode, $cityCode, $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);
- }
- $stateCode = $this->encryptionController->decrypt($stateCode);
- if(!$stateCode){
- return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
- }
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $line],
- ['ESTA_COES', '=', $stateCode]
- ])->first();
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
- }
- $cityCode = $this->encryptionController->decrypt($cityCode);
- if(!$cityCode){
- return $this->responseController->makeResponse(true, 'El código del municipio seleccionado no está encriptado correctamente', [], 400);
- }
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $line],
- ['MUNI_COMU', '=', $cityCode],
- ['MUNI_COES', '=', $stateCode],
- ])->first();
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no está registrado', [], 404);
- }
- $relatedZipCodes = DB::table('S002V01TCOPO')->select([
- DB::raw('DISTINCT(COPO_COLO) AS CODIGOLOCALIDAD'),
- 'LOCA_NOLO AS NOMBRELOCALIDAD'
- ])->where([
- ['COPO_NULI', '=', $line],
- ['COPO_COES', '=', $stateCode],
- ['COPO_COMU', '=', $cityCode],
- ])->leftJoin('S002V01TLOCA', function(JoinClause $join) {
- $join->on('LOCA_COLO', '=', 'COPO_COLO')
- ->on('LOCA_COES', '=', 'COPO_COES');
- })->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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las localidades relacionadas al estado " . $state->ESTA_NOES . " ($stateCode).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $relatedZipCodes);
- }
- public function getCitySettings($stateCode, $cityCode, $townCode, $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);
- }
- $stateCode = $this->encryptionController->decrypt($stateCode);
- if(!$stateCode){
- return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
- }
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $line],
- ['ESTA_COES', '=', $stateCode]
- ])->first();
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
- }
- $cityCode = $this->encryptionController->decrypt($cityCode);
- if(!$cityCode){
- return $this->responseController->makeResponse(true, 'El código del municipio seleccionado no está encriptado correctamente', [], 400);
- }
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $line],
- ['MUNI_COMU', '=', $cityCode],
- ['MUNI_COES', '=', $stateCode],
- ])->first();
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no está registrado', [], 404);
- }
- $townCode = $this->encryptionController->decrypt($townCode);
- if(!$townCode){
- return $this->responseController->makeResponse(true, 'El código de la localidad seleccionada no está encriptado correctamente', [], 400);
- }
- $townCode = $townCode == '-' ? null : $townCode;
- if(!is_null($townCode)){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $line],
- ['LOCA_COLO', '=', $townCode],
- ['LOCA_COES', '=', $stateCode]
- ])->first();
- if(is_null($town)){
- return $this->responseController->makeResponse(true, 'La localidad seleccionada no está registrada', [], 404);
- }
- }
- $settings = DB::table('S002V01TCOPO')->select([
- 'COLO_COCO AS CODIGOCOLONIA',
- 'COPO_COPO AS CODIGOPOSTAL',
- 'COLO_NOCO AS NOMBRECOLONIA',
- ])->where([
- ['COPO_NULI', '=', $line],
- ['COPO_COES', '=', $stateCode],
- ['COPO_COMU', '=', $cityCode],
- ['COPO_COLO', '=', $townCode],
- ])->join('S002V01TCOLO', 'COLO_COPO', '=', 'COPO_COPO')->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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las colonias relacionadas al estado " . $state->ESTA_NOES . " ($stateCode).",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $settings);
- }
- public function getGeneralCatalogueInfo($type, $headerRow, $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);
- }
- $catalogue = DB::table('S002V01TCATA')->where([
- ['CATA_TICA', '=', 'General'],
- ['CATA_ESTA', '=', 'Activo'],
- ['CATA_NULI', '=', $line],
- ])->orderBy('CATA_VERS', 'desc')->first();
- if(is_null($catalogue)){
- return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de General', [], 404);
- }
- $filesArr = json_decode($catalogue->CATA_ARRE, true);
- $fileDec = $this->encryptionController->decrypt($filesArr[0]);
- if(!$fileDec){
- return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
- }
- $fileArr = explode("=", $fileDec);
- $idArr = explode("-", $fileArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $idArr[1]],
- ['AFAL_CLDO', '=', $idArr[2]],
- ['AFAL_FECR', '=', $idArr[3]],
- ['AFAL_NUSE', '=', $idArr[4]],
- ['AFAL_NUVE', '=', $fileArr[1]],
- ])->first();
- if(is_null($file)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente no está registrado.', [], 404);
- }else if($file->AFAL_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente está eliminado.', [], 404);
- }else if(!file_exists($file->AFAL_UBIC)){
- return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente no existe en el almacenamiento final.', [], 404);
- }
- ini_set("memory_limit", "-1");
- set_time_limit(0);
- $spreadsheet = IOFactory::load($file->AFAL_UBIC);
- $sheetNames = $spreadsheet->getSheetNames();
- $relatedSheets = [];
- foreach($sheetNames as $sheet){
- if(str_contains($sheet, $type)){
- $relatedSheets[] = $sheet;
- }
- }
- if(count($relatedSheets) == 0){
- return $this->responseController->makeResponse(true, "No se encontraron hojas relacionadas al tipo $type.", [], 404);
- }
- $responseArr = [];
- foreach($relatedSheets as $sheet){
- $worksheet = $spreadsheet->getSheetByName($sheet);
- $maxCol = $worksheet->getHighestColumn();
- $maxColInd = Coordinate::columnIndexFromString($maxCol);
- $headers = [];
- $startRow = intval($headerRow);
- if($startRow == 0){
- return $this->responseController->makeResponse(true, 'La fila del encabezado no tiene un formato válido.', [], 400);
- }
- for($col = 1; $col <= $maxColInd; $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $header = $worksheet->getCell($colStr . $startRow)->getValue();
- if(!is_null($header)){
- $headers[$colStr] = $header;
- }else{
- $headers[$colStr] = $colStr;
- }
- }
- $startRow++;
- $maxRow = $worksheet->getHighestRow();
- for($row = $startRow; $row <= $maxRow; $row++){
- $arrAux = [];
- for($col = 1; $col <= count($headers); $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $val = $worksheet->getCell($colStr . $row)->getCalculatedValue();
- $header = $headers[$colStr];
- $isDate = Date::isDateTime($worksheet->getCell($colStr . $row));
- if($isDate){
- $val = Date::excelToTimestamp($val);
- $val = Carbon::createFromTimestamp($val);
- $val = $val->toDateTimeString();
- }
- $header = str_replace(' ', '_', $header);
- $arrAux[$header] = $val;
- }
- $responseArr[] = $arrAux;
- }
- }
- $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,
- 'S002V01M01ADSI',
- 'S002V01F10AGCA',
- 'S002V01P01HICA',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo General.",
- $idUser,
- $nowStr
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $responseArr);
- }
- public function saveTaxInformation(Request $request) {
- $validator = Validator::make($request->all(), [
- 'NOMBRE_FISCAL' => 'required|string',
- 'RFC' => 'required|string',
- 'CORREO_ELECTRONICO' => 'required|string',
- 'REGIMEN_FISCAL' => 'required|string',
- 'LADA1' => 'required|string',
- 'TELEFONO_FIJO' => 'required|integer',
- 'LADA2' => 'required|string',
- 'TELEFONO_MOVIL' => 'required|integer',
- 'CODIGO_POSTAL' => 'required|integer',
- 'TIPOVIALIDAD' => 'required|string',
- 'NOMBRE_VIALIDAD' => 'required|string',
- 'ENTRE_CALLE' => 'required|string',
- 'Y_CALLE' => 'required|string',
- 'NUMERO_EXTERIOR' => 'required|string',
- // 'NUMERO_INTERIOR' => 'required|string',
- 'COLONIA' => 'required|string',
- 'LOCALIDAD' => 'required|string',
- 'MUNICIPIO' => 'required|string',
- 'ENTIDAD_FEDERATIVA' => 'required|string',
- 'PAIS' => 'required|string',
- 'USER' => 'required|string',
- 'LINE_NUMBER' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $responseData = $request->all();
- try {
- $user = $this->encryptionController->decrypt($responseData['USER']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION001: Ocurrió un error al desencriptar los datos.", [], 401);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $existsActives = DB::table('S002V01TINFI')
- ->where('INFI_ESTA','=','Activo')
- ->where('INFI_NULI','=',$responseData['LINE_NUMBER'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION002: Ocurrió un error al validar los registros anteriores.", [], 401);
- }
- if ($existsActives) {
- try {
- $validateUpdate = DB::table('S002V01TINFI')
- ->where('INFI_ESTA','=','Activo')
- ->where('INFI_NULI','=',$responseData['LINE_NUMBER'])
- ->update([
- 'INFI_ESTA' => 'Inactivo',
- 'INFI_USMO' => $user,
- 'INFI_FEMO' => $currentDate,
- 'INFI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION002: Ocurrió un error al modificar los registros anteriores.", $th->getMessage(), 401);
- }
- if (!$validateUpdate) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION003: No se pudo modificar los registros anteriores.", [], 401);
- }
- }
- try {
- $validateInsert = DB::table('S002V01TINFI')->insert([
- 'INFI_NOFI' => $responseData['NOMBRE_FISCAL'],
- 'INFI_XRFC' => $responseData['RFC'],
- 'INFI_COEL' => $responseData['CORREO_ELECTRONICO'],
- 'INFI_CORF' => $responseData['REGIMEN_FISCAL'],
- 'INFI_LAD1' => $responseData['LADA1'],
- 'INFI_TEL1' => $responseData['TELEFONO_FIJO'],
- 'INFI_LAD2' => $responseData['LADA2'],
- 'INFI_TEL2' => $responseData['TELEFONO_MOVIL'],
- 'INFI_COPO' => $responseData['CODIGO_POSTAL'],
- 'INFI_TIVI' => $responseData['TIPOVIALIDAD'],
- 'INFI_VIAL' => $responseData['NOMBRE_VIALIDAD'],
- 'INFI_ENCA' => $responseData['ENTRE_CALLE'],
- 'INFI_YCAL' => $responseData['Y_CALLE'],
- 'INFI_NUEX' => $responseData['NUMERO_EXTERIOR'],
- 'INFI_NUIN' => $responseData['NUMERO_INTERIOR'],
- 'INFI_COLO' => $responseData['COLONIA'],
- 'INFI_LOCA' => $responseData['LOCALIDAD'],
- 'INFI_MUNI' => $responseData['MUNICIPIO'],
- 'INFI_ENFE' => $responseData['ENTIDAD_FEDERATIVA'],
- 'INFI_PAIS' => $responseData['PAIS'],
- 'INFI_NULI' => $responseData['LINE_NUMBER'],
- 'INFI_USRE' => $user,
- 'INFI_FERE' => $currentDate,
- 'INFI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION004: Ocurrió un error al insertar los datos en la base de datos.", $th->getMessage(), 401);
- }
- if (!$validateInsert) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION005: No se pudo insertar los datos en la base de datos.", [], 401);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
- }
- public function validateCatalog(Request $request) {
- $validator = Validator::make($request->all(), [
- 'CODIGO_POSTAL' => 'required|boolean',
- 'COLONIAS' => 'required|boolean',
- 'LOCALIDADES' => 'required|boolean',
- 'MUNICIPIOS' => 'required|boolean',
- 'ESTADOS' => 'required|boolean',
- 'PAISES' => 'required|boolean',
- 'REGIMEN_FISCAL' => 'required|boolean',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- $requestData = $request->all();
- $response['CODIGO_POSTAL'] = null;
- $response['COLONIAS'] = null;
- $response['LOCALIDADES'] = null;
- $response['MUNICIPIOS'] = null;
- $response['ESTADOS'] = null;
- $response['PAISES'] = null;
- $response['REGIMEN_FISCAL'] = null;
-
- if ($requestData['CODIGO_POSTAL'] === true) {
- $get = DB::table('S002V01TCOPO')->get();
- $get = json_decode(json_encode($get), true);
- $response['CODIGO_POSTAL'] = empty($get);
- }
- if ($requestData['COLONIAS'] === true) {
- $get = DB::table('S002V01TCOLO')->get();
- $get = json_decode(json_encode($get), true);
- $response['COLONIAS'] = empty($get);
- }
- if ($requestData['LOCALIDADES'] === true) {
- $get = DB::table('S002V01TCOLO')->get();
- $get = json_decode(json_encode($get), true);
- $response['LOCALIDADES'] = empty($get);
- }
- if ($requestData['MUNICIPIOS'] === true) {
- $get = DB::table('S002V01TMUNI')->get();
- $get = json_decode(json_encode($get), true);
- $response['MUNICIPIOS'] = empty($get);
- }
- if ($requestData['ESTADOS'] === true) {
- $get = DB::table('S002V01TESTA')->get();
- $get = json_decode(json_encode($get), true);
- $response['ESTADOS'] = empty($get);
- }
- if ($requestData['PAISES'] === true) {
- $get = DB::table('S002V01TPAIS')->get();
- $get = json_decode(json_encode($get), true);
- $response['PAISES'] = empty($get);
- }
- if ($requestData['REGIMEN_FISCAL'] === true) {
- $get = DB::table('S002V01TREFI')->get();
- $get = json_decode(json_encode($get), true);
- $response['REGIMEN_FISCAL'] = empty($get);
- }
- return $this->responseController->makeResponse(false, "ÉXITO", $response);
- }
- public function getCatalogCoins ($user, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- try {
- $arrCoins = DB::table('S002V01TCAMO')
- ->where('CAMO_NULI', '=', $line)
- ->where('CAMO_ESTA', '=', 'Activo')
- ->get([
- 'CAMO_COMO AS COIN',
- 'CAMO_DESC AS DESCRIPTION',
- ]);
- $arrCoins = json_decode(json_encode($arrCoins), true);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos del catálogo de monedas.', $th->getMessage(), 500);
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrCoins);
- }
- }
|