| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930 |
- <?php
- namespace App\Http\Controllers;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Database\Query\Builder;
- use Illuminate\Http\File;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
- use PhpOffice\PhpSpreadsheet\Style\Border;
- use ElephantIO\Client;
- use stdClass;
- use Throwable;
- class PersonnelManagementController extends Controller
- {
- private $responseController;
- private $encryptionController;
- private $documentManagementController;
- private $functionsController;
- private $resourcesController;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encryptionController = new EncryptionController();
- $this->documentManagementController = new DocumentManagementController();
- $this->functionsController = new FunctionsController();
- $this->resourcesController = new ResourcesController();
- }
- public function getConsultOfEmployees($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $employees = DB::table('S002V01TPERS')->select([
- 'PERS_IDPE AS ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- 'PERS_TICO AS CONTRACT_TYPE',
- 'PERS_IDPS AS ID_SUBCONTRATISTA',
- 'PERS_IDUS AS ID_USUARIO',
- 'PERS_ESPE AS SPECIALITY',
- 'PERS_EQTR AS TEAM_ID',
- 'EQMA_NOMB AS TEAM_NAME',
- 'PERS_FERE AS REGISTER_DATE',
- 'PERS_USRE AS REGISTERED_BY_USER',
- 'PERS_FEMO AS UPDATE_DATE',
- 'PERS_USMO AS UPDATED_BY_USER',
- 'PERS_ESTA AS STATUS'
- ])->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
- ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
- ->where('USUA_NULI', '=', $line)->get()->all();
- foreach($employees as $key=>$employee){
- $employee->ID_EMPLOYEE = $this->encryptionController->encrypt($employee->ID_EMPLOYEE);
- if(!is_null($employee->TEAM_ID)){
- $employee->TEAM_ID = $this->encryptionController->encrypt($employee->TEAM_ID);
- }
- if(!is_null($employee->ID_SUBCONTRATISTA)){
- $employee->ID_SUBCONTRATISTA = $this->encryptionController->encrypt($employee->ID_SUBCONTRATISTA);
- }
- $employee->ID_USUARIO = $this->encryptionController->encrypt($employee->ID_USUARIO);
- $specialtiesArr = json_decode($employee->SPECIALITY, true);
- foreach($specialtiesArr as $key0=>$specialtyCode){
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- $specialtyName = $specialtyCode . " - " . $specialty->GEES_NOES;
- $specialtiesArr[$key0] = $this->encryptionController->encrypt($specialtyName);
- }
- $employee->SPECIALITY = json_encode($specialtiesArr);
- $employees[$key] = $employee;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P01COEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los empleados registrados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $employees);
- }
-
- public function getEmployeeById($idEmployee, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($idEmployee);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado solicitado no está encriptado correctamente', [], 400);
- }
- $employee = DB::table('S002V01TPERS')->select([
- 'PERS_IDPE AS ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as EMPLOYEE_NAME'),
- 'PERS_IDUS AS USER_ID',
- 'EQMA_IDEQ AS WORKTEAM_ID',
- 'EQMA_NOMB AS WORKTEAM_NAME',
- 'PERS_TICO AS CONTRACT_TYPE',
- 'PERS_IDPS AS SUBCONTRATIST_ID',
- 'PESU_RASO AS SUBCONTRATIST_NAME',
- 'PESU_REFI AS TAX_REGIME',
- 'REFI_DRFI AS TAX_REGIME_DESCRIPTION',
- 'PERS_ESPE AS SPECIALITY',
- 'PERS_EXTR AS FOREIGNER',
- 'PERS_XRFC AS RFC',
- 'PERS_TAID AS TAX_ID',
- 'PERS_IDPA AS COUNTRY',
- 'PERS_ENFE AS STATE',
- 'PERS_CIUD AS CITY',
- 'PERS_LOCA AS TOWN',
- 'PERS_COLO AS SETTING',
- 'PERS_COPO AS ZIP_CODE',
- 'PERS_CALL AS STREET',
- 'PERS_NUEX AS EXTERIOR_NUMBER',
- 'PERS_NUIN AS INTERIOR_NUMBER',
- 'PERS_NOCE AS CONTACT_NAME',
- 'PERS_LCEM AS CONTACT_LADA',
- 'PERS_NUTC AS CONTACT_TELEPHONE',
- 'PERS_DCEM AS CONTACT_ADDRESS',
- 'PERS_DOAS AS DOCUMENTS',
- 'PERS_ESTA AS STATUS',
- 'PERS_USRE AS USRREG',
- 'PERS_USMO AS USRMOD',
- 'PERS_FERE AS FECREG',
- 'PERS_FEMO AS FECMOD',
- ])->leftJoin('S002V01TEQMA', 'EQMA_IDEQ', '=', 'PERS_EQTR')
- ->leftJoin('S002V01TPESU', 'PESU_IDPS', '=', 'PERS_IDPS')
- ->leftJoin('S002V01TREFI', 'REFI_CRFI', '=', 'PESU_REFI')
- ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idEmployee],
- ])->first();
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado consultado no existe.', [], 404);
- }else if($employee->STATUS == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El empleado consultado está eliminado.', [], 404);
- }
- if(!is_null($employee->RFC)){
- $employee->RFC = $this->encryptionController->encrypt($employee->RFC);
- }
- if(!is_null($employee->TAX_ID)){
- $employee->TAX_ID = $this->encryptionController->encrypt($employee->TAX_ID);
- }
- $attached = [];
- $docsArr = json_decode($employee->DOCUMENTS, true);
- foreach($docsArr as $doc){
- $docArr = explode('=', $doc['CODE']);
- $codeArr = explode('-', $docArr[0]);
- $document = DB::table('S002V01TAFAL')->select([
- 'AFAL_NOAR AS FILE_NAME',
- 'AFAL_EXTE AS FILE_EXTENSION',
- 'AFAL_TAMA AS FILE_SIZE',
- 'AFAL_ESTA AS FILE_STATUS'
- ])->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $codeArr[1]],
- ['AFAL_CLDO', '=', $codeArr[2]],
- ['AFAL_FECR', '=', $codeArr[3]],
- ['AFAL_NUSE', '=', $codeArr[4]],
- ['AFAL_NUVE', '=', $docArr[1]],
- ])->first();
- if (!is_null($document)) {
- $document->FILE_ID = $this->encryptionController->encrypt($doc['CODE']);
- $document->FILE_TYPE = $doc['TYPE'];
- $attached[] = $document;
- }
- }
- $employee->DOCUMENTS = json_encode($attached);
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $line],
- ['PAIS_IDPA', '=', $employee->COUNTRY]
- ])->first();
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $line],
- ['ESTA_COES', '=', $employee->STATE],
- ['ESTA_COPA', '=', $employee->COUNTRY]
- ])->first();
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $line],
- ['MUNI_COMU', '=', $employee->CITY],
- ['MUNI_COES', '=', $employee->STATE],
- ])->first();
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $line],
- ['LOCA_COLO', '=', $employee->TOWN],
- ['LOCA_COES', '=', $employee->STATE],
- ])->first();
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $line],
- ['COLO_COCO', '=', $employee->SETTING],
- ['COLO_COPO', '=', $employee->ZIP_CODE],
- ])->first();
- $employee->COUNTRY = $country->PAIS_NOMB . " (" . $employee->COUNTRY . ")";
- $employee->STATE = is_null($state) ? $employee->STATE : $state->ESTA_NOES . " (" . $employee->STATE . ")";
- $employee->CITY = is_null($city) ? $employee->CITY : $city->MUNI_NOMU . " (" . $employee->CITY . ")";
- $employee->TOWN = is_null($town) ? $employee->TOWN : $town->LOCA_NOLO . " (" . $employee->TOWN . ")";
- $employee->SETTING = is_null($setting) ? $employee->SETTING : $setting->COLO_NOCO . " (" . $employee->SETTING . ")";
- $employee->ZIP_CODE = $this->encryptionController->encrypt($employee->ZIP_CODE);
- $employee->CONTACT_TELEPHONE = $this->encryptionController->encrypt($employee->CONTACT_TELEPHONE);
- $employee->USER_ID = $this->encryptionController->encrypt($employee->USER_ID);
- $employee->WORKTEAM_ID = !is_null($employee->WORKTEAM_ID) ? $this->encryptionController->encrypt($employee->WORKTEAM_ID) : null;
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $employee->USRREG]
- ])->first();
- $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
- $employee->USRREG = "$nameReg (" . $employee->USRREG . ")";
- if(!is_null($employee->USRMOD)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $employee->USRMOD]
- ])->first();
- $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
- $employee->USRMOD = "$nameMod (" . $employee->USRMOD . ")";
- }
- $specialtiesArr = json_decode($employee->SPECIALITY, true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- $specialty = $specialtyCode . " - " . $specialtyObj->GEES_NOES;
- $specialtiesArr[$key] = $this->encryptionController->encrypt($specialty);
- }
- $employee->SPECIALITY = json_encode($specialtiesArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P03DEEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó al empleado " . $employee->EMPLOYEE_NAME . " ($idEmployee).",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $employee);
- }
- public function updateToInactiveStatusEmployee(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_employee' => 'required|string',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($form['id_employee']);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado que desea actualizar no fue encriptado correctamente.', [], 400);
- }
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idEmployee]
- ])->first();
-
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado que desea actualizar no existe.', [], 404);
- }
-
- if($idUser == $employee->PERS_IDUS){
- return $this->responseController->makeResponse(true, 'El usuario no puede eliminarse a sí mismo.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idEmployee]
- ])->update([
- 'PERS_ESTA' => 'Eliminado',
- 'PERS_USMO' => $idUser,
- 'PERS_FEMO' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P02REEM',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó al empleado $idEmployee.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getContractsOfEveryEmployee($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $contractsByEmployees = DB::table('S002V01TPERS')->select([
- DB::raw("
- TRIM(CONCAT(
- USUA_NOMB,
- ' ',
- USUA_APPA,
- IF(ISNULL(USUA_APMA), '', CONCAT(' ', USUA_APMA)),
- ' <(',
- PERS_IDPE,
- ')> (',
- PERS_IDUS,
- ')'
- )) AS EMPLOYEE
- "),
- DB::raw("COUNT(CONT_IDCO) AS CONTRACTS")
- ])->leftJoin('S002V01TCONT', 'CONT_IDEM', '=', 'PERS_IDPE')
- ->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')
- ->groupBy('EMPLOYEE')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_TICO', '=', 'Interno'],
- ])->get()->all();
- foreach($contractsByEmployees as $key=>$val){
- $employeeArr = explode('<', $val->EMPLOYEE);
- $employeeName = $employeeArr[0];
- $employeeArr = array_reverse($employeeArr);
- $employeeArr = explode('>', $employeeArr[0]);
- $employeeID = str_replace('(', '', $employeeArr[0]);
- $employeeID = str_replace(')', '', $employeeID);
- $val->ID_EMPLOYEE = $this->encryptionController->encrypt($employeeID);
- $val->EMPLOYEE = $employeeName . join('', $employeeArr);
- $contractsByEmployees[$key] = $val;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ACEM',
- 'S002V01P01HCEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos por empleados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $contractsByEmployees);
- }
- public function getDetailsOfContractsByEmployee($idEmployee, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($idEmployee);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idEmployee],
- ['PERS_TICO', '=', 'Interno'],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El empleado solicitado no existe.', [], 404);
- }
- $contracts = DB::table('S002V01TCONT')->select([
- 'CONT_NOCO AS CONTRACT_NAME',
- 'CONT_FEIN AS START_DATE',
- 'CONT_FEFI AS END_DATE',
- 'CONT_COST AS COST',
- ])->where([
- ['CONT_NULI', '=', $line],
- ['CONT_IDEM', '=', $idEmployee],
- ['CONT_TIPO', '=', 'Interno'],
- ])->get()->all();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ACEM',
- 'S002V01P01HCEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos del empleado #$idEmployee.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $contracts);
- }
- public function getInterventionsByEmployee($idEmployee, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($idEmployee);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado no fue encriptado correctamente.', [], 400);
- }
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idEmployee],
- ])->first();
-
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado solicitado no existe.', [], 404);
- }
- $preventiveOrders = DB::select("
- SELECT
- DISTINCT(S002V01TOTPR.OTPR_IDOT) AS IDORDEN,
- S002V01TOTPR.OTPR_DEIN AS DESCRIPCION,
- 'Preventivo' AS TIPOORDEN
- FROM
- S002V01TOTPR,
- JSON_TABLE(OTPR_OPPR, '$[*]' COLUMNS(
- OTPR_OPPR_ID INT PATH '$.ID',
- OTPR_OPPR_TYPE VARCHAR(100) PATH '$.TYPE'
- )) OPPR
- WHERE
- (OTPR_OPPR_ID = :emp_id AND OTPR_OPPR_TYPE = 'EM')
- OR (OTPR_OPPR_ID = :sub_id AND OTPR_OPPR_TYPE = 'SU')
- OR (OTPR_OPPR_ID = :team_id AND OTPR_OPPR_TYPE = 'EQ')
- ", [
- 'emp_id' => $employee->PERS_IDPE,
- 'sub_id' => $employee->PERS_IDPS,
- 'team_id' => $employee->PERS_EQTR
- ]);
- //PENDIENTE MANTENIMIENTO CORRECTIVO
- $ordersFN = [];
- $relatedOrders = [];
- foreach($preventiveOrders as $order){
- if(!in_array($order->IDORDEN, $relatedOrders)){
- $relatedOrders[] = $order->IDORDEN;
- $order->IDORDEN = $this->encryptionController->encrypt($order->IDORDEN);
- $ordersFN[] = $order;
- }
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P03DEEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las órdenes de trabajo relacionadas al empleado #$idEmployee.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $ordersFN);
- }
- public function getConsultOfEmployeesForLeader($idEmployee, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- try {
- $idEmployee = $this->encryptionController->decrypt($idEmployee);
- } catch (Throwable $th) {
- return $this->responseController->makeResponse(true, 'El ID del empleado no se encriptó correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- if ( is_null($idEmployee) || $idEmployee === '') {
- $employees = DB::table('S002V01TPERS')
- ->select([
- 'PERS_IDPE AS ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- 'PERS_TICO AS CONTRACT_TYPE',
- 'PERS_ESPE AS SPECIALITY',
- 'PERS_EQTR AS TEAM_ID',
- 'EQMA_NOMB AS TEAM_NAME',
- 'PERS_FERE AS REGISTER_DATE',
- 'PERS_USRE AS REGISTERED_BY_USER',
- 'PERS_FEMO AS UPDATE_DATE',
- 'PERS_USMO AS UPDATED_BY_USER',
- ])
- ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
- ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
- ->where('PERS_ESTA', '=', 'Activo')
- ->where('USUA_NULI', '=', $line)
- ->get()
- ->all();
- } else {
- $employees = DB::table('S002V01TPERS')
- ->select([
- 'PERS_IDPE AS ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- 'PERS_TICO AS CONTRACT_TYPE',
- 'PERS_ESPE AS SPECIALITY',
- 'PERS_EQTR AS TEAM_ID',
- 'EQMA_NOMB AS TEAM_NAME',
- 'PERS_FERE AS REGISTER_DATE',
- 'PERS_USRE AS REGISTERED_BY_USER',
- 'PERS_FEMO AS UPDATE_DATE',
- 'PERS_USMO AS UPDATED_BY_USER',
- ])
- ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
- ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
- ->where('PERS_ESTA', '=', 'Activo')
- ->where('USUA_NULI', '=', $line)
- ->where('PERS_IDPE', '!=', $idEmployee)
- ->get()
- ->all();
- }
-
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P01COEM',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los empleados registrados.",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $employees);
- }
- public function storeEmployee(Request $request) {
- DB::enableQueryLog();
- $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
- $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
- $request['CONTACT_NAME'] = $this->encryptionController->decrypt($request->CONTACT_NAME) ? $this->encryptionController->decrypt($request->CONTACT_NAME) : 'ENC_ERR';
- $request['CONTACT_TELEPHONE'] = $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) ? $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) : 'ENC_ERR';
- $request['CONTACT_LADA'] = $this->encryptionController->decrypt($request->CONTACT_LADA) ? $this->encryptionController->decrypt($request->CONTACT_LADA) : 'ENC_ERR';
- $request['CONTACT_ADDRESS'] = $this->encryptionController->decrypt($request->CONTACT_ADDRESS) ? $this->encryptionController->decrypt($request->CONTACT_ADDRESS) : 'ENC_ERR';
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'USER_ID' => 'required|string',
- 'WORKTEAM_ID' => 'required|string',
- 'CONTRACT_TYPE' => 'required|string|in:Subcontratista,Interno',
- 'SUBCONTRATIST_ID' => 'required_if:CONTRACT_TYPE,=,Subcontratista|string',
- 'SPECIALITY' => 'required|json',
- 'FOREIGNER' => 'required|string|in:Si,No',
- 'RFC' => 'required_if:FOREIGNER,=,No|string|max:13',
- 'TAX' => 'required_if:FOREIGNER,=,Si|string|max:13',
- 'COUNTRY' => 'required|string|max:75',
- 'FEDERAL_ENTITY' => 'required|string|max:75',
- 'CITY' => 'string|max:75',
- 'TOWN' => 'string|max:75',
- 'SUBURB' => 'required|string|max:75',
- 'POSTAL_CODE' => 'required|string|max:5',
- 'STREET' => 'required|string|max:150',
- 'EXTERIOR_NUMBER' => 'required|integer',
- 'INTERIOR_NUMBER' => 'integer',
- 'CONTACT_NAME' => 'required|string|max:150',
- 'CONTACT_LADA' => 'required|string|max:10',
- 'CONTACT_TELEPHONE' => 'required|string|max:11',
- 'CONTACT_ADDRESS' => 'required|string|max:250',
- 'ATTACHED' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- foreach($form as $k=>$v){
- if($k == 'INTERIOR_NUMBER' && $v == '0'){
- unset($form[$k]);
- }else if($v == '-'){
- unset($form[$k]);
- }
- }
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idUserReg = $this->encryptionController->decrypt($form['USER_ID']);
- if(!$idUserReg){
- return $this->responseController->makeResponse(true, 'El ID del usuario seleccionado no fue encriptado correctamente.', [], 400);
- }else if($idUser == $idUserReg){
- return $this->responseController->makeResponse(true, 'El usuario no puede registrarse a sí mismo.', [], 400);
- }
-
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUserReg]
- ])->first();
-
- if(is_null($usrReg)){
- return $this->responseController->makeResponse(true, 'El usuario seleccionado no existe.', [], 404);
- }
- $idTeam = null;
- if(isset($form['WORKTEAM_ID'])){
- $idTeam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
- if(!$idTeam){
- return $this->responseController->makeResponse(true, 'El ID del equipo seleccionado encriptado correctamente.', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $idTeam],
- ['EQMA_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo seleccionado no existe.', [], 404);
- }else if($team->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El equipo seleccionado está eliminado.', [], 404);
- }
- }
- $idSubcontratist = null;
- if(isset($form['SUBCONTRATIST_ID'])){
- $idSubcontratist = $this->encryptionController->decrypt($form['SUBCONTRATIST_ID']);
- if(!$idSubcontratist){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista seleccionado no fue encriptado correctamente.', [], 400);
- }
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $idSubcontratist],
- ['PESU_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, 'El subcontratista seleccionado no existe.', [], 404);
- }
- }
- $rfcx = null;
- if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
- }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
- $rfcx = $form['RFC'];
- }
- $taid = null;
- if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
- }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
- $taid = $form['TAX'];
- }
-
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($country)){
- return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
- }
- $colo = null;
- $ciud = null;
- $loca = null;
- if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
- ['ESTA_COPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
- }
- if($form['COUNTRY'] == 'MEX'){
- if(isset($form['CITY'])){
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $form['CITY']],
- ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
- }else{
- $ciud = $form['CITY'];
- }
- }
- if(isset($form['TOWN'])){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $form['TOWN']],
- ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($town)){
- return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
- }else{
- $loca = $form['TOWN'];
- }
- }
-
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $form['SUBURB']],
- ['COLO_COPO', '=', $form['POSTAL_CODE']],
- ])->first();
-
- if(is_null($setting)){
- return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
- }else{
- $colo = $form['SUBURB'];
- }
-
- $zipCode = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $form['POSTAL_CODE']],
- ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($zipCode)){
- return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- $subArr = DB::table('S002V01TPERS')->where('PERS_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form, $idUserReg) {
- $query->where('PERS_IDUS', '=', $idUserReg)
- ->orWhere('PERS_XRFC', '=', $form['RFC']);
- })->where('PERS_ESTA', '=', 'Activo')->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
- }
- $ladasValues = [];
- $ladas = DB::table('S002V01TPAIS')->select([
- 'PAIS_LADA AS LADA'
- ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
- foreach($ladas as $lada){
- if($lada->LADA != '' && $lada->LADA != '0'){
- $ladasValues[] = $lada->LADA;
- }
- }
- if($form['CONTACT_LADA'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "La lada del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }else if(!in_array($form['CONTACT_LADA'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[CONTACT_LADA] no está relacionada a ningún país.", [], 400);
- }else if($form['CONTACT_TELEPHONE'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico del contacto de emergencia no fue encriptado correctamente.', [], 400);
- }
- if($form['CONTACT_ADDRESS'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "La dirección del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }
- if($form['CONTACT_NAME'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "El nombre del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }
- $docsArr = json_decode($form['ATTACHED'], true);
- if(count($docsArr) == 0){
- return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos está vacío.", [], 400);
- }
- $authCont = 0;
- foreach($docsArr as $doc){
- if($doc['type'] == 'AU') $authCont++;
- }
- if($authCont < 1){
- return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos debe contener al menos un documento de autorización.", [], 400);
- }
- $finalDocsArr = [];
- foreach($docsArr as $doc){
- $idFileDec = $this->encryptionController->decrypt($doc['id']);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_NULI', '=', $form['linea']],
- ['ARTE_IDAR', '=', $idFileDec],
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El archivo $doc[name] no está registrado.", [], 404);
- }
- $classifications = ["AU" => "IN", "OF" => "CO", "CE" => "CE"];
- $cldo = $classifications[$doc['type']];
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], "GPRS", $cldo, $tempFile, $idUser);
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $finalDocsArr[] = [
- 'CODE' => $finalFile[1],
- 'TYPE' => $doc['type']
- ];
- }
- }
- $specialtiesArr = json_decode($form['SPECIALITY'], true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialtyCode = $this->encryptionController->decrypt($specialtyCode);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
- $specialtiesStr = json_encode($specialtiesArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $doas = json_encode($finalDocsArr);
- $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
- $employeeID = DB::table('S002V01TPERS')->insertGetId([
- 'PERS_NULI' => $form['linea'],
- 'PERS_IDUS' => $idUserReg,
- 'PERS_EQTR' => $idTeam,
- 'PERS_TICO' => $form['CONTRACT_TYPE'],
- 'PERS_IDPS' => $idSubcontratist,
- 'PERS_ESPE' => $specialtiesStr,
- 'PERS_EXTR' => $form['FOREIGNER'],
- 'PERS_XRFC' => $rfcx,
- 'PERS_TAID' => $taid,
- 'PERS_IDPA' => $form['COUNTRY'],
- 'PERS_ENFE' => $form['FEDERAL_ENTITY'],
- 'PERS_CIUD' => $ciud,
- 'PERS_LOCA' => $loca,
- 'PERS_COLO' => $colo,
- 'PERS_COPO' => $form['POSTAL_CODE'],
- 'PERS_CALL' => $form['STREET'],
- 'PERS_NUEX' => $form['EXTERIOR_NUMBER'],
- 'PERS_NUIN' => $nuin,
- 'PERS_NOCE' => $form['CONTACT_NAME'],
- 'PERS_LCEM' => $form['CONTACT_LADA'],
- 'PERS_NUTC' => $form['CONTACT_TELEPHONE'],
- 'PERS_DCEM' => $form['CONTACT_ADDRESS'],
- 'PERS_DOAS' => $doas,
- 'PERS_USRE' => $idUser,
- 'PERS_FERE' => $nowStr,
- ]);
- if ( !is_null($form['EMPLOYEE_BOSS']) && $form['EMPLOYEE_BOSS'] !== '' && $form['EMPLOYEE_BOSS'] !== 'null') {
- try {
- $validateRegister = DB::table('S002V01TCREM')->insert([
- 'CREM_IDES' => $employeeID,
- 'CREM_IDEJ' => $form['EMPLOYEE_BOSS'],
- 'CREM_NULI' => $form['linea'],
- 'CREM_USRE' => $idUser,
- 'CREM_FERE' => $nowStr,
- 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el cronograma.", [], 400);
- }
- if (!$validateRegister) {
- return $this->responseController->makeResponse(true, "No se pudo registrar los empleados en el cronograma.", [], 400);
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameEmp = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P02REEM',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró al empleado " . $nameEmp . "($employeeID).",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function updateEmployee(Request $request) {
- DB::enableQueryLog();
- $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
- $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
- $request['CONTACT_NAME'] = $this->encryptionController->decrypt($request->CONTACT_NAME) ? $this->encryptionController->decrypt($request->CONTACT_NAME) : 'ENC_ERR';
- $request['CONTACT_TELEPHONE'] = $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) ? $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) : 'ENC_ERR';
- $request['CONTACT_LADA'] = $this->encryptionController->decrypt($request->CONTACT_LADA) ? $this->encryptionController->decrypt($request->CONTACT_LADA) : 'ENC_ERR';
- $request['CONTACT_ADDRESS'] = $this->encryptionController->decrypt($request->CONTACT_ADDRESS) ? $this->encryptionController->decrypt($request->CONTACT_ADDRESS) : 'ENC_ERR';
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_employee' => 'required|string',
- 'USER_ID' => 'required|string',
- 'WORKTEAM_ID' => 'required|string',
- 'CONTRACT_TYPE' => 'required|string|in:Subcontratista,Interno',
- 'SUBCONTRATIST_ID' => 'required_if:CONTRACT_TYPE,=,Subcontratista|string',
- 'SPECIALITY' => 'required|json',
- 'FOREIGNER' => 'required|string|in:Si,No',
- 'RFC' => 'required_if:FOREIGNER,=,No|string|max:13',
- 'TAX' => 'required_if:FOREIGNER,=,Si|string|max:13',
- 'COUNTRY' => 'required|string|max:75',
- 'FEDERAL_ENTITY' => 'required|string|max:75',
- 'CITY' => 'string|max:75',
- 'TOWN' => 'string|max:75',
- 'SUBURB' => 'required|string|max:75',
- 'POSTAL_CODE' => 'required|string|max:5',
- 'STREET' => 'required|string|max:150',
- 'EXTERIOR_NUMBER' => 'required|integer',
- 'INTERIOR_NUMBER' => 'integer',
- 'CONTACT_NAME' => 'required|string|max:150',
- 'CONTACT_LADA' => 'required|string|max:10',
- 'CONTACT_TELEPHONE' => 'required|string|max:11',
- 'CONTACT_ADDRESS' => 'required|string|max:250',
- 'ATTACHED' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- foreach($form as $k=>$v){
- if($k == 'INTERIOR_NUMBER' && $v == '0'){
- unset($form[$k]);
- }else if($v == '-'){
- unset($form[$k]);
- }
- }
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($form['id_employee']);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado que desea actualizar no fue encriptado correctamente.', [], 400);
- }
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idEmployee]
- ])->first();
-
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado que desea actualizar no existe.', [], 404);
- }
- $idUserReg = $this->encryptionController->decrypt($form['USER_ID']);
- if(!$idUserReg){
- return $this->responseController->makeResponse(true, 'El ID del usuario seleccionado no fue encriptado correctamente.', [], 400);
- }else if($idUser == $idUserReg){
- return $this->responseController->makeResponse(true, 'El usuario no puede registrarse a sí mismo.', [], 400);
- }
-
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUserReg]
- ])->first();
-
- if(is_null($usrReg)){
- return $this->responseController->makeResponse(true, 'El usuario seleccionado no existe.', [], 404);
- }
- $idTeam = null;
- if(isset($form['WORKTEAM_ID'])){
- $idTeam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
- if(!$idTeam){
- return $this->responseController->makeResponse(true, 'El ID del equipo seleccionado encriptado correctamente.', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $idTeam],
- ['EQMA_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo seleccionado no existe.', [], 404);
- }else if($team->EQMA_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'El equipo seleccionado está eliminado.', [], 404);
- }
- }
- $idSubcontratist = null;
- if(isset($form['SUBCONTRATIST_ID'])){
- $idSubcontratist = $this->encryptionController->decrypt($form['SUBCONTRATIST_ID']);
- if(!$idSubcontratist){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista seleccionado no fue encriptado correctamente.', [], 400);
- }
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_IDPS', '=', $idSubcontratist],
- ['PESU_NULI', '=', $form['linea']],
- ])->first();
-
- if(is_null($subcontratist)){
- return $this->responseController->makeResponse(true, 'El subcontratista seleccionado no existe.', [], 404);
- }
- }
- $rfcx = null;
- if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
- }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
- $rfcx = $form['RFC'];
- }
- $taid = null;
- if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
- }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
- $taid = $form['TAX'];
- }
-
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($country)){
- return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
- }
- $colo = null;
- $ciud = null;
- $loca = null;
- if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
- ['ESTA_COPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
- }
- if($form['COUNTRY'] == 'MEX'){
- if(isset($form['CITY'])){
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $form['CITY']],
- ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
- }else{
- $ciud = $form['CITY'];
- }
- }
- if(isset($form['TOWN'])){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $form['TOWN']],
- ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($town)){
- return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
- }else{
- $loca = $form['TOWN'];
- }
- }
-
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $form['SUBURB']],
- ['COLO_COPO', '=', $form['POSTAL_CODE']],
- ])->first();
-
- if(is_null($setting)){
- return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
- }else{
- $colo = $form['SUBURB'];
- }
-
- $zipCode = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $form['POSTAL_CODE']],
- ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($zipCode)){
- return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- $subArr = DB::table('S002V01TPERS')->where('PERS_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form, $idUserReg) {
- $query->where('PERS_IDUS', '=', $idUserReg)
- ->orWhere('PERS_XRFC', '=', $form['RFC']);
- })->where([
- ['PERS_ESTA', '=', 'Activo'],
- ['PERS_IDPE', '!=', $idEmployee],
- ])->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
- }
- $ladasValues = [];
- $ladas = DB::table('S002V01TPAIS')->select([
- 'PAIS_LADA AS LADA'
- ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
- foreach($ladas as $lada){
- if($lada->LADA != '' && $lada->LADA != '0'){
- $ladasValues[] = $lada->LADA;
- }
- }
- if($form['CONTACT_LADA'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "La lada del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }else if(!in_array($form['CONTACT_LADA'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[CONTACT_LADA] no está relacionada a ningún país.", [], 400);
- }else if($form['CONTACT_TELEPHONE'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico del contacto de emergencia no fue encriptado correctamente.', [], 400);
- }
- if($form['CONTACT_ADDRESS'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "La dirección del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }
- if($form['CONTACT_NAME'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, "El nombre del contacto de emergencia no fue encriptada correctamente.", [], 400);
- }
- $docsArr = json_decode($form['ATTACHED'], true);
- if(count($docsArr) == 0){
- return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos está vacío.", [], 400);
- }
- $authCont = 0;
- foreach($docsArr as $doc){
- if($doc['type'] == 'AU') $authCont++;
- }
- if($authCont < 1){
- return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos debe contener al menos un documento de autorización.", [], 400);
- }
- $finalDocsArr = [];
- foreach($docsArr as $doc){
- if(!array_key_exists('isFinalFile', $doc)){
- return $this->responseController->makeResponse(true, "La información del archivo $doc[name] no tiene un formato correcto.", [], 400);
- }
- if($doc['isFinalFile']){
- $finalDocsArr[] = [
- 'CODE' => $doc['name'],
- 'TYPE' => $doc['type']
- ];
- }else{
- $idFileDec = $this->encryptionController->decrypt($doc['id']);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_NULI', '=', $form['linea']],
- ['ARTE_IDAR', '=', $idFileDec],
- ])->first();
-
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El archivo $doc[name] no está registrado.", [], 404);
- }
-
- $classifications = ["AU" => "IN", "OF" => "CO", "CE" => "CE"];
- $cldo = $classifications[$doc['type']];
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], "GPRS", $cldo, $tempFile, $idUser);
-
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $finalDocsArr[] = [
- 'CODE' => $finalFile[1],
- 'TYPE' => $doc['type']
- ];
- }
- }
- }
- $doas = json_encode($finalDocsArr);
- $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
- $specialtiesArr = json_decode($form['SPECIALITY'], true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialtyCode = $this->encryptionController->decrypt($specialtyCode);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
- $specialtiesStr = json_encode($specialtiesArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idEmployee]
- ])->update([
- 'PERS_EQTR' => $idTeam,
- 'PERS_TICO' => $form['CONTRACT_TYPE'],
- 'PERS_IDPS' => $idSubcontratist,
- 'PERS_ESPE' => $specialtiesStr,
- 'PERS_EXTR' => $form['FOREIGNER'],
- 'PERS_XRFC' => $rfcx,
- 'PERS_TAID' => $taid,
- 'PERS_IDPA' => $form['COUNTRY'],
- 'PERS_ENFE' => $form['FEDERAL_ENTITY'],
- 'PERS_CIUD' => $ciud,
- 'PERS_LOCA' => $loca,
- 'PERS_COLO' => $colo,
- 'PERS_COPO' => $form['POSTAL_CODE'],
- 'PERS_CALL' => $form['STREET'],
- 'PERS_NUEX' => $form['EXTERIOR_NUMBER'],
- 'PERS_NUIN' => $nuin,
- 'PERS_NOCE' => $form['CONTACT_NAME'],
- 'PERS_LCEM' => $form['CONTACT_LADA'],
- 'PERS_NUTC' => $form['CONTACT_TELEPHONE'],
- 'PERS_DCEM' => $form['CONTACT_ADDRESS'],
- 'PERS_DOAS' => $doas,
- 'PERS_USMO' => $idUser,
- 'PERS_FEMO' => $nowStr,
- ]);
- if ( !is_null($form['EMPLOYEE_BOSS']) && $form['EMPLOYEE_BOSS'] !== '' && $form['EMPLOYEE_BOSS'] !== 'null') {
- try {
- $arrCronograma = (array) DB::table('S002V01TCREM')
- ->where('CREM_IDES', '=', $idEmployee)
- ->where('CREM_IDEJ', '=', $form['EMPLOYEE_BOSS'])
- ->where('CREM_NULI', '=', $form['linea'])
- ->first([
- 'CREM_IDES AS ID_SUBORDINADO',
- 'CREM_IDEJ AS IS_JEFE',
- 'CREM_ESTA AS ESTADO',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el cronograma.", [], 400);
- }
- if ( count($arrCronograma) === 0 ) {
- try {
- $validateRegister = DB::table('S002V01TCREM')->insert([
- 'CREM_IDES' => $idEmployee,
- 'CREM_IDEJ' => $form['EMPLOYEE_BOSS'],
- 'CREM_NULI' => $form['linea'],
- 'CREM_USRE' => $idUser,
- 'CREM_FERE' => $nowStr,
- 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el cronograma.", [], 400);
- }
- if (!$validateRegister) {
- return $this->responseController->makeResponse(true, "No se pudo registrar los empleados en el cronograma.", [], 400);
- }
- } else {
- try {
- $validateUpdate = DB::table('S002V01TCREM')
- ->where('CREM_IDES', '=', $idEmployee)
- ->where('CREM_IDEJ', '=', $form['EMPLOYEE_BOSS'])
- ->where('CREM_NULI', '=', $form['linea'])
- ->update([
- 'CREM_ESTA' => 'Activo',
- 'CREM_USMO' => $idUser,
- 'CREM_FEMO' => $nowStr,
- 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "Ocurrió un error al modificar el cronograma.", [], 400);
- }
- if (!$validateUpdate) {
- return $this->responseController->makeResponse(true, "No se pudo modificar los empleados en el cronograma.", [], 400);
- }
- }
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $nameEmp = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GEPE',
- 'S002V01P02REEM',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al empleado " . $nameEmp . "($idEmployee).",
- $idUser,
- $nowStr,
- 'S002V01S02GEPE'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getScheduleActivitiesByEmployee($id, $user, $line) {
- try {
- $idEmployee = $this->encryptionController->decrypt($id);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY000: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
- }
- try {
- $getSheduleActivities = DB::table('S002V01TCOAC')
- ->where('COAC_NULI','=',$line)
- ->where('COAC_ESTA','=','Activo')
- ->where('COAC_IDPE','=',$idEmployee)
- ->get([
- 'COAC_IDAC AS ID_ACTIVIDAD',
- 'COAC_IDPE AS ID_EMPLEADO',
- 'COAC_ACTI AS ACTIVIDAD',
- 'COAC_DESC AS DESCRIPCION',
- 'COAC_TIPO AS TIPO_ACTIVIDAD',
- 'COAC_OTPR AS ID_ORDEN_PREVENTIVO',
- 'COAC_OTCO AS ID_ORDEN_CORRECTIVO',
- 'COAC_FEIN AS FECHA_INICIO',
- 'COAC_HOIN AS HORA_INICIO',
- 'COAC_FEFE AS FECHA_FINAL',
- 'COAC_HOFE AS HORA_FINAL',
- 'COAC_FEFR AS FECHA_FINAL_REAL',
- 'COAC_HOFR AS HORA_FINAL_REAL',
- 'COAC_PERI AS PERIODICIDAD',
- 'COAC_PEPE AS PERIODICIDAD_PERSONALIZADA',
- 'COAC_CLAS AS CLASIFICACION',
- 'COAC_COLO AS COLOR',
- 'COAC_ESTA AS ESTADO',
- 'COAC_FERE AS FECHA_REGISTRA',
- 'COAC_USRE AS USUARIO_REGISTRA',
- 'COAC_FEMO AS FECHA_MODIFICA',
- 'COAC_USMO AS USUARIO_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY001: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
- }
- $arrSheduleActivities = json_decode(json_encode($getSheduleActivities), true);
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSheduleActivities);
- }
- public function registerActivity(Request $request) {
- $valitador = Validator::make($request->all(), [
- 'ID_EMPLEADO' => 'required|string',
- 'ACTIVIDAD' => 'required|string',
- 'CLASIFICACION' => 'required|string',
- 'DESCRIPCION' => 'required|string',
- 'TIPO_ACTIVIDAD' => 'required|string',
- 'ID_ORDEN' => 'nullable|string',
- 'PERIODICIDAD' => 'nullable|string',
- 'FECHA_INICIO' => 'required|string',
- 'HORA_INICIO' => 'required|string',
- 'FECHA_FINAL' => 'nullable|string',
- 'HORA_FINAL' => 'nullable|string',
- 'PERIODICIDAD_PERSONALIZADA' => 'nullable|string',
- 'COLOR' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|integer',
- ]);
- if ($valitador->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_EMPLOYEE_REGACTIVITY000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($valitador->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $user = $this->encryptionController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
- }
- try {
- $validateUser = DB::table('S002V01TUSUA')
- ->where('USUA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('USUA_IDUS', '=', $user)
- ->exists();
- } catch(\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY002: Ocurrió al verificar la existencia del usuario.", $th->getMessage(), 404);
- }
- if (!$validateUser) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY003: El usuario no existe.", [], 404);
- }
-
- $idPreventiveMaintenance = null;
- $idCorrectiveMaintenance = null;
-
- if ($requestData['TIPO_ACTIVIDAD'] === 'MP') {
- if (is_null($requestData['ID_ORDEN'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY004: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
- }
- try {
- $validateMaintenance = DB::table('S002V01TOTPR')
- ->where('OTPR_IDOT', '=', $requestData['ID_ORDEN'])
- ->where('OTPR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY005: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
- }
- if (!$validateMaintenance) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY006: La orden de trabajo no existe en la lista de mantenimientos preventivos.", [], 404);
- }
- $idPreventiveMaintenance = $requestData['ID_ORDEN'];
- } else if ($requestData['TIPO_ACTIVIDAD'] === 'MC') {
- if (is_null($requestData['ID_ORDEN'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY007: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
- }
- try {
- $validateMaintenance = DB::table('S002V01TOTCO')
- ->where('OTCO_IDOT ', '=', $requestData['ID_ORDEN'])
- ->where('OTCO_NULI ', '=', $requestData['NUMERO_LINEA'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY008: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
- }
- if (!$validateMaintenance) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY009: La orden de trabajo no existe en la lista de mantenimientos correctivo.", [], 404);
- }
- $idCorrectiveMaintenance = $requestData['ID_ORDEN'];
- } else if ($requestData['TIPO_ACTIVIDAD'] === 'NA' && is_null($requestData['ID_ORDEN']) && !is_null($requestData['PERIODICIDAD']) ) {
- if ($requestData['PERIODICIDAD'] === 'PE' && is_null($requestData['PERIODICIDAD_PERSONALIZADA'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY010: El tipo de periodicidad personalizada debe estar incluida si el tipo de periodicidad está selecciona como Personalizada.", [], 404);
- }
- if ($requestData['PERIODICIDAD'] === 'NR' && (is_null($requestData['FECHA_FINAL']) | is_null($requestData['HORA_FINAL'])) ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY011: La fecha y la hora final esperada debe estar incluida en el formulario si la periodicidad está seleccionada como No se repite.", [], 404);
- }
- } else {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY012: El tipo de actividad no es correcto.", [], 404);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TCOAC')->insert([
- 'COAC_NULI' => $requestData['NUMERO_LINEA'],
- 'COAC_IDPE' => $requestData['ID_EMPLEADO'],
- 'COAC_ACTI' => $requestData['ACTIVIDAD'],
- 'COAC_DESC' => $requestData['DESCRIPCION'],
- 'COAC_TIPO' => $requestData['TIPO_ACTIVIDAD'],
- 'COAC_OTPR' => $idPreventiveMaintenance,
- 'COAC_OTCO' => $idCorrectiveMaintenance,
- 'COAC_FEIN' => $requestData['FECHA_INICIO'],
- 'COAC_HOIN' => $requestData['HORA_INICIO'],
- 'COAC_FEFE' => $requestData['FECHA_FINAL'],
- 'COAC_HOFE' => $requestData['HORA_FINAL'],
- // 'COAC_FEFR' => $requestData[''],
- // 'COAC_HOFR' => $requestData[''],
- 'COAC_PERI' => $requestData['PERIODICIDAD'],
- 'COAC_PEPE' => $requestData['PERIODICIDAD_PERSONALIZADA'],
- 'COAC_CLAS' => $requestData['CLASIFICACION'],
- 'COAC_COLO' => $requestData['COLOR'],
- 'COAC_FERE' => $currentDate,
- 'COAC_USRE' => $user,
- 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY013: Ocurrió un error al insertar los datos.", $th->getMessage(), 404);
- }
- if (!$validateInsert) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY014: No se pudo insertar los datos en la base de datos.", [], 404);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
- }
- public function updateActivity(Request $request, $idActivity) {
- $valitador = Validator::make($request->all(), [
- // 'ID_ACTIVIDAD' => 'required|integer',
- 'ID_EMPLEADO' => 'required|string',
- 'ACTIVIDAD' => 'required|string',
- 'CLASIFICACION' => 'required|string',
- 'DESCRIPCION' => 'required|string',
- 'TIPO_ACTIVIDAD' => 'required|string',
- 'ID_ORDEN' => 'nullable|string',
- 'PERIODICIDAD' => 'nullable|string',
- 'FECHA_INICIO' => 'required|string',
- 'HORA_INICIO' => 'required|string',
- 'FECHA_FINAL' => 'nullable|string',
- 'HORA_FINAL' => 'nullable|string',
- 'PERIODICIDAD_PERSONALIZADA' => 'nullable|string',
- 'COLOR' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|integer',
- ]);
- if ($valitador->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_EMPLOYEE_UPDACTIVITY000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($valitador->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $idActivity = $this->encryptionController->decrypt($idActivity);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY001: Ocurrió un error al desencriptar los datos de la actividad.", $th->getMessage(), 401);
- }
- try {
- $user = $this->encryptionController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY002: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
- }
- try {
- $validateUser = DB::table('S002V01TUSUA')
- ->where('USUA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('USUA_IDUS', '=', $user)
- ->exists();
- } catch(\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY003: Ocurrió al verificar la existencia del usuario.", $th->getMessage(), 404);
- }
- if (!$validateUser) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY004: El usuario no existe.", [], 404);
- }
- $idPreventiveMaintenance = null;
- $idCorrectiveMaintenance = null;
- if ($requestData['TIPO_ACTIVIDAD'] === 'MP') {
- if (is_null($requestData['ID_ORDEN'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY005: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
- }
- try {
- $validateMaintenance = DB::table('S002V01TOTPR')
- ->where('OTPR_IDOT', '=', $requestData['ID_ORDEN'])
- ->where('OTPR_NULI', '=', $requestData['NUMERO_LINEA'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY006: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
- }
- if (!$validateMaintenance) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY007: La orden de trabajo no existe en la lista de mantenimientos preventivos.", [], 404);
- }
- $idPreventiveMaintenance = $requestData['ID_ORDEN'];
- } else if ($requestData['TIPO_ACTIVIDAD'] === 'MC') {
- if (is_null($requestData['ID_ORDEN'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY008: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
- }
- try {
- $validateMaintenance = DB::table('S002V01TOTCO')
- ->where('OTCO_IDOT ', '=', $requestData['ID_ORDEN'])
- ->where('OTCO_NULI ', '=', $requestData['NUMERO_LINEA'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY009: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
- }
- if (!$validateMaintenance) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY010: La orden de trabajo no existe en la lista de mantenimientos correctivo.", [], 404);
- }
- $idCorrectiveMaintenance = $requestData['ID_ORDEN'];
- } else if ($requestData['TIPO_ACTIVIDAD'] === 'NA' && is_null($requestData['ID_ORDEN']) && !is_null($requestData['PERIODICIDAD']) ) {
- if ($requestData['PERIODICIDAD'] === 'PE' && is_null($requestData['PERIODICIDAD_PERSONALIZADA'])) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY011: El tipo de periodicidad personalizada debe estar incluida si el tipo de periodicidad está selecciona como Personalizada.", [], 404);
- }
- if ($requestData['PERIODICIDAD'] === 'NR' && (is_null($requestData['FECHA_FINAL']) | is_null($requestData['HORA_FINAL'])) ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY012: La fecha y la hora final esperada debe estar incluida en el formulario si la periodicidad está seleccionada como No se repite.", [], 404);
- }
- } else {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY013: El tipo de actividad no es correcto.", [], 404);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TCOAC')
- ->where('COAC_IDAC','=',$idActivity)
- ->where('COAC_NULI','=',$requestData['NUMERO_LINEA'])
- ->where('COAC_IDPE','=',$requestData['ID_EMPLEADO'])
- ->update([
- 'COAC_ACTI' => $requestData['ACTIVIDAD'],
- 'COAC_DESC' => $requestData['DESCRIPCION'],
- 'COAC_TIPO' => $requestData['TIPO_ACTIVIDAD'],
- 'COAC_OTPR' => $idPreventiveMaintenance,
- 'COAC_OTCO' => $idCorrectiveMaintenance,
- 'COAC_FEIN' => $requestData['FECHA_INICIO'],
- 'COAC_HOIN' => $requestData['HORA_INICIO'],
- 'COAC_FEFE' => $requestData['FECHA_FINAL'],
- 'COAC_HOFE' => $requestData['HORA_FINAL'],
- // 'COAC_FEFR' => $requestData[''],
- // 'COAC_HOFR' => $requestData[''],
- 'COAC_PERI' => $requestData['PERIODICIDAD'],
- 'COAC_PEPE' => $requestData['PERIODICIDAD_PERSONALIZADA'],
- 'COAC_CLAS' => $requestData['CLASIFICACION'],
- 'COAC_COLO' => $requestData['COLOR'],
- 'COAC_FEMO' => $currentDate,
- 'COAC_USMO' => $user,
- 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY014: Ocurrió un error al insertar los datos.", $th->getMessage(), 404);
- }
- if (!$validateInsert) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY015: No se pudo insertar los datos en la base de datos.", [], 404);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- public function deleteActivity(Request $request, $idActivity) {
- $valitador = Validator::make($request->all(), [
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|integer',
- ]);
- if ($valitador->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_EMPLOYEE_DELACTIVITY000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($valitador->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $idActivity = $this->encryptionController->decrypt($idActivity);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
- }
- try {
- $user = $this->encryptionController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY002: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateDelete = DB::table('S002V01TCOAC')
- ->where('COAC_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('COAC_IDAC', '=', $idActivity)
- ->update([
- 'COAC_ESTA' => 'Eliminado',
- 'COAC_FEMO' => $currentDate,
- 'COAC_USMO' => $user,
- 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY003: Ocurrió un error al eliminar la actividad.", $th->getMessage(), 401);
- }
- if (!$validateDelete) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY004: No se pudo eliminar la actividad.", [], 401);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- public function getScheduleActivitiesByActivity($id, $user, $line) {
- try {
- $idActivity = $this->encryptionController->decrypt($id);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY000: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
- }
- try {
- $arrSheduleActivities = (array) DB::table('S002V01TCOAC')
- ->where('COAC_NULI','=',$line)
- ->where('COAC_ESTA','=','Activo')
- ->where('COAC_IDAC','=',$idActivity)
- ->first([
- 'COAC_IDPE AS ID_EMPLEADO',
- 'COAC_ACTI AS ACTIVIDAD',
- 'COAC_DESC AS DESCRIPCION',
- 'COAC_TIPO AS TIPO_ACTIVIDAD',
- 'COAC_OTPR AS ID_ORDEN_PREVENTIVO',
- 'COAC_OTCO AS ID_ORDEN_CORRECTIVO',
- 'COAC_FEIN AS FECHA_INICIO',
- 'COAC_HOIN AS HORA_INICIO',
- 'COAC_FEFE AS FECHA_FINAL',
- 'COAC_HOFE AS HORA_FINAL',
- 'COAC_FEFR AS FECHA_FINAL_REAL',
- 'COAC_HOFR AS HORA_FINAL_REAL',
- 'COAC_PERI AS PERIODICIDAD',
- 'COAC_PEPE AS PERIODICIDAD_PERSONALIZADA',
- 'COAC_CLAS AS CLASIFICACION',
- 'COAC_COLO AS COLOR',
- 'COAC_ESTA AS ESTADO',
- 'COAC_FERE AS FECHA_REGISTRA',
- 'COAC_USRE AS USUARIO_REGISTRA',
- 'COAC_FEMO AS FECHA_MODIFICA',
- 'COAC_USMO AS USUARIO_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY001: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSheduleActivities);
- }
- public function getConsultOfSubcontratists($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $subcontratists = DB::table('S002V01TPESU')->select([
- 'PESU_IDPS as ID_SUBCONTRATIST',
- DB::raw('CONCAT(PESU_RASO, " (" , COALESCE(PESU_REFI, ""), ")") AS NAME'),
- 'PESU_EXTR AS TIPO',
- 'PESU_ESPE AS SPECIALTY',
- 'PESU_FERE AS REGISTER_DATE',
- 'PESU_FEMO AS UPDATE_DATE',
- 'PESU_USRE AS REGISTERED_BY_USER',
- 'PESU_USMO AS UPDATED_BY_USER',
- 'PESU_ESTA AS STATUS'
- ])->where('PESU_NULI', '=', $line)->get()->all();
- foreach($subcontratists as $subcontratist){
- $regUsr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $subcontratist->REGISTERED_BY_USER],
- ])->first();
- if(!is_null($regUsr)){
- $subcontratist->REGISTERED_BY_USER = $this->functionsController->joinName($regUsr->USUA_NOMB, $regUsr->USUA_APPA, $regUsr->USUA_APMA) . " (" . $subcontratist->REGISTERED_BY_USER . ")";
- }else{
- $subcontratist->REGISTERED_BY_USER = "DESCONOCIDO (" . $subcontratist->REGISTERED_BY_USER . ")";
- }
-
- if(!is_null($subcontratist->UPDATED_BY_USER)){
- $modUsr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $subcontratist->UPDATED_BY_USER],
- ])->first();
-
- if(!is_null($modUsr)){
- $subcontratist->UPDATED_BY_USER = $this->functionsController->joinName($modUsr->USUA_NOMB, $modUsr->USUA_APPA, $modUsr->USUA_APMA) . " (" . $subcontratist->UPDATED_BY_USER . ")";
- }else{
- $subcontratist->UPDATED_BY_USER = "DESCONOCIDO (" . $subcontratist->UPDATED_BY_USER . ")";
- }
- }
- if($subcontratist->TIPO == 'No'){
- $subcontratist->TIPO = 'Nacional';
- }else{
- $subcontratist->TIPO = 'Extranjero';
- }
- $preventiveInterventions = DB::select("
- SELECT
- DISTINCT(S002V01TOTPR.OTPR_IDOT),
- OPPR.*
- FROM
- S002V01TOTPR,
- JSON_TABLE(OTPR_OPPR, '$[*]' COLUMNS(
- OTPR_OPPR_ID INT PATH '$.ID',
- OTPR_OPPR_TYPE VARCHAR(100) PATH '$.TYPE'
- )) OPPR
- WHERE
- OPPR.OTPR_OPPR_TYPE = :emp_type
- AND OPPR.OTPR_OPPR_ID = :emp_id
- ", ['emp_type' => 'SU', 'emp_id' => $subcontratist->ID_SUBCONTRATIST]);
- //PENDIENTE IMPLEMENTAR INTERVENCIONES DE MANTENIMIENTO CORRECTIVO
- $subcontratist->INTERVENTIONS_COUNT = count($preventiveInterventions);
- $subcontratist->ID_SUBCONTRATIST = $this->encryptionController->encrypt($subcontratist->ID_SUBCONTRATIST);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GESU',
- 'S002V01P01COSU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los subcontratistas registrados.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $subcontratists);
- }
- public function storeSubcontratist(Request $request) {
- DB::enableQueryLog();
- $request['TELEPHONE1'] = $this->encryptionController->decrypt($request->TELEPHONE1) ? $this->encryptionController->decrypt($request->TELEPHONE1) : 'ENC_ERR';
- $request['TELEPHONE2'] = $this->encryptionController->decrypt($request->TELEPHONE2) ? $this->encryptionController->decrypt($request->TELEPHONE2) : 'ENC_ERR';
- $request['EMAIL'] = $this->encryptionController->decrypt($request->EMAIL) ? $this->encryptionController->decrypt($request->EMAIL) : 'ENC_ERR';
- if ( !is_null($request->RFC) ) {
- $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
- }
- if ( !is_null($request->TAX) ) {
- $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
- }
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'SOCIAL_REASON' => 'required|string|max:150',
- 'TAX_REFERENCE' => 'required|string|max:15',
- 'CONTRACT_TYPE' => 'required|string|in:Persona moral,Persona física',
- 'FOREIGNER' => 'required|string|in:Si,No',
- 'RFC' => 'required_if:FOREIGNER,=,No',
- 'TAX' => 'required_if:FOREIGNER,=,Si',
- 'EMAIL' => 'required|string|max:150',
- 'COUNTRY' => 'required|string|max:75',
- 'FEDERAL_ENTITY' => 'required|string|max:75',
- 'CITY' => 'string|max:75',
- 'TOWN' => 'string|max:75',
- 'SUBURB' => 'required|string|max:75',
- 'POSTAL_CODE' => 'required|string|max:5',
- 'STREET' => 'required|string|max:150',
- 'EXTERIOR_NUMBER' => 'required|string',
- 'INTERIOR_NUMBER' => 'string',
- 'LADA1' => 'required|string|max:15',
- 'TELEPHONE1' => 'required|string|min:7|max:11',
- 'LADA2' => 'string|max:15',
- 'TELEPHONE2' => 'string|min:7|max:11',
- 'SPECIALTY' => 'required|json',
- 'PROVIDER' => 'string|max:10'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- $form = $request->all();
- foreach($form as $k=>$v){
- if($k == 'INTERIOR_NUMBER' && $v == '0'){
- unset($form[$k]);
- }else if($v == '-'){
- unset($form[$k]);
- }
- }
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $ladasValues = [];
- $ladas = DB::table('S002V01TPAIS')->select([
- 'PAIS_LADA AS LADA'
- ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
- foreach($ladas as $lada){
- if($lada->LADA != '' && $lada->LADA != '0'){
- $ladasValues[] = $lada->LADA;
- }
- }
- if(!in_array($form['LADA1'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[LADA1] no está relacionada a ningún país.", [], 400);
- }else if($form['TELEPHONE1'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico 1 no fue encriptado correctamente.', [], 400);
- }
- $lada2 = null;
- $phone2 = null;
- if(isset($form['LADA2'])){
- if(!in_array($form['LADA2'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[LADA2] no está relacionada a ningún país.", [], 400);
- }else if($form['TELEPHONE2'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico 2 no fue encriptado correctamente.', [], 400);
- }
- $lada2 = $form['LADA2'];
- $phone2 = $form['TELEPHONE2'];
- }
- if($form['EMAIL'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El email no fue encriptado correctamente.', [], 400);
- }
- $rfcx = null;
- if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
- }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
- $rfcx = $form['RFC'];
- }
- $taid = null;
- if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
- }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
- $taid = $form['TAX'];
- }
-
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($country)){
- return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
- }
-
- $taxRegime = DB::table('S002V01TREFI')->where([
- ['REFI_NULI', '=', $form['linea']],
- ['REFI_CRFI', '=', $form['TAX_REFERENCE']],
- ])->first();
-
- if(is_null($taxRegime)){
- return $this->responseController->makeResponse(true, 'El régimen fiscal seleccionado no existe.', [], 404);
- }
- $colo = null;
- $ciud = null;
- $loca = null;
- if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
- ['ESTA_COPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
- }
- if($form['COUNTRY'] == 'MEX'){
- if(isset($form['CITY'])){
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $form['CITY']],
- ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
- }else{
- $ciud = $form['CITY'];
- }
- }
- if(isset($form['TOWN'])){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $form['TOWN']],
- ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($town)){
- return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
- }else{
- $loca = $form['TOWN'];
- }
- }
-
- if ($form['FOREIGNER'] === 'No') {
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $form['SUBURB']],
- ['COLO_COPO', '=', $form['POSTAL_CODE']],
- ])->first();
-
- if(is_null($setting)){
- return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
- }else{
- $colo = $form['SUBURB'];
- }
- } else {
- $colo = $form['SUBURB'];
- }
-
-
- $zipCode = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $form['POSTAL_CODE']],
- ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($zipCode)){
- return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- if (!is_null($form['RFC'])) {
- $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_XRFC', '=', $form['RFC'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where('PESU_ESTA', '=', 'Activo')->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados. 1', [], 401);
- }
- }
- if (!is_null($form['TAX'])) {
- $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_TAID', '=', $form['TAX'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where('PESU_ESTA', '=', 'Activo')->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el Tax ID o el correo electrónico ya fueron registrados. 2', [], 401);
- }
- }
- $idProvider = null;
- if ( array_key_exists('PROVIDER', $form) ) {
- $idProvider = $form['PROVIDER'];
- try {
- $validateExist = DB::table('S002V01TPROV')
- ->where('PROV_NUPR', '=', $idProvider)
- ->where('PROV_NULI', '=', $form['linea'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el proveedor.", $th->getMessage(), 500);
- }
- if (!$validateExist) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "El número del proveedor no existe.", [], 500);
- }
- }
- $specialtiesArr = json_decode($form['SPECIALTY'], true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialtyCode = $this->encryptionController->decrypt($specialtyCode);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
- $specialtiesStr = json_encode($specialtiesArr);
- $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $subcontratistID = DB::table('S002V01TPESU')->insertGetId([
- 'PESU_NULI' => $form['linea'],
- 'PESU_NUPR' => $idProvider,
- 'PESU_RASO' => $form['SOCIAL_REASON'],
- 'PESU_REFI' => $form['TAX_REFERENCE'],
- 'PESU_XRFC' => $rfcx === '' ? null : $rfcx,
- 'PESU_TIPO' => $form['CONTRACT_TYPE'],
- 'PESU_CORR' => $form['EMAIL'],
- 'PESU_EXTR' => $form['FOREIGNER'],
- 'PESU_TAID' => $taid === '' ? null : $taid,
- 'PESU_CALL' => $form['STREET'],
- 'PESU_NUEX' => $form['EXTERIOR_NUMBER'],
- 'PESU_NUIN' => $nuin,
- 'PESU_COLO' => $colo,
- 'PESU_CIUD' => $ciud,
- 'PESU_LOCA' => $loca,
- 'PESU_COPO' => $form['POSTAL_CODE'],
- 'PESU_ENFE' => $form['FEDERAL_ENTITY'],
- 'PESU_IDPA' => $form['COUNTRY'],
- 'PESU_TEL1' => $form['TELEPHONE1'],
- 'PESU_LAT1' => $form['LADA1'],
- 'PESU_TEL2' => $phone2,
- 'PESU_LAT2' => $lada2,
- 'PESU_ESPE' => $specialtiesStr,
- 'PESU_USRE' => $idUser,
- 'PESU_FERE' => $nowStr,
- ]);
- if (!is_null($idProvider)) {
- try {
- $validateUpdate = DB::table('S002V01TPROV')
- ->where('PROV_NUPR', '=', $idProvider)
- ->where('PROV_NULI', '=', $form['linea'])
- ->update([
- 'PROV_IDPS' => $subcontratistID,
- 'PROV_USMO' => $idUser,
- 'PROV_FEMO' => $nowStr,
- 'PROV_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al modificar el proveedor.", $th->getMessage(), 500);
- }
- if (!$validateUpdate) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "No se pudo modificar el proveedor.", [], 500);
- }
- }
- $response = array( 'idSubcontract' => $subcontratistID );
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GESU',
- 'S002V01P02RESU',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró al subcontratista $form[SOCIAL_REASON] ($subcontratistID).",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO', $response);
- }
- public function getSubcontratistById($idSub, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la consulta no está encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_IDUS', '=', $idUser],
- ['USUA_NULI', '=', $line]
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
-
- $idSub = $this->encryptionController->decrypt($idSub);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista consultado no está encriptado correctamente.', [], 400);
- }
- $subcontratists_info = DB::table('S002V01TPESU')->select([
- 'PESU_IDPS as ID_SUBCONTRATIST',
- 'PESU_RASO as SOCIAL_REASON',
- 'PESU_REFI as TAX_REFERENCE',
- 'PESU_XRFC as RFC',
- 'PESU_TIPO as CONTRACT_TYPE',
- 'PESU_CORR as EMAIL',
- 'PESU_EXTR as FOREIGNER',
- 'PESU_TAID as TAX',
- 'PESU_CALL as STREET',
- 'PESU_NUEX as EXTERIOR_NUMBER',
- 'PESU_NUIN as INTERIOR_NUMBER',
- 'PESU_COLO as SUBURB',
- 'PESU_CIUD as CITY',
- 'PESU_LOCA as TOWN',
- 'PESU_COPO as POSTAL_CODE',
- 'PESU_ENFE as FEDERAL_ENTITY',
- 'PESU_IDPA as COUNTRY',
- 'PESU_TEL1 as TELEPHONE1',
- 'PESU_LAT1 as LADA1',
- 'PESU_TEL2 as TELEPHONE2',
- 'PESU_LAT2 as LADA2',
- 'PESU_ESPE as SPECIALTY',
- 'PESU_ESTA as STATUS'
- ])->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $idSub],
- ])->first();
- $taxRegime = DB::table('S002V01TREFI')->where([
- ['REFI_NULI', '=', $line],
- ['REFI_CRFI', '=', $subcontratists_info->TAX_REFERENCE],
- ])->first();
- $subcontratists_info->TAX_REFERENCE = $taxRegime->REFI_DRFI . " (" . $subcontratists_info->TAX_REFERENCE . ")";
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $line],
- ['PAIS_IDPA', '=', $subcontratists_info->COUNTRY],
- ])->first();
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $line],
- ['ESTA_COES', '=', $subcontratists_info->FEDERAL_ENTITY],
- ['ESTA_COPA', '=', $subcontratists_info->COUNTRY],
- ])->first();
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $line],
- ['MUNI_COMU', '=', $subcontratists_info->CITY],
- ['MUNI_COES', '=', $subcontratists_info->FEDERAL_ENTITY],
- ])->first();
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $line],
- ['LOCA_COLO', '=', $subcontratists_info->TOWN],
- ['LOCA_COES', '=', $subcontratists_info->FEDERAL_ENTITY],
- ])->first();
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $line],
- ['COLO_COCO', '=', $subcontratists_info->SUBURB],
- ['COLO_COPO', '=', $subcontratists_info->POSTAL_CODE],
- ])->first();
- if(!is_null($country)){
- $subcontratists_info->COUNTRY = trim($country->PAIS_NOMB) . " (" . $subcontratists_info->COUNTRY . ")";
- }
- if(!is_null($state)){
- $subcontratists_info->FEDERAL_ENTITY = trim($state->ESTA_NOES) . " (" . $subcontratists_info->FEDERAL_ENTITY . ")";
- }
- if(!is_null($city)){
- $subcontratists_info->CITY = trim($city->MUNI_NOMU) . " (" . $subcontratists_info->CITY . ")";
- }
- if(!is_null($town)){
- $subcontratists_info->TOWN = trim($town->LOCA_NOLO) . " (" . $subcontratists_info->TOWN . ")";
- }
- if(!is_null($setting)){
- $subcontratists_info->SUBURB = trim($setting->COLO_NOCO) . " (" . $subcontratists_info->SUBURB . ")";
- }
- $specialtiesArr = json_decode($subcontratists_info->SPECIALTY, true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- $specialty = $specialtyCode . " - " . $specialty->GEES_NOES;
- $specialtyCode = $this->encryptionController->encrypt($specialty);
- $specialtiesArr[$key] = $specialtyCode;
- }
- $subcontratists_info->SPECIALTY = json_encode($specialtiesArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01GESU',
- 'S002V01P03DESU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó al subcontratista " . $subcontratists_info->SOCIAL_REASON . " ($idSub).",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $subcontratists_info);
- }
- public function updateSubcontratist(Request $request) {
- DB::enableQueryLog();
- $request['TELEPHONE1'] = $this->encryptionController->decrypt($request->TELEPHONE1) ? $this->encryptionController->decrypt($request->TELEPHONE1) : 'ENC_ERR';
- $request['TELEPHONE2'] = $this->encryptionController->decrypt($request->TELEPHONE2) ? $this->encryptionController->decrypt($request->TELEPHONE2) : 'ENC_ERR';
- $request['EMAIL'] = $this->encryptionController->decrypt($request->EMAIL) ? $this->encryptionController->decrypt($request->EMAIL) : 'ENC_ERR';
-
- if (!is_null($request->RFC)) {
- $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
- } else {
- $request['RFC'] = '';
- }
- if (!is_null($request->TAX)) {
- $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
- } else {
- $request['TAX'] = '';
- }
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_subcontratist' => 'required|string',
- 'SOCIAL_REASON' => 'required|string|max:150',
- 'TAX_REFERENCE' => 'required|string|max:15',
- 'CONTRACT_TYPE' => 'required|string|in:Persona moral,Persona física',
- 'FOREIGNER' => 'required|string|in:Si,No',
- 'RFC' => 'required_if:FOREIGNER,=,No|string|max:13',
- 'TAX' => 'required_if:FOREIGNER,=,Si|string|max:13',
- 'EMAIL' => 'required|string|max:150',
- 'COUNTRY' => 'required|string|max:75',
- 'FEDERAL_ENTITY' => 'required|string|max:75',
- 'CITY' => 'string|max:75',
- 'TOWN' => 'string|max:75',
- 'SUBURB' => 'required|string|max:75',
- 'POSTAL_CODE' => 'required|string|max:5',
- 'STREET' => 'required|string|max:150',
- 'EXTERIOR_NUMBER' => 'required|string',
- // 'INTERIOR_NUMBER' => 'string',
- 'LADA1' => 'required|string|max:15',
- 'TELEPHONE1' => 'required|string|min:7|max:11',
- 'LADA2' => 'string|max:15',
- 'TELEPHONE2' => 'string|min:7|max:11',
- 'SPECIALTY' => 'required|json'
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- foreach($form as $k=>$v){
- if($k == 'INTERIOR_NUMBER' && $v == '0'){
- unset($form[$k]);
- }else if($v == '-'){
- unset($form[$k]);
- }
- }
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSub = $this->encryptionController->decrypt($form['id_subcontratist']);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $idSub],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El subcontratista solicitado no existe.', [], 404);
- }
- $ladasValues = [];
- $ladas = DB::table('S002V01TPAIS')->select([
- 'PAIS_LADA AS LADA'
- ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
- foreach($ladas as $lada){
- if($lada->LADA != '' && $lada->LADA != '0'){
- $ladasValues[] = $lada->LADA;
- }
- }
- if(!in_array($form['LADA1'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[LADA1] no está relacionada a ningún país.", [], 400);
- }else if($form['TELEPHONE1'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico 1 no fue encriptado correctamente.', [], 400);
- }
- $lada2 = null;
- $phone2 = null;
- if(isset($form['LADA2'])){
- if(!in_array($form['LADA2'], $ladasValues)){
- return $this->responseController->makeResponse(true, "La lada $form[LADA2] no está relacionada a ningún país.", [], 400);
- }else if($form['TELEPHONE2'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El número telefónico 2 no fue encriptado correctamente.', [], 400);
- }
- $lada2 = $form['LADA2'];
- $phone2 = $form['TELEPHONE2'];
- }
- if($form['EMAIL'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El email no fue encriptado correctamente.', [], 400);
- }
- $rfcx = null;
- if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
- }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
- $rfcx = $form['RFC'];
- }
- $taid = null;
- if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
- return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
- }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
- $taid = $form['TAX'];
- }
-
- $country = DB::table('S002V01TPAIS')->where([
- ['PAIS_NULI', '=', $form['linea']],
- ['PAIS_IDPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($country)){
- return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
- }
-
- $taxRegime = DB::table('S002V01TREFI')->where([
- ['REFI_NULI', '=', $form['linea']],
- ['REFI_CRFI', '=', $form['TAX_REFERENCE']],
- ])->first();
-
- if(is_null($taxRegime)){
- return $this->responseController->makeResponse(true, 'El régimen fiscal seleccionado no existe.', [], 404);
- }
- $colo = null;
- $ciud = null;
- $loca = null;
- if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
- $state = DB::table('S002V01TESTA')->where([
- ['ESTA_NULI', '=', $form['linea']],
- ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
- ['ESTA_COPA', '=', $form['COUNTRY']],
- ])->first();
-
- if(is_null($state)){
- return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
- }
- if($form['COUNTRY'] == 'MEX'){
- if(isset($form['CITY'])){
- $city = DB::table('S002V01TMUNI')->where([
- ['MUNI_NULI', '=', $form['linea']],
- ['MUNI_COMU', '=', $form['CITY']],
- ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($city)){
- return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
- }else{
- $ciud = $form['CITY'];
- }
- }
- if(isset($form['TOWN'])){
- $town = DB::table('S002V01TLOCA')->where([
- ['LOCA_NULI', '=', $form['linea']],
- ['LOCA_COLO', '=', $form['TOWN']],
- ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($town)){
- return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
- }else{
- $loca = $form['TOWN'];
- }
- }
-
- $setting = DB::table('S002V01TCOLO')->where([
- ['COLO_NULI', '=', $form['linea']],
- ['COLO_COCO', '=', $form['SUBURB']],
- ['COLO_COPO', '=', $form['POSTAL_CODE']],
- ])->first();
-
- if(is_null($setting)){
- return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
- }else{
- $colo = $form['SUBURB'];
- }
-
- $zipCode = DB::table('S002V01TCOPO')->where([
- ['COPO_NULI', '=', $form['linea']],
- ['COPO_COPO', '=', $form['POSTAL_CODE']],
- ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
- ])->first();
-
- if(is_null($zipCode)){
- return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- }else{
- $colo = $form['SUBURB'];
- $ciud = $form['CITY'];
- $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
- }
- /* $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_XRFC', '=', $form['RFC'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where([
- ['PESU_IDPS', '!=', $idSub],
- ['PESU_ESTA', '=', 'Activo'],
- ])->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
- } */
- if (!is_null($form['RFC'])) {
- $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_XRFC', '=', $form['RFC'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where([
- ['PESU_IDPS', '!=', $idSub],
- ['PESU_ESTA', '=', 'Activo'],
- ])->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
- }
- }
- if (!is_null($form['TAX'])) {
- $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_XRFC', '=', $form['TAX'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where([
- ['PESU_IDPS', '!=', $idSub],
- ['PESU_ESTA', '=', 'Activo'],
- ])->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el Tax ID o el correo electrónico ya fueron registrados.', [], 401);
- }
- /* $subArr = DB::table('S002V01TPESU')->where('PESU_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form) {
- $query->where('PESU_RASO', '=', $form['SOCIAL_REASON'])
- ->orWhere('PESU_TAID', '=', $form['TAX'])
- ->orWhere('PESU_CORR', '=', $form['EMAIL']);
- })->where('PESU_ESTA', '=', 'Activo')->get()->all();
- if(count($subArr) > 0){
- return $this->responseController->makeResponse(true, 'La razón social, el Tax ID o el correo electrónico ya fueron registrados. 2', [], 401);
- } */
- }
- $specialtiesArr = json_decode($form['SPECIALTY'], true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialtyCode = $this->encryptionController->decrypt($specialtyCode);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
- $specialtiesStr = json_encode($specialtiesArr);
- $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $idSub],
- ])->update([
- 'PESU_RASO' => $form['SOCIAL_REASON'],
- 'PESU_REFI' => $form['TAX_REFERENCE'],
- 'PESU_XRFC' => $rfcx,
- 'PESU_TIPO' => $form['CONTRACT_TYPE'],
- 'PESU_CORR' => $form['EMAIL'],
- 'PESU_EXTR' => $form['FOREIGNER'],
- 'PESU_TAID' => $taid,
- 'PESU_CALL' => $form['STREET'],
- 'PESU_NUEX' => $form['EXTERIOR_NUMBER'],
- 'PESU_NUIN' => $nuin,
- 'PESU_COLO' => $colo,
- 'PESU_CIUD' => $ciud,
- 'PESU_LOCA' => $loca,
- 'PESU_COPO' => $form['POSTAL_CODE'],
- 'PESU_ENFE' => $form['FEDERAL_ENTITY'],
- 'PESU_IDPA' => $form['COUNTRY'],
- 'PESU_TEL1' => $form['TELEPHONE1'],
- 'PESU_LAT1' => $form['LADA1'],
- 'PESU_TEL2' => $phone2,
- 'PESU_LAT2' => $lada2,
- 'PESU_ESPE' => $specialtiesStr,
- 'PESU_USMO' => $idUser,
- 'PESU_FEMO' => $nowStr,
- ]);
- $response = array('idSubcontract' => $idSub);
- try {
- $getProvider = (array) DB::table('S002V01TPROV')
- ->where('PROV_IDPS', '=', $idSub)
- ->where('PROV_NULI', '=', $form['linea'])
- ->first();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al válidar si existe en proveedor.", $th->getMessage(), 500);
- }
- if ( !empty($getProvider) ) {
- try {
- $validateUpdateInformation = DB::table('S002V01TPROV')
- ->where('PROV_NUPR', '=', $getProvider['PROV_NUPR'])
- ->where('PROV_NULI', '=', $form['linea'])
- ->update([
- 'PROV_NOCO' => $form['SOCIAL_REASON'],
- 'PROV_CORR' => $form['EMAIL'],
- 'PROV_LAD1' => $form['LADA1'],
- 'PROV_TEL1' => $form['TELEPHONE1'],
- 'PROV_LAD2' => $lada2,
- 'PROV_TEL2' => $phone2,
- 'PROV_TICO' => $form['CONTRACT_TYPE'],
- 'PROV_XRFC' => $rfcx,
- 'PROV_XTAX' => $taid,
- 'PROV_CRFI' => $form['TAX_REFERENCE'],
- 'PROV_TIPO' => $form['FOREIGNER'] === 'No' ? 'Nacional' : 'Extranjero',
- 'PROV_CALL' => $form['STREET'],
- 'PROV_NUEX' => $form['EXTERIOR_NUMBER'],
- 'PROV_NUIN' => $nuin,
- 'PROV_COPO' => $form['POSTAL_CODE'],
- 'PROV_COLO' => $colo,
- 'PROV_LOCA' => $loca,
- 'PROV_MUNI' => $ciud,
- 'PROV_ENTI' => $form['FEDERAL_ENTITY'],
- 'PROV_PAIS' => $form['COUNTRY'],
- 'PROV_USMO' => $idUser,
- 'PROV_FEMO' => $nowStr,
- 'PROV_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "Ocurrió un error al modificar al proveedor", $th->getMessage(), 500);
- }
- if (!$validateUpdateInformation) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "No se pudo modificar el proveedor.", [], 500);
- }
- $response['provider'] = $getProvider;
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GESU',
- 'S002V01P02RESU',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al subcontratista $idSub.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO', $response);
- }
- public function updateToInactiveStatusSubcontract(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'id_subcontratist' => 'required|string',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- true,
- "Se encontraron uno o más errores.",
- $this->responseController->makeErrors(
- $validator->errors()->messages()
- ),
- 401
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSub = $this->encryptionController->decrypt($form['id_subcontratist']);
- if(!$idSub){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $idSub],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El subcontratista solicitado no existe.', [], 404);
- }
- $users = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_ESTA', '=', 'Activo'],
- ])->join('S002V01TPESU', 'PERS_IDPS', '=', 'PESU_IDPS')->get()->all();
- if(count($users) > 0){
- return $this->responseController->makeResponse(true, 'El subcontratista que desea eliminar tiene usuarios relacionados.', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $form['linea']],
- ['PESU_IDPS', '=', $idSub],
- ])->update([
- 'PESU_ESTA' => 'Eliminado',
- 'PESU_USMO' => $idUser,
- 'PESU_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01GESU',
- 'S002V01P02RESU',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó al subcontratista $idSub.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getContractsOfEverySubcontratist($idUser, $line) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($idUser, $line);
- if ($arrResponseCheckUser['error']) {
- return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
- }
- try {
- $arrSubcontratists = DB::table('S002V01TPERS')
- ->where([
- ['PERS_NULI', '=', $line],
- ['PERS_TICO', '=', 'Subcontratista'],
- ])
- ->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')
- ->join('S002V01TPESU', 'PESU_IDPS', '=', 'PERS_IDPS')
- ->get([
- 'PERS_IDPE AS ID_EMPLEADO',
- 'USUA_IDUS AS ID_USUARIO',
- 'USUA_NOMB AS NOMBRE',
- 'USUA_APPA AS APELLIDO_PATERNO',
- 'USUA_APMA AS APELLIDO_MATERNO',
- 'PESU_IDPS AS ID_SUBCONTRATISTA',
- 'PESU_RASO AS RAZON_SOCIAL',
- 'PESU_REFI AS REFERENCIA_FISCAL',
- ]);
- $arrSubcontratists = json_decode(json_encode($arrSubcontratists), true);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al recuperar los subcontratistas', $th->getMessage(), 404);
- }
-
- $contractsBySubcontratists = array();
- foreach ($arrSubcontratists as $key => $subcontratist) {
-
- try {
- $countSubcontract = DB::table('S002V01TCONT')
- ->where([
- ['CONT_IDEM', '=', $subcontratist['ID_EMPLEADO']],
- ['CONT_NULI', '=', $line],
- ['CONT_ESTA', '=', 'Activo'],
- ])
- ->count();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los contratos', $th->getMessage(), 404);
- }
- $employee = trim("{$subcontratist['NOMBRE']} {$subcontratist['APELLIDO_PATERNO']} {$subcontratist['APELLIDO_MATERNO']}");
- $contractsBySubcontratists[] = [
- 'ID_EMPLEADO' => $this->encryptionController->encrypt($subcontratist['ID_EMPLEADO']),
- 'ID_USUARIO' => $this->encryptionController->encrypt($subcontratist['ID_USUARIO']),
- 'ID_SUBCONTRATISTA' => $this->encryptionController->encrypt($subcontratist['ID_SUBCONTRATISTA']),
- 'EMPLEADO' => "{$employee} ({$subcontratist['ID_EMPLEADO']}) <{$subcontratist['ID_USUARIO']}>",
- 'RAZON_SOCIAL' => "{$subcontratist['RAZON_SOCIAL']} ({$subcontratist['ID_SUBCONTRATISTA']})",
- 'NUMERO_CONTRATOS' => $countSubcontract === 1 ? "{$countSubcontract} contrato" : "{$countSubcontract} contratos",
- ];
- }
- return $this->responseController->makeResponse(false, 'EXITO', $contractsBySubcontratists);
- }
- public function getContractsOfEverySubcontratistOld($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $contractsBySubcontratists = DB::table('S002V01TPERS')->select([
- DB::raw("
- TRIM(CONCAT(
- USUA_NOMB,
- ' ',
- USUA_APPA,
- IF(ISNULL(USUA_APMA), '', CONCAT(' ', USUA_APMA)),
- ' <(',
- PERS_IDPE,
- ')> (',
- PERS_IDUS,
- ')'
- )) AS EMPLOYEE
- "),
- DB::raw("COUNT(CONT_IDCO) AS CONTRACTS")
- ])->leftJoin('S002V01TCONT', 'CONT_IDEM', '=', 'PERS_IDPE')
- ->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')
- ->groupBy('EMPLOYEE')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_TICO', '=', 'Subcontratista'],
- ])->get()->all();
- foreach($contractsBySubcontratists as $key=>$val){
- $employeeArr = explode('<', $val->EMPLOYEE);
- $employeeName = $employeeArr[0];
- $employeeArr = array_reverse($employeeArr);
- $employeeArr = explode('>', $employeeArr[0]);
- $employeeID = str_replace('(', '', $employeeArr[0]);
- $employeeID = str_replace(')', '', $employeeID);
- $subcontratist = DB::table('S002V01TPESU')->where([
- ['PESU_NULI', '=', $line],
- ['PESU_IDPS', '=', $employeeID],
- ])->first();
- if (is_null($subcontratist)) {
- var_dump($employeeID);
- return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos del proveedor.', [], 404);
- }
- $val->ID_EMPLOYEE = $this->encryptionController->encrypt($employeeID);
- $val->EMPLOYEE = $employeeName . join('', $employeeArr);
- $val->ID_SUBCONTRATIST = $this->encryptionController->encrypt($employeeID);
- $val->SUBCONTRATIST = $subcontratist->PESU_RASO . " (" . $subcontratist->PESU_REFI . ")";
- $contractsBySubcontratists[$key] = $val;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ADCO',
- 'S002V01P01HCSU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos por subcontratista.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $contractsBySubcontratists);
- }
- public function getContractsBySubcontratist($idSubcontratist, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSubcontratist = $this->encryptionController->decrypt($idSubcontratist);
- if(!$idSubcontratist){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idSubcontratist],
- ['PERS_TICO', '=', 'Subcontratista'],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El subcontratista solicitado no existe.', [], 404);
- }
- $contracts = DB::table('S002V01TCONT')->select([
- 'CONT_NOCO AS CONTRACT_NAME',
- 'CONT_FEIN AS START_DATE',
- 'CONT_FEFI AS END_DATE',
- 'CONT_COST AS COST',
- ])->where([
- ['CONT_NULI', '=', $line],
- ['CONT_IDEM', '=', $idSubcontratist],
- ['CONT_TIPO', '=', 'Subcontratista'],
- ])->get()->all();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ADCO',
- 'S002V01P01HCSU',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos del subcontratista #$idSubcontratist.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $contracts);
- }
- public function downloadSubcontractInfoOnExcel($idSubcontratist, $idUser, $line){
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSubcontratist = $this->encryptionController->decrypt($idSubcontratist);
- if(!$idSubcontratist){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idSubcontratist],
- ['PERS_TICO', '=', 'Subcontratista'],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El subcontratista solicitado no existe.', [], 404);
- }
- $contracts = DB::table('S002V01TCONT')->select([
- 'CONT_IDCO AS IDCONTRATO',
- 'CONT_NOCO AS NOMBRECONTRATO',
- 'CONT_IDOT AS IDORDEN',
- 'CONT_TOTR AS TIPOORDEN',
- 'PERS_ESPE AS ESPECIALIDAD',
- 'CONT_FEIN AS FECHAINICIO',
- 'CONT_FEFI AS FECHAFIN',
- 'CONT_COST AS COSTO',
- ])->join('S002V01TPERS', 'PERS_IDPE', '=', 'CONT_IDEM')->where([
- ['CONT_NULI', '=', $line],
- ['CONT_IDEM', '=', $idSubcontratist],
- ['CONT_TIPO', '=', 'Subcontratista'],
- ])->get()->all();
- $document = $this->generateDocument($contracts, $line);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
-
- $dateTimeArr = explode(" ", $nowStr);
- $dateArr = explode("-", $dateTimeArr[0]);
- $year = substr($dateArr[0], 2);
- $como = 'GPRS';
- $cldo = 'IN';
- $fecr = $year . $dateArr[1] . $dateArr[2];
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ])->orderBy('AFAL_NUSE', 'desc')->first();
- $nuse = "";
- if(is_null($sec)){
- $nuse = '000001';
- }else{
- $secu = "" . intval($sec->AFAL_NUSE) + 1 . "";
- $nuse = "";
- for($i = strlen($secu); $i < 6; $i++){
- $nuse .= "0";
- }
- $nuse = $nuse . $secu;
- }
- $noar = "ficha_de_subcontratacion_del_subcontratista_$idSubcontratist";
- $exte = "xlsx";
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ['AFAL_NOAR', '=', $noar],
- ['AFAL_EXTE', '=', $exte],
- ])->orderBy('AFAL_NUVE', 'desc')->first();
- $nuve = "";
- if(is_null($ver)){
- $nuve = "01";
- }else{
- $vers = intval($ver->AFAL_NUVE) + 1;
- $nuve = $vers < 10 ? "0$vers" : "$vers";
- }
- $line = $line < 10 ? "0$line" : "$line";
- $filePath = $this->resourcesController->pathService.'\\public_files\\';
- $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
-
- $tempFile = $filePath . $fileName;
- if(file_exists($tempFile)){
- unlink($tempFile);
- }
- $writer = IOFactory::createWriter($document, 'Xlsx');
- $writer->save($tempFile);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- $ubic = $this->resourcesController->pathService."\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ADCO',
- 'S002V01P02FISU',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") generó la ficha de subcontratación del subcontratista #$idSubcontratist para Excel.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['fileID' => $fileName]);
- }
- public function downloadSubcontractInfoOnPdf($idSubcontratist, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $idSubcontratist = $this->encryptionController->decrypt($idSubcontratist);
- if(!$idSubcontratist){
- return $this->responseController->makeResponse(true, 'El ID del subcontratista no fue encriptado correctamente.', [], 400);
- }
- $sub = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $idSubcontratist],
- ['PERS_TICO', '=', 'Subcontratista'],
- ])->first();
-
- if(is_null($sub)){
- return $this->responseController->makeResponse(true, 'El subcontratista solicitado no existe.', [], 404);
- }
- $contracts = DB::table('S002V01TCONT')->select([
- 'CONT_IDCO AS IDCONTRATO',
- 'CONT_NOCO AS NOMBRECONTRATO',
- 'CONT_IDOT AS IDORDEN',
- 'CONT_TOTR AS TIPOORDEN',
- 'PERS_ESPE AS ESPECIALIDAD',
- 'CONT_FEIN AS FECHAINICIO',
- 'CONT_FEFI AS FECHAFIN',
- 'CONT_COST AS COSTO',
- ])->join('S002V01TPERS', 'PERS_IDPE', '=', 'CONT_IDEM')->where([
- ['CONT_NULI', '=', $line],
- ['CONT_IDEM', '=', $idSubcontratist],
- ['CONT_TIPO', '=', 'Subcontratista'],
- ])->get()->all();
- $document = $this->generateDocument($contracts, $line);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
-
- $dateTimeArr = explode(" ", $nowStr);
- $dateArr = explode("-", $dateTimeArr[0]);
- $year = substr($dateArr[0], 2);
- $como = 'GPRS';
- $cldo = 'IN';
- $fecr = $year . $dateArr[1] . $dateArr[2];
- $sec = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ])->orderBy('AFAL_NUSE', 'desc')->first();
- $nuse = "";
- if(is_null($sec)){
- $nuse = '000001';
- }else{
- $secu = "" . intval($sec->AFAL_NUSE) + 1 . "";
- $nuse = "";
- for($i = strlen($secu); $i < 6; $i++){
- $nuse .= "0";
- }
- $nuse = $nuse . $secu;
- }
- $noar = "ficha_de_subcontratacion_del_subcontratista_$idSubcontratist";
- $exte = "pdf";
- $ver = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $como],
- ['AFAL_CLDO', '=', $cldo],
- ['AFAL_NOAR', '=', $noar],
- ['AFAL_EXTE', '=', $exte],
- ])->orderBy('AFAL_NUVE', 'desc')->first();
- $nuve = "";
- if(is_null($ver)){
- $nuve = "01";
- }else{
- $vers = intval($ver->AFAL_NUVE) + 1;
- $nuve = $vers < 10 ? "0$vers" : "$vers";
- }
- $line = $line < 10 ? "0$line" : "$line";
- $filePath = $this->resourcesController->pathService.'\\public_files\\';
- $fileName = "$line-$como-$cldo-$fecr-$nuse=$nuve=$noar.$exte";
-
- $tempFile = $filePath . $fileName;
- if(file_exists($tempFile)){
- unlink($tempFile);
- }
- $writer = IOFactory::createWriter($document, 'Mpdf');
- $writer->save($tempFile);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- $ubic = $this->resourcesController->pathService."\storage\app\\" . $ubic;
- $tama = filesize($ubic);
- $usac = json_encode([$idUser]);
- unlink($tempFile);
- DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $idUser,
- 'AFAL_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ADCO',
- 'S002V01P02FISU',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") generó la ficha de subcontratación del subcontratista #$idSubcontratist para Excel.",
- $idUser,
- $nowStr,
- 'S002V01S01GESU'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', ['fileID' => $fileName]);
- }
- private function generateDocument($contracts, $line) : Spreadsheet {
- $spreadsheet = new Spreadsheet;
- $spreadsheet->getProperties()
- ->setCreator('STC')
- ->setTitle('Historial de contratos por subcontratista.')
- ->setSubject('Historial documento')
- ->setKeywords('Subcontratista Contratos Historial')
- ->setCategory('Historial archivo');
-
- $worksheet = $spreadsheet->getActiveSheet();
- $worksheet->setTitle('HISTORIAL DE CONTRATOS');
- $columns = ['# DE CONTRATO', 'NOMBRE DEL CONTRATO', 'ORDEN DE TRABAJO', 'TIPO DE ORDEN', 'ESPECIALIDAD', 'FECHA DE INICIO', 'FECHA DE TÉRMINO', 'COSTO'];
- $startRow = 2;
- $startCol = 2;
- $maxRow = $startRow + count($contracts) + 1;
- $maxCol = $startCol + 7;
- for($row = $startRow; $row <= $maxRow; $row++){
- $startColStr = Coordinate::stringFromColumnIndex($startCol);
- $maxColStr = Coordinate::stringFromColumnIndex($maxCol);
- if($row == 2){
- $worksheet->mergeCells($startColStr . $row . ':' . $maxColStr . $row);
- $worksheet->setCellValue($startColStr . $row, 'FICHA DE SUBCONTRATACIÓN')->getStyle($startColStr . $row)->getFill()
- ->setFillType(Fill::FILL_SOLID)
- ->getStartColor()->setRGB('B7BCC4');
- $worksheet->getStyle($startColStr . $row)->getFont()->setBold(true);
- $worksheet->getStyle($startColStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }else if($row == 3){
- for($col = $startCol; $col <= $maxCol; $col++){
- $colStr = Coordinate::stringFromColumnIndex($col);
- $colInd = $col - 2;
- $column = $columns[$colInd];
- $worksheet->setCellValue($colStr . $row, $column);
- $worksheet->getColumnDimension($colStr)->setAutoSize(true);
- $worksheet->getStyle($colStr . $row)->getFont()->setBold(true);
- $worksheet->getStyle($colStr . $row)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }
- }else if($row > 3){
- $rowInd = $row - 4;
- $contract = (array) $contracts[$rowInd];
- $keys = array_keys($contract);
- for($col = $startCol; $col <= $maxCol; $col++){
- $colInd = $col - 2;
- $key = $keys[$colInd];
- $value = $contract[$key];
- $colStr = Coordinate::stringFromColumnIndex($col);
- if($key == 'IDORDEN'){
- $value = "Orden #$value";
- }else if($key == 'FECHAINICIO' || $key == 'FECHAFIN'){
- $value = $this->functionsController->formatDateTime($value);
- }else if($key == 'COSTO'){
- $worksheet->getStyle($colStr . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
- }else if($key == 'ESPECIALIDAD'){
- $specialtiesArr = json_decode($value, true);
- $valueStr = "";
- foreach($specialtiesArr as $val0){
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $val0]
- ])->first();
- $valueStr .= $val0 . " - " . $specialty->GEES_NOES . ", ";
- }
- $value = substr($valueStr, 0, -2);
- }
- $worksheet->setCellValue($colStr . $row, $value);
- }
- }
- }
- if(count($contracts) == 0){
- $startColStr = Coordinate::stringFromColumnIndex($startCol);
- $maxColStr = Coordinate::stringFromColumnIndex($maxCol);
- $maxRow++;
- $worksheet->mergeCells($startColStr . $maxRow . ':' . $maxColStr . $maxRow);
- $worksheet->setCellValue($startColStr . $maxRow, 'Aún no se han asociado contratos al subcontratista.');
- $worksheet->getStyle($startColStr . $maxRow)->getFont()->setBold(true);
- $worksheet->getStyle($startColStr . $maxRow)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- }
- $worksheet->getStyle($startColStr . $startRow . ':' . $maxColStr . $maxRow)
- ->getBorders()
- ->getAllBorders()
- ->setBorderStyle(Border::BORDER_MEDIUM);
- return $spreadsheet;
- }
- public function storeWorkteam(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'NAME' => 'required|string|max:75',
- 'SPECIALITY' => 'required|json',
- ]);
- if($validator->fails()){
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $specialtiesArr = json_decode($form['SPECIALITY'], true);
- foreach($specialtiesArr as $key=>$specialty){
- $specialtyCode = $this->encryptionController->decrypt($specialty);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
- $specialtiesStr = json_encode($specialtiesArr);
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_NOMB', '=', $form['NAME']],
- ['EQMA_NULI', '=', $form['linea']],
- ['EQMA_ESTA', '=', 'Activo'],
- ])->get()->all();
- if(count($team) > 0){
- return $this->responseController->makeResponse(true, "El nombre $form[NAME] ya fue tomado", [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TEQMA')->insert([
- "EQMA_NULI" => $form['linea'],
- "EQMA_NOMB" => $form['NAME'],
- "EQMA_ESPE" => $specialtiesStr,
- "EQMA_USRE" => $idUser,
- "EQMA_FERE" => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P02REET',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el equipo de trabajo $form[NAME].",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function getConsultOfWorkteams($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $workteams = DB::table('S002V01TEQMA')->select([
- 'EQMA_IDEQ as WORKTEAM_ID',
- 'EQMA_NOMB as NAME',
- 'EQMA_ESPE as SPECIALITY',
- 'EQMA_ESTA as STATUS'
- ])->where('EQMA_NULI', '=', $line)->get()->all();
- foreach($workteams as $workteam){
- $workteam->WORKTEAM_ID = $this->encryptionController->encrypt($workteam->WORKTEAM_ID);
- $specialtiesArr = json_decode($workteam->SPECIALITY, true);
- foreach($specialtiesArr as $key=>$specialtyCode){
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $specialtyCode],
- ])->first();
- $specialtyName = $specialtyCode . " - " . $specialty->GEES_NOES;
- $specialtyCode = $this->encryptionController->encrypt($specialtyName);
- $specialtiesArr[$key] = $specialtyCode;
- }
- $workteam->SPECIALITY = json_encode($specialtiesArr);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P01CETR',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los equipos de trabajo registrados.",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $workteams);
- }
- public function getWorkteamById($workteam, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $workteam = $this->encryptionController->decrypt($workteam);
- if(!$workteam){
- return $this->responseController->makeResponse(true, 'El ID equipo de trabajo solicitado no está encriptado correctamente', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->select([
- 'EQMA_IDEQ as WORKTEAM_ID',
- 'EQMA_NOMB as NAME',
- 'EQMA_ESPE as SPECIALITY',
- 'EQMA_ESTA as STATUS'
- ])->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $line],
- ])->first();
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo de trabajo consultado no está registrado', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P03DETR',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los detalles del equipo de trabajo " . $team->NAME . ".",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $team);
- }
- public function getMembersOfWorkteamById($workteam, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $workteam = $this->encryptionController->decrypt($workteam);
- if(!$workteam){
- return $this->responseController->makeResponse(true, 'El ID equipo de trabajo solicitado no está encriptado correctamente', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $line],
- ])->first();
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo de trabajo consultado no está registrado', [], 404);
- }
- $members = DB::table('S002V01TPERS')->select([
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- 'PERS_IDPE AS IDEMPLEADO',
- 'PERS_IDUS AS IDUSUARIO'
- ])->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $line],
- ['PERS_ESTA', '=', 'Activo'],
- ])->join(
- 'S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS'
- )->join(
- 'S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ'
- )->get()->all();
- foreach($members as $key=>$member){
- $member->IDEMPLEADO = $this->encryptionController->encrypt($member->IDEMPLEADO);
- $member->IDUSUARIO = $this->encryptionController->encrypt($member->IDUSUARIO);
- $members[$key] = $member;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P03DETR',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los integrantes del equipo de trabajo " . $team->EQMA_NOMB . ".",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO.', $members);
- }
- public function updateWorkteam(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'WORKTEAM_ID' =>'required|string',
- 'NAME' => 'required|string|max:75',
- 'SPECIALITY' => 'required|json',
- ]);
- if($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_EQUIPO_TRABAJO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $workteam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
- if(!$workteam){
- return $this->responseController->makeResponse(true, 'El ID equipo de trabajo solicitado no está encriptado correctamente', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $form['linea']],
- ])->first();
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo de trabajo consultado no está registrado', [], 404);
- }
- $teams = DB::table('S002V01TEQMA')->where([
- ['EQMA_NOMB', '=', $form['NAME']],
- ['EQMA_NULI', '=', $form['linea']],
- ['EQMA_ESTA', '=', 'Activo'],
- ])->get()->all();
- if(count($teams) > 0){
- return $this->responseController->makeResponse(true, "El nombre $form[NAME] ya fue tomado", [], 401);
- }
- $specialtiesArr = json_decode($form['SPECIALITY'], true);
- foreach($specialtiesArr as $key=>$specialty){
- $specialtyCode = $this->encryptionController->decrypt($specialty);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, "El ID del elemento en la posición $key del arreglo de especialidades no fue encriptado correctamente.", [], 400);
- }
- $specialtyObj = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode]
- ])->first();
- if(is_null($specialtyObj)){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades no existe.", [], 404);
- }else if($specialtyObj->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, "El elemento en la posición $key del arreglo de especialidades está eliminado.", [], 404);
- }
- $specialtiesArr[$key] = $specialtyCode;
- }
-
- $specialtiesStr = json_encode($specialtiesArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TEQMA')->where([
- ["EQMA_IDEQ", '=', $workteam],
- ['EQMA_NULI', '=', $form['linea']]
- ])->update([
- "EQMA_NOMB" => $form['NAME'],
- "EQMA_ESPE" => $specialtiesStr,
- "EQMA_USMO" => $idUser,
- "EQMA_FEMO" => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P02REET',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el equipo de trabajo #$workteam.",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function updateToInactiveStatus(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'WORKTEAM_ID' =>'required|string',
- ]);
- if($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_EQUIPO_TRABAJO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $workteam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
- if(!$workteam){
- return $this->responseController->makeResponse(true, 'El ID equipo de trabajo solicitado no está encriptado correctamente', [], 400);
- }
- $team = DB::table('S002V01TEQMA')->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $form['linea']],
- ])->first();
- if(is_null($team)){
- return $this->responseController->makeResponse(true, 'El equipo de trabajo consultado no está registrado', [], 404);
- }
- $members = DB::table('S002V01TPERS')->select([
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- 'PERS_IDPE AS IDEMPLEADO',
- 'PERS_IDUS AS IDUSUARIO'
- ])->where([
- ['EQMA_IDEQ', '=', $workteam],
- ['EQMA_NULI', '=', $form['linea']],
- ['PERS_ESTA', '=', 'Activo'],
- ])->join(
- 'S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS'
- )->join(
- 'S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ'
- )->get()->all();
- if(count($members) > 0){
- return $this->responseController->makeResponse(true, 'El equipo de trabajo que desea eliminar tiene usuarios relacionados.', [], 401);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TEQMA')->where([
- ["EQMA_IDEQ", '=', $workteam],
- ['EQMA_NULI', '=', $form['linea']]
- ])->update([
- "EQMA_ESTA" => 'Eliminado',
- "EQMA_USMO" => $idUser,
- "EQMA_FEMO" => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F01AETR',
- 'S002V01P01CETR',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el equipo de trabajo #$workteam.",
- $idUser,
- $nowStr,
- 'S002V01S04GETR'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO.');
- }
- public function storeContract(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'CONTRACT_NAME' => 'required|string|max:100',
- 'WORK_ORDER' => 'required|string',
- 'CONTRACT_TYPE' => 'required|string|in:Subcontratista,Interno',
- 'DENOMINATION' => 'required|string',
- 'START_DATE' => 'required|date',
- 'END_DATE' => 'required|date',
- 'CONTRACT_COST' => 'required|string',
- 'DOCUMENT' => 'required|json',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_CONTRATO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $workOrder = $this->encryptionController->decrypt($form['WORK_ORDER']);
- if(!$workOrder){
- return $this->responseController->makeResponse(true, 'La información de la orden seleccionada no está encriptada correctamente.', [], 400);
- }
- $workOrderArr = explode('|', $workOrder);
- if(count($workOrderArr) != 3){
- return $this->responseController->makeResponse(true, 'El formato de la orden seleccionada es incorrecto.', [], 400);
- }
- $idOrder = $this->encryptionController->decrypt($workOrderArr[0]);
- if(!$idOrder){
- return $this->responseController->makeResponse(true, 'El ID de la orden seleccionada no está encriptado correctamente.', [], 400);
- }
- $order = null;
- $idOrderStr = null;
- if($workOrderArr[1] == 'MP'){
- $idOrderArr = explode('|', $idOrder);
- $order = DB::table('S002V01TBEOT')->join('S002V01TOTPR', 'OTPR_IDOT', '=', 'BEOT_IDOT')->where([
- ['BEOT_NULI', '=', $form['linea']],
- ['BEOT_IDRE', '=', $idOrderArr[0]]
- ])->first();
- $idOrderStr = $idOrderArr[0];
- }else if($workOrderArr[1] == 'MC'){
- if($workOrderArr[2] == 'S'){
- $order = DB::table('S002V01TOTCO')->where([
- ['OTCO_NULI', '=', $form['linea']],
- ['OTCO_IDOT', '=', $idOrder],
- ])->first();
- }else if($workOrderArr[2] == 'N'){
- $order = DB::table('S002V01TFCPE')->where([
- ['FCPE_NULI', '=', $form['linea']],
- ['FCPE_IDRE', '=', $idOrder]
- ])->first();
- }
- $idOrderStr = $idOrder;
- }
- if(is_null($order)){
- return $this->responseController->makeResponse(true, 'La orden seleccionada no existe.', [], 404);
- }
- $idEmployee = $this->encryptionController->decrypt($form['DENOMINATION']);
- if(!$idEmployee){
- return $this->responseController->makeResponse(true, 'El ID del empleado seleccionado no está encriptado correctamente.', [], 400);
- }
- $employee = DB::table('S002V01TPERS')->where([
- ['PERS_NULI', '=', $form['linea']],
- ['PERS_IDPE', '=', $idEmployee]
- ])->first();
-
- if(is_null($employee)){
- return $this->responseController->makeResponse(true, 'El empleado seleccionado no existe.', [], 404);
- }
- $orderType = $workOrderArr[1] == 'MP' ? 'Preventivo' : 'Correctivo';
- $contract = DB::table('S002V01TCONT')->where([
- ['CONT_NULI', '=', $form['linea']],
- ['CONT_IDEM', '=', $idEmployee],
- ['CONT_IDOT', '=', $idOrder],
- ['CONT_TOTR', '=', $orderType],
- ])->first();
- if(!is_null($contract)){
- return $this->responseController->makeResponse(true, "El empleado #$idEmployee ya tiene un contrato relacionado a la orden de trabajo $orderType #$idOrder", [], 404);
- }
-
- $docsArr = json_decode($form['DOCUMENT'], true);
- $finalDocsArr = [];
- foreach($docsArr as $doc){
- $idFileDec = $this->encryptionController->decrypt($doc['id']);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_NULI', '=', $form['linea']],
- ['ARTE_IDAR', '=', $idFileDec],
- ])->first();
-
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, "El archivo $doc[name] no está registrado.", [], 404);
- }
- $cldo = "CO";
- $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], "GPRS", $cldo, $tempFile, $idUser);
-
- if(!$finalFile[0]){
- return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
- }else{
- $finalDocsArr[] = $finalFile[1];
- }
- }
- $contractCostStr = $this->encryptionController->decrypt($form['CONTRACT_COST']);
- if(!$contractCostStr){
- return $this->responseController->makeResponse(true, 'El costo del contrato no fue encriptado correctamente.', [], 400);
- }
- $contractCostNum = floatval($contractCostStr);
- $lido = json_encode($finalDocsArr);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $idContract = DB::table('S002V01TCONT')->insertGetId([
- 'CONT_NULI' => $form['linea'],
- 'CONT_NOCO' => $form['CONTRACT_NAME'],
- 'CONT_IDEM' => $idEmployee,
- 'CONT_IDOT' => $idOrderStr,
- 'CONT_TOTR' => $orderType,
- 'CONT_TIPO' => $form['CONTRACT_TYPE'],
- 'CONT_FEIN' => $form['START_DATE'],
- 'CONT_FEFI' => $form['END_DATE'],
- 'CONT_COST' => $contractCostNum,
- 'CONT_LIDO' => $lido,
- 'CONT_USRE' => $idUser,
- 'CONT_FERE' => $nowStr,
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F02ADCN',
- 'S002V01P02RECO',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró el contrato #$idContract.",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getConsultOfContracts($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $contracts = DB::table('S002V01TCONT')->select([
- 'CONT_IDCO AS CONTRACT_ID',
- 'CONT_NOCO AS CONTRACT_NAME',
- 'CONT_IDEM AS DENOMINATION',
- 'CONT_IDOT AS WORK_ORDER_ID',
- 'CONT_TOTR AS WORK_ORDER_TYPE',
- 'CONT_TIPO AS CONTRACT_TYPE',
- 'CONT_FEIN AS START_DATE',
- 'CONT_FEFI AS END_DATE',
- 'CONT_COST AS CONTRACT_COST',
- 'CONT_LIDO AS DOCUMENT',
- 'CONT_USRE AS REGISTERED_BY',
- 'CONT_FERE AS REGISTER_DATE',
- 'CONT_USMO AS MODIFIED_BY',
- 'CONT_FEMO AS MODIFICATION_DATE',
- ])->where('CONT_NULI', '=', $line)->get()->all();
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- foreach($contracts as $key=>$contract){
- $contract->CONTRACT_ID = $this->encryptionController->encrypt($contract->CONTRACT_ID);
- $contract->CONTRACT_COST = $this->encryptionController->encrypt($contract->CONTRACT_COST);
- $docsArr = json_decode($contract->DOCUMENT);
- $docsFN = [];
- foreach($docsArr as $keyDoc=>$doc){
- $docIDArr = explode('=', $doc);
- $codeArr = explode('-', $docIDArr[0]);
- $file = DB::table('S002V01TAFAL')->where([
- ['AFAL_NULI', '=', $line],
- ['AFAL_COMO', '=', $codeArr[1]],
- ['AFAL_CLDO', '=', $codeArr[2]],
- ['AFAL_FECR', '=', $codeArr[3]],
- ['AFAL_NUSE', '=', $codeArr[4]],
- ['AFAL_NUVE', '=', $docIDArr[1]],
- ])->first();
- if (!is_null($file)) {
- $docsFN[] = [
- 'id' => $this->encryptionController->encrypt($doc),
- 'name' => $doc,
- 'size' => $file->AFAL_TAMA
- ];
- }
- }
- $contract->DOCUMENT = json_encode($docsFN);
- $usrReg = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $contract->REGISTERED_BY],
- ])->first();
- $contract->REGISTERED_BY = $this->functionsController->joinName(
- $usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA
- ) . " (" . $contract->REGISTERED_BY . ")";
- if(!is_null($contract->MODIFIED_BY)){
- $usrMod = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $contract->MODIFIED_BY],
- ])->first();
-
- $contract->MODIFIED_BY = $this->functionsController->joinName(
- $usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA
- ) . " (" . $contract->MODIFIED_BY . ")";
- }
- $employee = DB::table('S002V01TPERS')->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')->where([
- ['PERS_NULI', '=', $line],
- ['PERS_IDPE', '=', $contract->DENOMINATION],
- ])->first();
- $contract->DENOMINATION = $this->functionsController->joinName(
- $employee->USUA_NOMB, $employee->USUA_APPA, $employee->USUA_APMA
- ) . ' (' . $employee->PERS_IDPE . ') (' . $employee->PERS_IDUS . ')';
- $contract->DURATION = $this->functionsController->getDatesDifference($contract->START_DATE, $contract->END_DATE);
- $contracts[$key] = $contract;
- $endDate = new Carbon($contract->END_DATE);
- $status = $now->gt($endDate) ? 'Expirado' : 'Activo';
- $contract->STATUS = $status;
- }
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F02ADCN',
- 'S002V01P01COCO',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos registrados.",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $contracts);
- }
- public function getConsultOfInterventions($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $correctiveInterventions = DB::table('S002V01TOTCO')->select([
- 'OTCO_IDOT AS IDREG',
- 'OTCO_IDOT AS IDORDER',
- DB::raw("CONCAT(
- OTCO_EQIN, ' - ',
- EQUI_TIPO, ' - ',
- EQUI_MODE, ' (',
- EQUI_IDEQ, ')'
- ) AS EQUIPMENT"),
- DB::raw("'C' AS ORDER_TYPE"),
- 'OTCO_ESOR AS ACTION_TYPE',
- 'OTCO_FIFA AS START_DATE',
- 'OTCO_FTIN AS END_DATE'
- ])->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'OTCO_EQIN');
- $maintenanceInterventions = DB::table('S002V01TBEOT')->select([
- DB::raw('CONCAT(BEOT_IDRE, "|", BEOT_FEPR) AS IDREG'),
- 'OTPR_IDOT AS IDORDER',
- DB::raw("CONCAT(
- OTPR_EQIN, ' - ',
- EQUI_TIPO, ' - ',
- EQUI_MODE, ' (',
- EQUI_IDEQ, ')'
- ) AS EQUIPMENT"),
- DB::raw("'P' AS ORDER_TYPE"),
- 'BEOT_TIAC AS ACTION_TYPE',
- 'BEOT_FEEJ AS START_DATE',
- 'BEOT_FEFI AS END_DATE'
- ])->join('S002V01TOTPR', 'OTPR_IDOT', '=', 'BEOT_IDOT')
- ->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'OTPR_EQIN')
- ->union($correctiveInterventions)->orderBy('IDREG', 'desc')->get()->all();
- foreach($maintenanceInterventions as $key=>$val){
- $val->IDREG = $this->encryptionController->encrypt($val->IDREG);
- $val->IDORDER = $this->encryptionController->encrypt($val->IDORDER);
- $val->EQUIPMENT = $this->encryptionController->encrypt($val->EQUIPMENT);
- $preventiveInterventions[$key] = $val;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- 'S002V01F01ADIN',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") consultó las intervenciones registradas.",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $preventiveInterventions);
- }
- public function getAllRegisteredSpecialties($idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $specialties = DB::table('S002V01TGEES')->select([
- 'GEES_COES AS CODIGO_ESPECIALIDAD',
- 'GEES_NOES AS NOMBRE_ESPECIALIDAD',
- 'GEES_ESTA AS ESTADO',
- DB::raw("CONCAT(USRE.USUA_NOMB, ' ', USRE.USUA_APPA, IF(ISNULL(USRE.USUA_APMA), '', ' '), IF(ISNULL(USRE.USUA_APMA), '', USRE.USUA_APMA), ' (', GEES_USRE, ')') AS USRREG"),
- 'GEES_FERE AS FECREG',
- 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), ' (', GEES_USMO, ')')) AS USRMOD"),
- 'GEES_FEMO AS FECMOD',
- ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'GEES_USRE')
- ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'GEES_USMO')
- ->where('GEES_NULI', '=', $line)->get()->all();
- foreach($specialties as $key=>$specialty){
- $specialty->CODIGO_ESPECIALIDAD = $this->encryptionController->encrypt($specialty->CODIGO_ESPECIALIDAD);
- $specialties[$key] = $specialty;
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") las especialidades registradas.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $specialties);
- }
- public function registerSpecialty(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'specialty_code' => 'required|string',
- 'spacialty_name' => 'required|string|max:100',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_CONTRATO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $specialtyCode = $this->encryptionController->decrypt($form['specialty_code']);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, 'El código de la especialidad no fue encriptado correctamente.', [], 400);
- }
- $filtCode = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode],
- ['GEES_ESTA', '=', 'Activo']
- ])->first();
- if(!is_null($filtCode)){
- return $this->responseController->makeResponse(true, 'El código ingresado ya se encuentra registrado.', [], 400);
- }
- $filtName = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_NOES', '=', $form['spacialty_name']],
- ['GEES_ESTA', '=', 'Activo']
- ])->first();
- if(!is_null($filtName)){
- return $this->responseController->makeResponse(true, 'El nombre ingresado ya se encuentra registrado.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGEES')->insert([
- 'GEES_NULI' => $form['linea'],
- 'GEES_COES' => $specialtyCode,
- 'GEES_NOES' => $form['spacialty_name'],
- 'GEES_USRE' => $idUser,
- 'GEES_FERE' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F02ADCN',
- 'S002V01P02RECO',
- 'Registro',
- "El usuario $name (" . $usr->USUA_IDUS . ") registró la especialidad $form[spacialty_name]($specialtyCode).",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function getSpecialtyByCode($code, $idUser, $line) {
- DB::enableQueryLog();
- $idUser = $this->encryptionController->decrypt($idUser);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $line],
- ['USUA_IDUS', '=', $idUser],
- ])->first();
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
- }
- $code = $this->encryptionController->decrypt($code);
- if(!$code){
- return $this->responseController->makeResponse(true, 'El código de la especialidad consultada no está encriptado correctamente', [], 400);
- }
- $specialty = DB::table('S002V01TGEES')->select([
- 'GEES_COES AS CODIGO_ESPECIALIDAD',
- 'GEES_NOES AS NOMBRE_ESPECIALIDAD',
- 'GEES_ESTA AS ESTADO',
- DB::raw("CONCAT(USRE.USUA_NOMB, ' ', USRE.USUA_APPA, IF(ISNULL(USRE.USUA_APMA), '', ' '), IF(ISNULL(USRE.USUA_APMA), '', USRE.USUA_APMA), ' (', GEES_USRE, ')') AS USRREG"),
- 'GEES_FERE AS FECREG',
- 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), ' (', GEES_USMO, ')')) AS USRMOD"),
- 'GEES_FEMO AS FECMOD',
- ])->join(DB::raw('S002V01TUSUA USRE'), 'USRE.USUA_IDUS', '=', 'GEES_USRE')
- ->leftJoin(DB::raw('S002V01TUSUA USMO'), 'USMO.USUA_IDUS', '=', 'GEES_USMO')
- ->where([
- ['GEES_NULI', '=', $line],
- ['GEES_COES', '=', $code]
- ])->first();
- if(is_null($specialty)){
- return $this->responseController->makeResponse(true, 'La especialidad consultada no está registrada.', [], 404);
- }
- $specialty->CODIGO_ESPECIALIDAD = $this->encryptionController->encrypt($specialty->CODIGO_ESPECIALIDAD);
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $line,
- 'S002V01M11GPRS',
- '-',
- '-',
- 'Consulta',
- "El usuario $name (" . $usr->USUA_IDUS . ") la especialidad $code.",
- $idUser,
- $nowStr,
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
- return $this->responseController->makeResponse(false, 'EXITO', $specialty);
- }
- public function updateSpecialty(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'specialty_code' => 'required|string',
- 'spacialty_name' => 'required|string|max:75',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_CONTRATO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $specialtyCode = $this->encryptionController->decrypt($form['specialty_code']);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, 'El código de la especialidad no fue encriptado correctamente.', [], 400);
- }
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode],
- ])->first();
- if(is_null($specialty)){
- return $this->responseController->makeResponse(true, 'La especialidad que desea actualizar no existe.', [], 404);
- }else if($specialty->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La especialidad que desea actualizar está eliminada.', [], 404);
- }
- $filtName = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_NOES', '=', $form['spacialty_name']],
- ['GEES_ESTA', '=', 'Activo']
- ])->first();
- if(!is_null($filtName)){
- return $this->responseController->makeResponse(true, 'El nombre ingresado ya se encuentra registrado.', [], 400);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode],
- ])->update([
- 'GEES_NOES' => $form['spacialty_name'],
- 'GEES_USMO' => $idUser,
- 'GEES_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
-
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F02ADCN',
- 'S002V01P02RECO',
- 'Actualización',
- "El usuario $name (" . $usr->USUA_IDUS . ") actualizó la especialidad $specialtyCode.",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- public function deleteSpecialty(Request $request) {
- DB::enableQueryLog();
- $validator = Validator::make($request->all(), [
- 'id_user' => 'required|string',
- 'linea' => 'required|integer',
- 'specialty_code' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- TRUE,
- 'ERR_CONTRATO_REG001: Uno o más errores encontrados',
- $this->responseController->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- $form = $request->all();
- $idUser = $this->encryptionController->decrypt($form['id_user']);
- if(!$idUser){
- return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
- }
- $usr = DB::table('S002V01TUSUA')->where([
- ['USUA_NULI', '=', $form['linea']],
- ['USUA_IDUS', '=', $idUser]
- ])->first();
-
- if(is_null($usr)){
- return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
- }
- $specialtyCode = $this->encryptionController->decrypt($form['specialty_code']);
- if(!$specialtyCode){
- return $this->responseController->makeResponse(true, 'El código de la especialidad no fue encriptado correctamente.', [], 400);
- }
- $specialty = DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode],
- ])->first();
- if(is_null($specialty)){
- return $this->responseController->makeResponse(true, 'La especialidad que desea actualizar no existe.', [], 404);
- }else if($specialty->GEES_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'La especialidad que desea actualizar está eliminada.', [], 404);
- }
- $now = $this->functionsController->now();
- $nowStr = $now->toDateTimeString();
- DB::table('S002V01TGEES')->where([
- ['GEES_NULI', '=', $form['linea']],
- ['GEES_COES', '=', $specialtyCode],
- ])->update([
- 'GEES_ESTA' => 'Eliminado',
- 'GEES_USMO' => $idUser,
- 'GEES_FEMO' => $nowStr
- ]);
- $actions = DB::getQueryLog();
- $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
- $idac = $this->functionsController->registerActivity(
- $form['linea'],
- 'S002V01M11GPRS',
- 'S002V01F02ADCN',
- 'S002V01P02RECO',
- 'Eliminación',
- "El usuario $name (" . $usr->USUA_IDUS . ") eliminó la especialidad $specialtyCode.",
- $idUser,
- $nowStr,
- 'S002V01S03GEIN'
- );
- $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
- return $this->responseController->makeResponse(false, 'EXITO');
- }
- }
|