SystemAdministratorController.php 271 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Carbon;
  8. use Illuminate\Database\Query\JoinClause;
  9. use PhpOffice\PhpSpreadsheet\Reader\Exception as ExcelException;
  10. use PhpOffice\PhpSpreadsheet\IOFactory;
  11. use PhpOffice\PhpSpreadsheet\Shared\Date;
  12. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  13. use Jenssegers\Agent\Agent;
  14. use Firebase\JWT\JWT;
  15. use Firebase\JWT\Key;
  16. use Exception;
  17. class SystemAdministratorController extends Controller{
  18. private $responseController;
  19. private $encryptionController;
  20. private $functionsController;
  21. private $documentManagementController;
  22. private $resourcesController;
  23. private $publicKey = "zOgD0uF22+xg37nTmA+bg/6/E80BJYeHeByGpeTrNFw=";
  24. private $secretKey = "ydl27x22cNsNY0z6o3Fr6XZoUvsX0QMZx6MaiwN+KCnM6APS4Xbb7GDfudOYD5uD/r8TzQElh4d4HIal5Os0XA==";
  25. public function __construct(){
  26. $this->responseController = new ResponseController();
  27. $this->encryptionController = new EncryptionController();
  28. $this->functionsController = new FunctionsController();
  29. $this->resourcesController = new ResourcesController();
  30. $this->documentManagementController = new DocumentManagementController();
  31. }
  32. public function getLastConnections($idUser, $line){
  33. DB::enableQueryLog();
  34. $idUser = $this->encryptionController->decrypt($idUser);
  35. if(!$idUser){
  36. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  37. }
  38. $usr = DB::table('S002V01TUSUA')->where([
  39. ['USUA_NULI', '=', $line],
  40. ['USUA_IDUS', '=', $idUser]
  41. ])->first();
  42. if(is_null($usr)){
  43. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  44. }
  45. $lastConnections = DB::table('S002V01TUSUA')->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')->select(
  46. 'USUA_IDUS AS IDUSUARIO',
  47. 'BIAC_FECO AS ULCON'
  48. )->get()->all();
  49. $now = $this->functionsController->now();
  50. $nowStr = $now->toDateTimeString();
  51. $actions = DB::getQueryLog();
  52. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  53. $idac = $this->functionsController->registerActivity(
  54. $line,
  55. 'S002V01M01ADSI',
  56. 'S002V01F01MAUS',
  57. 'S002V01P02HICO',
  58. 'Consulta',
  59. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las últimas conexiones de los demás usuarios.",
  60. $idUser,
  61. $nowStr
  62. );
  63. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  64. return $this->responseController->makeresponse(false, "EXITO", $lastConnections);
  65. }
  66. public function setLastConnection(Request $request){
  67. DB::enableQueryLog();
  68. $validator = Validator::make($request->all(), [
  69. 'id' => 'required|string',
  70. 'linea' => 'required|integer',
  71. 'latitude' => 'required|numeric|between:-90,90',
  72. 'longitude' => 'required|numeric|between:-180,180',
  73. 'accuracy' => 'required|numeric|between:0,1000000',
  74. 'city' => 'string|max:100',
  75. 'state' => 'string|max:100',
  76. 'country' => 'required|string|max:50',
  77. ]);
  78. if($validator->fails()){
  79. return $this->responseController->makeResponse(
  80. true,
  81. "Se encontraron uno o más errores.",
  82. $this->responseController->makeErrors(
  83. $validator->errors()->messages()
  84. ),
  85. 401
  86. );
  87. }
  88. $form = $request->all();
  89. $idUser = $this->encryptionController->decrypt($form['id']);
  90. if(!$idUser){
  91. return $this->responseController->makeResponse(true, "La ID del usuario no está encriptado correctamente.", [], 400);
  92. }
  93. $usr = DB::table('S002V01TUSUA')->where([
  94. ['USUA_NULI', '=', $form['linea']],
  95. ['USUA_IDUS', '=', $idUser]
  96. ])->first();
  97. if(is_null($usr)){
  98. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  99. }
  100. $now = $this->functionsController->now();
  101. $nowStr = $now->toDateTimeString();
  102. $ipv = $request->ip();
  103. $v4 = filter_var($ipv, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? true : false;
  104. $state = isset($login['state']) ? $login['state'] : '-';
  105. //Se obtiene el dispositivo utilizado
  106. $agent = new Agent();
  107. $device = 'Desconocido';
  108. if($agent->isDesktop()) $device = 'PC';
  109. else if($agent->device()) $device = $agent->device();
  110. //Se obtiene el SO utilizado y la versión del mismo
  111. $platform = $agent->platform() ? $agent->platform() : 'Desconocido';
  112. $version = 'N/A';
  113. if($platform != 'Desconocido') $version = $agent->version($platform);
  114. //Se obtiene el navegador web utilizado
  115. $browser = $agent->browser() ? $agent->browser() : 'Desconocido';
  116. $idLastConn = DB::table('S002V01TBIAC')->insertGetId([
  117. 'BIAC_NULI' => $form['linea'],
  118. 'BIAC_IDUS' => $idUser,
  119. 'BIAC_FECO' => $nowStr,
  120. 'BIAC_IPV4' => $v4 ? $ipv : null,
  121. 'BIAC_IPV6' => !$v4 ? $ipv : null,
  122. 'BIAC_LATI' => $form['latitude'],
  123. 'BIAC_LONG' => $form['longitude'],
  124. 'BIAC_PREC' => $form['accuracy'],
  125. 'BIAC_CIUD' => $form['city'],
  126. 'BIAC_ESTA' => $state,
  127. 'BIAC_PAIS' => $form['country'],
  128. 'BIAC_DISP' => $device,
  129. 'BIAC_SIOP' => $platform,
  130. 'BIAC_VSOP' => $version,
  131. 'BIAC_NAVE' => $browser,
  132. ]);
  133. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update(['USUA_ULCO' => $idLastConn]);
  134. $actions = DB::getQueryLog();
  135. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  136. $idac = $this->functionsController->registerActivity(
  137. $form['linea'],
  138. 'S002V01M01ADSI',
  139. 'S002V01F01MAUS',
  140. 'S002V01P01MOCO',
  141. 'Registró',
  142. "El usuario $name (" . $usr->USUA_IDUS . ") registró su última conexión al sistema.",
  143. $idUser,
  144. $nowStr,
  145. );
  146. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  147. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  148. }
  149. public function getCatalogues($idUser, $line){
  150. DB::enableQueryLog();
  151. $idUser = $this->encryptionController->decrypt($idUser);
  152. if(!$idUser){
  153. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  154. }
  155. $usr = DB::table('S002V01TUSUA')->where([
  156. ['USUA_IDUS', '=', $idUser],
  157. ['USUA_NULI', '=', $line]
  158. ])->first();
  159. if(is_null($usr)){
  160. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  161. }
  162. $catalogues = DB::table('S002V01TCATA')->select(
  163. 'CATA_IDCA AS IDCATALOGO',
  164. 'CATA_TICA AS TIPOCATALOGO',
  165. 'CATA_VERS AS VERSION',
  166. 'CATA_ARRE AS ADJUNTOS',
  167. 'CATA_USRE AS USUARIOREGISTRO',
  168. 'CATA_FERE AS FECHAREGISTRO',
  169. )->where([
  170. ['CATA_NULI', '=', $line],
  171. ['CATA_ESTA', '=', 'Activo']
  172. ])->get()->all();
  173. $cataloguesF = [];
  174. foreach($catalogues as $catalogue){
  175. $usrReg = DB::table('S002V01TUSUA')->where([
  176. ['USUA_NULI', '=', $line],
  177. ['USUA_IDUS', '=', $catalogue->USUARIOREGISTRO],
  178. ])->first();
  179. $idReg = $catalogue->USUARIOREGISTRO;
  180. $catalogue->USUARIOREGISTRO = $this->functionsController->joinName(
  181. $usrReg->USUA_NOMB,
  182. $usrReg->USUA_APPA,
  183. $usrReg->USUA_APMA
  184. ) . " ($idReg)";
  185. $cataloguesF[] = $catalogue;
  186. }
  187. $now = $this->functionsController->now();
  188. $nowStr = $now->toDateTimeString();
  189. $actions = DB::getQueryLog();
  190. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  191. $idac = $this->functionsController->registerActivity(
  192. $line,
  193. 'S002V01M01ADSI',
  194. 'S002V01F10AGCA',
  195. 'S002V01P01HICA',
  196. 'Consulta',
  197. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los catálogos registrados.",
  198. $idUser,
  199. $nowStr
  200. );
  201. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  202. return $this->responseController->makeResponse(false, 'EXITO', $cataloguesF);
  203. }
  204. public function getUserConnections($id, $idUser, $line){
  205. DB::enableQueryLog();
  206. $idUser = $this->encryptionController->decrypt($idUser);
  207. if(!$idUser){
  208. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente.', [], 400);
  209. }
  210. $usr = DB::table('S002V01TUSUA')->where([
  211. ['USUA_NULI', '=', $line],
  212. ['USUA_IDUS', '=', $idUser]
  213. ])->first();
  214. if(is_null($usr)){
  215. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  216. }
  217. $id = $this->encryptionController->decrypt($id);
  218. if(!$id){
  219. return $this->responseController->makeResponse(true, "El ID del usuario que desea consultar no está encriptado correctamente.", [], 400);
  220. }
  221. $usrCons = DB::table('S002V01TUSUA')->where([
  222. ['USUA_NULI', '=', $line],
  223. ['USUA_IDUS', '=', $id]
  224. ])->first();
  225. if(is_null($usrCons)){
  226. return $this->responseController->makeResponse(true, 'El usuario consultado no existe.', [], 404);
  227. }
  228. $connections = DB::table('S002V01TBIAC')->select(
  229. 'BIAC_IPV4 AS IP4',
  230. 'BIAC_IPV6 AS IP6',
  231. 'BIAC_FECO AS FECHA',
  232. 'BIAC_LATI AS LATITUD',
  233. 'BIAC_LONG AS LONGITUD',
  234. 'BIAC_PREC AS PRECISION',
  235. 'BIAC_CIUD AS CIUDAD',
  236. 'BIAC_ESTA AS ESTADO',
  237. 'BIAC_PAIS AS PAIS',
  238. 'BIAC_DISP AS DISPOSITIVO',
  239. 'BIAC_SIOP AS SITEMAOPERATIVO',
  240. 'BIAC_VSOP AS VERSIONSO',
  241. 'BIAC_NAVE AS NAVEGADOR',
  242. )->where([
  243. ['BIAC_IDUS', '=', $id],
  244. ['BIAC_NULI', '=', $line]
  245. ])->orderBy('BIAC_FECO', 'desc')->get()->all();
  246. $responseArr = [
  247. 'NOMBRE' => $usrCons->USUA_NOMB,
  248. 'APPAT' => $usrCons->USUA_APPA,
  249. 'APMAT' => $usrCons->USUA_APMA,
  250. 'ULTCON' => $usrCons->USUA_ULCO,
  251. 'HISTORIAL' => $connections
  252. ];
  253. $now = $this->functionsController->now();
  254. $nowStr = $now->toDateTimeString();
  255. $actions = DB::getQueryLog();
  256. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  257. $nameCons = $this->functionsController->joinName($usrCons->USUA_NOMB, $usrCons->USUA_APPA, $usrCons->USUA_APMA);
  258. $idac = $this->functionsController->registerActivity(
  259. $line,
  260. 'S002V01M01ADSI',
  261. 'S002V01F01MAUS',
  262. 'S002V01P02HICO',
  263. 'Consulta',
  264. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las conexiones del usuario $nameCons ($id).",
  265. $idUser,
  266. $nowStr,
  267. );
  268. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  269. return $this->responseController->makeResponse(false, "EXITO", $responseArr);
  270. }
  271. public function getLastActions($idUser, $line){
  272. DB::enableQueryLog();
  273. $idUser = $this->encryptionController->decrypt($idUser);
  274. if(!$idUser){
  275. return $this->responseController->makeResponse(true, "El ID el usuario que realizó la petición no está encriptado correctamente.", [], 400);
  276. }
  277. $usr = DB::table('S002V01TUSUA')->where([
  278. ['USUA_IDUS', '=', $idUser],
  279. ['USUA_NULI', '=', $line]
  280. ])->first();
  281. if(is_null($usr)){
  282. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  283. }
  284. $lastActions = DB::table('S002V01TUSUA')->leftJoin('S002V01TACCI', 'USUA_ULAC', '=', 'ACCI_IDAC')->select(
  285. 'USUA_IDUS AS IDUSUARIO',
  286. 'USUA_NOMB AS NOMBRE',
  287. 'USUA_APPA AS APEPAT',
  288. 'USUA_APMA AS APEMAT',
  289. 'ACCI_IDMO AS IDMODULO',
  290. 'ACCI_IDSM AS IDSUBMODULO',
  291. 'ACCI_IDFU AS IDFUNCION',
  292. 'ACCI_IDPA AS IDPANTALLA',
  293. 'ACCI_TIAC AS TIPOACCION',
  294. 'ACCI_DESC AS DESCRIPCION',
  295. 'ACCI_FEAC AS FECHAACCION',
  296. )->get()->all();
  297. $now = $this->functionsController->now();
  298. $nowStr = $now->toDateTimeString();
  299. $actions = DB::getQueryLog();
  300. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  301. $idac = $this->functionsController->registerActivity(
  302. $line,
  303. 'S002V01M01ADSI',
  304. 'S002V01F02SAUS',
  305. 'S002V01P01MOAC',
  306. 'Consulta',
  307. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las últimas acciónes realizadas.",
  308. $idUser,
  309. $nowStr
  310. );
  311. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  312. return $this->responseController->makeResponse(false, 'EXITO', $lastActions);
  313. }
  314. public function getUserActions($id, $idUser, $line){
  315. DB::enableQueryLog();
  316. $id = $this->encryptionController->decrypt($id);
  317. if(!$id){
  318. return $this->responseController->makeResponse(true, 'El ID del usuario que desea consultar no está encriptado correctamente.', [], 400);
  319. }
  320. $idUser = $this->encryptionController->decrypt($idUser);
  321. if(!$idUser){
  322. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  323. }
  324. $usr = DB::table('S002V01TUSUA')->where([
  325. ['USUA_IDUS', '=', $idUser],
  326. ['USUA_NULI', '=', $line]
  327. ])->first();
  328. if(is_null($usr)){
  329. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  330. }
  331. $userInfo = DB::table('S002V01TUSUA')->select(
  332. 'USUA_IDUS AS IDUSUARIO',
  333. 'USUA_NOMB AS NOMBRE',
  334. 'USUA_APPA AS APEPAT',
  335. 'USUA_APMA AS APEMAT'
  336. )->where([
  337. ['USUA_IDUS', '=', $id],
  338. ['USUA_NULI', '=', $line],
  339. ])->get()->first();
  340. if(is_null($userInfo)){
  341. return $this->responseController->makeResponse(true, 'El usuario solicitado no existe.', [], 404);
  342. }
  343. $actions = DB::table('S002V01TACCI')->select(
  344. 'MODU_NOMO AS MODULO',
  345. 'SUBM_NOMB AS SUBMODULO',
  346. 'FUNC_NOMB AS FUNCION',
  347. 'PANT_NOMB AS PANTALLA',
  348. 'ACCI_TIAC AS TIPOACCION',
  349. 'ACCI_DESC AS DESCRIPCION',
  350. 'ACCI_FEAC AS FECHA',
  351. )->leftJoin('S002V01TMODU', 'ACCI_IDMO', '=', 'MODU_IDMO')
  352. ->leftJoin('S002V01TSUBM', 'ACCI_IDSM', '=', 'SUBM_IDSM')
  353. ->leftJoin('S002V01TPANT', 'ACCI_IDPA', '=', 'PANT_IDPA')
  354. ->leftJoin('S002V01TFUNC', 'ACCI_IDFU', '=', 'FUNC_IDFU')->where([
  355. ['ACCI_IDUS', '=', $id],
  356. ['ACCI_NULI', '=', $line],
  357. ])->orderBy('ACCI_FEAC', 'desc')->get()->all();
  358. $userInfo->HISTORIAL = $actions;
  359. $now = $this->functionsController->now();
  360. $nowStr = $now->toDateTimeString();
  361. $actions = DB::getQueryLog();
  362. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  363. $nameCons = $this->functionsController->joinName($userInfo->NOMBRE, $userInfo->APEPAT, $userInfo->APEMAT);
  364. $idac = $this->functionsController->registerActivity(
  365. $line,
  366. 'S002V01M01ADSI',
  367. 'S002V01F02SAUS',
  368. 'S002V01P02HIAC',
  369. 'Consulta',
  370. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las acciones del usuario $nameCons (" . $userInfo->IDUSUARIO . ")",
  371. $idUser,
  372. $nowStr
  373. );
  374. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  375. return $this->responseController->makeResponse(false, 'EXITO', $userInfo);
  376. }
  377. public function readCatalogue($id, $idUser, $line){
  378. DB::enableQueryLog();
  379. $id = $this->encryptionController->decrypt($id);
  380. if(!$id){
  381. return $this->responseController->makeResponse(true, "El ID del catálogo no fue encriptado correctamente");
  382. }
  383. $idUser = $this->encryptionController->decrypt($idUser);
  384. if(!$idUser){
  385. return $this->responseController->makeResponse(true, "El ID del usuario no fue encriptado correctamente");
  386. }
  387. $usr = DB::table('S002V01TUSUA')->where([
  388. ['USUA_IDUS', '=', $idUser],
  389. ['USUA_NULI', '=', $line]
  390. ])->first();
  391. if(is_null($usr)){
  392. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  393. }
  394. $idArr = explode("-", $id);
  395. $idArr2 = explode("=", end($idArr));
  396. $catalogue = DB::table('S002V01TAFAL')->where([
  397. ['AFAL_NULI', '=', $idArr[0]],
  398. ['AFAL_COMO', '=', $idArr[1]],
  399. ['AFAL_CLDO', '=', $idArr[2]],
  400. ['AFAL_FECR', '=', $idArr[3]],
  401. ['AFAL_NUSE', '=', $idArr2[0]],
  402. ['AFAL_NUVE', '=', $idArr2[1]],
  403. ])->first();
  404. if(is_null($catalogue)){
  405. return $this->responseController->makeResponse(true, 'El catálogo solicitado no existe.', [], 404);
  406. }
  407. $now = $this->functionsController->now();
  408. $nowStr = $now->toDateTimeString();
  409. $response = [
  410. "IDCATALOGO" => $this->encryptionController->encrypt($id),
  411. "EXTENSION" => $catalogue->AFAL_EXTE,
  412. "FECHA" => $now->timestamp
  413. ];
  414. copy($catalogue->AFAL_UBIC, 'C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public_files\\' . $id);
  415. $actions = DB::getQueryLog();
  416. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  417. $idac = $this->functionsController->registerActivity(
  418. $line,
  419. 'S002V01M01ADSI',
  420. 'S002V01F10AGCA',
  421. 'S002V01P01HICA',
  422. 'Consulta',
  423. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo $id.",
  424. $idUser,
  425. $nowStr,
  426. );
  427. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  428. return $this->responseController->makeResponse(false, "EXITO", $response);
  429. }
  430. public function getAdvices($idUser, $line){
  431. DB::enableQueryLog();
  432. $idUser = $this->encryptionController->decrypt($idUser);
  433. if(!$idUser){
  434. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  435. }
  436. $usr = DB::table('S002V01TUSUA')->where([
  437. ['USUA_IDUS', '=', $idUser],
  438. ['USUA_NULI', '=', $line]
  439. ])->first();
  440. if(is_null($usr)){
  441. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  442. }
  443. $advices = DB::table('S002V01TAVIS')->select(
  444. 'AVIS_IDAV AS IDAVISO',
  445. 'AVIS_TIAV AS TITULO',
  446. 'AVIS_CADU AS CADUCIDAD',
  447. DB::raw("IF(
  448. AVIS_ESTA != 'Activo',
  449. AVIS_ESTA,
  450. IF(
  451. NOW() > AVIS_CADU,
  452. 'Caducado',
  453. AVIS_ESTA
  454. )
  455. ) AS ESTATUS"),
  456. )->orderBy('AVIS_IDAV', 'asc')->get()->all();
  457. foreach($advices as $key=>$advice){
  458. $advice->IDAVISO = $this->encryptionController->encrypt($advice->IDAVISO);
  459. $advices[$key] = $advice;
  460. }
  461. $now = $this->functionsController->now();
  462. $nowStr = $now->toDateTimeString();
  463. $actions = DB::getQueryLog();
  464. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  465. $idac = $this->functionsController->registerActivity(
  466. $line,
  467. 'S002V01M01ADSI',
  468. 'S002V01F03CRAV',
  469. 'S002V01P01HIAV',
  470. 'Consulta',
  471. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los avisos registrados.",
  472. $idUser,
  473. $nowStr
  474. );
  475. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  476. return $this->responseController->makeResponse(false, 'EXITO', $advices);
  477. }
  478. public function getAdvice($idAdvice, $idUser, $line){
  479. DB::enableQueryLog();
  480. $idUser = $this->encryptionController->decrypt($idUser);
  481. if(!$idUser){
  482. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  483. }
  484. $usr = DB::table('S002V01TUSUA')->where([
  485. ['USUA_IDUS', '=', $idUser],
  486. ['USUA_NULI', '=', $line]
  487. ])->first();
  488. if(is_null($usr)){
  489. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  490. }
  491. $idAdvice = $this->encryptionController->decrypt($idAdvice);
  492. if(!$idAdvice){
  493. return $this->responseController->makeResponse(true, 'El ID del aviso que consultó no está encriptado correctamente.', [], 400);
  494. }
  495. $advice = DB::table('S002V01TAVIS')->select([
  496. 'AVIS_IDAV AS IDAVISO',
  497. 'AVIS_TIAV AS TITULO',
  498. 'AVIS_COAV AS CONTENIDO',
  499. 'AVIS_CADU AS CADUCIDAD',
  500. 'AVIS_ALAV AS AUDIENCIA',
  501. 'AVIS_ADJU AS ADJUNTOS',
  502. DB::raw("IF(
  503. AVIS_ESTA != 'Activo',
  504. AVIS_ESTA,
  505. IF(
  506. NOW() > AVIS_CADU,
  507. 'Caducado',
  508. AVIS_ESTA
  509. )
  510. ) AS ESTADO"),
  511. 'AVIS_FERE AS FECREG',
  512. 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"),
  513. 'AVIS_FEMO AS FECMOD',
  514. 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")
  515. ])->where([
  516. ['AVIS_NULI', '=', $line],
  517. ['AVIS_IDAV', '=', $idAdvice]
  518. ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'AVIS_USRE')
  519. ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'AVIS_USMO')->first();
  520. if(is_null($advice)){
  521. return $this->responseController->makeResponse(true, 'El aviso consultado no existe.', [], 404);
  522. }else if($advice->ESTADO != 'Activo'){
  523. return $this->responseController->makeResponse(true, 'El aviso consultado no está disponible.', [], 401);
  524. }
  525. $caduStr = $advice->CADUCIDAD;
  526. $caduObj = new Carbon($caduStr);
  527. $now = $this->functionsController->now();
  528. if($now->gt($caduObj)){
  529. return $this->responseController->makeResponse(true, 'El aviso consultado está caducado.', [], 401);
  530. }
  531. $attachedArr = json_decode($advice->ADJUNTOS, true);
  532. $attachedF = [];
  533. foreach($attachedArr as $fileCode){
  534. $nameArr = explode('=', $fileCode);
  535. $idArr = explode('-', $nameArr[0]);
  536. $file = DB::table('S002V01TAFAL')->where([
  537. ['AFAL_NULI', '=', $idArr[0]],
  538. ['AFAL_COMO', '=', $idArr[1]],
  539. ['AFAL_CLDO', '=', $idArr[2]],
  540. ['AFAL_FECR', '=', $idArr[3]],
  541. ['AFAL_NUSE', '=', $idArr[4]],
  542. ['AFAL_NUVE', '=', $nameArr[1]],
  543. ])->first();
  544. $attachedF[] = [
  545. 'id' => $this->encryptionController->encrypt($fileCode),
  546. 'name' => $file->AFAL_NOAR . '.' . $file->AFAL_EXTE,
  547. 'size' => $file->AFAL_TAMA
  548. ];
  549. }
  550. $audienceArr = json_decode($advice->AUDIENCIA, true);
  551. foreach($audienceArr as $key=>$item){
  552. $itemName = '';
  553. if($item['type'] == 'user'){
  554. $user = DB::table('S002V01TUSUA')->where([
  555. ['USUA_NULI', '=', $line],
  556. ['USUA_IDUS', '=', $item['id']]
  557. ])->first();
  558. $itemName = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
  559. }else{
  560. $profile = DB::table('S002V01TPERF')->where([
  561. ['PERF_NULI', '=', $line],
  562. ['PERF_IDPE', '=', $item['id']]
  563. ])->first();
  564. $itemName = $profile->PERF_NOPE;
  565. }
  566. $item['name'] = $itemName;
  567. $item['id'] = $this->encryptionController->encrypt($item['id']);
  568. $audienceArr[$key] = $item;
  569. }
  570. $advice->AUDIENCIA = json_encode($audienceArr);
  571. $advice->ADJUNTOS = json_encode($attachedF);
  572. $advice->IDAVISO = $this->encryptionController->encrypt($advice->IDAVISO);
  573. $actions = DB::getQueryLog();
  574. $nowStr = $now->toDateTimeString();
  575. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  576. $idac = $this->functionsController->registerActivity(
  577. $line,
  578. 'S002V01M01ADSI',
  579. 'S002V01F03CRAV',
  580. 'S002V01P01HIAV',
  581. 'Consulta',
  582. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el aviso " . $advice->TITULO . " ($idAdvice).",
  583. $idUser,
  584. $nowStr
  585. );
  586. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  587. return $this->responseController->makeResponse(false, 'EXITO', $advice);
  588. }
  589. public function publishAdvice(Request $request){
  590. DB::enableQueryLog();
  591. $validator = Validator::make($request->all(), [
  592. 'id_user' => 'required|string',
  593. 'linea' => 'required|integer',
  594. 'titulo' => 'required|string|max:100',
  595. 'caducidad' => 'required|date_format:Y-m-d H:i:s',
  596. 'contenido' => 'required|string',
  597. 'audiencia' => 'required|json',
  598. 'archivos' => 'required|json',
  599. ]);
  600. if($validator->fails()){
  601. return $this->responseController->makeResponse(
  602. true,
  603. "Se encontraron uno o más errores.",
  604. $this->responseController->makeErrors(
  605. $validator->errors()->messages()
  606. ),
  607. 401
  608. );
  609. }
  610. $advice = $request->all();
  611. $idUser = $this->encryptionController->decrypt($advice['id_user']);
  612. if(!$idUser){
  613. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la petición no fue encriptado correctamente", [], 400);
  614. }
  615. $usr = DB::table('S002V01TUSUA')->where([
  616. ['USUA_IDUS', '=', $idUser],
  617. ['USUA_NULI', '=', $advice['linea']]
  618. ])->first();
  619. if(is_null($usr)){
  620. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  621. }
  622. $audienceArr = json_decode($advice['audiencia'], true);
  623. $audienceArrFn = [];
  624. foreach($audienceArr as $key=>$item){
  625. $itemArr = explode('-', $item);
  626. if(count($itemArr) != 2){
  627. return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de audiencia tiene un formáto inválido.", [], 400);
  628. }
  629. $idElementDec = $this->encryptionController->decrypt($itemArr[1]);
  630. if(!$idElementDec){
  631. return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de audiencia no fue encriptado correctamente.", [], 400);
  632. }
  633. $element = null;
  634. if($itemArr[0] == 'prof'){
  635. $element = DB::table('S002V01TPERF')->where([
  636. ['PERF_NULI', '=', $advice['linea']],
  637. ['PERF_IDPE', '=', $idElementDec]
  638. ])->first();
  639. }else{
  640. $element = DB::table('S002V01TUSUA')->where([
  641. ['USUA_NULI', '=', $advice['linea']],
  642. ['USUA_IDUS', '=', $idElementDec]
  643. ])->first();
  644. }
  645. if(is_null($element)){
  646. return $this->responseController->makeResponse(true, "El elemento en la posición $key no existe.", [], 404);
  647. }
  648. $audienceArrFn[] = [
  649. 'type' => $itemArr[0],
  650. 'id' => $idElementDec
  651. ];
  652. }
  653. $audienceStr = json_encode($audienceArrFn);
  654. $filesArr = json_decode($advice['archivos'], true);
  655. $attachedArr = [];
  656. foreach($filesArr as $key=>$file){
  657. $idFileDec = $this->encryptionController->decrypt($file['id']);
  658. if(!$idFileDec){
  659. return $this->responseController->makeResponse(true, "El ID del archivo en la posición $key del arreglo de adjuntos no fue encriptado correctamente.", [], 400);
  660. }
  661. $document = DB::table('S002V01TARTE')->where([
  662. ['ARTE_IDAR', '=', $idFileDec],
  663. ['ARTE_NULI', '=', $advice['linea']]
  664. ])->first();
  665. if(is_null($document)){
  666. return $this->responseController->makeResponse(true, "El archivo en la posición $key del arreglo de adjuntos no existe.", [], 404);
  667. }else if($document->ARTE_ESTA == 'Eliminado'){
  668. return $this->responseController->makeResponse(true, "El archivo en la posición $key del arreglo de adjuntos está eliminado.", [], 404);
  669. }
  670. $fileRes = $this->documentManagementController->moveFinalFile(
  671. $advice['linea'],
  672. 'ADSI',
  673. 'AV',
  674. $document,
  675. $idUser
  676. );
  677. if(!$fileRes[0]){
  678. return $this->responseController->makeResponse(true, "El archivo en la posición $key no pudo ser procesado: $fileRes[1].", [], 400);
  679. }
  680. $attachedArr[] = $fileRes[1];
  681. }
  682. $now = $this->functionsController->now();
  683. $nowStr = $now->toDateTimeString();
  684. $attachedStr = json_encode($attachedArr);
  685. $idav = DB::table('S002V01TAVIS')->insertGetId([
  686. 'AVIS_NULI' => $advice['linea'],
  687. 'AVIS_TIAV' => $advice['titulo'],
  688. 'AVIS_COAV' => $advice['contenido'],
  689. 'AVIS_ALAV' => $audienceStr,
  690. 'AVIS_ADJU' => $attachedStr,
  691. 'AVIS_CADU' => $advice['caducidad'],
  692. 'AVIS_FERE' => $nowStr,
  693. 'AVIS_USRE' => $idUser
  694. ]);
  695. $actions = DB::getQueryLog();
  696. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  697. $idac = $this->functionsController->registerActivity(
  698. $advice['linea'],
  699. 'S002V01M01ADSI',
  700. 'S002V01F03CRAV',
  701. 'S002V01P02CNAV',
  702. 'Registro',
  703. "El usuario $name (" . $usr->USUA_IDUS . ") registró un nuevo aviso.",
  704. $idUser,
  705. $nowStr,
  706. );
  707. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $advice['linea']);
  708. return $this->responseController->makeresponse(false, "EXITO", ['idav' => $this->encryptionController->encrypt($idav)]);
  709. }
  710. public function updateAdvice(Request $request){
  711. DB::enableQueryLog();
  712. $validator = Validator::make($request->all(), [
  713. 'id_user' => 'required|string',
  714. 'id_advice' =>'required|string',
  715. 'linea' => 'required|integer',
  716. 'titulo' => 'required|string|max:100',
  717. 'caducidad' => 'required|date_format:Y-m-d H:i:s',
  718. 'contenido' => 'required|string',
  719. 'audiencia' => 'required|json',
  720. ]);
  721. if($validator->fails()){
  722. return $this->responseController->makeResponse(
  723. true,
  724. "Se encontraron uno o más errores.",
  725. $this->responseController->makeErrors(
  726. $validator->errors()->messages()
  727. ),
  728. 401
  729. );
  730. }
  731. $form = $request->all();
  732. $idUser = $this->encryptionController->decrypt($form['id_user']);
  733. if(!$idUser){
  734. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
  735. }
  736. $usr = DB::table('S002V01TUSUA')->where([
  737. ['USUA_IDUS', '=', $idUser],
  738. ['USUA_NULI', '=', $form['linea']]
  739. ])->first();
  740. if(is_null($usr)){
  741. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  742. }
  743. $idAdvice = $this->encryptionController->decrypt($form['id_advice']);
  744. if(!$idAdvice){
  745. return $this->responseController->makeResponse(true, "El ID del aviso no fue encriptado correctamente.", [], 401);
  746. }
  747. $advice = DB::table('S002V01TAVIS')->where([
  748. ['AVIS_NULI', '=', $form['linea']],
  749. ['AVIS_IDAV', '=', $idAdvice]
  750. ])->first();
  751. if(is_null($advice)){
  752. return $this->responseController->makeResponse(true, 'El aviso seleccionado no está registrado', [], 404);
  753. }
  754. $audienceArr = json_decode($form['audiencia'], true);
  755. $audienceArrFn = [];
  756. foreach($audienceArr as $key=>$item){
  757. $itemArr = explode('-', $item);
  758. if(count($itemArr) != 2){
  759. return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de audiencia tiene un formáto inválido.", [], 400);
  760. }
  761. $idElementDec = $this->encryptionController->decrypt($itemArr[1]);
  762. if(!$idElementDec){
  763. return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de audiencia no fue encriptado correctamente.", [], 400);
  764. }
  765. $element = null;
  766. if($itemArr[0] == 'prof'){
  767. $element = DB::table('S002V01TPERF')->where([
  768. ['PERF_NULI', '=', $form['linea']],
  769. ['PERF_IDPE', '=', $idElementDec]
  770. ])->first();
  771. }else{
  772. $element = DB::table('S002V01TUSUA')->where([
  773. ['USUA_NULI', '=', $form['linea']],
  774. ['USUA_IDUS', '=', $idElementDec]
  775. ])->first();
  776. }
  777. if(is_null($element)){
  778. return $this->responseController->makeResponse(true, "El elemento en la posición $key no existe.", [], 404);
  779. }
  780. $audienceArrFn[] = [
  781. 'type' => $itemArr[0],
  782. 'id' => $idElementDec
  783. ];
  784. }
  785. $audienceStr = json_encode($audienceArrFn);
  786. $now = $this->functionsController->now();
  787. $nowStr = $now->toDateTimeString();
  788. DB::table('S002V01TAVIS')->where([
  789. ['AVIS_NULI', '=', $form['linea']],
  790. ['AVIS_IDAV', '=', $idAdvice]
  791. ])->update([
  792. 'AVIS_TIAV' => $form['titulo'],
  793. 'AVIS_COAV' => $form['contenido'],
  794. 'AVIS_ALAV' => $audienceStr,
  795. 'AVIS_CADU' => $form['caducidad'],
  796. 'AVIS_FEMO' => $nowStr,
  797. 'AVIS_USMO' => $idUser,
  798. ]);
  799. $actions = DB::getQueryLog();
  800. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  801. $idac = $this->functionsController->registerActivity(
  802. $form['linea'],
  803. 'S002V01M01ADSI',
  804. 'S002V01F03CRAV',
  805. 'S002V01P03EDAV',
  806. 'Actualización',
  807. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el aviso $idAdvice.",
  808. $idUser,
  809. $nowStr,
  810. );
  811. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  812. return $this->responseController->makeresponse(false, "EXITO");
  813. }
  814. public function deleteAdvice(Request $request){
  815. DB::enableQueryLog();
  816. $validator = Validator::make($request->all(), [
  817. 'id_user' => 'required|string',
  818. 'id_advice' =>'required|string',
  819. 'linea' => 'required|integer',
  820. ]);
  821. if($validator->fails()){
  822. return $this->responseController->makeResponse(
  823. true,
  824. "Se encontraron uno o más errores.",
  825. $this->responseController->makeErrors(
  826. $validator->errors()->messages()
  827. ),
  828. 401
  829. );
  830. }
  831. $advice = $request->all();
  832. $idAdvice = $this->encryptionController->decrypt($advice['id_advice']);
  833. if(!$idAdvice){
  834. return $this->responseController->makeResponse(true, "El ID del aviso no fue encriptado correctamente.", [], 401);
  835. }
  836. $idUser = $this->encryptionController->decrypt($advice['id_user']);
  837. if(!$idUser){
  838. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
  839. }
  840. $usr = DB::table('S002V01TUSUA')->where([
  841. ['USUA_IDUS', '=', $idUser],
  842. ['USUA_NULI', '=', $advice['linea']]
  843. ])->first();
  844. if(is_null($usr)){
  845. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  846. }
  847. $now = $this->functionsController->now();
  848. $nowStr = $now->toDateTimeString();
  849. DB::table('S002V01TAVIS')->where([
  850. ['AVIS_NULI', '=', $advice['linea']],
  851. ['AVIS_IDAV', '=', $idAdvice]
  852. ])->update([
  853. 'AVIS_ESTA' => 'Eliminado',
  854. 'AVIS_FEMO' => $nowStr,
  855. 'AVIS_USMO' => $idUser,
  856. ]);
  857. $actions = DB::getQueryLog();
  858. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  859. $idac = $this->functionsController->registerActivity(
  860. $advice['linea'],
  861. 'S002V01M01ADSI',
  862. 'S002V01F03CRAV',
  863. 'S002V01P01HIAV',
  864. 'Eliminación',
  865. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el aviso $idAdvice.",
  866. $idUser,
  867. $nowStr,
  868. );
  869. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $advice['linea']);
  870. return $this->responseController->makeresponse(false, "EXITO");
  871. }
  872. public function getTwoStepsAuthUsers($idUser, $line){
  873. DB::enableQueryLog();
  874. $idUser = $this->encryptionController->decrypt($idUser);
  875. if(!$idUser){
  876. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  877. }
  878. $usr = DB::table('S002V01TUSUA')->where([
  879. ['USUA_IDUS', '=', $idUser],
  880. ['USUA_NULI', '=', $line]
  881. ])->first();
  882. if(is_null($usr)){
  883. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  884. }
  885. $usersAuth = DB::table('S002V01TUSUA')->select([
  886. 'USUA_IDUS',
  887. 'USUA_NOMB',
  888. 'USUA_APPA',
  889. 'USUA_APMA',
  890. 'USUA_FADO',
  891. ])->where('USUA_NULI', '=', $line)->get()->all();
  892. $arrAuth = [];
  893. foreach($usersAuth as $user){
  894. $name = $this->functionsController->joinName($user->USUA_NOMB, $user->USUA_APPA, $user->USUA_APMA);
  895. $authEnabled = $user->USUA_FADO == 'Si';
  896. $arrAuth[] = [
  897. 'IDUSUARIO' => $this->encryptionController->encrypt($user->USUA_IDUS),
  898. 'NOMBREUSUARIO' => $name,
  899. 'AUTHENABLED' => $authEnabled
  900. ];
  901. }
  902. $now = $this->functionsController->now();
  903. $nowStr = $now->toDateTimeString();
  904. $actions = DB::getQueryLog();
  905. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  906. $idac = $this->functionsController->registerActivity(
  907. $line,
  908. 'S002V01M01ADSI',
  909. 'S002V01F04POSE',
  910. 'S002V01P03ADPA',
  911. 'Consulta',
  912. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las autenticaciones en dos pasos de los usuarios.",
  913. $idUser,
  914. $nowStr
  915. );
  916. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  917. return $this->responseController->makeResponse(false, 'EXITO', $arrAuth);
  918. }
  919. public function setTwoStepsAuth(Request $request){
  920. DB::enableQueryLog();
  921. $validator = Validator::make($request->all(), [
  922. 'id_user' => 'required|string',
  923. 'factor_doble' => 'required|in:Si,No',
  924. 'usuario' => 'required|string',
  925. 'linea' => 'required|integer',
  926. ]);
  927. if($validator->fails()){
  928. return $this->responseController->makeResponse(
  929. true,
  930. "Se encontraron uno o más errores.",
  931. $this->responseController->makeErrors(
  932. $validator->errors()->messages()
  933. ),
  934. 401
  935. );
  936. }
  937. $form = $request->all();
  938. $idUser = $this->encryptionController->decrypt($form['id_user']);
  939. if(!$idUser){
  940. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente.", [], 401);
  941. }
  942. $usr = DB::table('S002V01TUSUA')->where([
  943. ['USUA_IDUS', '=', $idUser],
  944. ['USUA_NULI', '=', $form['linea']]
  945. ])->first();
  946. if(is_null($usr)){
  947. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  948. }
  949. $idChange = $this->encryptionController->decrypt($form['usuario']);
  950. if(!$idChange){
  951. return $this->responseController->makeResponse(true, "El ID del usuario que desea modificar no fue encriptado correctamente.", [], 401);
  952. }
  953. $usrMod = DB::table('S002V01TUSUA')->where([
  954. ['USUA_IDUS', '=', $idChange],
  955. ['USUA_NULI', '=', $form['linea']]
  956. ])->first();
  957. if(is_null($usrMod)){
  958. return $this->responseController->makeResponse(true, 'El usuario que desea actualizar no está registrado', [], 404);
  959. }
  960. $now = $this->functionsController->now();
  961. $nowStr = $now->toDateTimeString();
  962. DB::table('S002V01TUSUA')->where([
  963. ['USUA_IDUS', '=', $idChange],
  964. ['USUA_NULI', '=', $form['linea']]
  965. ])->update([
  966. 'USUA_FADO' => $form['factor_doble'],
  967. 'USUA_USMO' => $idUser,
  968. 'USUA_FEMO' => $nowStr
  969. ]);
  970. $actions = DB::getQueryLog();
  971. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  972. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  973. $idac = $this->functionsController->registerActivity(
  974. $form['linea'],
  975. 'S002V01M01ADSI',
  976. 'S002V01F04POSE',
  977. 'S002V01P03ADPA',
  978. 'Actualización',
  979. "El usuario $name (" . $usr->USUA_IDUS . ") cambió el factor de dos pasos del usuario $nameMod ($idChange).",
  980. $idUser,
  981. $nowStr,
  982. );
  983. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  984. return $this->responseController->makeresponse(false, "EXITO");
  985. }
  986. public function getPasswordFormat($idUser, $line){
  987. DB::enableQueryLog();
  988. $idUser = $this->encryptionController->decrypt($idUser);
  989. if(!$idUser){
  990. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  991. }
  992. $usr = DB::table('S002V01TUSUA')->where([
  993. ['USUA_IDUS', '=', $idUser],
  994. ['USUA_NULI', '=', $line]
  995. ])->first();
  996. if(is_null($usr)){
  997. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  998. }
  999. $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
  1000. $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
  1001. $politicsStr = file_get_contents($politicsInfoRoute);
  1002. $politicsArr = json_decode($politicsStr, true);
  1003. $now = $this->functionsController->now();
  1004. $nowStr = $now->toDateTimeString();
  1005. $passwordFormat = $politicsArr['password_format'];
  1006. $actions = DB::getQueryLog();
  1007. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1008. $idac = $this->functionsController->registerActivity(
  1009. $line,
  1010. 'S002V01M01ADSI',
  1011. 'S002V01F04POSE',
  1012. 'S002V01P01PACO',
  1013. 'Consulta',
  1014. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el formato de las contraseñas.",
  1015. $idUser,
  1016. $nowStr
  1017. );
  1018. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1019. return $this->responseController->makeResponse(false, 'EXITO', ['password_format' => $passwordFormat]);
  1020. }
  1021. public function savePasswordFormat(Request $request){
  1022. DB::enableQueryLog();
  1023. $validator = Validator::make($request->all(), [
  1024. 'id_user' => 'required|string',
  1025. 'linea' => 'required|integer',
  1026. 'min_length' => 'required|integer|between:8,30',
  1027. 'upper_enabled' => 'required|boolean',
  1028. 'min_upper' => 'required|integer|between:1,10',
  1029. 'number_enabled' => 'required|boolean',
  1030. 'min_number' => 'required|integer|between:1,10',
  1031. 'chars_enabled' => 'required|boolean',
  1032. 'min_chars' => 'required|integer|between:1,10',
  1033. ]);
  1034. if($validator->fails()){
  1035. return $this->responseController->makeResponse(
  1036. true,
  1037. "Se encontraron uno o más errores.",
  1038. $this->responseController->makeErrors(
  1039. $validator->errors()->messages()
  1040. ),
  1041. 401
  1042. );
  1043. }
  1044. $info = $request->all();
  1045. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1046. if(!$idUser){
  1047. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1048. }
  1049. $usr = DB::table('S002V01TUSUA')->where([
  1050. ['USUA_IDUS', '=', $idUser],
  1051. ['USUA_NULI', '=', $info['linea']],
  1052. ])->first();
  1053. if(is_null($usr)){
  1054. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1055. }
  1056. $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1057. if(!$filePoliticsExists){
  1058. return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
  1059. }
  1060. $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1061. $politicsArr = json_decode($politicsStr, true);
  1062. $passwordFormat = $politicsArr['password_format'];
  1063. $formatBKP = $politicsStr;
  1064. $passwordFormat['min_length'] = intval($info['min_length']);
  1065. $passwordFormat['upper_enabled'] = intval($info['upper_enabled']) == 1;
  1066. $passwordFormat['min_upper'] = intval($info['min_upper']);
  1067. $passwordFormat['number_enabled'] = intval($info['number_enabled']) == 1;
  1068. $passwordFormat['min_number'] = intval($info['min_number']);
  1069. $passwordFormat['chars_enabled'] = intval($info['chars_enabled']) == 1;
  1070. $passwordFormat['min_chars'] = intval($info['min_chars']);
  1071. $politicsArr['password_format'] = $passwordFormat;
  1072. $finalStr = json_encode($politicsArr);
  1073. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
  1074. $now = $this->functionsController->now();
  1075. $nowStr = $now->toDateTimeString();
  1076. DB::table('S002V01TAPSE')->insert([
  1077. 'APSE_NULI' => $info['linea'],
  1078. 'APSE_USMO' => $idUser,
  1079. 'APSE_FEMO' => $nowStr,
  1080. 'APSE_VAAN' => $formatBKP,
  1081. 'APSE_VAAC' => $finalStr
  1082. ]);
  1083. $actions = DB::getQueryLog();
  1084. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1085. $idac = $this->functionsController->registerActivity(
  1086. $info['linea'],
  1087. 'S002V01M01ADSI',
  1088. 'S002V01F04POSE',
  1089. 'S002V01P01PACO',
  1090. 'Actualización',
  1091. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el formato de las contraseñas.",
  1092. $idUser,
  1093. $nowStr
  1094. );
  1095. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1096. return $this->responseController->makeResponse(false, 'EXITO.');
  1097. }
  1098. public function getSessionsDuration($idUser, $line){
  1099. DB::enableQueryLog();
  1100. $idUser = $this->encryptionController->decrypt($idUser);
  1101. if(!$idUser){
  1102. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1103. }
  1104. $usr = DB::table('S002V01TUSUA')->where([
  1105. ['USUA_IDUS', '=', $idUser],
  1106. ['USUA_NULI', '=', $line]
  1107. ])->first();
  1108. if(is_null($usr)){
  1109. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1110. }
  1111. $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
  1112. $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
  1113. $politicsStr = file_get_contents($politicsInfoRoute);
  1114. $politicsArr = json_decode($politicsStr, true);
  1115. $now = $this->functionsController->now();
  1116. $nowStr = $now->toDateTimeString();
  1117. $sessionsDuration = $politicsArr['sessions_duration'];
  1118. $actions = DB::getQueryLog();
  1119. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1120. $idac = $this->functionsController->registerActivity(
  1121. $line,
  1122. 'S002V01M01ADSI',
  1123. 'S002V01F04POSE',
  1124. 'S002V01P02DUSE',
  1125. 'Consulta',
  1126. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración de duración de sesiones.",
  1127. $idUser,
  1128. $nowStr
  1129. );
  1130. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1131. return $this->responseController->makeResponse(false, 'EXITO', ['sessions_duration' => $sessionsDuration]);
  1132. }
  1133. public function saveSessionsDuration(Request $request){
  1134. DB::enableQueryLog();
  1135. $validator = Validator::make($request->all(), [
  1136. 'id_user' => 'required|string',
  1137. 'linea' => 'required|integer',
  1138. 'days' => 'required|integer|max:30',
  1139. 'hours' => 'required|integer|max:23',
  1140. 'minutes' => 'required|integer|max:59',
  1141. 'seconds' => 'required|integer|max:59',
  1142. ]);
  1143. if($validator->fails()){
  1144. return $this->responseController->makeResponse(
  1145. true,
  1146. "Se encontraron uno o más errores.",
  1147. $this->responseController->makeErrors(
  1148. $validator->errors()->messages()
  1149. ),
  1150. 401
  1151. );
  1152. }
  1153. $info = $request->all();
  1154. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1155. if(!$idUser){
  1156. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1157. }
  1158. $usr = DB::table('S002V01TUSUA')->where([
  1159. ['USUA_IDUS', '=', $idUser],
  1160. ['USUA_NULI', '=', $info['linea']],
  1161. ])->first();
  1162. if(is_null($usr)){
  1163. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1164. }
  1165. $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1166. if(!$filePoliticsExists){
  1167. return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
  1168. }
  1169. $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1170. $politicsArr = json_decode($politicsStr, true);
  1171. $sessionsDuration = $politicsArr['sessions_duration'];
  1172. $formatBKP = $politicsStr;
  1173. $sessionsDuration['days'] = intval($info['days']);
  1174. $sessionsDuration['hours'] = intval($info['hours']);
  1175. $sessionsDuration['minutes'] = intval($info['minutes']);
  1176. $sessionsDuration['seconds'] = intval($info['seconds']);
  1177. $politicsArr['sessions_duration'] = $sessionsDuration;
  1178. $finalStr = json_encode($politicsArr);
  1179. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
  1180. $now = $this->functionsController->now();
  1181. $nowStr = $now->toDateTimeString();
  1182. DB::table('S002V01TAPSE')->insert([
  1183. 'APSE_NULI' => $info['linea'],
  1184. 'APSE_USMO' => $idUser,
  1185. 'APSE_FEMO' => $nowStr,
  1186. 'APSE_VAAN' => $formatBKP,
  1187. 'APSE_VAAC' => $finalStr
  1188. ]);
  1189. $actions = DB::getQueryLog();
  1190. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1191. $idac = $this->functionsController->registerActivity(
  1192. $info['linea'],
  1193. 'S002V01M01ADSI',
  1194. 'S002V01F04POSE',
  1195. 'S002V01P02DUSE',
  1196. 'Actualización',
  1197. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la duración de las sesiones.",
  1198. $idUser,
  1199. $nowStr
  1200. );
  1201. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1202. return $this->responseController->makeResponse(false, 'EXITO.');
  1203. }
  1204. public function getActiveSessionsNumber($idUser, $line){
  1205. DB::enableQueryLog();
  1206. $idUser = $this->encryptionController->decrypt($idUser);
  1207. if(!$idUser){
  1208. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1209. }
  1210. $usr = DB::table('S002V01TUSUA')->where([
  1211. ['USUA_IDUS', '=', $idUser],
  1212. ['USUA_NULI', '=', $line]
  1213. ])->first();
  1214. if(is_null($usr)){
  1215. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1216. }
  1217. $politicsInfoRoute = str_replace("app\Http\Controllers", "", __DIR__);
  1218. $politicsInfoRoute .= "storage\\app\\files\\security-politics.json";
  1219. $politicsStr = file_get_contents($politicsInfoRoute);
  1220. $politicsArr = json_decode($politicsStr, true);
  1221. $now = $this->functionsController->now();
  1222. $nowStr = $now->toDateTimeString();
  1223. $activeSessionsNumber = $politicsArr['active_sessions_number'];
  1224. $actions = DB::getQueryLog();
  1225. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1226. $idac = $this->functionsController->registerActivity(
  1227. $line,
  1228. 'S002V01M01ADSI',
  1229. 'S002V01F04POSE',
  1230. 'S002V01P04NSAC',
  1231. 'Consulta',
  1232. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración del número de sesiones activas.",
  1233. $idUser,
  1234. $nowStr
  1235. );
  1236. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1237. return $this->responseController->makeResponse(false, 'EXITO', ['active_sessions_number' => $activeSessionsNumber]);
  1238. }
  1239. public function saveActiveSessionsNumber(Request $request){
  1240. DB::enableQueryLog();
  1241. $validator = Validator::make($request->all(), [
  1242. 'id_user' => 'required|string',
  1243. 'linea' => 'required|integer',
  1244. 'sessions' => 'required|integer|between:1,5',
  1245. ]);
  1246. if($validator->fails()){
  1247. return $this->responseController->makeResponse(
  1248. true,
  1249. "Se encontraron uno o más errores.",
  1250. $this->responseController->makeErrors(
  1251. $validator->errors()->messages()
  1252. ),
  1253. 401
  1254. );
  1255. }
  1256. $info = $request->all();
  1257. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1258. if(!$idUser){
  1259. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1260. }
  1261. $usr = DB::table('S002V01TUSUA')->where([
  1262. ['USUA_IDUS', '=', $idUser],
  1263. ['USUA_NULI', '=', $info['linea']],
  1264. ])->first();
  1265. if(is_null($usr)){
  1266. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1267. }
  1268. $filePoliticsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1269. if(!$filePoliticsExists){
  1270. return $this->responseController->makeResponse(true, 'El archivo de politicas de seguridad no fue encontrado.', [], 500);
  1271. }
  1272. $politicsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json');
  1273. $politicsArr = json_decode($politicsStr, true);
  1274. $formatBKP = $politicsStr;
  1275. $politicsArr['active_sessions_number'] = intval($info['sessions']);
  1276. $finalStr = json_encode($politicsArr);
  1277. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\security-politics.json', $finalStr);
  1278. $now = $this->functionsController->now();
  1279. $nowStr = $now->toDateTimeString();
  1280. DB::table('S002V01TAPSE')->insert([
  1281. 'APSE_NULI' => $info['linea'],
  1282. 'APSE_USMO' => $idUser,
  1283. 'APSE_FEMO' => $nowStr,
  1284. 'APSE_VAAN' => $formatBKP,
  1285. 'APSE_VAAC' => $finalStr
  1286. ]);
  1287. $actions = DB::getQueryLog();
  1288. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1289. $idac = $this->functionsController->registerActivity(
  1290. $info['linea'],
  1291. 'S002V01M01ADSI',
  1292. 'S002V01F04POSE',
  1293. 'S002V01P04NSAC',
  1294. 'Actualización',
  1295. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el número de sesiones activas.",
  1296. $idUser,
  1297. $nowStr
  1298. );
  1299. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1300. return $this->responseController->makeResponse(false, 'EXITO.');
  1301. }
  1302. public function activateMaintenanceMode(Request $request){
  1303. DB::enableQueryLog();
  1304. $validator = Validator::make($request->all(), [
  1305. 'id_user' => 'required|string',
  1306. 'linea' => 'required|integer',
  1307. 'motivos' => 'required|string',
  1308. ]);
  1309. if($validator->fails()){
  1310. return $this->responseController->makeResponse(
  1311. true,
  1312. "Se encontraron uno o más errores.",
  1313. $this->responseController->makeErrors(
  1314. $validator->errors()->messages()
  1315. ),
  1316. 401
  1317. );
  1318. }
  1319. $info = $request->all();
  1320. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1321. if(!$idUser){
  1322. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1323. }
  1324. $usr = DB::table('S002V01TUSUA')->where([
  1325. ['USUA_IDUS', '=', $idUser],
  1326. ['USUA_NULI', '=', $info['linea']],
  1327. ])->first();
  1328. if(is_null($usr)){
  1329. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1330. }
  1331. $maintenanceModeExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1332. if(!$maintenanceModeExists){
  1333. return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
  1334. }
  1335. $maintenanceStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1336. $maintenanceArr = json_decode($maintenanceStr, true);
  1337. if($maintenanceArr['activated']){
  1338. return $this->responseController->makeResponse(true, 'El modo mantenimiento ya se encuentra activado', [], 401);
  1339. }
  1340. $now = $this->functionsController->now();
  1341. $nowStr = $now->toDateTimeString();
  1342. $idMant = DB::table('S002V01THMSA')->insertGetId([
  1343. 'HMSA_NULI' => $info['linea'],
  1344. 'HMSA_USAC' => $idUser,
  1345. 'HMSA_FEAC' => $nowStr,
  1346. 'HMSA_MOAC' => $info['motivos']
  1347. ]);
  1348. $maintenanceArr['activated'] = true;
  1349. $maintenanceArr['last_activation_id'] = $idMant;
  1350. $finalStr = json_encode($maintenanceArr);
  1351. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
  1352. $actions = DB::getQueryLog();
  1353. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1354. $idac = $this->functionsController->registerActivity(
  1355. $info['linea'],
  1356. 'S002V01M01ADSI',
  1357. 'S002V01F05MOMA',
  1358. 'S002V01P01AMMA',
  1359. 'Registro',
  1360. "El usuario $name (" . $usr->USUA_IDUS . ") activó el modo mantenimiento",
  1361. $idUser,
  1362. $nowStr
  1363. );
  1364. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1365. return $this->responseController->makeResponse(false, 'EXITO.');
  1366. }
  1367. public function deactivateMaintenanceMode(Request $request){
  1368. DB::enableQueryLog();
  1369. $validator = Validator::make($request->all(), [
  1370. 'id_user' => 'required|string',
  1371. 'linea' => 'required|integer',
  1372. 'justificacion' => 'required|string',
  1373. ]);
  1374. if($validator->fails()){
  1375. return $this->responseController->makeResponse(
  1376. true,
  1377. "Se encontraron uno o más errores.",
  1378. $this->responseController->makeErrors(
  1379. $validator->errors()->messages()
  1380. ),
  1381. 401
  1382. );
  1383. }
  1384. $info = $request->all();
  1385. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1386. if(!$idUser){
  1387. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1388. }
  1389. $usr = DB::table('S002V01TUSUA')->where([
  1390. ['USUA_IDUS', '=', $idUser],
  1391. ['USUA_NULI', '=', $info['linea']],
  1392. ])->first();
  1393. if(is_null($usr)){
  1394. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1395. }
  1396. $maintenanceModeExists = file_exists('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1397. if(!$maintenanceModeExists){
  1398. return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
  1399. }
  1400. $maintenanceStr = file_get_contents('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1401. $maintenanceArr = json_decode($maintenanceStr, true);
  1402. if(!$maintenanceArr['activated']){
  1403. return $this->responseController->makeResponse(true, 'El modo mantenimiento ya se encuentra desactivado', [], 401);
  1404. }
  1405. $maintenanceDB = DB::table('S002V01THMSA')->where([
  1406. ['HMSA_IDAC', '=', $maintenanceArr['last_activation_id']],
  1407. ['HMSA_NULI', '=', $info['linea']],
  1408. ])->first();
  1409. if(!is_null($maintenanceDB->HMSA_USDE)){
  1410. $maintenanceArr['activated'] = false;
  1411. $finalStr = json_encode($maintenanceArr);
  1412. file_put_contents('C:\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
  1413. return $this->responseController->makeResponse(true, 'El modo mantenimiento ya fue desactivado en la base de datos.', [], 500);
  1414. }
  1415. $now = $this->functionsController->now();
  1416. $nowStr = $now->toDateTimeString();
  1417. DB::table('S002V01THMSA')->where([
  1418. ['HMSA_IDAC', '=', $maintenanceArr['last_activation_id']],
  1419. ['HMSA_NULI', '=', $info['linea']],
  1420. ])->update([
  1421. 'HMSA_USDE' => $idUser,
  1422. 'HMSA_FEDE' => $nowStr,
  1423. 'HMSA_JUDE' => $info['justificacion']
  1424. ]);
  1425. $maintenanceArr['activated'] = false;
  1426. $finalStr = json_encode($maintenanceArr);
  1427. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json', $finalStr);
  1428. $actions = DB::getQueryLog();
  1429. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1430. $idac = $this->functionsController->registerActivity(
  1431. $info['linea'],
  1432. 'S002V01M01ADSI',
  1433. 'S002V01F05MOMA',
  1434. 'S002V01P01AMMA',
  1435. 'Actualización',
  1436. "El usuario $name (" . $usr->USUA_IDUS . ") desactivó el modo mantenimiento",
  1437. $idUser,
  1438. $nowStr
  1439. );
  1440. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1441. return $this->responseController->makeResponse(false, 'EXITO.');
  1442. }
  1443. public function getMaintenanceHistory($idUser, $line){
  1444. DB::enableQueryLog();
  1445. $idUser = $this->encryptionController->decrypt($idUser);
  1446. if(!$idUser){
  1447. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1448. }
  1449. $usr = DB::table('S002V01TUSUA')->where([
  1450. ['USUA_IDUS', '=', $idUser],
  1451. ['USUA_NULI', '=', $line]
  1452. ])->first();
  1453. if(is_null($usr)){
  1454. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1455. }
  1456. $history = DB::table('S002V01THMSA')->where('HMSA_NULI', '=', $line)->get()->all();
  1457. $historyF = array();
  1458. foreach($history as $val){
  1459. $activationDate = new Carbon($val->HMSA_FEAC, 'America/Mexico_city');
  1460. $deactivationDate = new Carbon($val->HMSA_FEDE, 'America/Mexico_city');
  1461. $diffDays = $deactivationDate->diffInDays($activationDate);
  1462. $activationDate->addDays($diffDays);
  1463. $diffHours = $deactivationDate->diffInHours($activationDate);
  1464. $activationDate->addHours($diffHours);
  1465. $diffMinutes = $deactivationDate->diffInMinutes($activationDate);
  1466. $activationDate->addMinutes($diffMinutes);
  1467. $diffSeconds = $deactivationDate->diffInSeconds($activationDate);
  1468. $duration = "";
  1469. if($diffDays > 0) $duration .= "$diffDays días, ";
  1470. if($diffHours > 0) $duration .= "$diffHours horas, ";
  1471. if($diffMinutes > 0) $duration .= "$diffMinutes minutos, ";
  1472. if($diffSeconds > 0) $duration .= "$diffSeconds segundos, ";
  1473. $duration = substr($duration, 0, -2);
  1474. $usac = DB::table('S002V01TUSUA')->select([
  1475. 'USUA_NOMB', 'USUA_APPA', 'USUA_APMA'
  1476. ])->where([
  1477. ['USUA_NULI', '=', $line],
  1478. ['USUA_IDUS', '=', $val->HMSA_USAC]
  1479. ])->first();
  1480. $nomUSAC = $this->functionsController->joinName($usac->USUA_NOMB, $usac->USUA_APPA, $usac->USUA_APMA);
  1481. $usde = DB::table('S002V01TUSUA')->select([
  1482. 'USUA_NOMB', 'USUA_APPA', 'USUA_APMA'
  1483. ])->where([
  1484. ['USUA_NULI', '=', $line],
  1485. ['USUA_IDUS', '=', $val->HMSA_USDE]
  1486. ])->first();
  1487. $nomUSDE = $this->functionsController->joinName($usde->USUA_NOMB, $usde->USUA_APPA, $usde->USUA_APMA);
  1488. $historyF[] = [
  1489. "IDACTIVACION" => $val->HMSA_IDAC,
  1490. "LINEA" => $val->HMSA_NULI,
  1491. "USUARIOACTIVO" => $nomUSAC . " (" . $val->HMSA_USAC . ")",
  1492. "FECHAACTIVACION" => $val->HMSA_FEAC,
  1493. "MOTIVOS" => $val->HMSA_MOAC,
  1494. "USUARIODESACTIVO" => $nomUSDE . " (" . $val->HMSA_USDE . ")",
  1495. "FECHADESACTIVACION" => $val->HMSA_FEDE,
  1496. "JUSTIFICACION" => $val->HMSA_JUDE,
  1497. "DURACION" => $duration
  1498. ];
  1499. }
  1500. $now = $this->functionsController->now();
  1501. $actions = DB::getQueryLog();
  1502. $nowStr = $now->toDateTimeString();
  1503. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1504. $idac = $this->functionsController->registerActivity(
  1505. $line,
  1506. 'S002V01M01ADSI',
  1507. 'S002V01F05MOMA',
  1508. 'S002V01P02HIMA',
  1509. 'Consulta',
  1510. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el historial de mantenimientos.",
  1511. $idUser,
  1512. $nowStr
  1513. );
  1514. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1515. return $this->responseController->makeResponse(false, 'EXITO', $historyF);
  1516. }
  1517. public function getMaintenanceStatus($idUser, $line){
  1518. DB::enableQueryLog();
  1519. $idUser = $this->encryptionController->decrypt($idUser);
  1520. if(!$idUser){
  1521. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1522. }
  1523. $usr = DB::table('S002V01TUSUA')->where([
  1524. ['USUA_IDUS', '=', $idUser],
  1525. ['USUA_NULI', '=', $line]
  1526. ])->first();
  1527. if(is_null($usr)){
  1528. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1529. }
  1530. $maintenanceModeExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1531. if(!$maintenanceModeExists){
  1532. return $this->responseController->makeResponse(true, 'El archivo de mantenimiento no fue encontrado.', [], 500);
  1533. }
  1534. $maintenanceStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\maintenance_mode.json');
  1535. $maintenanceArr = json_decode($maintenanceStr, true);
  1536. $now = $this->functionsController->now();
  1537. $nowStr = $now->toDateTimeString();
  1538. $actions = DB::getQueryLog();
  1539. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1540. $idac = $this->functionsController->registerActivity(
  1541. $line,
  1542. 'S002V01M01ADSI',
  1543. 'S002V01F05MOMA',
  1544. 'S002V01P02HIMA',
  1545. 'Consulta',
  1546. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el estado actual del modo mantenimiento.",
  1547. $idUser,
  1548. $nowStr
  1549. );
  1550. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1551. return $this->responseController->makeResponse(false, 'EXITO', ['activated' => $maintenanceArr['activated']]);
  1552. }
  1553. public function getEmailServers($idUser, $line){
  1554. DB::enableQueryLog();
  1555. $idUser = $this->encryptionController->decrypt($idUser);
  1556. if(!$idUser){
  1557. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1558. }
  1559. $usr = DB::table('S002V01TUSUA')->where([
  1560. ['USUA_IDUS', '=', $idUser],
  1561. ['USUA_NULI', '=', $line]
  1562. ])->first();
  1563. if(is_null($usr)){
  1564. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1565. }
  1566. $emailServers = DB::table('S002V01TSCEL')->where('SCEL_NULI', '=', $line)->orderBy('SCEL_PRIO')->get()->all();
  1567. $serversArr = [];
  1568. foreach($emailServers as $server){
  1569. $usal = DB::table('S002V01TUSUA')->where([
  1570. ['USUA_IDUS', '=', $server->SCEL_USAL],
  1571. ['USUA_NULI', '=', $line],
  1572. ])->first();
  1573. $usalName = $this->functionsController->joinName($usal->USUA_NOMB, $usal->USUA_APPA, $usal->USUA_APMA);
  1574. $usmo = DB::table('S002V01TUSUA')->where([
  1575. ['USUA_IDUS', '=', $server->SCEL_USMO],
  1576. ['USUA_NULI', '=', $line],
  1577. ])->first();
  1578. $usmoName = is_null($usmo) ? '-' : $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA);
  1579. $serversArr[] = [
  1580. 'USUARIO' => $server->SCEL_USUA,
  1581. 'HOST' => $server->SCEL_HOST,
  1582. 'PRIORIDAD' => $server->SCEL_PRIO,
  1583. 'USRREG' => "$usalName (" . $server->SCEL_USAL . ")",
  1584. 'FECREG' => $server->SCEL_FEAL,
  1585. 'USRMOD' => is_null($usmo) ? $usmoName : "$usalName (" . $server->SCEL_USMO . ")",
  1586. 'FECMOD' => is_null($server->SCEL_FEMO) ? '-' : $server->SCEL_FEMO,
  1587. 'ESTADO' => $server->SCEL_ESCO,
  1588. ];
  1589. }
  1590. $now = $this->functionsController->now();
  1591. $nowStr = $now->toDateTimeString();
  1592. $actions = DB::getQueryLog();
  1593. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1594. $idac = $this->functionsController->registerActivity(
  1595. $line,
  1596. 'S002V01M01ADSI',
  1597. 'S002V01F07CCEL',
  1598. 'S002V01P01CNSC',
  1599. 'Consulta',
  1600. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los servidores de correo electrónico registrados.",
  1601. $idUser,
  1602. $nowStr
  1603. );
  1604. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1605. return $this->responseController->makeResponse(false, 'EXITO', $serversArr);
  1606. }
  1607. public function registerEmailServer(Request $request){
  1608. DB::enableQueryLog();
  1609. $validator = Validator::make($request->all(), [
  1610. 'id_user' => 'required|string',
  1611. 'linea' => 'required|integer',
  1612. 'user' => 'required|string|max:50',
  1613. 'host' => 'required|string|max:50',
  1614. 'priority' => 'required|integer|between:1,100',
  1615. 'smtpsec' => 'string|max:50',
  1616. 'port' => 'required|string|max:10',
  1617. 'password' => 'required|string|max:2000',
  1618. 'timeout' => 'required|string|max:3',
  1619. 'smtpaut' => 'required|string|max:2',
  1620. 'portals' => 'required|json',
  1621. ]);
  1622. if($validator->fails()){
  1623. return $this->responseController->makeResponse(
  1624. true,
  1625. "Se encontraron uno o más errores.",
  1626. $this->responseController->makeErrors(
  1627. $validator->errors()->messages()
  1628. ),
  1629. 401
  1630. );
  1631. }
  1632. $form = $request->all();
  1633. $idUser = $this->encryptionController->decrypt($form['id_user']);
  1634. if(!$idUser){
  1635. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1636. }
  1637. $usr = DB::table('S002V01TUSUA')->where([
  1638. ['USUA_IDUS', '=', $idUser],
  1639. ['USUA_NULI', '=', $form['linea']],
  1640. ])->first();
  1641. if(is_null($usr)){
  1642. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1643. }
  1644. $now = $this->functionsController->now();
  1645. $nowStr = $now->toDateTimeString();
  1646. $smtpsec = isset($form['smtpsec']) ? $form['smtpsec'] : null;
  1647. DB::table('S002V01TSCEL')->insert([
  1648. 'SCEL_NULI' => $form['linea'],
  1649. 'SCEL_USUA' => $form['user'],
  1650. 'SCEL_HOST' => $form['host'],
  1651. 'SCEL_PRIO' => $form['priority'],
  1652. 'SCEL_SESM' => $smtpsec,
  1653. 'SCEL_PUER' => $form['port'],
  1654. 'SCEL_CONT' => $form['password'],
  1655. 'SCEL_TIES' => $form['timeout'],
  1656. 'SCEL_AUSM' => $form['smtpaut'],
  1657. 'SCEL_ADPO' => $form['portals'],
  1658. 'SCEL_USAL' => $idUser,
  1659. 'SCEL_FEAL' => $nowStr,
  1660. ]);
  1661. $actions = DB::getQueryLog();
  1662. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1663. $idac = $this->functionsController->registerActivity(
  1664. $form['linea'],
  1665. 'S002V01M01ADSI',
  1666. 'S002V01F07CCEL',
  1667. 'S002V01P01CNSC',
  1668. 'Registro',
  1669. "El usuario $name (" . $usr->USUA_IDUS . ") registró el servidor $form[host]",
  1670. $idUser,
  1671. $nowStr
  1672. );
  1673. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  1674. return $this->responseController->makeResponse(false, 'EXITO.');
  1675. }
  1676. public function getEmailServer($host, $user, $idUser, $line){
  1677. DB::enableQueryLog();
  1678. $idUser = $this->encryptionController->decrypt($idUser);
  1679. if(!$idUser){
  1680. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  1681. }
  1682. $usr = DB::table('S002V01TUSUA')->where([
  1683. ['USUA_IDUS', '=', $idUser],
  1684. ['USUA_NULI', '=', $line]
  1685. ])->first();
  1686. if(is_null($usr)){
  1687. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1688. }
  1689. $host = $this->encryptionController->decrypt($host);
  1690. if(!$host){
  1691. return $this->responseController->makeResponse(true, 'El HOST del servidor no está encriptado correctamente.', [], 400);
  1692. }
  1693. $user = $this->encryptionController->decrypt($user);
  1694. if(!$user){
  1695. return $this->responseController->makeResponse(true, 'El USUARIO del servidor no está encriptado correctamente.', [], 400);
  1696. }
  1697. $server = DB::table('S002V01TSCEL')->select([
  1698. 'SCEL_USUA AS USUARIO',
  1699. 'SCEL_HOST AS HOST',
  1700. 'SCEL_PRIO AS PRIORIDAD',
  1701. 'SCEL_SESM AS SEGSMTP',
  1702. 'SCEL_PUER AS PUERTO',
  1703. 'SCEL_CONT AS CONTRASENA',
  1704. 'SCEL_TIES AS TIEMPOESPERA',
  1705. 'SCEL_AUSM AS AUTSMTP',
  1706. 'SCEL_ADPO AS PORTALES'
  1707. ])->where([
  1708. ['SCEL_NULI', '=', $line],
  1709. ['SCEL_USUA', '=', $user],
  1710. ['SCEL_HOST', '=', $host],
  1711. ])->first();
  1712. $now = $this->functionsController->now();
  1713. $nowStr = $now->toDateTimeString();
  1714. $actions = DB::getQueryLog();
  1715. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1716. $idac = $this->functionsController->registerActivity(
  1717. $line,
  1718. 'S002V01M01ADSI',
  1719. 'S002V01F07CCEL',
  1720. 'S002V01P01CNSC',
  1721. 'Consulta',
  1722. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el servidor $host.",
  1723. $idUser,
  1724. $nowStr
  1725. );
  1726. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1727. return $this->responseController->makeResponse(false, 'EXITO', $server);
  1728. }
  1729. public function updateEmailServer(Request $request){
  1730. DB::enableQueryLog();
  1731. $validator = Validator::make($request->all(), [
  1732. 'id_user' => 'required|string',
  1733. 'linea' => 'required|integer',
  1734. 'user' => 'required|string|max:50',
  1735. 'host' => 'required|string|max:50',
  1736. 'priority' => 'required|integer|between:1,100',
  1737. 'smtpsec' => 'string|max:50',
  1738. 'port' => 'required|string|max:10',
  1739. 'password' => 'required|string|max:2000',
  1740. 'timeout' => 'required|string|max:3',
  1741. 'smtpaut' => 'required|string|max:2',
  1742. 'portals' => 'required|json',
  1743. ]);
  1744. if($validator->fails()){
  1745. return $this->responseController->makeResponse(
  1746. true,
  1747. "Se encontraron uno o más errores.",
  1748. $this->responseController->makeErrors(
  1749. $validator->errors()->messages()
  1750. ),
  1751. 401
  1752. );
  1753. }
  1754. $form = $request->all();
  1755. $idUser = $this->encryptionController->decrypt($form['id_user']);
  1756. if(!$idUser){
  1757. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1758. }
  1759. $usr = DB::table('S002V01TUSUA')->where([
  1760. ['USUA_IDUS', '=', $idUser],
  1761. ['USUA_NULI', '=', $form['linea']]
  1762. ])->first();
  1763. if(is_null($usr)){
  1764. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1765. }
  1766. $server = DB::table('S002V01TSCEL')->where([
  1767. ['SCEL_NULI', '=', $form['linea']],
  1768. ['SCEL_USUA', '=', $form['user']],
  1769. ['SCEL_HOST', '=', $form['host']],
  1770. ])->first();
  1771. if(is_null($server)){
  1772. return $this->responseController->makeResponse(true, 'El servidor que desea modificar no existe.', [], 404);
  1773. }
  1774. $now = $this->functionsController->now();
  1775. $nowStr = $now->toDateTimeString();
  1776. $smtpsec = isset($form['smtpsec']) ? $form['smtpsec'] : null;
  1777. DB::table('S002V01TSCEL')->where([
  1778. ['SCEL_NULI', '=', $form['linea']],
  1779. ['SCEL_USUA', '=', $form['user']],
  1780. ['SCEL_HOST', '=', $form['host']],
  1781. ])->update([
  1782. 'SCEL_PRIO' => $form['priority'],
  1783. 'SCEL_SESM' => $smtpsec,
  1784. 'SCEL_PUER' => $form['port'],
  1785. 'SCEL_CONT' => $form['password'],
  1786. 'SCEL_TIES' => $form['timeout'],
  1787. 'SCEL_AUSM' => $form['smtpaut'],
  1788. 'SCEL_ADPO' => $form['portals'],
  1789. 'SCEL_USMO' => $idUser,
  1790. 'SCEL_FEMO' => $nowStr
  1791. ]);
  1792. $actions = DB::getQueryLog();
  1793. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1794. $idac = $this->functionsController->registerActivity(
  1795. $form['linea'],
  1796. 'S002V01M01ADSI',
  1797. 'S002V01F07CCEL',
  1798. 'S002V01P01CNSC',
  1799. 'Actualización',
  1800. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servidor $form[host]",
  1801. $idUser,
  1802. $nowStr
  1803. );
  1804. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  1805. return $this->responseController->makeResponse(false, 'EXITO.');
  1806. }
  1807. public function deleteEmailServer(Request $request){
  1808. DB::enableQueryLog();
  1809. $validator = Validator::make($request->all(), [
  1810. 'id_user' => 'required|string',
  1811. 'linea' => 'required|integer',
  1812. 'user' => 'required|string|max:50',
  1813. 'host' => 'required|string|max:50'
  1814. ]);
  1815. if($validator->fails()){
  1816. return $this->responseController->makeResponse(
  1817. true,
  1818. "Se encontraron uno o más errores.",
  1819. $this->responseController->makeErrors(
  1820. $validator->errors()->messages()
  1821. ),
  1822. 401
  1823. );
  1824. }
  1825. $form = $request->all();
  1826. $idUser = $this->encryptionController->decrypt($form['id_user']);
  1827. if(!$idUser){
  1828. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1829. }
  1830. $usr = DB::table('S002V01TUSUA')->where([
  1831. ['USUA_IDUS', '=', $idUser],
  1832. ['USUA_NULI', '=', $form['linea']]
  1833. ])->first();
  1834. if(is_null($usr)){
  1835. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1836. }
  1837. $server = DB::table('S002V01TSCEL')->where([
  1838. ['SCEL_NULI', '=', $form['linea']],
  1839. ['SCEL_USUA', '=', $form['user']],
  1840. ['SCEL_HOST', '=', $form['host']],
  1841. ])->first();
  1842. if(is_null($server)){
  1843. return $this->responseController->makeResponse(true, 'El servidor que desea eliminar no existe.', [], 404);
  1844. }
  1845. $now = $this->functionsController->now();
  1846. $nowStr = $now->toDateTimeString();
  1847. DB::table('S002V01TSCEL')->where([
  1848. ['SCEL_NULI', '=', $form['linea']],
  1849. ['SCEL_USUA', '=', $form['user']],
  1850. ['SCEL_HOST', '=', $form['host']],
  1851. ])->update([
  1852. 'SCEL_ESCO' => 'Eliminado',
  1853. 'SCEL_USMO' => $idUser,
  1854. 'SCEL_FEMO' => $nowStr
  1855. ]);
  1856. $actions = DB::getQueryLog();
  1857. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1858. $idac = $this->functionsController->registerActivity(
  1859. $form['linea'],
  1860. 'S002V01M01ADSI',
  1861. 'S002V01F07CCEL',
  1862. 'S002V01P01CNSC',
  1863. 'Eliminación',
  1864. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el servidor $form[host]",
  1865. $idUser,
  1866. $nowStr
  1867. );
  1868. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  1869. return $this->responseController->makeResponse(false, 'EXITO.');
  1870. }
  1871. public function deactivateEmailServer(Request $request){
  1872. DB::enableQueryLog();
  1873. $validator = Validator::make($request->all(), [
  1874. 'id_user' => 'required|string',
  1875. 'linea' => 'required|integer',
  1876. 'user' => 'required|string|max:50',
  1877. 'host' => 'required|string|max:50',
  1878. 'state' => 'required|string|in:Activo,Inactivo',
  1879. ]);
  1880. if($validator->fails()){
  1881. return $this->responseController->makeResponse(
  1882. true,
  1883. "Se encontraron uno o más errores.",
  1884. $this->responseController->makeErrors(
  1885. $validator->errors()->messages()
  1886. ),
  1887. 401
  1888. );
  1889. }
  1890. $form = $request->all();
  1891. $idUser = $this->encryptionController->decrypt($form['id_user']);
  1892. if(!$idUser){
  1893. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1894. }
  1895. $usr = DB::table('S002V01TUSUA')->where([
  1896. ['USUA_IDUS', '=', $idUser],
  1897. ['USUA_NULI', '=', $form['linea']]
  1898. ])->first();
  1899. if(is_null($usr)){
  1900. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1901. }
  1902. $server = DB::table('S002V01TSCEL')->where([
  1903. ['SCEL_NULI', '=', $form['linea']],
  1904. ['SCEL_USUA', '=', $form['user']],
  1905. ['SCEL_HOST', '=', $form['host']],
  1906. ])->first();
  1907. if(is_null($server)){
  1908. return $this->responseController->makeResponse(true, 'El servidor que desea modificar no existe.', [], 404);
  1909. }
  1910. $now = $this->functionsController->now();
  1911. $nowStr = $now->toDateTimeString();
  1912. DB::table('S002V01TSCEL')->where([
  1913. ['SCEL_NULI', '=', $form['linea']],
  1914. ['SCEL_USUA', '=', $form['user']],
  1915. ['SCEL_HOST', '=', $form['host']],
  1916. ])->update([
  1917. 'SCEL_ESCO' => $form['state'],
  1918. 'SCEL_USMO' => $idUser,
  1919. 'SCEL_FEMO' => $nowStr
  1920. ]);
  1921. $actions = DB::getQueryLog();
  1922. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1923. $idac = $this->functionsController->registerActivity(
  1924. $form['linea'],
  1925. 'S002V01M01ADSI',
  1926. 'S002V01F07CCEL',
  1927. 'S002V01P01CNSC',
  1928. 'Actualización',
  1929. "El usuario $name (" . $usr->USUA_IDUS . ") cambió el estado del servidor $form[host]",
  1930. $idUser,
  1931. $nowStr
  1932. );
  1933. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  1934. return $this->responseController->makeResponse(false, 'EXITO.');
  1935. }
  1936. public function registerEmailTemplate(Request $request){
  1937. DB::enableQueryLog();
  1938. $validator = Validator::make($request->all(), [
  1939. 'id_user' => 'required|string',
  1940. 'linea' => 'required|integer',
  1941. 'module' => 'required|string|max:25',
  1942. 'submodule' => 'string|max:25',
  1943. 'function' => 'required|string|max:25',
  1944. 'screen' => 'required|string|max:25',
  1945. 'subject' => 'required|string|max:50',
  1946. 'body' => 'required|string',
  1947. ]);
  1948. if($validator->fails()){
  1949. return $this->responseController->makeResponse(
  1950. true,
  1951. "Se encontraron uno o más errores.",
  1952. $this->responseController->makeErrors(
  1953. $validator->errors()->messages()
  1954. ),
  1955. 401
  1956. );
  1957. }
  1958. $form = $request->all();
  1959. $idUser = $this->encryptionController->decrypt($form['id_user']);
  1960. if(!$idUser){
  1961. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  1962. }
  1963. $usr = DB::table('S002V01TUSUA')->where([
  1964. ['USUA_IDUS', '=', $idUser],
  1965. ['USUA_NULI', '=', $form['linea']]
  1966. ])->first();
  1967. if(is_null($usr)){
  1968. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  1969. }
  1970. $module = DB::table('S002V01TMODU')->where([
  1971. ['MODU_IDMO', '=', $form['module']],
  1972. ['MODU_NULI', '=', $form['linea']]
  1973. ])->first();
  1974. if(is_null($module)){
  1975. return $this->responseController->makeResponse(true, 'El módulo seleccionado no existe.', [], 404);
  1976. }
  1977. $hasSubmodule = isset($form['submodule']);
  1978. if($hasSubmodule){
  1979. $submodule = DB::table('S002V01TSUBM')->where([
  1980. ['SUBM_IDSM', '=', $form['submodule']],
  1981. ['SUBM_IDMO', '=', $form['module']],
  1982. ['SUBM_NULI', '=', $form['linea']],
  1983. ])->first();
  1984. if(is_null($submodule)){
  1985. return $this->responseController->makeResponse(true, 'El submódulo seleccionado no existe.', [], 404);
  1986. }
  1987. }
  1988. $submodule = $hasSubmodule ? $form['submodule'] : null;
  1989. $function = DB::table('S002V01TFUNC')->where([
  1990. ['FUNC_NULI', '=', $form['linea']],
  1991. ['FUNC_IDFU', '=', $form['function']],
  1992. ['FUNC_IDMO', '=', $form['module']],
  1993. ['FUNC_IDSM', '=', $submodule],
  1994. ])->first();
  1995. if(is_null($function)){
  1996. return $this->responseController->makeResponse(true, 'La función seleccionada no existe.', [], 404);
  1997. }
  1998. $screen = DB::table('S002V01TPANT')->where([
  1999. ['PANT_NULI', '=', $form['linea']],
  2000. ['PANT_IDPA', '=', $form['screen']],
  2001. ['PANT_IDFU', '=', $form['function']],
  2002. ])->first();
  2003. if(is_null($screen)){
  2004. return $this->responseController->makeResponse(true, 'La pantalla seleccionada no existe.', [], 404);
  2005. }
  2006. $now = $this->functionsController->now();
  2007. $nowStr = $now->toDateTimeString();
  2008. $idPlan = DB::table('S002V01TPCEL')->insertGetId([
  2009. 'PCEL_NULI' => $form['linea'],
  2010. 'PCEL_IDMO' => $form['module'],
  2011. 'PCEL_IDSM' => $submodule,
  2012. 'PCEL_IDFU' => $form['function'],
  2013. 'PCEL_IDPA' => $form['screen'],
  2014. 'PCEL_ASCO' => $form['subject'],
  2015. 'PCEL_CUCO' => $form['body'],
  2016. 'PCEL_USRE' => $idUser,
  2017. 'PCEL_FERE' => $nowStr,
  2018. ]);
  2019. $actions = DB::getQueryLog();
  2020. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2021. $idac = $this->functionsController->registerActivity(
  2022. $form['linea'],
  2023. 'S002V01M01ADSI',
  2024. 'S002V01F08CPCE',
  2025. 'S002V01P02NPEP',
  2026. 'Registro',
  2027. "El usuario $name (" . $usr->USUA_IDUS . ") registró la plantilla $form[subject] ($idPlan)",
  2028. $idUser,
  2029. $nowStr
  2030. );
  2031. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2032. return $this->responseController->makeResponse(false, 'EXITO.');
  2033. }
  2034. public function getEmailTemplates($idUser, $line){
  2035. DB::enableQueryLog();
  2036. $idUser = $this->encryptionController->decrypt($idUser);
  2037. if(!$idUser){
  2038. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2039. }
  2040. $usr = DB::table('S002V01TUSUA')->where([
  2041. ['USUA_IDUS', '=', $idUser],
  2042. ['USUA_NULI', '=', $line]
  2043. ])->first();
  2044. if(is_null($usr)){
  2045. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  2046. }
  2047. $emailTemplates = DB::table('S002V01TPCEL')->select([
  2048. 'PCEL_IDPL AS IDPLANTILLA',
  2049. 'PCEL_NULI AS LINEA',
  2050. 'MODU_NOMO AS NOMBREMODULO',
  2051. 'SUBM_NOMB AS NOMBRESUBMODULO',
  2052. 'FUNC_NOMB AS NOMBREFUNCION',
  2053. 'PANT_NOMB AS NOMBREPANTALLA',
  2054. 'PCEL_ASCO AS ASUNTO',
  2055. 'PCEL_CUCO AS CUERPO',
  2056. 'PCEL_ESTA AS ESTADO',
  2057. 'PCEL_USRE AS USUARIOREGISTRA',
  2058. 'PCEL_FERE AS FECHAREGISTRO',
  2059. 'PCEL_USMO AS USUARIOMODIFICA',
  2060. 'PCEL_FEMO AS FECHAMODIFICACION'
  2061. ])->join('S002V01TMODU', 'MODU_IDMO', '=', 'PCEL_IDMO')
  2062. ->leftJoin('S002V01TSUBM', 'SUBM_IDSM', '=', 'PCEL_IDSM')
  2063. ->join('S002V01TFUNC', 'FUNC_IDFU', '=', 'PCEL_IDFU')
  2064. ->join('S002V01TPANT', 'PANT_IDPA', '=', 'PCEL_IDPA')->where([
  2065. ['PCEL_NULI', '=', $line]
  2066. ])->orderBy('PCEL_IDPL', 'asc')->get()->all();
  2067. $emailTemplatesF = [];
  2068. foreach($emailTemplates as $template){
  2069. $usrTemplate = DB::table('S002V01TUSUA')->where([
  2070. ['USUA_NULI', '=', $line],
  2071. ['USUA_IDUS', '=', $template->USUARIOREGISTRA],
  2072. ])->first();
  2073. $idus = $template->USUARIOREGISTRA;
  2074. $template->USUARIOREGISTRA = $this->functionsController->joinName(
  2075. $usrTemplate->USUA_NOMB,
  2076. $usrTemplate->USUA_APPA,
  2077. $usrTemplate->USUA_APMA
  2078. ) . " ($idus)";
  2079. if(!is_null($template->USUARIOMODIFICA)){
  2080. $usrTemplate = DB::table('S002V01TUSUA')->where([
  2081. ['USUA_NULI', '=', $line],
  2082. ['USUA_IDUS', '=', $template->USUARIOMODIFICA],
  2083. ])->first();
  2084. $idus = $template->USUARIOMODIFICA;
  2085. $template->USUARIOMODIFICA = $this->functionsController->joinName(
  2086. $usrTemplate->USUA_NOMB,
  2087. $usrTemplate->USUA_APPA,
  2088. $usrTemplate->USUA_APMA
  2089. ) . " ($idus)";
  2090. }
  2091. $emailTemplatesF[] = $template;
  2092. }
  2093. $now = $this->functionsController->now();
  2094. $nowStr = $now->toDateTimeString();
  2095. $actions = DB::getQueryLog();
  2096. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2097. $idac = $this->functionsController->registerActivity(
  2098. $line,
  2099. 'S002V01M01ADSI',
  2100. 'S002V01F09MACS',
  2101. 'S002V01P01HIPL',
  2102. 'Consulta',
  2103. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las plantillas de correo electrónico registradas.",
  2104. $idUser,
  2105. $nowStr
  2106. );
  2107. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2108. return $this->responseController->makeResponse(false, 'EXITO', $emailTemplatesF);
  2109. }
  2110. public function getEmailTemplate($id, $idUser, $line){
  2111. DB::enableQueryLog();
  2112. $idUser = $this->encryptionController->decrypt($idUser);
  2113. if(!$idUser){
  2114. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2115. }
  2116. $usr = DB::table('S002V01TUSUA')->where([
  2117. ['USUA_IDUS', '=', $idUser],
  2118. ['USUA_NULI', '=', $line]
  2119. ])->first();
  2120. if(is_null($usr)){
  2121. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  2122. }
  2123. $id = $this->encryptionController->decrypt($id);
  2124. if(!$id){
  2125. return $this->responseController->makeResponse(true, 'El ID de la plantilla consultada no está encriptado correctamente.', [], 400);
  2126. }
  2127. $emailTemplate = DB::table('S002V01TPCEL')->select([
  2128. 'PCEL_IDPL AS IDPLANTILLA',
  2129. 'PCEL_IDMO AS MODULO',
  2130. 'PCEL_IDSM AS SUBMODULO',
  2131. 'PCEL_IDFU AS FUNCION',
  2132. 'PCEL_IDPA AS PANTALLA',
  2133. 'PCEL_ASCO AS ASUNTO',
  2134. 'PCEL_CUCO AS CUERPO'
  2135. ])->where([
  2136. ['PCEL_IDPL', '=', $id],
  2137. ['PCEL_NULI', '=', $line],
  2138. ])->first();
  2139. if(is_null($emailTemplate)){
  2140. return $this->responseController->makeResponse(true, 'La plantilla solicitada no existe.', [], 404);
  2141. }
  2142. $now = $this->functionsController->now();
  2143. $nowStr = $now->toDateTimeString();
  2144. $actions = DB::getQueryLog();
  2145. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2146. $idac = $this->functionsController->registerActivity(
  2147. $line,
  2148. 'S002V01M01ADSI',
  2149. 'S002V01F09MACS',
  2150. 'S002V01P01HIPL',
  2151. 'Consulta',
  2152. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la plantilla " . $emailTemplate->ASUNTO . " ($id).",
  2153. $idUser,
  2154. $nowStr
  2155. );
  2156. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2157. return $this->responseController->makeResponse(false, 'EXITO', $emailTemplate);
  2158. }
  2159. public function updateEmailTemplate(Request $request){
  2160. DB::enableQueryLog();
  2161. $validator = Validator::make($request->all(), [
  2162. 'id_user' => 'required|string',
  2163. 'linea' => 'required|integer',
  2164. 'id_template' => 'required|string',
  2165. 'module' => 'required|string|max:25',
  2166. 'submodule' => 'string|max:25',
  2167. 'function' => 'required|string|max:25',
  2168. 'screen' => 'required|string|max:25',
  2169. 'subject' => 'required|string|max:50',
  2170. 'body' => 'required|string',
  2171. ]);
  2172. if($validator->fails()){
  2173. return $this->responseController->makeResponse(
  2174. true,
  2175. "Se encontraron uno o más errores.",
  2176. $this->responseController->makeErrors(
  2177. $validator->errors()->messages()
  2178. ),
  2179. 401
  2180. );
  2181. }
  2182. $form = $request->all();
  2183. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2184. if(!$idUser){
  2185. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2186. }
  2187. $usr = DB::table('S002V01TUSUA')->where([
  2188. ['USUA_IDUS', '=', $idUser],
  2189. ['USUA_NULI', '=', $form['linea']]
  2190. ])->first();
  2191. if(is_null($usr)){
  2192. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2193. }
  2194. $idTemplate = $this->encryptionController->decrypt($form['id_template']);
  2195. if(!$idTemplate){
  2196. return $this->responseController->makeResponse(true, 'El ID de la plantilla no fue encriptado correctamente.', [], 400);
  2197. }
  2198. $now = $this->functionsController->now();
  2199. $nowStr = $now->toDateTimeString();
  2200. $submodule = isset($form['submodule']) ? $form['submodule'] : null;
  2201. DB::table('S002V01TPCEL')->where([
  2202. ['PCEL_NULI', '=', $form['linea']],
  2203. ['PCEL_IDPL', '=', $idTemplate]
  2204. ])->update([
  2205. 'PCEL_IDMO' => $form['module'],
  2206. 'PCEL_IDSM' => $submodule,
  2207. 'PCEL_IDFU' => $form['function'],
  2208. 'PCEL_IDPA' => $form['screen'],
  2209. 'PCEL_ASCO' => $form['subject'],
  2210. 'PCEL_CUCO' => $form['body'],
  2211. 'PCEL_USMO' => $idUser,
  2212. 'PCEL_FEMO' => $nowStr,
  2213. ]);
  2214. $actions = DB::getQueryLog();
  2215. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2216. $idac = $this->functionsController->registerActivity(
  2217. $form['linea'],
  2218. 'S002V01M01ADSI',
  2219. 'S002V01F08CPCE',
  2220. 'S002V01P02NPEP',
  2221. 'Actualización',
  2222. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la plantilla $form[subject] ($idTemplate)",
  2223. $idUser,
  2224. $nowStr
  2225. );
  2226. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2227. return $this->responseController->makeResponse(false, 'EXITO.');
  2228. }
  2229. public function deleteEmailTemplate(Request $request){
  2230. DB::enableQueryLog();
  2231. $validator = Validator::make($request->all(), [
  2232. 'id_user' => 'required|string',
  2233. 'linea' => 'required|integer',
  2234. 'id_template' => 'required|string',
  2235. ]);
  2236. if($validator->fails()){
  2237. return $this->responseController->makeResponse(
  2238. true,
  2239. "Se encontraron uno o más errores.",
  2240. $this->responseController->makeErrors(
  2241. $validator->errors()->messages()
  2242. ),
  2243. 401
  2244. );
  2245. }
  2246. $form = $request->all();
  2247. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2248. if(!$idUser){
  2249. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2250. }
  2251. $usr = DB::table('S002V01TUSUA')->where([
  2252. ['USUA_IDUS', '=', $idUser],
  2253. ['USUA_NULI', '=', $form['linea']]
  2254. ])->first();
  2255. if(is_null($usr)){
  2256. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2257. }
  2258. $idTemplate = $this->encryptionController->decrypt($form['id_template']);
  2259. if(!$idTemplate){
  2260. return $this->responseController->makeResponse(true, 'El ID de la plantilla no fue encriptado correctamente.', [], 400);
  2261. }
  2262. $template = DB::table('S002V01TPCEL')->where([
  2263. ['PCEL_IDPL', '=', $idTemplate],
  2264. ['PCEL_NULI', '=', $form['linea']]
  2265. ])->first();
  2266. if(is_null($template)){
  2267. return $this->responseController->makeResponse(true, 'La plantilla solicitada no existe.', [], 404);
  2268. }
  2269. $now = $this->functionsController->now();
  2270. $nowStr = $now->toDateTimeString();
  2271. DB::table('S002V01TPCEL')->where([
  2272. ['PCEL_IDPL', '=', $idTemplate],
  2273. ['PCEL_NULI', '=', $form['linea']]
  2274. ])->update([
  2275. 'PCEL_ESTA' => 'Eliminado',
  2276. 'PCEL_USMO' => $idUser,
  2277. 'PCEL_FEMO' => $nowStr,
  2278. ]);
  2279. $actions = DB::getQueryLog();
  2280. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2281. $idac = $this->functionsController->registerActivity(
  2282. $form['linea'],
  2283. 'S002V01M01ADSI',
  2284. 'S002V01F08CPCE',
  2285. 'S002V01P01HIPL',
  2286. 'Eliminación',
  2287. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la plantilla ($idTemplate)",
  2288. $idUser,
  2289. $nowStr
  2290. );
  2291. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2292. return $this->responseController->makeResponse(false, 'EXITO.');
  2293. }
  2294. public function saveCatalogue(Request $request){
  2295. DB::enableQueryLog();
  2296. $validator = Validator::make($request->all(), [
  2297. 'id_user' => 'required|string',
  2298. 'linea' => 'required|integer',
  2299. 'tipo' => 'required|string|max:35',
  2300. 'adjuntos' => 'required|json',
  2301. ]);
  2302. if($validator->fails()){
  2303. return $this->responseController->makeResponse(
  2304. true,
  2305. "Se encontraron uno o más errores.",
  2306. $this->responseController->makeErrors(
  2307. $validator->errors()->messages()
  2308. ),
  2309. 401
  2310. );
  2311. }
  2312. $form = $request->all();
  2313. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2314. if(!$idUser){
  2315. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2316. }
  2317. $usr = DB::table('S002V01TUSUA')->where([
  2318. ['USUA_IDUS', '=', $idUser],
  2319. ['USUA_NULI', '=', $form['linea']]
  2320. ])->first();
  2321. if(is_null($usr)){
  2322. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2323. }
  2324. $allowedFiles = ["Colonias", "Códigos postales", "Estados", "Localidades", "Municipios", "Países", "Régimen fiscal", "Monedas", "General"];
  2325. if(!in_array($form['tipo'], $allowedFiles)){
  2326. return $this->responseController->makeResponse(true, "El tipo de catálogo no está soportado.", [], 400);
  2327. }
  2328. $now = $this->functionsController->now();
  2329. $nowStr = $now->toDateTimeString();
  2330. $attachedFiles = json_decode($form['adjuntos'], true);
  2331. $attachedArr = [];
  2332. foreach($attachedFiles as $file){
  2333. $idFile = $file['id'];
  2334. $idFile = $this->encryptionController->decrypt($idFile);
  2335. if(!$idFile){
  2336. return $this->responseController->makeResponse(true, "El ID del archivo $file[name] no fue encriptado correctamente", [], 400);
  2337. }
  2338. $fileObj = DB::table('S002V01TARTE')->where([
  2339. ['ARTE_IDAR', '=', $idFile],
  2340. ['ARTE_NULI', '=', $form['linea']]
  2341. ])->first();
  2342. if(is_null($fileObj)){
  2343. return $this->responseController->makeResponse(true, "El ID del archivo $file[name] no existe", [], 404);
  2344. }else if($fileObj->ARTE_ESTA == 'Eliminado'){
  2345. return $this->responseController->makeResponse(true, "El archivo $file[name] está eliminado", [], 404);
  2346. }
  2347. $fileRes = $this->documentManagementController->moveFinalFile(
  2348. $form['linea'],
  2349. 'ADSI',
  2350. 'CA',
  2351. $fileObj,
  2352. $idUser
  2353. );
  2354. if(!$fileRes[0]){
  2355. return $this->responseController->makeResponse(true, "El archivo no pudo guardarse: $fileRes[1]", [], 500);
  2356. }
  2357. $attachedArr[] = $this->encryptionController->encrypt($fileRes[1]);
  2358. DB::table('S002V01TARTE')->where([
  2359. ['ARTE_IDAR', '=', $idFile],
  2360. ['ARTE_NULI', '=', $form['linea']],
  2361. ])->update([
  2362. 'ARTE_ESTA' => 'Eliminado',
  2363. 'ARTE_USMO' => $idUser,
  2364. 'ARTE_FEMO' => $nowStr
  2365. ]);
  2366. }
  2367. $lastVersionObj = DB::table('S002V01TCATA')->where([
  2368. ['CATA_NULI', '=', $form['linea']],
  2369. ['CATA_TICA', '=', $form['tipo']]
  2370. ])->orderBy('CATA_IDCA', 'desc')->first();
  2371. $lastVersion = 0;
  2372. if(is_null($lastVersionObj)){
  2373. $lastVersion = 1;
  2374. }else{
  2375. DB::table('S002V01TCATA')->where([
  2376. ['CATA_NULI', '=', $form['linea']],
  2377. ['CATA_IDCA', '=', $lastVersionObj->CATA_IDCA],
  2378. ])->update([
  2379. 'CATA_ESTA' => 'Obsoleto',
  2380. ]);
  2381. $lastVersion = intval($lastVersionObj->CATA_VERS) + 1;
  2382. }
  2383. $attachedStr = json_encode($attachedArr);
  2384. DB::table('S002V01TCATA')->insert([
  2385. 'CATA_NULI' => $form['linea'],
  2386. 'CATA_TICA' => $form['tipo'],
  2387. 'CATA_VERS' => $lastVersion,
  2388. 'CATA_ARRE' => $attachedStr,
  2389. 'CATA_USRE' => $idUser,
  2390. 'CATA_FERE' => $nowStr,
  2391. ]);
  2392. $actions = DB::getQueryLog();
  2393. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2394. $idac = $this->functionsController->registerActivity(
  2395. $form['linea'],
  2396. 'S002V01M01ADSI',
  2397. 'S002V01F10AGCA',
  2398. 'S002V01P02NUCA',
  2399. 'Registro',
  2400. "El usuario $name (" . $usr->USUA_IDUS . ") registró un nuevo catálogo.",
  2401. $idUser,
  2402. $nowStr,
  2403. );
  2404. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2405. return $this->responseController->makeresponse(false, "EXITO");
  2406. }
  2407. public function getCatalogueHistory($type, $idUser, $line){
  2408. DB::enableQueryLog();
  2409. $idUser = $this->encryptionController->decrypt($idUser);
  2410. if(!$idUser){
  2411. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2412. }
  2413. $usr = DB::table('S002V01TUSUA')->where([
  2414. ['USUA_IDUS', '=', $idUser],
  2415. ['USUA_NULI', '=', $line]
  2416. ])->first();
  2417. if(is_null($usr)){
  2418. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  2419. }
  2420. $types = ['Colonias', 'Códigos postales', 'Estados', 'Localidades', 'Municipios', 'Países', 'Monedas', 'Régimen fiscal'];
  2421. if(!in_array($type, $types)){
  2422. return $this->responseController->makeResponse(true, 'El tipo de catálogo no está soportado.', [], 404);
  2423. }
  2424. $catalogueHistory = DB::table('S002V01TCATA')->select([
  2425. 'CATA_IDCA AS IDCATALOGO',
  2426. 'CATA_VERS AS VERSION',
  2427. 'CATA_ARRE AS ARCHIVO',
  2428. 'CATA_ESTA AS ESTADO',
  2429. 'CATA_USRE AS USUARIOREGISTRA',
  2430. 'CATA_FERE AS FECHAREGISTRO',
  2431. ])->where([
  2432. ['CATA_NULI', '=', $line],
  2433. ['CATA_TICA', '=', $type],
  2434. ])->get()->all();
  2435. $cont = 0;
  2436. foreach($catalogueHistory as $reg){
  2437. $usrReg = DB::table('S002V01TUSUA')->where([
  2438. ['USUA_NULI', '=', $line],
  2439. ['USUA_IDUS', '=', $reg->USUARIOREGISTRA]
  2440. ])->first();
  2441. $catalogueHistory[$cont]->USUARIOREGISTRA = $this->functionsController->joinName(
  2442. $usrReg->USUA_NOMB,
  2443. $usrReg->USUA_APPA,
  2444. $usrReg->USUA_APMA,
  2445. ) . " (" . $reg->USUARIOREGISTRA . ")";
  2446. $cont++;
  2447. }
  2448. $now = $this->functionsController->now();
  2449. $nowStr = $now->toDateTimeString();
  2450. $actions = DB::getQueryLog();
  2451. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2452. $idac = $this->functionsController->registerActivity(
  2453. $line,
  2454. 'S002V01M01ADSI',
  2455. 'S002V01F10AGCA',
  2456. 'S002V01P01HICA',
  2457. 'Consulta',
  2458. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el historial de catálogos $type.",
  2459. $idUser,
  2460. $nowStr
  2461. );
  2462. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2463. return $this->responseController->makeResponse(false, 'EXITO', $catalogueHistory);
  2464. }
  2465. public function getMaterialIcons($idUser, $line){
  2466. DB::enableQueryLog();
  2467. $idUser = $this->encryptionController->decrypt($idUser);
  2468. if(!$idUser){
  2469. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2470. }
  2471. $usr = DB::table('S002V01TUSUA')->where([
  2472. ['USUA_IDUS', '=', $idUser],
  2473. ['USUA_NULI', '=', $line]
  2474. ])->first();
  2475. if(is_null($usr)){
  2476. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado.', [], 404);
  2477. }
  2478. $iconsStr = file_get_contents("C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\storage\\app\\files\\icons.json");
  2479. $iconsArr = json_decode($iconsStr, true);
  2480. $icons = $iconsArr['icons'];
  2481. $iconsF = [];
  2482. foreach($icons as $icon){
  2483. if(!array_key_exists($icon['name'], $iconsF)){
  2484. $iconsF[$icon['name']] = [
  2485. 'name' => $icon['name'],
  2486. 'categorie' => $icon['categories'],
  2487. ];
  2488. }
  2489. }
  2490. $now = $this->functionsController->now();
  2491. $nowStr = $now->toDateTimeString();
  2492. $actions = DB::getQueryLog();
  2493. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2494. $idac = $this->functionsController->registerActivity(
  2495. $line,
  2496. '-',
  2497. '-',
  2498. '-',
  2499. 'Consulta',
  2500. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los íconos de Material.",
  2501. $idUser,
  2502. $nowStr
  2503. );
  2504. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2505. return $this->responseController->makeResponse(false, 'EXITO', array_values($iconsF));
  2506. }
  2507. public function getOrderPriorities($idUser, $line){
  2508. DB::enableQueryLog();
  2509. $idUser = $this->encryptionController->decrypt($idUser);
  2510. if(!$idUser){
  2511. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2512. }
  2513. $usr = DB::table('S002V01TUSUA')->where([
  2514. ['USUA_NULI', '=', $line],
  2515. ['USUA_IDUS', '=', $idUser],
  2516. ])->first();
  2517. if(is_null($usr)){
  2518. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  2519. }
  2520. $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2521. if(!$systemParamsExists){
  2522. return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
  2523. }
  2524. $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2525. $paramsArr = json_decode($paramsStr, true);
  2526. $now = $this->functionsController->now();
  2527. $nowStr = $now->toDateTimeString();
  2528. $actions = DB::getQueryLog();
  2529. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2530. $idac = $this->functionsController->registerActivity(
  2531. $line,
  2532. 'S002V01M01ADSI',
  2533. 'S002V01F11PASI',
  2534. 'S002V01P08EPOT',
  2535. 'Consulta',
  2536. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la configuración de las prioridades de las órdenes de trabajo.",
  2537. $idUser,
  2538. $nowStr
  2539. );
  2540. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2541. return $this->responseController->makeResponse(false, 'EXITO', ['order_priorities' => $paramsArr['order_priorities']]);
  2542. }
  2543. public function updateOrderPriorities(Request $request){
  2544. DB::enableQueryLog();
  2545. $validator = Validator::make($request->all(), [
  2546. 'id_user' => 'required|string',
  2547. 'linea' => 'required|integer',
  2548. 'priorities' => 'required|json',
  2549. ]);
  2550. if($validator->fails()){
  2551. return $this->responseController->makeResponse(
  2552. true,
  2553. "Se encontraron uno o más errores.",
  2554. $this->responseController->makeErrors(
  2555. $validator->errors()->messages()
  2556. ),
  2557. 401
  2558. );
  2559. }
  2560. $form = $request->all();
  2561. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2562. if(!$idUser){
  2563. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2564. }
  2565. $usr = DB::table('S002V01TUSUA')->where([
  2566. ['USUA_IDUS', '=', $idUser],
  2567. ['USUA_NULI', '=', $form['linea']]
  2568. ])->first();
  2569. if(is_null($usr)){
  2570. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2571. }
  2572. $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2573. if(!$systemParamsExists){
  2574. return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
  2575. }
  2576. $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2577. $paramsArr = json_decode($paramsStr, true);
  2578. $newPriorities = json_decode($form['priorities'], true);
  2579. if(empty($newPriorities)){
  2580. return $this->responseController->makeResponse(true, 'El arreglo de prioridades enviado está vacío', [], 400);
  2581. }
  2582. $paramsArr['order_priorities'] = $newPriorities;
  2583. $paramsStr = json_encode($paramsArr);
  2584. file_put_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json', $paramsStr);
  2585. $now = $this->functionsController->now();
  2586. $nowStr = $now->toDateTimeString();
  2587. $actions = DB::getQueryLog();
  2588. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2589. $idac = $this->functionsController->registerActivity(
  2590. $form['linea'],
  2591. 'S002V01M01ADSI',
  2592. 'S002V01F11PASI',
  2593. 'S002V01P08EPOT',
  2594. 'Actualización',
  2595. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la configuración de las prioridades de las órdenes de trabajo.",
  2596. $idUser,
  2597. $nowStr
  2598. );
  2599. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2600. return $this->responseController->makeResponse(false, 'EXITO');
  2601. }
  2602. public function getLoginImages($idUser, $line){
  2603. DB::enableQueryLog();
  2604. $idUser = $this->encryptionController->decrypt($idUser);
  2605. if(!$idUser){
  2606. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
  2607. }
  2608. $usr = DB::table('S002V01TUSUA')->where([
  2609. ['USUA_IDUS', '=', $idUser],
  2610. ['USUA_NULI', '=', $line]
  2611. ])->first();
  2612. if(is_null($usr)){
  2613. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  2614. }
  2615. $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2616. if(!$systemParamsExists){
  2617. return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
  2618. }
  2619. $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2620. $paramsArr = json_decode($paramsStr, true);
  2621. $now = $this->functionsController->now();
  2622. $nowStr = $now->toDateTimeString();
  2623. $actions = DB::getQueryLog();
  2624. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2625. $idac = $this->functionsController->registerActivity(
  2626. $line,
  2627. 'S002V01M01ADSI',
  2628. 'S002V01F11PASI',
  2629. 'S002V01P04EILO',
  2630. 'Consulta',
  2631. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las imágenes de la pantalla del inicio de sesión.",
  2632. $idUser,
  2633. $nowStr
  2634. );
  2635. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2636. return $this->responseController->makeResponse(false, 'EXITO', ['login_params' => $paramsArr['login_params']]);
  2637. }
  2638. public function saveLoginImage(Request $request){
  2639. DB::enableQueryLog();
  2640. $validator = Validator::make($request->all(), [
  2641. 'id_user' => 'required|string',
  2642. 'linea' => 'required|integer',
  2643. 'tipo' => 'required|string|in:image,background',
  2644. 'archivo' => 'required|string',
  2645. ]);
  2646. if($validator->fails()){
  2647. return $this->responseController->makeResponse(
  2648. true,
  2649. "Se encontraron uno o más errores.",
  2650. $this->responseController->makeErrors(
  2651. $validator->errors()->messages()
  2652. ),
  2653. 401
  2654. );
  2655. }
  2656. $form = $request->all();
  2657. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2658. if(!$idUser){
  2659. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2660. }
  2661. $usr = DB::table('S002V01TUSUA')->where([
  2662. ['USUA_IDUS', '=', $idUser],
  2663. ['USUA_NULI', '=', $form['linea']]
  2664. ])->first();
  2665. if(is_null($usr)){
  2666. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2667. }
  2668. $systemParamsExists = file_exists('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2669. if(!$systemParamsExists){
  2670. return $this->responseController->makeResponse(true, 'El archivo de parámetros del sistema no fue encontrado.', [], 500);
  2671. }
  2672. $paramsStr = file_get_contents('C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\files\system-params.json');
  2673. $paramsArr = json_decode($paramsStr, true);
  2674. $actualImage = $paramsArr["login_params"]["login_$form[tipo]"];
  2675. $replaceImage = $this->encryptionController->decrypt($form['archivo']);
  2676. if(!$replaceImage){
  2677. return $this->responseController->makeResponse(true, 'El ID de la imágen enviada no fue encriptado correctamente.', [], 500);
  2678. }
  2679. $imageObj = DB::table('S002V01TARTE')->where([
  2680. ['ARTE_IDAR', '=', $replaceImage],
  2681. ['ARTE_NULI', '=', $form['linea']]
  2682. ])->first();
  2683. $ubiImgTmp = $imageObj->ARTE_UBTE;
  2684. if(!file_exists($ubiImgTmp)){
  2685. return $this->responseController->makeResponse(true, 'El archivo de la imagen enviada no existe.', [], 500);
  2686. }
  2687. $ubiImgAct = "C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public\\assets\\$actualImage";
  2688. if(!file_exists($ubiImgAct)){
  2689. return $this->responseController->makeResponse(true, 'La imagen actual no existe.', [], 500);
  2690. }
  2691. $now = $this->functionsController->now();
  2692. $timestamp = $now->timestamp;
  2693. rename($ubiImgAct, "C:\\ITTEC\\SAM\\Dev\\SistemaMantenimiento\\sistema-mantenimiento-back\\public\\assets\\UPDATED_$timestamp.png");
  2694. copy($ubiImgTmp, $ubiImgAct);
  2695. $nowStr = $now->toDateTimeString();
  2696. $actions = DB::getQueryLog();
  2697. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2698. $idac = $this->functionsController->registerActivity(
  2699. $form['linea'],
  2700. 'S002V01M01ADSI',
  2701. 'S002V01F11PASI',
  2702. 'S002V01P04EILO',
  2703. 'Actualización',
  2704. "El usuario $name (" . $usr->USUA_IDUS . ") cambió la apariencia del login.",
  2705. $idUser,
  2706. $nowStr
  2707. );
  2708. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2709. return $this->responseController->makeResponse(false, 'EXITO.');
  2710. }
  2711. public function updateModuleIcons(Request $request){
  2712. DB::enableQueryLog();
  2713. $validator = Validator::make($request->all(), [
  2714. 'id_user' => 'required|string',
  2715. 'linea' => 'required|integer',
  2716. 'module_icons' => 'required|string',
  2717. ]);
  2718. if($validator->fails()){
  2719. return $this->responseController->makeResponse(
  2720. true,
  2721. "Se encontraron uno o más errores.",
  2722. $this->responseController->makeErrors(
  2723. $validator->errors()->messages()
  2724. ),
  2725. 401
  2726. );
  2727. }
  2728. $form = $request->all();
  2729. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2730. if(!$idUser){
  2731. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2732. }
  2733. $usr = DB::table('S002V01TUSUA')->where([
  2734. ['USUA_IDUS', '=', $idUser],
  2735. ['USUA_NULI', '=', $form['linea']]
  2736. ])->first();
  2737. if(is_null($usr)){
  2738. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2739. }
  2740. $moduleIconsStr = $form['module_icons'];
  2741. $moduleIconsDec = $this->encryptionController->decrypt($moduleIconsStr);
  2742. if(!$moduleIconsDec){
  2743. return $this->responseController->makeResponse(true, 'El arreglo de módulos no fue encriptado correctamente.', [], 400);
  2744. }
  2745. $now = $this->functionsController->now();
  2746. $nowStr = $now->toDateTimeString();
  2747. $moduleIconsArr = json_decode($moduleIconsDec, true);
  2748. foreach($moduleIconsArr as $modIcon){
  2749. DB::table('S002V01TMODU')->where([
  2750. ['MODU_NULI', '=', $form['linea']],
  2751. ['MODU_IDMO', '=', $modIcon['IDMODULO']]
  2752. ])->update([
  2753. 'MODU_ICON' => $modIcon['ICONOMODULO'],
  2754. 'MODU_USMO' => $idUser,
  2755. 'MODU_FEMO' => $nowStr,
  2756. ]);
  2757. }
  2758. $actions = DB::getQueryLog();
  2759. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2760. $idac = $this->functionsController->registerActivity(
  2761. $form['linea'],
  2762. 'S002V01M01ADSI',
  2763. 'S002V01F11PASI',
  2764. 'S002V01P05EIMO',
  2765. 'Actualización',
  2766. "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de los módulos.",
  2767. $idUser,
  2768. $nowStr
  2769. );
  2770. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2771. return $this->responseController->makeResponse(false, 'EXITO.');
  2772. }
  2773. public function updateSubmoduleIcons(Request $request){
  2774. DB::enableQueryLog();
  2775. $validator = Validator::make($request->all(), [
  2776. 'id_user' => 'required|string',
  2777. 'linea' => 'required|integer',
  2778. 'submodule_icons' => 'required|string',
  2779. ]);
  2780. if($validator->fails()){
  2781. return $this->responseController->makeResponse(
  2782. true,
  2783. "Se encontraron uno o más errores.",
  2784. $this->responseController->makeErrors(
  2785. $validator->errors()->messages()
  2786. ),
  2787. 401
  2788. );
  2789. }
  2790. $form = $request->all();
  2791. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2792. if(!$idUser){
  2793. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2794. }
  2795. $usr = DB::table('S002V01TUSUA')->where([
  2796. ['USUA_IDUS', '=', $idUser],
  2797. ['USUA_NULI', '=', $form['linea']]
  2798. ])->first();
  2799. if(is_null($usr)){
  2800. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2801. }
  2802. $submoduleIconsDec = $this->encryptionController->decrypt($form['submodule_icons']);
  2803. if(!$submoduleIconsDec){
  2804. return $this->responseController->makeResponse(true, 'El arreglo de submódulos no fue encriptado correctamente.', [], 400);
  2805. }
  2806. $now = $this->functionsController->now();
  2807. $nowStr = $now->toDateTimeString();
  2808. $submodulesArr = json_decode($submoduleIconsDec, true);
  2809. foreach($submodulesArr as $module=>$submodules){
  2810. foreach($submodules as $submodule){
  2811. DB::table('S002V01TSUBM')->where([
  2812. ['SUBM_NULI', '=', $form['linea']],
  2813. ['SUBM_IDSM', '=', $submodule['IDSUBMODULO']],
  2814. ['SUBM_IDMO', '=', $module],
  2815. ])->update([
  2816. 'SUBM_ICON' => $submodule['ICONOSUBMODULO'],
  2817. 'SUBM_USMO' => $idUser,
  2818. 'SUBM_FEMO' => $nowStr,
  2819. ]);
  2820. }
  2821. }
  2822. $actions = DB::getQueryLog();
  2823. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2824. $idac = $this->functionsController->registerActivity(
  2825. $form['linea'],
  2826. 'S002V01M01ADSI',
  2827. 'S002V01F11PASI',
  2828. 'S002V01P06EISU',
  2829. 'Actualización',
  2830. "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de los submódulos.",
  2831. $idUser,
  2832. $nowStr
  2833. );
  2834. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2835. return $this->responseController->makeResponse(false, 'EXITO.');
  2836. }
  2837. public function updateFunctionIcons(Request $request){
  2838. DB::enableQueryLog();
  2839. $validator = Validator::make($request->all(), [
  2840. 'id_user' => 'required|string',
  2841. 'linea' => 'required|integer',
  2842. 'module_functions_icons' => 'required|string',
  2843. 'submodule_functions_icons' => 'required|string',
  2844. ]);
  2845. if($validator->fails()){
  2846. return $this->responseController->makeResponse(
  2847. true,
  2848. "Se encontraron uno o más errores.",
  2849. $this->responseController->makeErrors(
  2850. $validator->errors()->messages()
  2851. ),
  2852. 401
  2853. );
  2854. }
  2855. $form = $request->all();
  2856. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2857. if(!$idUser){
  2858. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2859. }
  2860. $usr = DB::table('S002V01TUSUA')->where([
  2861. ['USUA_IDUS', '=', $idUser],
  2862. ['USUA_NULI', '=', $form['linea']]
  2863. ])->first();
  2864. if(is_null($usr)){
  2865. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  2866. }
  2867. $moduleFunctionIconsDec = $this->encryptionController->decrypt($form['module_functions_icons']);
  2868. if(!$moduleFunctionIconsDec){
  2869. return $this->responseController->makeResponse(true, 'El arreglo de funciones por módulo no fue encriptado correctamente.', [], 400);
  2870. }
  2871. $submoduleFunctionIconsDec = $this->encryptionController->decrypt($form['submodule_functions_icons']);
  2872. if(!$submoduleFunctionIconsDec){
  2873. return $this->responseController->makeResponse(true, 'El arreglo de funciones por submódulo no fue encriptado correctamente.', [], 400);
  2874. }
  2875. $now = $this->functionsController->now();
  2876. $nowStr = $now->toDateTimeString();
  2877. $moduleFunctionIconsArr = json_decode($moduleFunctionIconsDec, true);
  2878. foreach($moduleFunctionIconsArr as $module=>$functions){
  2879. foreach($functions as $function){
  2880. DB::table('S002V01TFUNC')->where([
  2881. ['FUNC_NULI', '=', $form['linea']],
  2882. ['FUNC_IDFU', '=', $function['IDFUNCION']],
  2883. ['FUNC_IDMO', '=', $module],
  2884. ['FUNC_IDSM', '=', null],
  2885. ])->update([
  2886. 'FUNC_ICON' => $function['ICONOFUNCION'],
  2887. 'FUNC_USMO' => $idUser,
  2888. 'FUNC_FEMO' => $nowStr,
  2889. ]);
  2890. }
  2891. }
  2892. $submoduleFunctionIconsArr = json_decode($submoduleFunctionIconsDec, true);
  2893. foreach($submoduleFunctionIconsArr as $module=>$submodules){
  2894. foreach($submodules as $submodule=>$functions){
  2895. foreach($functions as $function){
  2896. DB::table('S002V01TFUNC')->where([
  2897. ['FUNC_NULI', '=', $form['linea']],
  2898. ['FUNC_IDFU', '=', $function['IDFUNCION']],
  2899. ['FUNC_IDMO', '=', $module],
  2900. ['FUNC_IDSM', '=', $submodule],
  2901. ])->update([
  2902. 'FUNC_ICON' => $function['ICONOFUNCION'],
  2903. 'FUNC_USMO' => $idUser,
  2904. 'FUNC_FEMO' => $nowStr,
  2905. ]);
  2906. }
  2907. }
  2908. }
  2909. $actions = DB::getQueryLog();
  2910. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2911. $idac = $this->functionsController->registerActivity(
  2912. $form['linea'],
  2913. 'S002V01M01ADSI',
  2914. 'S002V01F11PASI',
  2915. 'S002V01P07EIFU',
  2916. 'Actualización',
  2917. "El usuario $name (" . $usr->USUA_IDUS . ") cambió los íconos de las funciones.",
  2918. $idUser,
  2919. $nowStr
  2920. );
  2921. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  2922. return $this->responseController->makeResponse(false, 'EXITO.');
  2923. }
  2924. public function getModuleFunctions($idMod, $idUser, $line){
  2925. DB::enableQueryLog();
  2926. $idUser = $this->encryptionController->decrypt($idUser);
  2927. if(!$idUser){
  2928. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  2929. }
  2930. $usr = DB::table('S002V01TUSUA')->where([
  2931. ['USUA_IDUS', '=', $idUser],
  2932. ['USUA_NULI', '=', $line]
  2933. ])->first();
  2934. if(is_null($usr)){
  2935. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  2936. }
  2937. $idMod = $this->encryptionController->decrypt($idMod);
  2938. if(!$idMod){
  2939. return $this->responseController->makeResponse(true, 'El ID del módulo no fue encriptado correctamente', [], 400);
  2940. }
  2941. $mod = DB::table('S002V01TMODU')->where([
  2942. ['MODU_NULI', '=', $line],
  2943. ['MODU_IDMO', '=', $idMod]
  2944. ])->first();
  2945. if(is_null($mod)){
  2946. return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
  2947. }
  2948. $functions = DB::table('S002V01TFUNC')->where([
  2949. ['FUNC_NULI', '=', $line],
  2950. ['FUNC_IDMO', '=', $idMod],
  2951. ['FUNC_IDSM', '=', null],
  2952. ])->select([
  2953. 'FUNC_IDFU AS IDFUNCION',
  2954. 'FUNC_NOMB AS NOMBREFUNCION',
  2955. 'FUNC_ICON AS ICONOFUNCION'
  2956. ])->get()->all();
  2957. $now = $this->functionsController->now();
  2958. $nowStr = $now->toDateTimeString();
  2959. $actions = DB::getQueryLog();
  2960. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  2961. $idac = $this->functionsController->registerActivity(
  2962. $line,
  2963. '-',
  2964. '-',
  2965. '-',
  2966. 'Consulta',
  2967. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las funciones del módulo '" . $mod->MODU_NOMO . "'.",
  2968. $idUser,
  2969. $nowStr
  2970. );
  2971. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  2972. return $this->responseController->makeResponse(false, 'EXITO', $functions);
  2973. }
  2974. public function registerSCADA(Request $request){
  2975. DB::enableQueryLog();
  2976. $validator = Validator::make($request->all(), [
  2977. 'id_user' => 'required|string',
  2978. 'linea' => 'required|integer',
  2979. 'scada_name' => 'required|string|max:100',
  2980. ]);
  2981. if($validator->fails()){
  2982. return $this->responseController->makeResponse(
  2983. true,
  2984. "Se encontraron uno o más errores.",
  2985. $this->responseController->makeErrors(
  2986. $validator->errors()->messages()
  2987. ),
  2988. 401
  2989. );
  2990. }
  2991. $form = $request->all();
  2992. $idUser = $this->encryptionController->decrypt($form['id_user']);
  2993. if(!$idUser){
  2994. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  2995. }
  2996. $usr = DB::table('S002V01TUSUA')->where([
  2997. ['USUA_IDUS', '=', $idUser],
  2998. ['USUA_NULI', '=', $form['linea']]
  2999. ])->first();
  3000. if(is_null($usr)){
  3001. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3002. }
  3003. $now = $this->functionsController->now();
  3004. $nowStr = $now->toDateTimeString();
  3005. DB::table('S002V01TLISC')->insert([
  3006. 'LISC_NULI' => $form['linea'],
  3007. 'LISC_NOSC' => $form['scada_name'],
  3008. 'LISC_USRE' => $idUser,
  3009. 'LISC_FERE' => $nowStr,
  3010. ]);
  3011. $actions = DB::getQueryLog();
  3012. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3013. $idac = $this->functionsController->registerActivity(
  3014. $form['linea'],
  3015. 'S002V01M01ADSI',
  3016. 'S002V01F06ASWA',
  3017. 'S002V01P02RESC',
  3018. 'Registro',
  3019. "El usuario $name (" . $usr->USUA_IDUS . ") registró el SCADA $form[scada_name].",
  3020. $idUser,
  3021. $nowStr
  3022. );
  3023. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3024. return $this->responseController->makeResponse(false, 'EXITO.');
  3025. }
  3026. public function getSCADAList($idUser, $line){
  3027. DB::enableQueryLog();
  3028. $idUser = $this->encryptionController->decrypt($idUser);
  3029. if(!$idUser){
  3030. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3031. }
  3032. $usr = DB::table('S002V01TUSUA')->where([
  3033. ['USUA_IDUS', '=', $idUser],
  3034. ['USUA_NULI', '=', $line]
  3035. ])->first();
  3036. if(is_null($usr)){
  3037. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3038. }
  3039. $list = DB::table('S002V01TLISC')->select([
  3040. 'LISC_IDSC AS IDSCADA',
  3041. 'LISC_NOSC AS NOMBRESCADA',
  3042. 'LISC_ESTA AS ESTATUS',
  3043. 'LISC_USRE AS USUARIOREGISTRO',
  3044. 'LISC_FERE AS FECHAREGISTRO',
  3045. 'LISC_USMO AS USUARIOMODIFICO',
  3046. 'LISC_FEMO AS FECHAMODIFICACION',
  3047. ])->where([
  3048. ['LISC_NULI', '=', $line],
  3049. ['LISC_ESTA', '=', 'Activo'],
  3050. ])->get()->all();
  3051. foreach($list as $item){
  3052. $usrReg = DB::table('S002V01TUSUA')->where([
  3053. ['USUA_NULI', '=', $line],
  3054. ['USUA_IDUS', '=', $item->USUARIOREGISTRO],
  3055. ])->first();
  3056. $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA) . " (" . $item->USUARIOREGISTRO . ")";
  3057. $item->USUARIOREGISTRO = $nameReg;
  3058. $usrMod = DB::table('S002V01TUSUA')->where([
  3059. ['USUA_NULI', '=', $line],
  3060. ['USUA_IDUS', '=', $item->USUARIOMODIFICO],
  3061. ])->first();
  3062. if(!is_null($usrMod)){
  3063. $nameMod = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA) . " (" . $item->USUARIOMODIFICO . ")";
  3064. $item->USUARIOMODIFICO = $nameMod;
  3065. }
  3066. }
  3067. $now = $this->functionsController->now();
  3068. $nowStr = $now->toDateTimeString();
  3069. $actions = DB::getQueryLog();
  3070. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3071. $idac = $this->functionsController->registerActivity(
  3072. $line,
  3073. 'S002V01M01ADSI',
  3074. 'S002V01F06ASWA',
  3075. 'S002V01P01ADSC',
  3076. 'Consulta',
  3077. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los SCADA registrados en el sistema.",
  3078. $idUser,
  3079. $nowStr
  3080. );
  3081. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3082. return $this->responseController->makeResponse(false, 'EXITO', $list);
  3083. }
  3084. public function updateSCADA(Request $request){
  3085. DB::enableQueryLog();
  3086. $validator = Validator::make($request->all(), [
  3087. 'id_user' => 'required|string',
  3088. 'id_scada' => 'required|string',
  3089. 'linea' => 'required|integer',
  3090. 'scada_name' => 'required|string|max:100',
  3091. ]);
  3092. if($validator->fails()){
  3093. return $this->responseController->makeResponse(
  3094. true,
  3095. "Se encontraron uno o más errores.",
  3096. $this->responseController->makeErrors(
  3097. $validator->errors()->messages()
  3098. ),
  3099. 401
  3100. );
  3101. }
  3102. $form = $request->all();
  3103. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3104. if(!$idUser){
  3105. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3106. }
  3107. $usr = DB::table('S002V01TUSUA')->where([
  3108. ['USUA_NULI', '=', $form['linea']],
  3109. ['USUA_IDUS', '=', $idUser]
  3110. ])->first();
  3111. if(is_null($usr)){
  3112. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3113. }
  3114. $idSCADA = $this->encryptionController->decrypt($form['id_scada']);
  3115. if(!$idSCADA){
  3116. return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
  3117. }
  3118. $scada = DB::table('S002V01TLISC')->where([
  3119. ['LISC_NULI', '=', $form['linea']],
  3120. ['LISC_IDSC', '=', $idSCADA],
  3121. ])->first();
  3122. if(is_null($scada)){
  3123. return $this->responseController->makeResponse(true, 'El SCADA solicitado no existe.', [], 404);
  3124. }
  3125. $now = $this->functionsController->now();
  3126. $nowStr = $now->toDateTimeString();
  3127. DB::table('S002V01TLISC')->where([
  3128. ['LISC_NULI', '=', $form['linea']],
  3129. ['LISC_IDSC', '=', $idSCADA],
  3130. ])->update([
  3131. 'LISC_NOSC' => $form['scada_name'],
  3132. 'LISC_USMO' => $idUser,
  3133. 'LISC_FEMO' => $nowStr,
  3134. ]);
  3135. $actions = DB::getQueryLog();
  3136. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3137. $idac = $this->functionsController->registerActivity(
  3138. $form['linea'],
  3139. 'S002V01M01ADSI',
  3140. 'S002V01F06ASWA',
  3141. 'S002V01P02RESC',
  3142. 'Actualización',
  3143. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el SCADA $form[scada_name] ($idSCADA).",
  3144. $idUser,
  3145. $nowStr
  3146. );
  3147. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3148. return $this->responseController->makeResponse(false, 'EXITO.');
  3149. }
  3150. public function deleteSCADA(Request $request){
  3151. DB::enableQueryLog();
  3152. $validator = Validator::make($request->all(), [
  3153. 'id_user' => 'required|string',
  3154. 'id_scada' => 'required|string',
  3155. 'linea' => 'required|integer',
  3156. ]);
  3157. if($validator->fails()){
  3158. return $this->responseController->makeResponse(
  3159. true,
  3160. "Se encontraron uno o más errores.",
  3161. $this->responseController->makeErrors(
  3162. $validator->errors()->messages()
  3163. ),
  3164. 401
  3165. );
  3166. }
  3167. $form = $request->all();
  3168. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3169. if(!$idUser){
  3170. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3171. }
  3172. $usr = DB::table('S002V01TUSUA')->where([
  3173. ['USUA_IDUS', '=', $idUser],
  3174. ['USUA_NULI', '=', $form['linea']]
  3175. ])->first();
  3176. if(is_null($usr)){
  3177. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3178. }
  3179. $idSCADA = $this->encryptionController->decrypt($form['id_scada']);
  3180. if(!$idSCADA){
  3181. return $this->responseController->makeResponse(true, 'El ID del SCADA no fue encriptado correctamente.', [], 400);
  3182. }
  3183. $scada = DB::table('S002V01TLISC')->where([
  3184. ['LISC_NULI', '=', $form['linea']],
  3185. ['LISC_IDSC', '=', $idSCADA],
  3186. ])->first();
  3187. if(is_null($scada)){
  3188. return $this->responseController->makeResponse(true, 'El SCADA solicitado no existe.', [], 404);
  3189. }
  3190. $tokensSCADA = DB::table('S002V01TTASW')->where([
  3191. ['TASW_NULI', '=', $form['linea']],
  3192. ['TASW_IDSC', '=', $idSCADA],
  3193. ])->get()->all();
  3194. if(!empty($tokensSCADA)){
  3195. return $this->responseController->makeResponse(true, 'No se pudo eliminar el SCADA porque tiene tokens asignados.', [], 400);
  3196. }
  3197. $now = $this->functionsController->now();
  3198. $nowStr = $now->toDateTimeString();
  3199. DB::table('S002V01TLISC')->where([
  3200. ['LISC_NULI', '=', $form['linea']],
  3201. ['LISC_IDSC', '=', $idSCADA],
  3202. ])->update([
  3203. 'LISC_ESTA' => 'Eliminado',
  3204. 'LISC_USMO' => $idUser,
  3205. 'LISC_FEMO' => $nowStr,
  3206. ]);
  3207. $actions = DB::getQueryLog();
  3208. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3209. $idac = $this->functionsController->registerActivity(
  3210. $form['linea'],
  3211. 'S002V01M01ADSI',
  3212. 'S002V01F06ASWA',
  3213. 'S002V01P01ADSC',
  3214. 'Eliminación',
  3215. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el SCADA " . $scada->LISC_NOSC . " ($idSCADA).",
  3216. $idUser,
  3217. $nowStr
  3218. );
  3219. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3220. return $this->responseController->makeResponse(false, 'EXITO.');
  3221. }
  3222. public function generateSCADAtoken(Request $request){
  3223. DB::enableQueryLog();
  3224. $validator = Validator::make($request->all(), [
  3225. 'id_user' => 'required|string',
  3226. 'id_scada' => 'required|string',
  3227. 'linea' => 'required|integer',
  3228. 'descripcion' => 'required|string',
  3229. ]);
  3230. if($validator->fails()){
  3231. return $this->responseController->makeResponse(
  3232. true,
  3233. "Se encontraron uno o más errores.",
  3234. $this->responseController->makeErrors(
  3235. $validator->errors()->messages()
  3236. ),
  3237. 401
  3238. );
  3239. }
  3240. $form = $request->all();
  3241. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3242. if(!$idUser){
  3243. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3244. }
  3245. $usr = DB::table('S002V01TUSUA')->where([
  3246. ['USUA_IDUS', '=', $idUser],
  3247. ['USUA_NULI', '=', $form['linea']]
  3248. ])->first();
  3249. if(is_null($usr)){
  3250. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3251. }
  3252. $id = $this->encryptionController->decrypt($form['id_scada']);
  3253. if(!$id){
  3254. return $this->responseController->makeResponse(true, 'El ID del SCADA no está encriptado correctamente', [], 400);
  3255. }
  3256. $scada = DB::table('S002V01TLISC')->where([
  3257. ['LISC_NULI', '=', $form['linea']],
  3258. ['LISC_IDSC', '=', $id],
  3259. ])->first();
  3260. if(is_null($scada)){
  3261. return $this->responseController->makeResponse(true, 'El SCADA consultado no existe', [], 404);
  3262. }
  3263. $now = $this->functionsController->now();
  3264. $iat = $now->timestamp;
  3265. $cad = $now->addYear()->timestamp;
  3266. $payload = [
  3267. "iss" => $scada->LISC_IDSC,
  3268. "aud" => "dominio.syp.mx",
  3269. "iat" => $iat,
  3270. "cad" => $cad
  3271. ];
  3272. $token = JWT::encode($payload, $this->secretKey, 'EdDSA');
  3273. $nowStr = $now->subYear()->toDateTimeString();
  3274. DB::table('S002V01TTASW')->insert([
  3275. 'TASW_NULI' => $form['linea'],
  3276. 'TASW_IDSC' => $scada->LISC_IDSC,
  3277. 'TASW_TOKE' => $token,
  3278. 'TASW_DETO' => $form['descripcion'],
  3279. 'TASW_TIMO' => "PRUEBA",
  3280. 'TASW_USRE' => $idUser,
  3281. 'TASW_FERE' => $nowStr,
  3282. ]);
  3283. $actions = DB::getQueryLog();
  3284. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3285. $idac = $this->functionsController->registerActivity(
  3286. $form['linea'],
  3287. 'S002V01M01ADSI',
  3288. 'S002V01F06ASWA',
  3289. 'S002V01P04GETO',
  3290. 'Registro',
  3291. "El usuario $name (" . $usr->USUA_IDUS . ") registró y asignó el token \"$token\" al SCADA \"" . $scada->LISC_NOSC . " ($id)\".",
  3292. $idUser,
  3293. $nowStr
  3294. );
  3295. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3296. return $this->responseController->makeResponse(false, 'EXITO.', ['token' => $token]);
  3297. }
  3298. public function getGeneratedTokens($idUser, $line){
  3299. DB::enableQueryLog();
  3300. $idUser = $this->encryptionController->decrypt($idUser);
  3301. if(!$idUser){
  3302. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3303. }
  3304. $usr = DB::table('S002V01TUSUA')->where([
  3305. ['USUA_IDUS', '=', $idUser],
  3306. ['USUA_NULI', '=', $line]
  3307. ])->first();
  3308. if(is_null($usr)){
  3309. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3310. }
  3311. $tokens = DB::table('S002V01TTASW')->join('S002V01TLISC', 'LISC_IDSC', '=', 'TASW_IDSC')->select([
  3312. 'LISC_NOSC AS NOMBRESCADA',
  3313. 'TASW_DETO AS DESCRIPCION',
  3314. 'TASW_ESTA AS ESTATUS',
  3315. 'TASW_USRE AS USUARIOREGISTRO',
  3316. 'TASW_FERE AS FECHAREGISTRO',
  3317. 'TASW_USMO AS USUARIOMODIFICACION',
  3318. 'TASW_FEMO AS FECHAMODIFICACION',
  3319. 'TASW_IDSC AS IDSCADA',
  3320. 'TASW_TOKE AS TOKEN'
  3321. ])->where([
  3322. ['TASW_NULI', '=', $line],
  3323. ['LISC_ESTA', '=', 'Activo'],
  3324. ])->get()->all();
  3325. foreach($tokens as $token){
  3326. $usre = DB::table('S002V01TUSUA')->where([
  3327. ['USUA_NULI', '=', $line],
  3328. ['USUA_IDUS', '=', $token->USUARIOREGISTRO]
  3329. ])->first();
  3330. $usreName = $this->functionsController->joinName($usre->USUA_NOMB, $usre->USUA_APPA, $usre->USUA_APMA) . " (" . $token->USUARIOREGISTRO . ")";
  3331. $token->USUARIOREGISTRO = $usreName;
  3332. $usmo = DB::table('S002V01TUSUA')->where([
  3333. ['USUA_NULI', '=', $line],
  3334. ['USUA_IDUS', '=', $token->USUARIOMODIFICACION]
  3335. ])->first();
  3336. if(!is_null($usmo)){
  3337. $usmoName = $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA) . " (" . $token->USUARIOMODIFICACION . ")";
  3338. $token->USUARIOMODIFICACION = $usmoName;
  3339. }
  3340. $keyStr = $token->IDSCADA . "|" . $token->TOKEN;
  3341. $keyEnc = $this->encryptionController->encrypt($keyStr);
  3342. unset($token->IDSCADA);
  3343. unset($token->TOKEN);
  3344. $token->KEY = $keyEnc;
  3345. }
  3346. $now = $this->functionsController->now();
  3347. $nowStr = $now->toDateTimeString();
  3348. $actions = DB::getQueryLog();
  3349. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3350. $idac = $this->functionsController->registerActivity(
  3351. $line,
  3352. 'S002V01M01ADSI',
  3353. 'S002V01F06ASWA',
  3354. 'S002V01P03ADTO',
  3355. 'Consulta',
  3356. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los tokens generados.",
  3357. $idUser,
  3358. $nowStr
  3359. );
  3360. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3361. return $this->responseController->makeResponse(false, 'EXITO', $tokens);
  3362. }
  3363. public function revokeToken(Request $request){
  3364. DB::enableQueryLog();
  3365. $validator = Validator::make($request->all(), [
  3366. 'id_user' => 'required|string',
  3367. 'token_key' => 'required|string',
  3368. 'linea' => 'required|integer',
  3369. ]);
  3370. if($validator->fails()){
  3371. return $this->responseController->makeResponse(
  3372. true,
  3373. "Se encontraron uno o más errores.",
  3374. $this->responseController->makeErrors(
  3375. $validator->errors()->messages()
  3376. ),
  3377. 401
  3378. );
  3379. }
  3380. $form = $request->all();
  3381. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3382. if(!$idUser){
  3383. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3384. }
  3385. $usr = DB::table('S002V01TUSUA')->where([
  3386. ['USUA_IDUS', '=', $idUser],
  3387. ['USUA_NULI', '=', $form['linea']]
  3388. ])->first();
  3389. if(is_null($usr)){
  3390. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3391. }
  3392. $tokenKey = $this->encryptionController->decrypt($form['token_key']);
  3393. if(!$tokenKey){
  3394. return $this->responseController->makeResponse(true, 'La llave del token solicitado no fue encriptado correctamente.', [], 400);
  3395. }
  3396. $keyArr = explode("|", $tokenKey);
  3397. $token = DB::table('S002V01TTASW')->where([
  3398. ['TASW_NULI', '=', $form['linea']],
  3399. ['TASW_IDSC', '=', $keyArr[0]],
  3400. ['TASW_TOKE', '=', $keyArr[1]]
  3401. ])->first();
  3402. if(is_null($token)){
  3403. return $this->responseController->makeResponse(true, 'El token solicitado no existe.', [], 404);
  3404. }
  3405. $now = $this->functionsController->now();
  3406. $nowStr = $now->toDateTimeString();
  3407. DB::table('S002V01TTASW')->where([
  3408. ['TASW_NULI', '=', $form['linea']],
  3409. ['TASW_IDSC', '=', $keyArr[0]],
  3410. ['TASW_TOKE', '=', $keyArr[1]]
  3411. ])->update([
  3412. 'TASW_ESTA' => 'Revocado',
  3413. 'TASW_USMO' => $idUser,
  3414. 'TASW_FEMO' => $nowStr,
  3415. ]);
  3416. $actions = DB::getQueryLog();
  3417. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3418. $idac = $this->functionsController->registerActivity(
  3419. $form['linea'],
  3420. 'S002V01M01ADSI',
  3421. 'S002V01F06ASWA',
  3422. 'S002V01P03ADTO',
  3423. 'Actualización',
  3424. "El usuario $name (" . $usr->USUA_IDUS . ") revocó el token \"$keyArr[1]\".",
  3425. $idUser,
  3426. $nowStr
  3427. );
  3428. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3429. return $this->responseController->makeResponse(false, 'EXITO.');
  3430. }
  3431. public function registerWebService(Request $request){
  3432. DB::enableQueryLog();
  3433. $validator = Validator::make($request->all(), [
  3434. 'id_user' => 'required|string',
  3435. 'linea' => 'required|integer',
  3436. 'url' => 'required|string|max:250',
  3437. 'description' => 'required|string|max:100',
  3438. ]);
  3439. if($validator->fails()){
  3440. return $this->responseController->makeResponse(
  3441. true,
  3442. "Se encontraron uno o más errores.",
  3443. $this->responseController->makeErrors(
  3444. $validator->errors()->messages()
  3445. ),
  3446. 401
  3447. );
  3448. }
  3449. $form = $request->all();
  3450. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3451. if(!$idUser){
  3452. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3453. }
  3454. $usr = DB::table('S002V01TUSUA')->where([
  3455. ['USUA_NULI', '=', $form['linea']],
  3456. ['USUA_IDUS', '=', $idUser]
  3457. ])->first();
  3458. if(is_null($usr)){
  3459. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3460. }
  3461. $now = $this->functionsController->now();
  3462. $nowStr = $now->toDateTimeString();
  3463. $idWebService = DB::table('S002V01TLSWE')->insertGetId([
  3464. 'LSWE_NULI' => $form['linea'],
  3465. 'LSWE_URLX' => $form['url'],
  3466. 'LSWE_DESC' => $form['description'],
  3467. 'LSWE_USRE' => $idUser,
  3468. 'LSWE_FERE' => $nowStr
  3469. ]);
  3470. $actions = DB::getQueryLog();
  3471. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3472. $idac = $this->functionsController->registerActivity(
  3473. $form['linea'],
  3474. 'S002V01M01ADSI',
  3475. 'S002V01F06ASWA',
  3476. 'S002V01P07RESW',
  3477. 'Registro',
  3478. "El usuario $name (" . $usr->USUA_IDUS . ") registró el servicio web $form[url] ($idWebService).",
  3479. $idUser,
  3480. $nowStr
  3481. );
  3482. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3483. return $this->responseController->makeResponse(false, 'EXITO.');
  3484. }
  3485. public function getWebServices($idUser, $line){
  3486. DB::enableQueryLog();
  3487. $idUser = $this->encryptionController->decrypt($idUser);
  3488. if(!$idUser){
  3489. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3490. }
  3491. $usr = DB::table('S002V01TUSUA')->where([
  3492. ['USUA_IDUS', '=', $idUser],
  3493. ['USUA_NULI', '=', $line]
  3494. ])->first();
  3495. if(is_null($usr)){
  3496. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3497. }
  3498. $webServices = DB::table('S002V01TLSWE')->where([
  3499. ['LSWE_NULI', '=', $line]
  3500. ])->select([
  3501. 'LSWE_IDSW AS IDSERVICIO',
  3502. 'LSWE_URLX AS URL',
  3503. 'LSWE_DESC AS DESCRIPCION',
  3504. 'LSWE_ESTA AS ESTADO',
  3505. 'LSWE_USRE AS USUREG',
  3506. 'LSWE_FERE AS FECREG',
  3507. 'LSWE_USMO AS USUMOD',
  3508. 'LSWE_FEMO AS FECMOD'
  3509. ])->get()->all();
  3510. foreach($webServices as $webService){
  3511. $usre = DB::table('S002V01TUSUA')->where([
  3512. ['USUA_NULI', '=', $line],
  3513. ['USUA_IDUS', '=', $webService->USUREG],
  3514. ])->first();
  3515. $usreName = $this->functionsController->joinName($usre->USUA_NOMB, $usre->USUA_APPA, $usre->USUA_APMA) . " (" . $webService->USUREG . ")";
  3516. $webService->USUREG = $usreName;
  3517. $usmo = DB::table('S002V01TUSUA')->where([
  3518. ['USUA_NULI', '=', $line],
  3519. ['USUA_IDUS', '=', $webService->USUMOD],
  3520. ])->first();
  3521. if(!is_null($usmo)){
  3522. $usmoName = $this->functionsController->joinName($usmo->USUA_NOMB, $usmo->USUA_APPA, $usmo->USUA_APMA) . " (" . $webService->USUMOD . ")";
  3523. $webService->USUMOD = $usmoName;
  3524. }
  3525. $vinculos = DB::table('S002V01TTASW')->where([
  3526. ['TASW_NULI', '=', $line],
  3527. ['TASW_IDSW', '=', $webService->IDSERVICIO],
  3528. ])->get()->all();
  3529. $webService->VINCULOS = count($vinculos);
  3530. }
  3531. $now = $this->functionsController->now();
  3532. $actions = DB::getQueryLog();
  3533. $nowStr = $now->toDateTimeString();
  3534. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3535. $idac = $this->functionsController->registerActivity(
  3536. $line,
  3537. 'S002V01M01ADSI',
  3538. 'S002V01F06ASWA',
  3539. 'S002V01P06LSWE',
  3540. 'Consulta',
  3541. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los servicios web almacenados.",
  3542. $idUser,
  3543. $nowStr
  3544. );
  3545. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3546. return $this->responseController->makeResponse(false, 'EXITO', $webServices);
  3547. }
  3548. public function getRoutedTokens($idUser, $line){
  3549. DB::enableQueryLog();
  3550. $idUser = $this->encryptionController->decrypt($idUser);
  3551. if(!$idUser){
  3552. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3553. }
  3554. $usr = DB::table('S002V01TUSUA')->where([
  3555. ['USUA_IDUS', '=', $idUser],
  3556. ['USUA_NULI', '=', $line]
  3557. ])->first();
  3558. if(is_null($usr)){
  3559. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3560. }
  3561. $list = DB::table('S002V01TTASW')
  3562. ->join('S002V01TLISC', 'LISC_IDSC', '=', 'TASW_IDSC')
  3563. ->leftJoin('S002V01TLSWE', 'LSWE_IDSW', '=', 'TASW_IDSW')
  3564. ->where([
  3565. ['TASW_NULI', '=', $line],
  3566. ['TASW_ESTA', '!=', 'Revocado'],
  3567. ])->get()->all();
  3568. $arrList = [];
  3569. foreach($list as $val){
  3570. $key = $this->encryptionController->encrypt($val->TASW_IDSC . "|" . $val->TASW_TOKE);
  3571. $arrList[] = [
  3572. 'SCADA' => $val->LISC_NOSC . " (" . $val->LISC_IDSC . ")",
  3573. 'DESCRIPCIONSC' => $val->TASW_DETO,
  3574. 'SERVICIOWEB' => is_null($val->LSWE_IDSW) ? 'No asignado' : $val->LSWE_URLX . " (" . $val->LSWE_IDSW . ")",
  3575. 'DESCRIPCIONSW' => $val->LSWE_DESC,
  3576. 'ESTADO' => $val->TASW_ESTA,
  3577. "KEY" => $key
  3578. ];
  3579. }
  3580. $now = $this->functionsController->now();
  3581. $nowStr = $now->toDateTimeString();
  3582. $actions = DB::getQueryLog();
  3583. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3584. $idac = $this->functionsController->registerActivity(
  3585. $line,
  3586. 'S002V01M01ADSI',
  3587. 'S002V01F06ASWA',
  3588. 'S002V01P05ESSW',
  3589. 'Consulta',
  3590. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el enrutamiento de los SCADA a los servicios web.",
  3591. $idUser,
  3592. $nowStr
  3593. );
  3594. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3595. return $this->responseController->makeResponse(false, 'EXITO', $arrList);
  3596. }
  3597. public function changeTokenAccess(Request $request){
  3598. DB::enableQueryLog();
  3599. $validator = Validator::make($request->all(), [
  3600. 'id_user' => 'required|string',
  3601. 'linea' => 'required|integer',
  3602. 'estado' => 'required|string|in:Activo,Inactivo',
  3603. 'key' => 'required|string',
  3604. ]);
  3605. if($validator->fails()){
  3606. return $this->responseController->makeResponse(
  3607. true,
  3608. "Se encontraron uno o más errores.",
  3609. $this->responseController->makeErrors(
  3610. $validator->errors()->messages()
  3611. ),
  3612. 401
  3613. );
  3614. }
  3615. $form = $request->all();
  3616. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3617. if(!$idUser){
  3618. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3619. }
  3620. $usr = DB::table('S002V01TUSUA')->where([
  3621. ['USUA_NULI', '=', $form['linea']],
  3622. ['USUA_IDUS', '=', $idUser]
  3623. ])->first();
  3624. if(is_null($usr)){
  3625. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3626. }
  3627. $keyStr = $this->encryptionController->decrypt($form['key']);
  3628. if(!$keyStr){
  3629. return $this->responseController->makeResponse(true, 'La llave del token no fue encriptada correctamente.', [], 400);
  3630. }
  3631. $keyArr = explode('|', $keyStr);
  3632. if(count($keyArr) != 2){
  3633. return $this->responseController->makeResponse(true, 'La llave del token no tiene un formato correcto.', [], 400);
  3634. }
  3635. $now = $this->functionsController->now();
  3636. $nowStr = $now->toDateTimeString();
  3637. DB::table('S002V01TTASW')->where([
  3638. ['TASW_NULI', '=', $form['linea']],
  3639. ['TASW_IDSC', '=', $keyArr[0]],
  3640. ['TASW_TOKE', '=', $keyArr[1]],
  3641. ])->update([
  3642. 'TASW_ESTA' => $form['estado'],
  3643. 'TASW_TIMO' => 'Cambio de estado del token',
  3644. 'TASW_USMO' => $idUser,
  3645. 'TASW_FEMO' => $nowStr,
  3646. ]);
  3647. $actions = DB::getQueryLog();
  3648. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3649. $idac = $this->functionsController->registerActivity(
  3650. $form['linea'],
  3651. 'S002V01M01ADSI',
  3652. 'S002V01F06ASWA',
  3653. 'S002V01P05ESSW',
  3654. 'Actualización',
  3655. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el estado de un token.",
  3656. $idUser,
  3657. $nowStr
  3658. );
  3659. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3660. return $this->responseController->makeResponse(false, 'EXITO.');
  3661. }
  3662. public function changeWebService(Request $request){
  3663. DB::enableQueryLog();
  3664. $validator = Validator::make($request->all(), [
  3665. 'id_user' => 'required|string',
  3666. 'linea' => 'required|integer',
  3667. 'key' => 'required|string',
  3668. 'id_web_service' => 'required|string',
  3669. ]);
  3670. if($validator->fails()){
  3671. return $this->responseController->makeResponse(
  3672. true,
  3673. "Se encontraron uno o más errores.",
  3674. $this->responseController->makeErrors(
  3675. $validator->errors()->messages()
  3676. ),
  3677. 401
  3678. );
  3679. }
  3680. $form = $request->all();
  3681. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3682. if(!$idUser){
  3683. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3684. }
  3685. $usr = DB::table('S002V01TUSUA')->where([
  3686. ['USUA_NULI', '=', $form['linea']],
  3687. ['USUA_IDUS', '=', $idUser]
  3688. ])->first();
  3689. if(is_null($usr)){
  3690. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3691. }
  3692. $keyToken = $this->encryptionController->decrypt($form['key']);
  3693. if(!$keyToken){
  3694. return $this->responseController->makeResponse(true, 'La llave del token no está encriptada correctamente.', [], 400);
  3695. }
  3696. $keyArr = explode('|', $keyToken);
  3697. $token = DB::table('S002V01TTASW')->where([
  3698. ['TASW_NULI', '=', $form['linea']],
  3699. ['TASW_IDSC', '=', $keyArr[0]],
  3700. ['TASW_TOKE', '=', $keyArr[1]],
  3701. ])->first();
  3702. if(is_null($token)){
  3703. return $this->responseController->makeResponse(true, 'El token solicitado no existe.', [], 404);
  3704. }
  3705. $idWS = $this->encryptionController->decrypt($form['id_web_service']);
  3706. if(!$idWS){
  3707. return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
  3708. }
  3709. $webService = DB::table('S002V01TLSWE')->where([
  3710. ['LSWE_NULI', '=', $form['linea']],
  3711. ['LSWE_IDSW', '=', $idWS]
  3712. ])->first();
  3713. if(is_null($webService)){
  3714. return $this->responseController->makeResponse(true, 'El servicio web solicitado no existe', [], 404);
  3715. }
  3716. $now = $this->functionsController->now();
  3717. $nowStr = $now->toDateTimeString();
  3718. DB::table('S002V01TTASW')->where([
  3719. ['TASW_NULI', '=', $form['linea']],
  3720. ['TASW_IDSC', '=', $keyArr[0]],
  3721. ['TASW_TOKE', '=', $keyArr[1]],
  3722. ])->update([
  3723. 'TASW_IDSW' => $idWS,
  3724. 'TASW_TIMO' => 'Cambio de servicio web',
  3725. 'TASW_USMO' => $idUser,
  3726. 'TASW_FEMO' => $nowStr,
  3727. ]);
  3728. $actions = DB::getQueryLog();
  3729. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3730. $idac = $this->functionsController->registerActivity(
  3731. $form['linea'],
  3732. 'S002V01M01ADSI',
  3733. 'S002V01F06ASWA',
  3734. 'S002V01P05ESSW',
  3735. 'Actualización',
  3736. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servicio web de un SCADA.",
  3737. $idUser,
  3738. $nowStr
  3739. );
  3740. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3741. return $this->responseController->makeResponse(false, 'EXITO.');
  3742. }
  3743. public function updateWebService(Request $request){
  3744. DB::enableQueryLog();
  3745. $validator = Validator::make($request->all(), [
  3746. 'id_user' => 'required|string',
  3747. 'linea' => 'required|integer',
  3748. 'id_web_service' => 'required|string',
  3749. 'url' => 'required|string|max:250',
  3750. 'description' => 'required|string|max:100',
  3751. ]);
  3752. if($validator->fails()){
  3753. return $this->responseController->makeResponse(
  3754. true,
  3755. "Se encontraron uno o más errores.",
  3756. $this->responseController->makeErrors(
  3757. $validator->errors()->messages()
  3758. ),
  3759. 401
  3760. );
  3761. }
  3762. $form = $request->all();
  3763. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3764. if(!$idUser){
  3765. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3766. }
  3767. $usr = DB::table('S002V01TUSUA')->where([
  3768. ['USUA_NULI', '=', $form['linea']],
  3769. ['USUA_IDUS', '=', $idUser]
  3770. ])->first();
  3771. if(is_null($usr)){
  3772. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3773. }
  3774. $idWS = $this->encryptionController->decrypt($form['id_web_service']);
  3775. if(!$idWS){
  3776. return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
  3777. }
  3778. $now = $this->functionsController->now();
  3779. $nowStr = $now ->toDateTimeString();
  3780. DB::table('S002V01TLSWE')->where([
  3781. ['LSWE_IDSW', '=', $idWS],
  3782. ['LSWE_NULI', '=', $form['linea']]
  3783. ])->update([
  3784. 'LSWE_URLX' => $form['url'],
  3785. 'LSWE_DESC' => $form['description'],
  3786. 'LSWE_USMO' => $idUser,
  3787. 'LSWE_FEMO' => $nowStr,
  3788. ]);
  3789. $actions = DB::getQueryLog();
  3790. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3791. $idac = $this->functionsController->registerActivity(
  3792. $form['linea'],
  3793. 'S002V01M01ADSI',
  3794. 'S002V01F06ASWA',
  3795. 'S002V01P07RESW',
  3796. 'Actualización',
  3797. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el servicio web $form[url] ($idWS).",
  3798. $idUser,
  3799. $nowStr
  3800. );
  3801. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3802. return $this->responseController->makeResponse(false, 'EXITO.');
  3803. }
  3804. public function changeWSstatus(Request $request){
  3805. DB::enableQueryLog();
  3806. $validator = Validator::make($request->all(), [
  3807. 'id_user' => 'required|string',
  3808. 'linea' => 'required|integer',
  3809. 'id_web_service' => 'required|string',
  3810. 'status' => 'required|string|in:Activo,Inactivo',
  3811. ]);
  3812. if($validator->fails()){
  3813. return $this->responseController->makeResponse(
  3814. true,
  3815. "Se encontraron uno o más errores.",
  3816. $this->responseController->makeErrors(
  3817. $validator->errors()->messages()
  3818. ),
  3819. 401
  3820. );
  3821. }
  3822. $form = $request->all();
  3823. $idUser = $this->encryptionController->decrypt($form['id_user']);
  3824. if(!$idUser){
  3825. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  3826. }
  3827. $usr = DB::table('S002V01TUSUA')->where([
  3828. ['USUA_NULI', '=', $form['linea']],
  3829. ['USUA_IDUS', '=', $idUser]
  3830. ])->first();
  3831. if(is_null($usr)){
  3832. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  3833. }
  3834. $idWS = $this->encryptionController->decrypt($form['id_web_service']);
  3835. if(!$idWS){
  3836. return $this->responseController->makeResponse(true, 'El ID del servicio web no fue encriptado correctamente.', [], 400);
  3837. }
  3838. $webService = DB::table('S002V01TLSWE')->where([
  3839. ['LSWE_NULI', '=', $form['linea']],
  3840. ['LSWE_IDSW', '=', $idWS]
  3841. ])->first();
  3842. if(is_null($webService)){
  3843. return $this->responseController->makeResponse(true, 'El servicio web solicitado no existe.', [], 404);
  3844. }
  3845. $now = $this->functionsController->now();
  3846. $nowStr = $now->toDateTimeString();
  3847. DB::table('S002V01TLSWE')->where([
  3848. ['LSWE_NULI', '=', $form['linea']],
  3849. ['LSWE_IDSW', '=', $idWS],
  3850. ])->update([
  3851. 'LSWE_ESTA' => $form['status'],
  3852. 'LSWE_USMO' => $idUser,
  3853. 'LSWE_FEMO' => $nowStr,
  3854. ]);
  3855. $actions = DB::getQueryLog();
  3856. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3857. $idac = $this->functionsController->registerActivity(
  3858. $form['linea'],
  3859. 'S002V01M01ADSI',
  3860. 'S002V01F06ASWA',
  3861. 'S002V01P07RESW',
  3862. 'Actualización',
  3863. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el estado servicio web de un SCADA.",
  3864. $idUser,
  3865. $nowStr
  3866. );
  3867. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  3868. return $this->responseController->makeResponse(false, 'EXITO.');
  3869. }
  3870. public function getBackupsList($idUser, $line){
  3871. DB::enableQueryLog();
  3872. $idUser = $this->encryptionController->decrypt($idUser);
  3873. if(!$idUser){
  3874. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3875. }
  3876. $usr = DB::table('S002V01TUSUA')->where([
  3877. ['USUA_IDUS', '=', $idUser],
  3878. ['USUA_NULI', '=', $line]
  3879. ])->first();
  3880. if(is_null($usr)){
  3881. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3882. }
  3883. $backups = DB::table('S002V01TRESP')->select([
  3884. 'RESP_IDRE AS IDRESPALDO',
  3885. 'RESP_FERE AS FECHARESPALDO',
  3886. 'RESP_ESTA AS ESTADO',
  3887. 'RESP_LORE AS LOG',
  3888. ])->where('RESP_NULI', '=', $line)->get()->all();
  3889. $now = $this->functionsController->now();
  3890. $nowStr = $now->toDateTimeString();
  3891. $actions = DB::getQueryLog();
  3892. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3893. $idac = $this->functionsController->registerActivity(
  3894. $line,
  3895. 'S002V01M01ADSI',
  3896. 'S002V01F12GERE',
  3897. 'S002V01P01HRES',
  3898. 'Consulta',
  3899. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la lista de respaldos.",
  3900. $idUser,
  3901. $nowStr
  3902. );
  3903. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3904. return $this->responseController->makeResponse(false, 'EXITO', $backups);
  3905. }
  3906. public function getSubmoduleFunctions($idMod, $idSub, $idUser, $line){
  3907. DB::enableQueryLog();
  3908. $idUser = $this->encryptionController->decrypt($idUser);
  3909. if(!$idUser){
  3910. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  3911. }
  3912. $usr = DB::table('S002V01TUSUA')->where([
  3913. ['USUA_IDUS', '=', $idUser],
  3914. ['USUA_NULI', '=', $line]
  3915. ])->first();
  3916. if(is_null($usr)){
  3917. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  3918. }
  3919. $idMod = $this->encryptionController->decrypt($idMod);
  3920. if(!$idMod){
  3921. return $this->responseController->makeResponse(true, 'El ID del módulo no está encriptado correctamente', [], 400);
  3922. }
  3923. $mod = DB::table('S002V01TMODU')->where([
  3924. ['MODU_NULI', '=', $line],
  3925. ['MODU_IDMO', '=', $idMod]
  3926. ])->first();
  3927. if(is_null($mod)){
  3928. return $this->responseController->makeResponse(true, 'El módulo enviado no existe', [], 404);
  3929. }
  3930. $idSub = $this->encryptionController->decrypt($idSub);
  3931. if(!$idSub){
  3932. return $this->responseController->makeResponse(true, 'El ID del submódulo no está encriptado correctamente', [], 400);
  3933. }
  3934. $sub = DB::table('S002V01TSUBM')->where([
  3935. ['SUBM_NULI', '=', $line],
  3936. ['SUBM_IDSM', '=', $idSub],
  3937. ['SUBM_IDMO', '=', $idMod],
  3938. ])->first();
  3939. if(is_null($sub)){
  3940. return $this->responseController->makeResponse(true, 'El submódulo enviado no existe', [], 404);
  3941. }
  3942. $functions = DB::table('S002V01TFUNC')->select([
  3943. 'FUNC_IDFU AS IDFUNCION',
  3944. 'FUNC_NOMB AS NOMBREFUNCION',
  3945. 'FUNC_ICON AS ICONOFUNCION',
  3946. ])->where([
  3947. ['FUNC_NULI', '=', $line],
  3948. ['FUNC_IDMO', '=', $idMod],
  3949. ['FUNC_IDSM', '=', $idSub],
  3950. ])->get()->all();
  3951. foreach($functions as $function){
  3952. $screens = DB::table('S002V01TPANT')->where([
  3953. ['PANT_NULI', '=', $line],
  3954. ['PANT_IDFU', '=', $function->IDFUNCION],
  3955. ])->get()->all();
  3956. $function->HASSCREENS = count($screens) > 0;
  3957. }
  3958. $now = $this->functionsController->now();
  3959. $nowStr = $now->toDateTimeString();
  3960. $actions = DB::getQueryLog();
  3961. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  3962. $idac = $this->functionsController->registerActivity(
  3963. $line,
  3964. '-',
  3965. '-',
  3966. '-',
  3967. 'Consulta',
  3968. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las funciones del submódulo " . $sub->SUBM_NOMB . " ($idSub).",
  3969. $idUser,
  3970. $nowStr
  3971. );
  3972. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  3973. return $this->responseController->makeResponse(false, 'EXITO', $functions);
  3974. }
  3975. public function getTaxInformation($line){
  3976. try {
  3977. $getTaxInformation = DB::table('S002V01TINFI')
  3978. ->where('INFI_NULI','=',$line)
  3979. ->where('INFI_ESTA','=','Activo')
  3980. ->first([
  3981. 'INFI_IDIN',
  3982. 'INFI_NOFI',
  3983. 'INFI_XRFC',
  3984. 'INFI_COEL',
  3985. 'INFI_CORF',
  3986. 'INFI_LAD1',
  3987. 'INFI_TEL1',
  3988. 'INFI_LAD2',
  3989. 'INFI_TEL2',
  3990. 'INFI_COPO',
  3991. 'INFI_TIVI',
  3992. 'INFI_VIAL',
  3993. 'INFI_ENCA',
  3994. 'INFI_YCAL',
  3995. 'INFI_NUEX',
  3996. 'INFI_NUIN',
  3997. 'INFI_COLO',
  3998. 'INFI_LOCA',
  3999. 'INFI_MUNI',
  4000. 'INFI_ENFE',
  4001. 'INFI_PAIS',
  4002. 'INFI_USRE',
  4003. 'INFI_FERE',
  4004. 'INFI_USMO',
  4005. 'INFI_FEMO',
  4006. ]);
  4007. } catch (\Throwable $th) {
  4008. DB::rollBack();
  4009. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_GET_TAX_INFORMATION000: Ocurrió un error al obtener la información fiscal.", [], 401);
  4010. }
  4011. return $this->responseController->makeResponse(false, 'EXITO', $getTaxInformation);
  4012. }
  4013. public function getCountriesList($idUser, $line) {
  4014. DB::enableQueryLog();
  4015. $idUser = $this->encryptionController->decrypt($idUser);
  4016. if(!$idUser){
  4017. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4018. }
  4019. $usr = DB::table('S002V01TUSUA')->where([
  4020. ['USUA_NULI', '=', $line],
  4021. ['USUA_IDUS', '=', $idUser],
  4022. ])->first();
  4023. if(is_null($usr)){
  4024. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4025. }
  4026. $catalogue = DB::table('S002V01TCATA')->where([
  4027. ['CATA_TICA', '=', 'Países'],
  4028. ['CATA_ESTA', '=', 'Activo'],
  4029. ['CATA_NULI', '=', $line],
  4030. ])->orderBy('CATA_VERS', 'desc')->first();
  4031. if(is_null($catalogue)){
  4032. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de paises', [], 404);
  4033. }
  4034. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4035. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4036. if(!$fileDec){
  4037. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  4038. }
  4039. $fileArr = explode("=", $fileDec);
  4040. $idArr = explode("-", $fileArr[0]);
  4041. $file = DB::table('S002V01TAFAL')->where([
  4042. ['AFAL_NULI', '=', $line],
  4043. ['AFAL_COMO', '=', $idArr[1]],
  4044. ['AFAL_CLDO', '=', $idArr[2]],
  4045. ['AFAL_FECR', '=', $idArr[3]],
  4046. ['AFAL_NUSE', '=', $idArr[4]],
  4047. ['AFAL_NUVE', '=', $fileArr[1]],
  4048. ])->first();
  4049. if(is_null($file)){
  4050. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  4051. }else if($file->AFAL_ESTA == 'Eliminado'){
  4052. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  4053. }else if(!file_exists($file->AFAL_UBIC)){
  4054. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  4055. }
  4056. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4057. $sheetNames = $spreadsheet->getSheetNames();
  4058. if(!in_array('c_Pais', $sheetNames)){
  4059. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Pais.', [], 400);
  4060. }
  4061. $worksheet = $spreadsheet->getActiveSheet();
  4062. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  4063. if($fileValidatorCell != 'c_Pais'){
  4064. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4065. }
  4066. $countries = [];
  4067. $maxRow = $worksheet->getHighestRow();
  4068. for($row = 6; $row <= $maxRow; $row++){
  4069. $countryKey = $worksheet->getCell("A$row")->getValue();
  4070. $countryName = $worksheet->getCell("B$row")->getValue();
  4071. $countryInfo = DB::table('S002V01TPAIS')->where([
  4072. ['PAIS_NULI', '=', $line],
  4073. ['PAIS_IDPA', '=', $countryKey],
  4074. ])->first();
  4075. $countries[] = [
  4076. 'COUNTRY_ID' => $countryKey,
  4077. 'NAME' => $countryName,
  4078. 'LADA' => is_null($countryInfo) ? null : $countryInfo->PAIS_LADA,
  4079. 'NOMECLARUTA_ISO2' => is_null($countryInfo) ? null : $countryInfo->PAIS_NOME
  4080. ];
  4081. }
  4082. $now = $this->functionsController->now();
  4083. $nowStr = $now->toDateTimeString();
  4084. $actions = DB::getQueryLog();
  4085. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4086. $idac = $this->functionsController->registerActivity(
  4087. $line,
  4088. 'S002V01M01ADSI',
  4089. 'S002V01F10AGCA',
  4090. 'S002V01P01HICA',
  4091. 'Consulta',
  4092. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Países.",
  4093. $idUser,
  4094. $nowStr
  4095. );
  4096. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4097. return $this->responseController->makeResponse(false, 'EXITO', $countries);
  4098. }
  4099. public function saveCatalogueConfig(Request $request) {
  4100. DB::enableQueryLog();
  4101. $validator = Validator::make($request->all(), [
  4102. 'id_user' => 'required|string',
  4103. 'linea' => 'required|integer',
  4104. 'catalogue_type' => 'required|string',
  4105. 'config' => 'required|json',
  4106. ]);
  4107. if($validator->fails()){
  4108. return $this->responseController->makeResponse(
  4109. true,
  4110. "Se encontraron uno o más errores.",
  4111. $this->responseController->makeErrors(
  4112. $validator->errors()->messages()
  4113. ),
  4114. 401
  4115. );
  4116. }
  4117. $form = $request->all();
  4118. $idUser = $this->encryptionController->decrypt($form['id_user']);
  4119. if(!$idUser){
  4120. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  4121. }
  4122. $usr = DB::table('S002V01TUSUA')->where([
  4123. ['USUA_NULI', '=', $form['linea']],
  4124. ['USUA_IDUS', '=', $idUser]
  4125. ])->first();
  4126. if(is_null($usr)){
  4127. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  4128. }
  4129. $allowedFiles = ["Colonias", "Códigos postales", "Estados", "Localidades", "Municipios", "Países", "Monedas", "Régimen fiscal"];
  4130. if(!in_array($form['catalogue_type'], $allowedFiles)){
  4131. return $this->responseController->makeResponse(true, "El tipo de catálogo no está soportado.", [], 400);
  4132. }
  4133. $catalogue = DB::table('S002V01TCATA')->where([
  4134. ['CATA_TICA', '=', $form['catalogue_type']],
  4135. ['CATA_ESTA', '=', 'Activo'],
  4136. ['CATA_NULI', '=', $form['linea']],
  4137. ])->orderBy('CATA_VERS', 'desc')->first();
  4138. if(is_null($catalogue)){
  4139. return $this->responseController->makeResponse(true, "Aún no se ha registrado ningún catálogo de $form[catalogue_type]", [], 404);
  4140. }
  4141. $now = $this->functionsController->now();
  4142. $nowStr = $now->toDateTimeString();
  4143. switch($form['catalogue_type']){
  4144. case "Países":
  4145. $configArr = json_decode($form['config'], true);
  4146. foreach($configArr as $val){
  4147. $country = DB::table('S002V01TPAIS')->where([
  4148. ['PAIS_NULI', '=', $form['linea']],
  4149. ['PAIS_IDPA', '=', $val['COUNTRY_ID']],
  4150. ])->first();
  4151. if(is_null($val['COUNTRY_ID'])) continue;
  4152. if(is_null($country)){
  4153. DB::table('S002V01TPAIS')->insert([
  4154. 'PAIS_NULI' => $form['linea'],
  4155. 'PAIS_IDPA' => $val['COUNTRY_ID'],
  4156. 'PAIS_NOMB' => $val['NAME'],
  4157. 'PAIS_NOME' => $val['NOMECLARUTA_ISO2'],
  4158. 'PAIS_LADA' => $val['LADA'],
  4159. 'PAIS_USRE' => $idUser,
  4160. 'PAIS_FERE' => $nowStr,
  4161. ]);
  4162. }else{
  4163. DB::table('S002V01TPAIS')->where([
  4164. ['PAIS_NULI', '=', $form['linea']],
  4165. ['PAIS_IDPA', '=', $val['COUNTRY_ID']],
  4166. ])->update([
  4167. 'PAIS_NOME' => $val['NOMECLARUTA_ISO2'],
  4168. 'PAIS_LADA' => $val['LADA'],
  4169. 'PAIS_USMO' => $idUser,
  4170. 'PAIS_FEMO' => $nowStr,
  4171. ]);
  4172. }
  4173. }
  4174. break;
  4175. case "Códigos postales":
  4176. $configArr = json_decode($form['config'], true);
  4177. foreach($configArr as $val){
  4178. $zipCode = DB::table('S002V01TCOPO')->where([
  4179. ['COPO_NULI', '=', $form['linea']],
  4180. ['COPO_COPO', '=', $val['CODIGO_POSTAL']],
  4181. ['COPO_COES', '=', $val['ESTADO']],
  4182. ])->first();
  4183. if(is_null($val['CODIGO_POSTAL'])) continue;
  4184. if(is_null($zipCode)){
  4185. DB::table('S002V01TCOPO')->insert([
  4186. 'COPO_NULI' => $form['linea'],
  4187. 'COPO_COPO' => $val['CODIGO_POSTAL'],
  4188. 'COPO_COES' => $val['ESTADO'],
  4189. 'COPO_COMU' => $val['MUNICIPIO'],
  4190. 'COPO_COLO' => $val['LOCALIDAD'],
  4191. 'COPO_USRE' => $idUser,
  4192. 'COPO_FERE' => $nowStr,
  4193. ]);
  4194. }else{
  4195. DB::table('S002V01TCOPO')->where([
  4196. ['COPO_NULI', '=', $form['linea']],
  4197. ['COPO_COPO', '=', $val['CODIGO_POSTAL']],
  4198. ['COPO_COES', '=', $val['ESTADO']],
  4199. ])->update([
  4200. 'COPO_COMU' => $val['MUNICIPIO'],
  4201. 'COPO_COLO' => $val['LOCALIDAD'],
  4202. 'COPO_USMO' => $idUser,
  4203. 'COPO_FEMO' => $nowStr,
  4204. ]);
  4205. }
  4206. }
  4207. break;
  4208. case "Estados":
  4209. $configArr = json_decode($form['config'], true);
  4210. foreach($configArr as $val){
  4211. $state = DB::table('S002V01TESTA')->where([
  4212. ['ESTA_NULI', '=', $form['linea']],
  4213. ['ESTA_COES', '=', $val['STATE_KEY']],
  4214. ['ESTA_COPA', '=', $val['COUNTRY_KEY']],
  4215. ])->first();
  4216. if(is_null($val['STATE_KEY'])) continue;
  4217. if(is_null($state)){
  4218. DB::table('S002V01TESTA')->insert([
  4219. 'ESTA_NULI' => $form['linea'],
  4220. 'ESTA_COES' => $val['STATE_KEY'],
  4221. 'ESTA_COPA' => $val['COUNTRY_KEY'],
  4222. 'ESTA_NOES' => $val['STATE_NAME'],
  4223. 'ESTA_USRE' => $idUser,
  4224. 'ESTA_FERE' => $nowStr,
  4225. ]);
  4226. }else{
  4227. DB::table('S002V01TESTA')->where([
  4228. ['ESTA_NULI', '=', $form['linea']],
  4229. ['ESTA_COES', '=', $val['STATE_KEY']],
  4230. ['ESTA_COPA', '=', $val['COUNTRY_KEY']],
  4231. ])->update([
  4232. 'ESTA_NOES' => $val['STATE_NAME'],
  4233. 'ESTA_USMO' => $idUser,
  4234. 'ESTA_FEMO' => $nowStr,
  4235. ]);
  4236. }
  4237. }
  4238. break;
  4239. case "Municipios":
  4240. $configArr = json_decode($form['config'], true);
  4241. foreach($configArr as $val){
  4242. $city = DB::table('S002V01TMUNI')->where([
  4243. ['MUNI_NULI', '=', $form['linea']],
  4244. ['MUNI_COMU', '=', $val['CITY_KEY']],
  4245. ['MUNI_COES', '=', $val['STATE_KEY']],
  4246. ])->first();
  4247. if(is_null($val['CITY_KEY'])) continue;
  4248. if(is_null($city)){
  4249. DB::table('S002V01TMUNI')->insert([
  4250. 'MUNI_NULI' => $form['linea'],
  4251. 'MUNI_COMU' => $val['CITY_KEY'],
  4252. 'MUNI_COES' => $val['STATE_KEY'],
  4253. 'MUNI_NOMU' => $val['CITY_NAME'],
  4254. 'MUNI_USRE' => $idUser,
  4255. 'MUNI_FERE' => $nowStr,
  4256. ]);
  4257. }else{
  4258. DB::table('S002V01TMUNI')->where([
  4259. ['MUNI_NULI', '=', $form['linea']],
  4260. ['MUNI_COMU', '=', $val['CITY_KEY']],
  4261. ['MUNI_COES', '=', $val['STATE_KEY']],
  4262. ])->update([
  4263. 'MUNI_NOMU' => $val['CITY_NAME'],
  4264. 'MUNI_USMO' => $idUser,
  4265. 'MUNI_FEMO' => $nowStr,
  4266. ]);
  4267. }
  4268. }
  4269. break;
  4270. case "Localidades":
  4271. $configArr = json_decode($form['config'], true);
  4272. foreach($configArr as $val){
  4273. $town = DB::table('S002V01TLOCA')->where([
  4274. ['LOCA_NULI', '=', $form['linea']],
  4275. ['LOCA_COLO', '=', $val['TOWN_KEY']],
  4276. ['LOCA_COES', '=', $val['STATE_KEY']],
  4277. ])->first();
  4278. if(is_null($val['TOWN_KEY'])) continue;
  4279. if(is_null($town)){
  4280. DB::table('S002V01TLOCA')->insert([
  4281. 'LOCA_NULI' => $form['linea'],
  4282. 'LOCA_COLO' => $val['TOWN_KEY'],
  4283. 'LOCA_COES' => $val['STATE_KEY'],
  4284. 'LOCA_NOLO' => $val['TOWN_NAME'],
  4285. 'LOCA_USRE' => $idUser,
  4286. 'LOCA_FERE' => $nowStr,
  4287. ]);
  4288. }else{
  4289. DB::table('S002V01TLOCA')->where([
  4290. ['LOCA_NULI', '=', $form['linea']],
  4291. ['LOCA_COLO', '=', $val['TOWN_KEY']],
  4292. ['LOCA_COES', '=', $val['CITY_NAME']],
  4293. ])->update([
  4294. 'LOCA_NOLO' => $val['CITY_NAME'],
  4295. 'LOCA_USMO' => $idUser,
  4296. 'LOCA_FEMO' => $nowStr,
  4297. ]);
  4298. }
  4299. }
  4300. break;
  4301. case "Colonias":
  4302. $configArr = json_decode($form['config'], true);
  4303. foreach($configArr as $val){
  4304. $town = DB::table('S002V01TCOLO')->where([
  4305. ['COLO_NULI', '=', $form['linea']],
  4306. ['COLO_COCO', '=', $val['SETTING_KEY']],
  4307. ['COLO_COPO', '=', $val['CODIGO_POSTAL']],
  4308. ])->first();
  4309. if(is_null($val['SETTING_KEY'])) continue;
  4310. if(is_null($town)){
  4311. DB::table('S002V01TCOLO')->insert([
  4312. 'COLO_NULI' => $form['linea'],
  4313. 'COLO_COCO' => $val['SETTING_KEY'],
  4314. 'COLO_COPO' => $val['CODIGO_POSTAL'],
  4315. 'COLO_NOCO' => $val['SETTING_NAME'],
  4316. 'COLO_USRE' => $idUser,
  4317. 'COLO_FERE' => $nowStr,
  4318. ]);
  4319. }else{
  4320. DB::table('S002V01TCOLO')->where([
  4321. ['COLO_NULI', '=', $form['linea']],
  4322. ['COLO_COCO', '=', $val['SETTING_KEY']],
  4323. ['COLO_COPO', '=', $val['CODIGO_POSTAL']],
  4324. ])->update([
  4325. 'COLO_NOCO' => $val['SETTING_NAME'],
  4326. 'COLO_USMO' => $idUser,
  4327. 'COLO_FEMO' => $nowStr,
  4328. ]);
  4329. }
  4330. }
  4331. break;
  4332. case "Monedas":
  4333. $configArr = json_decode($form['config'], true);
  4334. foreach($configArr as $val){
  4335. $camo = DB::table('S002V01TCAMO')->where([
  4336. ['CAMO_NULI', '=', $form['linea']],
  4337. ['CAMO_COMO', '=', $val['COIN']],
  4338. ['CAMO_DESC', '=', $val['DESCRIPTION']],
  4339. ])->first();
  4340. if(is_null($val['COIN'])) continue;
  4341. if(is_null($camo)){
  4342. DB::table('S002V01TCAMO')->insert([
  4343. 'CAMO_COMO' => $val['COIN'],
  4344. 'CAMO_NULI' => $form['linea'],
  4345. 'CAMO_DESC' => $val['DESCRIPTION'],
  4346. 'CAMO_USRE' => $idUser,
  4347. 'CAMO_FERE' => $nowStr,
  4348. 'CAMO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  4349. ]);
  4350. }else{
  4351. DB::table('S002V01TCAMO')->where([
  4352. ['CAMO_NULI', '=', $form['linea']],
  4353. ['CAMO_COMO', '=', $val['COIN']],
  4354. ])->update([
  4355. 'CAMO_DESC' => $val['DESCRIPTION'],
  4356. 'CAMO_USMO' => $idUser,
  4357. 'CAMO_FEMO' => $nowStr,
  4358. 'CAMO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  4359. ]);
  4360. }
  4361. }
  4362. break;
  4363. case "Régimen fiscal":
  4364. $configArr = json_decode($form['config'], true);
  4365. foreach($configArr as $val){
  4366. $taxRegime = DB::table('S002V01TREFI')->where([
  4367. ['REFI_NULI', '=', $form['linea']],
  4368. ['REFI_CRFI', '=', $val['TAX_REGIME_KEY']],
  4369. ])->first();
  4370. if(is_null($val['TAX_REGIME_KEY'])) continue;
  4371. if(is_null($taxRegime)){
  4372. DB::table('S002V01TREFI')->insert([
  4373. 'REFI_NULI' => $form['linea'],
  4374. 'REFI_CRFI' => $val['TAX_REGIME_KEY'],
  4375. 'REFI_DRFI' => $val['TAX_REGIME_DESC'],
  4376. 'REFI_APFI' => $val['APPLY_PHISIC'],
  4377. 'REFI_APMO' => $val['APPLY_MORAL'],
  4378. 'REFI_FERE' => $nowStr,
  4379. 'REFI_USRE' => $idUser,
  4380. ]);
  4381. }else{
  4382. DB::table('S002V01TREFI')->where([
  4383. ['REFI_NULI', '=', $form['linea']],
  4384. ['REFI_CRFI', '=', $val['TAX_REGIME_KEY']],
  4385. ])->update([
  4386. 'REFI_DRFI' => $val['TAX_REGIME_DESC'],
  4387. 'REFI_APFI' => $val['APPLY_PHISIC'],
  4388. 'REFI_APMO' => $val['APPLY_MORAL'],
  4389. 'REFI_USMO' => $idUser,
  4390. 'REFI_FEMO' => $nowStr,
  4391. ]);
  4392. }
  4393. }
  4394. break;
  4395. }
  4396. $actions = DB::getQueryLog();
  4397. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4398. $idac = $this->functionsController->registerActivity(
  4399. $form['linea'],
  4400. 'S002V01M01ADSI',
  4401. 'S002V01F10AGCA',
  4402. 'S002V01P02NUCA',
  4403. 'Actualización',
  4404. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el catálogo $form[catalogue_type].",
  4405. $idUser,
  4406. $nowStr,
  4407. );
  4408. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  4409. return $this->responseController->makeresponse(false, "EXITO");
  4410. }
  4411. public function getZipCodes($idUser, $line){
  4412. ini_set("display_errors", 1);
  4413. ini_set("memory_limit", "-1");
  4414. DB::enableQueryLog();
  4415. $idUser = $this->encryptionController->decrypt($idUser);
  4416. if(!$idUser){
  4417. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4418. }
  4419. $usr = DB::table('S002V01TUSUA')->where([
  4420. ['USUA_NULI', '=', $line],
  4421. ['USUA_IDUS', '=', $idUser],
  4422. ])->first();
  4423. if(is_null($usr)){
  4424. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4425. }
  4426. $catalogue = DB::table('S002V01TCATA')->where([
  4427. ['CATA_TICA', '=', 'Códigos postales'],
  4428. ['CATA_ESTA', '=', 'Activo'],
  4429. ['CATA_NULI', '=', $line],
  4430. ])->orderBy('CATA_VERS', 'desc')->first();
  4431. if(is_null($catalogue)){
  4432. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de códigos postales', [], 404);
  4433. }
  4434. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4435. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4436. if(!$fileDec){
  4437. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de códigos postales no fue encriptado correctamente.', [], 400);
  4438. }
  4439. $fileArr = explode("=", $fileDec);
  4440. $idArr = explode("-", $fileArr[0]);
  4441. $file = DB::table('S002V01TAFAL')->where([
  4442. ['AFAL_NULI', '=', $line],
  4443. ['AFAL_COMO', '=', $idArr[1]],
  4444. ['AFAL_CLDO', '=', $idArr[2]],
  4445. ['AFAL_FECR', '=', $idArr[3]],
  4446. ['AFAL_NUSE', '=', $idArr[4]],
  4447. ['AFAL_NUVE', '=', $fileArr[1]],
  4448. ])->first();
  4449. if(is_null($file)){
  4450. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales no está registrado.', [], 404);
  4451. }else if($file->AFAL_ESTA == 'Eliminado'){
  4452. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales está eliminado.', [], 404);
  4453. }else if(!file_exists($file->AFAL_UBIC)){
  4454. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de códigos postales no existe en el almacenamiento final.', [], 404);
  4455. }
  4456. $now = $this->functionsController->now();
  4457. $nowStr = $now->toDateTimeString();
  4458. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4459. $sheetNames = $spreadsheet->getSheetNames();
  4460. $zipCodes = [];
  4461. foreach($sheetNames as $name){
  4462. if(!str_contains($name, 'c_CodigoPostal')){
  4463. return $this->responseController->makeResponse(true, "La hoja $name no pertenece al catálogo de códigos postales.", [], 400);
  4464. }
  4465. $worksheet = $spreadsheet->getSheetByName($name);
  4466. $fileValidatorCell = $worksheet->getCell('A6')->getValue();
  4467. if($fileValidatorCell != 'c_CodigoPostal'){
  4468. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4469. }
  4470. $maxRow = $worksheet->getHighestRow();
  4471. for($row = 8; $row <= $maxRow; $row++){
  4472. $zipCode = $worksheet->getCell("A$row")->getValue();
  4473. if($zipCode == null) continue;
  4474. $state = $worksheet->getCell("B$row")->getValue();
  4475. $city = $worksheet->getCell("C$row")->getValue();
  4476. $town = $worksheet->getCell("D$row")->getValue();
  4477. if(is_null($state)) continue;
  4478. $endDateNum = $worksheet->getCell("G$row")->getValue();
  4479. if(is_null($endDateNum)){
  4480. $zipCodes[] = [
  4481. 'CODIGO_POSTAL' => $zipCode,
  4482. 'ESTADO' => $state,
  4483. 'MUNICIPIO' => $city,
  4484. 'LOCALIDAD' => $town,
  4485. ];
  4486. }else{
  4487. $endDateStr = Date::excelToTimestamp($endDateNum);
  4488. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  4489. if($endDateObj->gte($now)){
  4490. $zipCodes[] = [
  4491. 'CODIGO_POSTAL' => $zipCode,
  4492. 'ESTADO' => $state,
  4493. 'MUNICIPIO' => $city,
  4494. 'LOCALIDAD' => $town,
  4495. ];
  4496. }
  4497. }
  4498. }
  4499. }
  4500. $actions = DB::getQueryLog();
  4501. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4502. $idac = $this->functionsController->registerActivity(
  4503. $line,
  4504. 'S002V01M01ADSI',
  4505. 'S002V01F10AGCA',
  4506. 'S002V01P01HICA',
  4507. 'Consulta',
  4508. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Códigos postales.",
  4509. $idUser,
  4510. $nowStr
  4511. );
  4512. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4513. return $this->responseController->makeResponse(false, 'EXITO', $zipCodes);
  4514. }
  4515. public function getZipCodesTotal($idUser, $line) {
  4516. DB::enableQueryLog();
  4517. $idUser = $this->encryptionController->decrypt($idUser);
  4518. if(!$idUser){
  4519. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4520. }
  4521. $usr = DB::table('S002V01TUSUA')->where([
  4522. ['USUA_NULI', '=', $line],
  4523. ['USUA_IDUS', '=', $idUser],
  4524. ])->first();
  4525. if(is_null($usr)){
  4526. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4527. }
  4528. $totalZipCodes = DB::table('S002V01TCOPO')->select(DB::raw('count(*) as total_zip_codes'))->where(
  4529. 'COPO_NULI', '=', $line
  4530. )->first();
  4531. $now = $this->functionsController->now();
  4532. $nowStr = $now->toDateTimeString();
  4533. $actions = DB::getQueryLog();
  4534. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4535. $idac = $this->functionsController->registerActivity(
  4536. $line,
  4537. 'S002V01M01ADSI',
  4538. 'S002V01F10AGCA',
  4539. 'S002V01P01HICA',
  4540. 'Consulta',
  4541. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el total de Códigos postales.",
  4542. $idUser,
  4543. $nowStr
  4544. );
  4545. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4546. return $this->responseController->makeResponse(false, 'EXITO', ["TOTAL_ZIP_CODES" => $totalZipCodes->total_zip_codes]);
  4547. }
  4548. public function getZipCodesPage($limit, $offset, $idUser, $line) {
  4549. DB::enableQueryLog();
  4550. $idUser = $this->encryptionController->decrypt($idUser);
  4551. if(!$idUser){
  4552. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4553. }
  4554. $usr = DB::table('S002V01TUSUA')->where([
  4555. ['USUA_NULI', '=', $line],
  4556. ['USUA_IDUS', '=', $idUser],
  4557. ])->first();
  4558. if(is_null($usr)){
  4559. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4560. }
  4561. $limit = intval($limit);
  4562. $offset = intval($offset);
  4563. $zipCodesPaginated = DB::table('S002V01TCOPO')->select([
  4564. 'COPO_COPO AS CODIGO_POSTAL',
  4565. 'COPO_COES AS ESTADO',
  4566. 'COPO_COMU AS MUNICIPIO',
  4567. 'COPO_COLO AS LOCALIDAD',
  4568. ])->where([
  4569. ['COPO_NULI', '=', $line],
  4570. ['COPO_ESTA', '=', 'Activo']
  4571. ])->offset($offset)->limit($limit)->orderBy('COPO_COES', 'ASC')->orderBy('COPO_COPO', 'ASC')->get()->all();
  4572. $now = $this->functionsController->now();
  4573. $nowStr = $now->toDateTimeString();
  4574. $actions = DB::getQueryLog();
  4575. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4576. $idac = $this->functionsController->registerActivity(
  4577. $line,
  4578. 'S002V01M01ADSI',
  4579. 'S002V01F10AGCA',
  4580. 'S002V01P01HICA',
  4581. 'Consulta',
  4582. "El usuario $name (" . $usr->USUA_IDUS . ") consultó $limit registros desde el $offset del catálogo de Códigos postales.",
  4583. $idUser,
  4584. $nowStr
  4585. );
  4586. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4587. return $this->responseController->makeResponse(false, 'EXITO', $zipCodesPaginated);
  4588. }
  4589. public function getAddressByZipCode($zipCode, $idUser, $line) {
  4590. DB::enableQueryLog();
  4591. $idUser = $this->encryptionController->decrypt($idUser);
  4592. if(!$idUser){
  4593. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4594. }
  4595. $usr = DB::table('S002V01TUSUA')->where([
  4596. ['USUA_NULI', '=', $line],
  4597. ['USUA_IDUS', '=', $idUser],
  4598. ])->first();
  4599. if(is_null($usr)){
  4600. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4601. }
  4602. $zipCode = $this->encryptionController->decrypt($zipCode);
  4603. if(!$zipCode){
  4604. return $this->responseController->makeResponse(true, 'El código postal enviado no está encriptado correctamente', [], 400);
  4605. }
  4606. $code = DB::table('S002V01TCOPO')->where([
  4607. ['COPO_NULI', '=', $line],
  4608. ['COPO_COPO', '=', $zipCode]
  4609. ])->first();
  4610. if(is_null($code)){
  4611. return $this->responseController->makeResponse(true, "El código postal $zipCode no está registrado.", [], 404);
  4612. }else if($code->COPO_ESTA == 'Eliminado'){
  4613. return $this->responseController->makeResponse(true, "El código postal $zipCode está eliminado.", [], 404);
  4614. }
  4615. $address = DB::table('S002V01TCOPO')->select([
  4616. 'COPO_COPO AS CODIGO_POSTAL',
  4617. 'COPO_COES AS CODIGO_ESTADO',
  4618. 'ESTA_NOES AS NOMBRE_ESTADO',
  4619. 'COPO_COMU AS CODIGO_MUNICIPIO',
  4620. 'MUNI_NOMU AS NOMBRE_MUNICIPIO',
  4621. 'COPO_COLO AS CODIGO_LOCALIDAD',
  4622. 'LOCA_NOLO AS NOMBRE_LOCALIDAD'
  4623. ])->where([
  4624. ['COPO_NULI', '=', $line],
  4625. ['COPO_COPO', '=', $zipCode]
  4626. ])->join('S002V01TESTA', 'COPO_COES', '=', 'ESTA_COES')
  4627. ->leftJoin('S002V01TMUNI', function(JoinClause $join) {
  4628. $join->on('COPO_COMU', '=', 'MUNI_COMU')
  4629. ->on('COPO_COES', '=', 'MUNI_COES');
  4630. })->leftJoin('S002V01TLOCA', function(JoinClause $join) {
  4631. $join->on('COPO_COLO', '=', 'LOCA_COLO')
  4632. ->on('COPO_COES', '=', 'LOCA_COES');
  4633. })->first();
  4634. $settings = DB::table('S002V01TCOLO')->select([
  4635. 'COLO_COCO AS CODIGO_COLONIA',
  4636. 'COLO_NOCO AS NOMBRE_COLONIA'
  4637. ])->where([
  4638. ['COLO_NULI', '=', $line],
  4639. ['COLO_COPO', '=', $zipCode],
  4640. ])->get()->all();
  4641. $address->COLONIAS = $settings;
  4642. $now = $this->functionsController->now();
  4643. $nowStr = $now->toDateTimeString();
  4644. $actions = DB::getQueryLog();
  4645. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4646. $idac = $this->functionsController->registerActivity(
  4647. $line,
  4648. 'S002V01M01ADSI',
  4649. 'S002V01F10AGCA',
  4650. 'S002V01P02NUCA',
  4651. 'Consulta',
  4652. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la dirección del código postal $zipCode.",
  4653. $idUser,
  4654. $nowStr,
  4655. );
  4656. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4657. return $this->responseController->makeresponse(false, "EXITO", $address);
  4658. }
  4659. public function getStatesList($idUser, $line) {
  4660. DB::enableQueryLog();
  4661. $idUser = $this->encryptionController->decrypt($idUser);
  4662. if(!$idUser){
  4663. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4664. }
  4665. $usr = DB::table('S002V01TUSUA')->where([
  4666. ['USUA_NULI', '=', $line],
  4667. ['USUA_IDUS', '=', $idUser],
  4668. ])->first();
  4669. if(is_null($usr)){
  4670. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4671. }
  4672. $catalogue = DB::table('S002V01TCATA')->where([
  4673. ['CATA_TICA', '=', 'Estados'],
  4674. ['CATA_ESTA', '=', 'Activo'],
  4675. ['CATA_NULI', '=', $line],
  4676. ])->orderBy('CATA_VERS', 'desc')->first();
  4677. if(is_null($catalogue)){
  4678. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
  4679. }
  4680. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4681. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4682. if(!$fileDec){
  4683. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  4684. }
  4685. $fileArr = explode("=", $fileDec);
  4686. $idArr = explode("-", $fileArr[0]);
  4687. $file = DB::table('S002V01TAFAL')->where([
  4688. ['AFAL_NULI', '=', $line],
  4689. ['AFAL_COMO', '=', $idArr[1]],
  4690. ['AFAL_CLDO', '=', $idArr[2]],
  4691. ['AFAL_FECR', '=', $idArr[3]],
  4692. ['AFAL_NUSE', '=', $idArr[4]],
  4693. ['AFAL_NUVE', '=', $fileArr[1]],
  4694. ])->first();
  4695. if(is_null($file)){
  4696. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  4697. }else if($file->AFAL_ESTA == 'Eliminado'){
  4698. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  4699. }else if(!file_exists($file->AFAL_UBIC)){
  4700. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  4701. }
  4702. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4703. $sheetNames = $spreadsheet->getSheetNames();
  4704. if(!in_array('c_Estado', $sheetNames)){
  4705. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Estado.', [], 400);
  4706. }
  4707. $worksheet = $spreadsheet->getActiveSheet();
  4708. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  4709. if($fileValidatorCell != 'c_Estado'){
  4710. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4711. }
  4712. $now = $this->functionsController->now();
  4713. $nowStr = $now->toDateTimeString();
  4714. $states = [];
  4715. $maxRow = $worksheet->getHighestRow();
  4716. for($row = 6; $row <= $maxRow; $row++){
  4717. $stateKey = $worksheet->getCell("A$row")->getValue();
  4718. $countryKey = $worksheet->getCell("B$row")->getValue();
  4719. $stateName = $worksheet->getCell("C$row")->getValue();
  4720. $endDateNum = $worksheet->getCell("E$row")->getValue();
  4721. if(is_null($endDateNum)){
  4722. $states[] = [
  4723. 'STATE_KEY' => $stateKey,
  4724. 'COUNTRY_KEY' => $countryKey,
  4725. 'STATE_NAME' => $stateName,
  4726. ];
  4727. }else{
  4728. $endDateStr = Date::excelToTimestamp($endDateNum);
  4729. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  4730. if($endDateObj->gte($now)){
  4731. $states[] = [
  4732. 'STATE_KEY' => $stateKey,
  4733. 'COUNTRY_KEY' => $countryKey,
  4734. 'STATE_NAME' => $stateName,
  4735. ];
  4736. }
  4737. }
  4738. }
  4739. $actions = DB::getQueryLog();
  4740. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4741. $idac = $this->functionsController->registerActivity(
  4742. $line,
  4743. 'S002V01M01ADSI',
  4744. 'S002V01F10AGCA',
  4745. 'S002V01P01HICA',
  4746. 'Consulta',
  4747. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Estados.",
  4748. $idUser,
  4749. $nowStr
  4750. );
  4751. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4752. return $this->responseController->makeResponse(false, 'EXITO', $states);
  4753. }
  4754. public function getCitiesList($idUser, $line) {
  4755. DB::enableQueryLog();
  4756. $idUser = $this->encryptionController->decrypt($idUser);
  4757. if(!$idUser){
  4758. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4759. }
  4760. $usr = DB::table('S002V01TUSUA')->where([
  4761. ['USUA_NULI', '=', $line],
  4762. ['USUA_IDUS', '=', $idUser],
  4763. ])->first();
  4764. if(is_null($usr)){
  4765. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4766. }
  4767. $catalogue = DB::table('S002V01TCATA')->where([
  4768. ['CATA_TICA', '=', 'Municipios'],
  4769. ['CATA_ESTA', '=', 'Activo'],
  4770. ['CATA_NULI', '=', $line],
  4771. ])->orderBy('CATA_VERS', 'desc')->first();
  4772. if(is_null($catalogue)){
  4773. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
  4774. }
  4775. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4776. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4777. if(!$fileDec){
  4778. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  4779. }
  4780. $fileArr = explode("=", $fileDec);
  4781. $idArr = explode("-", $fileArr[0]);
  4782. $file = DB::table('S002V01TAFAL')->where([
  4783. ['AFAL_NULI', '=', $line],
  4784. ['AFAL_COMO', '=', $idArr[1]],
  4785. ['AFAL_CLDO', '=', $idArr[2]],
  4786. ['AFAL_FECR', '=', $idArr[3]],
  4787. ['AFAL_NUSE', '=', $idArr[4]],
  4788. ['AFAL_NUVE', '=', $fileArr[1]],
  4789. ])->first();
  4790. if(is_null($file)){
  4791. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  4792. }else if($file->AFAL_ESTA == 'Eliminado'){
  4793. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  4794. }else if(!file_exists($file->AFAL_UBIC)){
  4795. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  4796. }
  4797. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4798. $sheetNames = $spreadsheet->getSheetNames();
  4799. if(!in_array('c_Municipio', $sheetNames)){
  4800. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Municipio.', [], 400);
  4801. }
  4802. $worksheet = $spreadsheet->getActiveSheet();
  4803. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  4804. if($fileValidatorCell != 'c_Municipio'){
  4805. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4806. }
  4807. $now = $this->functionsController->now();
  4808. $nowStr = $now->toDateTimeString();
  4809. $cities = [];
  4810. $maxRow = $worksheet->getHighestRow();
  4811. for($row = 6; $row <= $maxRow; $row++){
  4812. $cityKey = $worksheet->getCell("A$row")->getValue();
  4813. $stateKey = $worksheet->getCell("B$row")->getValue();
  4814. $cityName = $worksheet->getCell("C$row")->getValue();
  4815. $endDateNum = $worksheet->getCell("E$row")->getValue();
  4816. if(is_null($endDateNum)){
  4817. $cities[] = [
  4818. 'CITY_KEY' => $cityKey,
  4819. 'STATE_KEY' => $stateKey,
  4820. 'CITY_NAME' => $cityName,
  4821. ];
  4822. }else{
  4823. $endDateStr = Date::excelToTimestamp($endDateNum);
  4824. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  4825. if($endDateObj->gte($now)){
  4826. $cities[] = [
  4827. 'CITY_KEY' => $cityKey,
  4828. 'STATE_KEY' => $stateKey,
  4829. 'CITY_NAME' => $cityName,
  4830. ];
  4831. }
  4832. }
  4833. }
  4834. $actions = DB::getQueryLog();
  4835. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4836. $idac = $this->functionsController->registerActivity(
  4837. $line,
  4838. 'S002V01M01ADSI',
  4839. 'S002V01F10AGCA',
  4840. 'S002V01P01HICA',
  4841. 'Consulta',
  4842. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Municipios.",
  4843. $idUser,
  4844. $nowStr
  4845. );
  4846. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4847. return $this->responseController->makeResponse(false, 'EXITO', $cities);
  4848. }
  4849. public function getTownsList($idUser, $line) {
  4850. DB::enableQueryLog();
  4851. $idUser = $this->encryptionController->decrypt($idUser);
  4852. if(!$idUser){
  4853. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  4854. }
  4855. $usr = DB::table('S002V01TUSUA')->where([
  4856. ['USUA_NULI', '=', $line],
  4857. ['USUA_IDUS', '=', $idUser],
  4858. ])->first();
  4859. if(is_null($usr)){
  4860. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  4861. }
  4862. $catalogue = DB::table('S002V01TCATA')->where([
  4863. ['CATA_TICA', '=', 'Localidades'],
  4864. ['CATA_ESTA', '=', 'Activo'],
  4865. ['CATA_NULI', '=', $line],
  4866. ])->orderBy('CATA_VERS', 'desc')->first();
  4867. if(is_null($catalogue)){
  4868. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
  4869. }
  4870. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4871. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4872. if(!$fileDec){
  4873. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  4874. }
  4875. $fileArr = explode("=", $fileDec);
  4876. $idArr = explode("-", $fileArr[0]);
  4877. $file = DB::table('S002V01TAFAL')->where([
  4878. ['AFAL_NULI', '=', $line],
  4879. ['AFAL_COMO', '=', $idArr[1]],
  4880. ['AFAL_CLDO', '=', $idArr[2]],
  4881. ['AFAL_FECR', '=', $idArr[3]],
  4882. ['AFAL_NUSE', '=', $idArr[4]],
  4883. ['AFAL_NUVE', '=', $fileArr[1]],
  4884. ])->first();
  4885. if(is_null($file)){
  4886. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  4887. }else if($file->AFAL_ESTA == 'Eliminado'){
  4888. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  4889. }else if(!file_exists($file->AFAL_UBIC)){
  4890. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  4891. }
  4892. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4893. $sheetNames = $spreadsheet->getSheetNames();
  4894. if(!in_array('c_Localidad', $sheetNames)){
  4895. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Localidad.', [], 400);
  4896. }
  4897. $worksheet = $spreadsheet->getActiveSheet();
  4898. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  4899. if($fileValidatorCell != 'c_Localidad'){
  4900. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4901. }
  4902. $now = $this->functionsController->now();
  4903. $nowStr = $now->toDateTimeString();
  4904. $towns = [];
  4905. $maxRow = $worksheet->getHighestRow();
  4906. for($row = 6; $row <= $maxRow; $row++){
  4907. $townKey = $worksheet->getCell("A$row")->getValue();
  4908. $stateKey = $worksheet->getCell("B$row")->getValue();
  4909. $townName = $worksheet->getCell("C$row")->getValue();
  4910. $endDateNum = $worksheet->getCell("E$row")->getValue();
  4911. if(is_null($endDateNum)){
  4912. $towns[] = [
  4913. 'TOWN_KEY' => $townKey,
  4914. 'STATE_KEY' => $stateKey,
  4915. 'TOWN_NAME' => $townName,
  4916. ];
  4917. }else{
  4918. $endDateStr = Date::excelToTimestamp($endDateNum);
  4919. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  4920. if($endDateObj->gte($now)){
  4921. $towns[] = [
  4922. 'TOWN_KEY' => $townKey,
  4923. 'STATE_KEY' => $stateKey,
  4924. 'TOWN_NAME' => $townName,
  4925. ];
  4926. }
  4927. }
  4928. }
  4929. $actions = DB::getQueryLog();
  4930. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  4931. $idac = $this->functionsController->registerActivity(
  4932. $line,
  4933. 'S002V01M01ADSI',
  4934. 'S002V01F10AGCA',
  4935. 'S002V01P01HICA',
  4936. 'Consulta',
  4937. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Localidades.",
  4938. $idUser,
  4939. $nowStr
  4940. );
  4941. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  4942. return $this->responseController->makeResponse(false, 'EXITO', $towns);
  4943. }
  4944. public function getCoinsList($idUser, $line) {
  4945. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($idUser, $line);
  4946. if ($arrResponseCheckUser['error']) {
  4947. DB::rollBack();
  4948. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  4949. }
  4950. $user = $arrResponseCheckUser['response'];
  4951. $usr = DB::table('S002V01TUSUA')->where([
  4952. ['USUA_NULI', '=', $line],
  4953. ['USUA_IDUS', '=', $user],
  4954. ])->first();
  4955. try {
  4956. $catalogue = DB::table('S002V01TCATA')->where([
  4957. ['CATA_TICA', '=', 'Monedas'],
  4958. ['CATA_ESTA', '=', 'Activo'],
  4959. ['CATA_NULI', '=', $line],
  4960. ])->orderBy('CATA_VERS', 'desc')->first();
  4961. } catch (\Throwable $th) {
  4962. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los catálogos de monedas.', $th->getMessage(), 500);
  4963. }
  4964. if (is_null($catalogue)) {
  4965. return $this->responseController->makeResponse(true, 'No se pudo obtener los catálogos de monedas.', [], 500);
  4966. }
  4967. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  4968. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  4969. if(!$fileDec){
  4970. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  4971. }
  4972. $fileArr = explode("=", $fileDec);
  4973. $idArr = explode("-", $fileArr[0]);
  4974. $file = DB::table('S002V01TAFAL')->where([
  4975. ['AFAL_NULI', '=', $line],
  4976. ['AFAL_COMO', '=', $idArr[1]],
  4977. ['AFAL_CLDO', '=', $idArr[2]],
  4978. ['AFAL_FECR', '=', $idArr[3]],
  4979. ['AFAL_NUSE', '=', $idArr[4]],
  4980. ['AFAL_NUVE', '=', $fileArr[1]],
  4981. ])->first();
  4982. if(is_null($file)){
  4983. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas no está registrado.', [], 404);
  4984. }else if($file->AFAL_ESTA == 'Eliminado'){
  4985. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas está eliminado.', [], 404);
  4986. }else if(!file_exists($file->AFAL_UBIC)){
  4987. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de monedas no existe en el almacenamiento final.', [], 404);
  4988. }
  4989. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  4990. $sheetNames = $spreadsheet->getSheetNames();
  4991. if(!in_array('c_Moneda', $sheetNames)){
  4992. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_Moneda.', [], 400);
  4993. }
  4994. $worksheet = $spreadsheet->getActiveSheet();
  4995. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  4996. if($fileValidatorCell != 'c_Moneda'){
  4997. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  4998. }
  4999. $now = $this->functionsController->now();
  5000. $nowStr = $now->toDateTimeString();
  5001. $towns = [];
  5002. $maxRow = $worksheet->getHighestRow();
  5003. for($row = 6; $row <= $maxRow; $row++){
  5004. $coinKey = $worksheet->getCell("A$row")->getValue();
  5005. $descriptionKey = $worksheet->getCell("B$row")->getValue();
  5006. $endDateNum = $worksheet->getCell("F$row")->getValue();
  5007. if(is_null($endDateNum)){
  5008. $towns[] = [
  5009. 'COIN' => $coinKey,
  5010. 'DESCRIPTION' => $descriptionKey,
  5011. ];
  5012. }else{
  5013. $endDateStr = Date::excelToTimestamp($endDateNum);
  5014. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  5015. if($endDateObj->gte($now)){
  5016. $towns[] = [
  5017. 'COIN' => $coinKey,
  5018. 'DESCRIPTION' => $descriptionKey,
  5019. ];
  5020. }
  5021. }
  5022. }
  5023. $actions = DB::getQueryLog();
  5024. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5025. $idac = $this->functionsController->registerActivity(
  5026. $line,
  5027. 'S002V01M01ADSI',
  5028. 'S002V01F10AGCA',
  5029. 'S002V01P01HICA',
  5030. 'Consulta',
  5031. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Monedas.",
  5032. $user,
  5033. $nowStr
  5034. );
  5035. $this->functionsController->registerLog($actions, $user, $nowStr, $idac, $line);
  5036. return $this->responseController->makeResponse(false, 'EXITO', $towns);
  5037. }
  5038. public function getSettingsList($idUser, $line) {
  5039. DB::enableQueryLog();
  5040. $idUser = $this->encryptionController->decrypt($idUser);
  5041. if(!$idUser){
  5042. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5043. }
  5044. $usr = DB::table('S002V01TUSUA')->where([
  5045. ['USUA_NULI', '=', $line],
  5046. ['USUA_IDUS', '=', $idUser],
  5047. ])->first();
  5048. if(is_null($usr)){
  5049. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5050. }
  5051. $catalogue = DB::table('S002V01TCATA')->where([
  5052. ['CATA_TICA', '=', 'Colonias'],
  5053. ['CATA_ESTA', '=', 'Activo'],
  5054. ['CATA_NULI', '=', $line],
  5055. ])->orderBy('CATA_VERS', 'desc')->first();
  5056. if(is_null($catalogue)){
  5057. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
  5058. }
  5059. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  5060. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  5061. if(!$fileDec){
  5062. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  5063. }
  5064. $fileArr = explode("=", $fileDec);
  5065. $idArr = explode("-", $fileArr[0]);
  5066. $file = DB::table('S002V01TAFAL')->where([
  5067. ['AFAL_NULI', '=', $line],
  5068. ['AFAL_COMO', '=', $idArr[1]],
  5069. ['AFAL_CLDO', '=', $idArr[2]],
  5070. ['AFAL_FECR', '=', $idArr[3]],
  5071. ['AFAL_NUSE', '=', $idArr[4]],
  5072. ['AFAL_NUVE', '=', $fileArr[1]],
  5073. ])->first();
  5074. if(is_null($file)){
  5075. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  5076. }else if($file->AFAL_ESTA == 'Eliminado'){
  5077. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  5078. }else if(!file_exists($file->AFAL_UBIC)){
  5079. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  5080. }
  5081. $now = $this->functionsController->now();
  5082. $nowStr = $now->toDateTimeString();
  5083. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  5084. $sheetNames = $spreadsheet->getSheetNames();
  5085. $settings = [];
  5086. foreach($sheetNames as $name){
  5087. if(!str_contains($name, 'c_Colonia')){
  5088. return $this->responseController->makeResponse(true, "La hoja $name no pertenece al catálogo de colonias.", [], 400);
  5089. }
  5090. $worksheet = $spreadsheet->getSheetByName($name);
  5091. $fileValidatorCell = $worksheet->getCell('A5')->getValue();
  5092. if($fileValidatorCell != 'c_Colonia'){
  5093. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  5094. }
  5095. $maxRow = $worksheet->getHighestRow();
  5096. for($row = 6; $row <= $maxRow; $row++){
  5097. $settingKey = $worksheet->getCell("A$row")->getValue();
  5098. if($settingKey == null) continue;
  5099. $zipCode = $worksheet->getCell("B$row")->getValue();
  5100. $settingName = $worksheet->getCell("C$row")->getValue();
  5101. if(is_null($zipCode)) continue;
  5102. $settings[] = [
  5103. 'SETTING_KEY' => $settingKey,
  5104. 'CODIGO_POSTAL' => $zipCode,
  5105. 'SETTING_NAME' => $settingName,
  5106. ];
  5107. }
  5108. }
  5109. $actions = DB::getQueryLog();
  5110. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5111. $idac = $this->functionsController->registerActivity(
  5112. $line,
  5113. 'S002V01M01ADSI',
  5114. 'S002V01F10AGCA',
  5115. 'S002V01P01HICA',
  5116. 'Consulta',
  5117. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Colonias.",
  5118. $idUser,
  5119. $nowStr
  5120. );
  5121. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5122. return $this->responseController->makeResponse(false, 'EXITO', $settings);
  5123. }
  5124. public function getTaxRegimeList($idUser, $line) {
  5125. DB::enableQueryLog();
  5126. $idUser = $this->encryptionController->decrypt($idUser);
  5127. if(!$idUser){
  5128. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5129. }
  5130. $usr = DB::table('S002V01TUSUA')->where([
  5131. ['USUA_NULI', '=', $line],
  5132. ['USUA_IDUS', '=', $idUser],
  5133. ])->first();
  5134. if(is_null($usr)){
  5135. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5136. }
  5137. $catalogue = DB::table('S002V01TCATA')->where([
  5138. ['CATA_TICA', '=', 'Régimen fiscal'],
  5139. ['CATA_ESTA', '=', 'Activo'],
  5140. ['CATA_NULI', '=', $line],
  5141. ])->orderBy('CATA_VERS', 'desc')->first();
  5142. if(is_null($catalogue)){
  5143. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de Estados', [], 404);
  5144. }
  5145. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  5146. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  5147. if(!$fileDec){
  5148. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  5149. }
  5150. $fileArr = explode("=", $fileDec);
  5151. $idArr = explode("-", $fileArr[0]);
  5152. $file = DB::table('S002V01TAFAL')->where([
  5153. ['AFAL_NULI', '=', $line],
  5154. ['AFAL_COMO', '=', $idArr[1]],
  5155. ['AFAL_CLDO', '=', $idArr[2]],
  5156. ['AFAL_FECR', '=', $idArr[3]],
  5157. ['AFAL_NUSE', '=', $idArr[4]],
  5158. ['AFAL_NUVE', '=', $fileArr[1]],
  5159. ])->first();
  5160. if(is_null($file)){
  5161. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no está registrado.', [], 404);
  5162. }else if($file->AFAL_ESTA == 'Eliminado'){
  5163. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países está eliminado.', [], 404);
  5164. }else if(!file_exists($file->AFAL_UBIC)){
  5165. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo vigente de países no existe en el almacenamiento final.', [], 404);
  5166. }
  5167. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  5168. $sheetNames = $spreadsheet->getSheetNames();
  5169. if(!in_array('c_RegimenFiscal', $sheetNames)){
  5170. return $this->responseController->makeResponse(true, 'El archivo asociado no contiene la hoja c_RegimenFiscal.', [], 400);
  5171. }
  5172. $worksheet = $spreadsheet->getActiveSheet();
  5173. $fileValidatorCell = $worksheet->getCell('A6')->getValue();
  5174. if($fileValidatorCell != 'c_RegimenFiscal'){
  5175. return $this->responseController->makeResponse(true, 'El archivo asociado no tiene un formato válido.', [], 400);
  5176. }
  5177. $now = $this->functionsController->now();
  5178. $nowStr = $now->toDateTimeString();
  5179. $taxRegime = [];
  5180. $maxRow = $worksheet->getHighestRow();
  5181. for($row = 7; $row <= $maxRow; $row++){
  5182. $taxRegimeKey = $worksheet->getCell("A$row")->getValue();
  5183. $taxRegimeDesc = $worksheet->getCell("B$row")->getValue();
  5184. $applyPhisic = $worksheet->getCell("C$row")->getValue();
  5185. $applyMoral = $worksheet->getCell("D$row")->getValue();
  5186. $endDateNum = $worksheet->getCell("F$row")->getValue();
  5187. if(is_null($endDateNum)){
  5188. $taxRegime[] = [
  5189. 'TAX_REGIME_KEY' => $taxRegimeKey,
  5190. 'TAX_REGIME_DESC' => $taxRegimeDesc,
  5191. 'APPLY_PHISIC' => $applyPhisic,
  5192. 'APPLY_MORAL' => $applyMoral,
  5193. ];
  5194. }else{
  5195. $endDateStr = Date::excelToTimestamp($endDateNum);
  5196. $endDateObj = Carbon::createFromTimestamp($endDateStr);
  5197. if($endDateObj->gte($now)){
  5198. $taxRegime[] = [
  5199. 'TAX_REGIME_KEY' => $taxRegimeKey,
  5200. 'TAX_REGIME_DESC' => $taxRegimeDesc,
  5201. 'APPLY_PHISIC' => $applyPhisic,
  5202. 'APPLY_MORAL' => $applyMoral,
  5203. ];
  5204. }
  5205. }
  5206. }
  5207. $actions = DB::getQueryLog();
  5208. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5209. $idac = $this->functionsController->registerActivity(
  5210. $line,
  5211. 'S002V01M01ADSI',
  5212. 'S002V01F10AGCA',
  5213. 'S002V01P01HICA',
  5214. 'Consulta',
  5215. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo de Régimen fiscal.",
  5216. $idUser,
  5217. $nowStr
  5218. );
  5219. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5220. return $this->responseController->makeResponse(false, 'EXITO', $taxRegime);
  5221. }
  5222. public function getStatesByCountryCode($countryCode, $idUser, $line) {
  5223. DB::enableQueryLog();
  5224. $idUser = $this->encryptionController->decrypt($idUser);
  5225. if(!$idUser){
  5226. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5227. }
  5228. $usr = DB::table('S002V01TUSUA')->where([
  5229. ['USUA_NULI', '=', $line],
  5230. ['USUA_IDUS', '=', $idUser],
  5231. ])->first();
  5232. if(is_null($usr)){
  5233. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5234. }
  5235. $countryCode = $this->encryptionController->decrypt($countryCode);
  5236. if(!$countryCode){
  5237. return $this->responseController->makeResponse(true, 'El código del país seleccionado no está encriptado correctamente', [], 400);
  5238. }
  5239. $country = DB::table('S002V01TPAIS')->where([
  5240. ['PAIS_NULI', '=', $line],
  5241. ['PAIS_IDPA', '=', $countryCode]
  5242. ])->first();
  5243. if(is_null($country)){
  5244. return $this->responseController->makeResponse(true, 'El país seleccionado no está registrado', [], 404);
  5245. }
  5246. $relatedStates = DB::table('S002V01TESTA')->select([
  5247. 'ESTA_COES AS CODIGOESTADO',
  5248. 'ESTA_NOES AS NOMBREESTADO'
  5249. ])->where([
  5250. ['ESTA_COPA', '=', $countryCode],
  5251. ['ESTA_NULI', '=', $line],
  5252. ])->orderBy('ESTA_COES', 'asc')->get()->all();
  5253. $now = $this->functionsController->now();
  5254. $nowStr = $now->toDateTimeString();
  5255. $actions = DB::getQueryLog();
  5256. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5257. $idac = $this->functionsController->registerActivity(
  5258. $line,
  5259. 'S002V01M01ADSI',
  5260. 'S002V01F10AGCA',
  5261. 'S002V01P01HICA',
  5262. 'Consulta',
  5263. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los estados relacionados al país " . $country->PAIS_NOMB . " ($countryCode).",
  5264. $idUser,
  5265. $nowStr
  5266. );
  5267. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5268. return $this->responseController->makeResponse(false, 'EXITO', $relatedStates);
  5269. }
  5270. public function getCitiesByStateCode($stateCode, $idUser, $line) {
  5271. DB::enableQueryLog();
  5272. $idUser = $this->encryptionController->decrypt($idUser);
  5273. if(!$idUser){
  5274. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5275. }
  5276. $usr = DB::table('S002V01TUSUA')->where([
  5277. ['USUA_NULI', '=', $line],
  5278. ['USUA_IDUS', '=', $idUser],
  5279. ])->first();
  5280. if(is_null($usr)){
  5281. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5282. }
  5283. $stateCode = $this->encryptionController->decrypt($stateCode);
  5284. if(!$stateCode){
  5285. return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
  5286. }
  5287. $state = DB::table('S002V01TESTA')->where([
  5288. ['ESTA_NULI', '=', $line],
  5289. ['ESTA_COES', '=', $stateCode]
  5290. ])->first();
  5291. if(is_null($state)){
  5292. return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
  5293. }
  5294. $relatedCities = DB::table('S002V01TMUNI')->select([
  5295. 'MUNI_COMU AS CODIGOMUNICIPIO',
  5296. 'MUNI_NOMU AS NOMBREMUNICIPIO'
  5297. ])->where([
  5298. ['MUNI_COES', '=', $stateCode],
  5299. ['MUNI_NULI', '=', $line],
  5300. ])->orderBy('MUNI_COMU', 'asc')->get()->all();
  5301. $now = $this->functionsController->now();
  5302. $nowStr = $now->toDateTimeString();
  5303. $actions = DB::getQueryLog();
  5304. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5305. $idac = $this->functionsController->registerActivity(
  5306. $line,
  5307. 'S002V01M01ADSI',
  5308. 'S002V01F10AGCA',
  5309. 'S002V01P01HICA',
  5310. 'Consulta',
  5311. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los municipios relacionados al estado " . $state->ESTA_NOES . " ($stateCode).",
  5312. $idUser,
  5313. $nowStr
  5314. );
  5315. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5316. return $this->responseController->makeResponse(false, 'EXITO', $relatedCities);
  5317. }
  5318. public function getTowns($stateCode, $cityCode, $idUser, $line) {
  5319. DB::enableQueryLog();
  5320. $idUser = $this->encryptionController->decrypt($idUser);
  5321. if(!$idUser){
  5322. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5323. }
  5324. $usr = DB::table('S002V01TUSUA')->where([
  5325. ['USUA_NULI', '=', $line],
  5326. ['USUA_IDUS', '=', $idUser],
  5327. ])->first();
  5328. if(is_null($usr)){
  5329. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5330. }
  5331. $stateCode = $this->encryptionController->decrypt($stateCode);
  5332. if(!$stateCode){
  5333. return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
  5334. }
  5335. $state = DB::table('S002V01TESTA')->where([
  5336. ['ESTA_NULI', '=', $line],
  5337. ['ESTA_COES', '=', $stateCode]
  5338. ])->first();
  5339. if(is_null($state)){
  5340. return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
  5341. }
  5342. $cityCode = $this->encryptionController->decrypt($cityCode);
  5343. if(!$cityCode){
  5344. return $this->responseController->makeResponse(true, 'El código del municipio seleccionado no está encriptado correctamente', [], 400);
  5345. }
  5346. $city = DB::table('S002V01TMUNI')->where([
  5347. ['MUNI_NULI', '=', $line],
  5348. ['MUNI_COMU', '=', $cityCode],
  5349. ['MUNI_COES', '=', $stateCode],
  5350. ])->first();
  5351. if(is_null($city)){
  5352. return $this->responseController->makeResponse(true, 'El municipio seleccionado no está registrado', [], 404);
  5353. }
  5354. $relatedZipCodes = DB::table('S002V01TCOPO')->select([
  5355. DB::raw('DISTINCT(COPO_COLO) AS CODIGOLOCALIDAD'),
  5356. 'LOCA_NOLO AS NOMBRELOCALIDAD'
  5357. ])->where([
  5358. ['COPO_NULI', '=', $line],
  5359. ['COPO_COES', '=', $stateCode],
  5360. ['COPO_COMU', '=', $cityCode],
  5361. ])->leftJoin('S002V01TLOCA', function(JoinClause $join) {
  5362. $join->on('LOCA_COLO', '=', 'COPO_COLO')
  5363. ->on('LOCA_COES', '=', 'COPO_COES');
  5364. })->get()->all();
  5365. $now = $this->functionsController->now();
  5366. $nowStr = $now->toDateTimeString();
  5367. $actions = DB::getQueryLog();
  5368. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5369. $idac = $this->functionsController->registerActivity(
  5370. $line,
  5371. 'S002V01M01ADSI',
  5372. 'S002V01F10AGCA',
  5373. 'S002V01P01HICA',
  5374. 'Consulta',
  5375. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las localidades relacionadas al estado " . $state->ESTA_NOES . " ($stateCode).",
  5376. $idUser,
  5377. $nowStr
  5378. );
  5379. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5380. return $this->responseController->makeResponse(false, 'EXITO', $relatedZipCodes);
  5381. }
  5382. public function getCitySettings($stateCode, $cityCode, $townCode, $idUser, $line) {
  5383. DB::enableQueryLog();
  5384. $idUser = $this->encryptionController->decrypt($idUser);
  5385. if(!$idUser){
  5386. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5387. }
  5388. $usr = DB::table('S002V01TUSUA')->where([
  5389. ['USUA_NULI', '=', $line],
  5390. ['USUA_IDUS', '=', $idUser],
  5391. ])->first();
  5392. if(is_null($usr)){
  5393. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5394. }
  5395. $stateCode = $this->encryptionController->decrypt($stateCode);
  5396. if(!$stateCode){
  5397. return $this->responseController->makeResponse(true, 'El código del estado seleccionado no está encriptado correctamente', [], 400);
  5398. }
  5399. $state = DB::table('S002V01TESTA')->where([
  5400. ['ESTA_NULI', '=', $line],
  5401. ['ESTA_COES', '=', $stateCode]
  5402. ])->first();
  5403. if(is_null($state)){
  5404. return $this->responseController->makeResponse(true, 'El estado seleccionado no está registrado', [], 404);
  5405. }
  5406. $cityCode = $this->encryptionController->decrypt($cityCode);
  5407. if(!$cityCode){
  5408. return $this->responseController->makeResponse(true, 'El código del municipio seleccionado no está encriptado correctamente', [], 400);
  5409. }
  5410. $city = DB::table('S002V01TMUNI')->where([
  5411. ['MUNI_NULI', '=', $line],
  5412. ['MUNI_COMU', '=', $cityCode],
  5413. ['MUNI_COES', '=', $stateCode],
  5414. ])->first();
  5415. if(is_null($city)){
  5416. return $this->responseController->makeResponse(true, 'El municipio seleccionado no está registrado', [], 404);
  5417. }
  5418. $townCode = $this->encryptionController->decrypt($townCode);
  5419. if(!$townCode){
  5420. return $this->responseController->makeResponse(true, 'El código de la localidad seleccionada no está encriptado correctamente', [], 400);
  5421. }
  5422. $townCode = $townCode == '-' ? null : $townCode;
  5423. if(!is_null($townCode)){
  5424. $town = DB::table('S002V01TLOCA')->where([
  5425. ['LOCA_NULI', '=', $line],
  5426. ['LOCA_COLO', '=', $townCode],
  5427. ['LOCA_COES', '=', $stateCode]
  5428. ])->first();
  5429. if(is_null($town)){
  5430. return $this->responseController->makeResponse(true, 'La localidad seleccionada no está registrada', [], 404);
  5431. }
  5432. }
  5433. $settings = DB::table('S002V01TCOPO')->select([
  5434. 'COLO_COCO AS CODIGOCOLONIA',
  5435. 'COPO_COPO AS CODIGOPOSTAL',
  5436. 'COLO_NOCO AS NOMBRECOLONIA',
  5437. ])->where([
  5438. ['COPO_NULI', '=', $line],
  5439. ['COPO_COES', '=', $stateCode],
  5440. ['COPO_COMU', '=', $cityCode],
  5441. ['COPO_COLO', '=', $townCode],
  5442. ])->join('S002V01TCOLO', 'COLO_COPO', '=', 'COPO_COPO')->get()->all();
  5443. $now = $this->functionsController->now();
  5444. $nowStr = $now->toDateTimeString();
  5445. $actions = DB::getQueryLog();
  5446. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5447. $idac = $this->functionsController->registerActivity(
  5448. $line,
  5449. 'S002V01M01ADSI',
  5450. 'S002V01F10AGCA',
  5451. 'S002V01P01HICA',
  5452. 'Consulta',
  5453. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las colonias relacionadas al estado " . $state->ESTA_NOES . " ($stateCode).",
  5454. $idUser,
  5455. $nowStr
  5456. );
  5457. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5458. return $this->responseController->makeResponse(false, 'EXITO', $settings);
  5459. }
  5460. public function getGeneralCatalogueInfo($type, $headerRow, $idUser, $line) {
  5461. DB::enableQueryLog();
  5462. $idUser = $this->encryptionController->decrypt($idUser);
  5463. if(!$idUser){
  5464. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  5465. }
  5466. $usr = DB::table('S002V01TUSUA')->where([
  5467. ['USUA_NULI', '=', $line],
  5468. ['USUA_IDUS', '=', $idUser],
  5469. ])->first();
  5470. if(is_null($usr)){
  5471. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  5472. }
  5473. $catalogue = DB::table('S002V01TCATA')->where([
  5474. ['CATA_TICA', '=', 'General'],
  5475. ['CATA_ESTA', '=', 'Activo'],
  5476. ['CATA_NULI', '=', $line],
  5477. ])->orderBy('CATA_VERS', 'desc')->first();
  5478. if(is_null($catalogue)){
  5479. return $this->responseController->makeResponse(true, 'Aún no se ha registrado ningún catálogo de General', [], 404);
  5480. }
  5481. $filesArr = json_decode($catalogue->CATA_ARRE, true);
  5482. $fileDec = $this->encryptionController->decrypt($filesArr[0]);
  5483. if(!$fileDec){
  5484. return $this->responseController->makeResponse(true, 'El ID catálogo vigente de países no fue encriptado correctamente.', [], 400);
  5485. }
  5486. $fileArr = explode("=", $fileDec);
  5487. $idArr = explode("-", $fileArr[0]);
  5488. $file = DB::table('S002V01TAFAL')->where([
  5489. ['AFAL_NULI', '=', $line],
  5490. ['AFAL_COMO', '=', $idArr[1]],
  5491. ['AFAL_CLDO', '=', $idArr[2]],
  5492. ['AFAL_FECR', '=', $idArr[3]],
  5493. ['AFAL_NUSE', '=', $idArr[4]],
  5494. ['AFAL_NUVE', '=', $fileArr[1]],
  5495. ])->first();
  5496. if(is_null($file)){
  5497. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente no está registrado.', [], 404);
  5498. }else if($file->AFAL_ESTA == 'Eliminado'){
  5499. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente está eliminado.', [], 404);
  5500. }else if(!file_exists($file->AFAL_UBIC)){
  5501. return $this->responseController->makeResponse(true, 'El archivo asociado al catálogo general vigente no existe en el almacenamiento final.', [], 404);
  5502. }
  5503. ini_set("memory_limit", "-1");
  5504. set_time_limit(0);
  5505. $spreadsheet = IOFactory::load($file->AFAL_UBIC);
  5506. $sheetNames = $spreadsheet->getSheetNames();
  5507. $relatedSheets = [];
  5508. foreach($sheetNames as $sheet){
  5509. if(str_contains($sheet, $type)){
  5510. $relatedSheets[] = $sheet;
  5511. }
  5512. }
  5513. if(count($relatedSheets) == 0){
  5514. return $this->responseController->makeResponse(true, "No se encontraron hojas relacionadas al tipo $type.", [], 404);
  5515. }
  5516. $responseArr = [];
  5517. foreach($relatedSheets as $sheet){
  5518. $worksheet = $spreadsheet->getSheetByName($sheet);
  5519. $maxCol = $worksheet->getHighestColumn();
  5520. $maxColInd = Coordinate::columnIndexFromString($maxCol);
  5521. $headers = [];
  5522. $startRow = intval($headerRow);
  5523. if($startRow == 0){
  5524. return $this->responseController->makeResponse(true, 'La fila del encabezado no tiene un formato válido.', [], 400);
  5525. }
  5526. for($col = 1; $col <= $maxColInd; $col++){
  5527. $colStr = Coordinate::stringFromColumnIndex($col);
  5528. $header = $worksheet->getCell($colStr . $startRow)->getValue();
  5529. if(!is_null($header)){
  5530. $headers[$colStr] = $header;
  5531. }else{
  5532. $headers[$colStr] = $colStr;
  5533. }
  5534. }
  5535. $startRow++;
  5536. $maxRow = $worksheet->getHighestRow();
  5537. for($row = $startRow; $row <= $maxRow; $row++){
  5538. $arrAux = [];
  5539. for($col = 1; $col <= count($headers); $col++){
  5540. $colStr = Coordinate::stringFromColumnIndex($col);
  5541. $val = $worksheet->getCell($colStr . $row)->getCalculatedValue();
  5542. $header = $headers[$colStr];
  5543. $isDate = Date::isDateTime($worksheet->getCell($colStr . $row));
  5544. if($isDate){
  5545. $val = Date::excelToTimestamp($val);
  5546. $val = Carbon::createFromTimestamp($val);
  5547. $val = $val->toDateTimeString();
  5548. }
  5549. $header = str_replace(' ', '_', $header);
  5550. $arrAux[$header] = $val;
  5551. }
  5552. $responseArr[] = $arrAux;
  5553. }
  5554. }
  5555. $now = $this->functionsController->now();
  5556. $nowStr = $now->toDateTimeString();
  5557. $actions = DB::getQueryLog();
  5558. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  5559. $idac = $this->functionsController->registerActivity(
  5560. $line,
  5561. 'S002V01M01ADSI',
  5562. 'S002V01F10AGCA',
  5563. 'S002V01P01HICA',
  5564. 'Consulta',
  5565. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el contenido del catálogo General.",
  5566. $idUser,
  5567. $nowStr
  5568. );
  5569. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  5570. return $this->responseController->makeResponse(false, 'EXITO', $responseArr);
  5571. }
  5572. public function saveTaxInformation(Request $request) {
  5573. $validator = Validator::make($request->all(), [
  5574. 'NOMBRE_FISCAL' => 'required|string',
  5575. 'RFC' => 'required|string',
  5576. 'CORREO_ELECTRONICO' => 'required|string',
  5577. 'REGIMEN_FISCAL' => 'required|string',
  5578. 'LADA1' => 'required|string',
  5579. 'TELEFONO_FIJO' => 'required|integer',
  5580. 'LADA2' => 'required|string',
  5581. 'TELEFONO_MOVIL' => 'required|integer',
  5582. 'CODIGO_POSTAL' => 'required|integer',
  5583. 'TIPOVIALIDAD' => 'required|string',
  5584. 'NOMBRE_VIALIDAD' => 'required|string',
  5585. 'ENTRE_CALLE' => 'required|string',
  5586. 'Y_CALLE' => 'required|string',
  5587. 'NUMERO_EXTERIOR' => 'required|string',
  5588. // 'NUMERO_INTERIOR' => 'required|string',
  5589. 'COLONIA' => 'required|string',
  5590. 'LOCALIDAD' => 'required|string',
  5591. 'MUNICIPIO' => 'required|string',
  5592. 'ENTIDAD_FEDERATIVA' => 'required|string',
  5593. 'PAIS' => 'required|string',
  5594. 'USER' => 'required|string',
  5595. 'LINE_NUMBER' => 'required|integer',
  5596. ]);
  5597. if ($validator->fails()) {
  5598. return $this->responseController->makeResponse(
  5599. true,
  5600. "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION000: Se encontraron uno o más errores.",
  5601. $this->responseController->makeErrors($validator->errors()->messages()),
  5602. 401
  5603. );
  5604. }
  5605. DB::beginTransaction();
  5606. $responseData = $request->all();
  5607. try {
  5608. $user = $this->encryptionController->decrypt($responseData['USER']);
  5609. } catch (\Throwable $th) {
  5610. DB::rollBack();
  5611. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION001: Ocurrió un error al desencriptar los datos.", [], 401);
  5612. }
  5613. $now = $this->functionsController->now();
  5614. $currentDate = $now->toDateTimeString();
  5615. try {
  5616. $existsActives = DB::table('S002V01TINFI')
  5617. ->where('INFI_ESTA','=','Activo')
  5618. ->where('INFI_NULI','=',$responseData['LINE_NUMBER'])
  5619. ->exists();
  5620. } catch (\Throwable $th) {
  5621. DB::rollBack();
  5622. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION002: Ocurrió un error al validar los registros anteriores.", [], 401);
  5623. }
  5624. if ($existsActives) {
  5625. try {
  5626. $validateUpdate = DB::table('S002V01TINFI')
  5627. ->where('INFI_ESTA','=','Activo')
  5628. ->where('INFI_NULI','=',$responseData['LINE_NUMBER'])
  5629. ->update([
  5630. 'INFI_ESTA' => 'Inactivo',
  5631. 'INFI_USMO' => $user,
  5632. 'INFI_FEMO' => $currentDate,
  5633. 'INFI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  5634. ]);
  5635. } catch (\Throwable $th) {
  5636. DB::rollBack();
  5637. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION002: Ocurrió un error al modificar los registros anteriores.", $th->getMessage(), 401);
  5638. }
  5639. if (!$validateUpdate) {
  5640. DB::rollBack();
  5641. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION003: No se pudo modificar los registros anteriores.", [], 401);
  5642. }
  5643. }
  5644. try {
  5645. $validateInsert = DB::table('S002V01TINFI')->insert([
  5646. 'INFI_NOFI' => $responseData['NOMBRE_FISCAL'],
  5647. 'INFI_XRFC' => $responseData['RFC'],
  5648. 'INFI_COEL' => $responseData['CORREO_ELECTRONICO'],
  5649. 'INFI_CORF' => $responseData['REGIMEN_FISCAL'],
  5650. 'INFI_LAD1' => $responseData['LADA1'],
  5651. 'INFI_TEL1' => $responseData['TELEFONO_FIJO'],
  5652. 'INFI_LAD2' => $responseData['LADA2'],
  5653. 'INFI_TEL2' => $responseData['TELEFONO_MOVIL'],
  5654. 'INFI_COPO' => $responseData['CODIGO_POSTAL'],
  5655. 'INFI_TIVI' => $responseData['TIPOVIALIDAD'],
  5656. 'INFI_VIAL' => $responseData['NOMBRE_VIALIDAD'],
  5657. 'INFI_ENCA' => $responseData['ENTRE_CALLE'],
  5658. 'INFI_YCAL' => $responseData['Y_CALLE'],
  5659. 'INFI_NUEX' => $responseData['NUMERO_EXTERIOR'],
  5660. 'INFI_NUIN' => $responseData['NUMERO_INTERIOR'],
  5661. 'INFI_COLO' => $responseData['COLONIA'],
  5662. 'INFI_LOCA' => $responseData['LOCALIDAD'],
  5663. 'INFI_MUNI' => $responseData['MUNICIPIO'],
  5664. 'INFI_ENFE' => $responseData['ENTIDAD_FEDERATIVA'],
  5665. 'INFI_PAIS' => $responseData['PAIS'],
  5666. 'INFI_NULI' => $responseData['LINE_NUMBER'],
  5667. 'INFI_USRE' => $user,
  5668. 'INFI_FERE' => $currentDate,
  5669. 'INFI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  5670. ]);
  5671. } catch (\Throwable $th) {
  5672. DB::rollBack();
  5673. 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);
  5674. }
  5675. if (!$validateInsert) {
  5676. DB::rollBack();
  5677. return $this->responseController->makeResponse(true, "ERR_SYSTEM_ADMINISTRATOR_TAX_INFORMATION005: No se pudo insertar los datos en la base de datos.", [], 401);
  5678. }
  5679. DB::commit();
  5680. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  5681. }
  5682. public function validateCatalog(Request $request) {
  5683. $validator = Validator::make($request->all(), [
  5684. 'CODIGO_POSTAL' => 'required|boolean',
  5685. 'COLONIAS' => 'required|boolean',
  5686. 'LOCALIDADES' => 'required|boolean',
  5687. 'MUNICIPIOS' => 'required|boolean',
  5688. 'ESTADOS' => 'required|boolean',
  5689. 'PAISES' => 'required|boolean',
  5690. 'REGIMEN_FISCAL' => 'required|boolean',
  5691. 'USUARIO' => 'required|string',
  5692. 'NUMERO_LINEA' => 'required|integer',
  5693. ]);
  5694. if ($validator->fails()) {
  5695. return $this->responseController->makeResponse(
  5696. true,
  5697. "Se encontraron uno o más errores.",
  5698. $this->responseController->makeErrors($validator->errors()->messages()),
  5699. 401
  5700. );
  5701. }
  5702. $requestData = $request->all();
  5703. $response['CODIGO_POSTAL'] = null;
  5704. $response['COLONIAS'] = null;
  5705. $response['LOCALIDADES'] = null;
  5706. $response['MUNICIPIOS'] = null;
  5707. $response['ESTADOS'] = null;
  5708. $response['PAISES'] = null;
  5709. $response['REGIMEN_FISCAL'] = null;
  5710. if ($requestData['CODIGO_POSTAL'] === true) {
  5711. $get = DB::table('S002V01TCOPO')->get();
  5712. $get = json_decode(json_encode($get), true);
  5713. $response['CODIGO_POSTAL'] = empty($get);
  5714. }
  5715. if ($requestData['COLONIAS'] === true) {
  5716. $get = DB::table('S002V01TCOLO')->get();
  5717. $get = json_decode(json_encode($get), true);
  5718. $response['COLONIAS'] = empty($get);
  5719. }
  5720. if ($requestData['LOCALIDADES'] === true) {
  5721. $get = DB::table('S002V01TCOLO')->get();
  5722. $get = json_decode(json_encode($get), true);
  5723. $response['LOCALIDADES'] = empty($get);
  5724. }
  5725. if ($requestData['MUNICIPIOS'] === true) {
  5726. $get = DB::table('S002V01TMUNI')->get();
  5727. $get = json_decode(json_encode($get), true);
  5728. $response['MUNICIPIOS'] = empty($get);
  5729. }
  5730. if ($requestData['ESTADOS'] === true) {
  5731. $get = DB::table('S002V01TESTA')->get();
  5732. $get = json_decode(json_encode($get), true);
  5733. $response['ESTADOS'] = empty($get);
  5734. }
  5735. if ($requestData['PAISES'] === true) {
  5736. $get = DB::table('S002V01TPAIS')->get();
  5737. $get = json_decode(json_encode($get), true);
  5738. $response['PAISES'] = empty($get);
  5739. }
  5740. if ($requestData['REGIMEN_FISCAL'] === true) {
  5741. $get = DB::table('S002V01TREFI')->get();
  5742. $get = json_decode(json_encode($get), true);
  5743. $response['REGIMEN_FISCAL'] = empty($get);
  5744. }
  5745. return $this->responseController->makeResponse(false, "ÉXITO", $response);
  5746. }
  5747. public function getCatalogCoins ($user, $line) {
  5748. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  5749. if ($arrResponseCheckUser['error']) {
  5750. DB::rollBack();
  5751. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  5752. }
  5753. $user = $arrResponseCheckUser['response'];
  5754. try {
  5755. $arrCoins = DB::table('S002V01TCAMO')
  5756. ->where('CAMO_NULI', '=', $line)
  5757. ->where('CAMO_ESTA', '=', 'Activo')
  5758. ->get([
  5759. 'CAMO_COMO AS COIN',
  5760. 'CAMO_DESC AS DESCRIPTION',
  5761. ]);
  5762. $arrCoins = json_decode(json_encode($arrCoins), true);
  5763. } catch (\Throwable $th) {
  5764. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos del catálogo de monedas.', $th->getMessage(), 500);
  5765. }
  5766. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrCoins);
  5767. }
  5768. }