ProviderController.php 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 05/09/2023
  5. Módulo: Gestión de Adquisiciones
  6. */
  7. namespace App\Http\Controllers;
  8. use App\Http\Controllers\Controller;
  9. use App\Http\Controllers\ResponseController;
  10. use App\Http\Controllers\EncryptionController;
  11. use App\Http\Controllers\FunctionsController;
  12. use App\Http\Controllers\DocumentManagementController;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Validator;
  16. use Illuminate\Support\Facades\Storage;
  17. use Illuminate\Http\File;
  18. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  19. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  20. use Dompdf\Dompdf;
  21. class ProviderController extends Controller{
  22. private $responseController;
  23. private $encController;
  24. private $resourcesController;
  25. private $functionsController;
  26. private $documentManagementController;
  27. public function __construct() {
  28. $this->responseController = new ResponseController();
  29. $this->encController = new EncryptionController();
  30. $this->resourcesController = new ResourcesController();
  31. $this->functionsController = new FunctionsController();
  32. $this->documentManagementController = new DocumentManagementController();
  33. }
  34. public function getAllProvider($user, $line){
  35. try {
  36. $arrProvider = DB::table('S002V01TPROV')
  37. ->where('PROV_NULI', '=', $line)
  38. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  39. ->get([
  40. 'PROV_NUPR AS NUMERO_PROVEEDOR',
  41. 'PROV_NOCO AS RAZON_SOCIAL',
  42. 'PROV_NOMB AS NOMBRE',
  43. 'PROV_APPA AS PRIMER_APELLIDO',
  44. 'PROV_APMA AS SEGUNDO_APELLIDO',
  45. 'PROV_CORR AS CORREO',
  46. 'PROV_LAD1 AS LADA1',
  47. 'PROV_TEL1 AS TELEFONO1',
  48. 'PROV_LAD2 AS LADA2',
  49. 'PROV_TEL2 AS TELEFONO2',
  50. 'PROV_XRFC AS RFC',
  51. 'PROV_XTAX AS TAXID',
  52. 'PROV_CRFI AS REGIMEN_FISCAL',
  53. DB::raw('CONCAT(REFI_DRFI, " (", REFI_CRFI, ")") AS REGIMEN_FISCAL'),
  54. 'PROV_TIPO AS TIPO',
  55. 'PROV_TICO AS TIPO_CONTRIBUYENTE',
  56. 'PROV_SIWE AS SITIOWEB',
  57. 'PROV_MEPA AS METODO_PAGO',
  58. 'PROV_ESTA AS ESTADO',
  59. 'PROV_USRE AS USUARIO_REGISTRA',
  60. 'PROV_FERE AS FECHA_REGISTRA',
  61. 'PROV_USMO AS USUARIO_MODIFICA',
  62. 'PROV_FEMO AS FECHA_MODIFICA',
  63. 'PROV_CALL AS CALLE',
  64. 'PROV_NUEX AS EXTERIOR',
  65. 'PROV_NUIN AS INTERIOR',
  66. 'PROV_COPO AS CODIGO_POSTAL',
  67. 'PROV_COLO AS COLONIA',
  68. 'PROV_LOCA AS LOCALIDAD',
  69. 'PROV_MUNI AS MUNICIPIO',
  70. 'PROV_ENTI AS ENTIDAD',
  71. 'PROV_PAIS AS PAIS',
  72. ]);
  73. $arrResponse = array();
  74. foreach ($arrProvider as $provider) {
  75. $provider = (array) $provider;
  76. $provider['SEGUNDO_APELLIDO'] = $provider['SEGUNDO_APELLIDO'] == null ? '' : $provider['SEGUNDO_APELLIDO'];
  77. $arrReferences = DB::table('S002V01TPRRE')
  78. ->where('PRRE_NULI', '=', $line)
  79. ->where('PRRE_ESTA', '=', 'Activo')
  80. ->where('PRRE_NUPR', '=', $provider['NUMERO_PROVEEDOR'])
  81. ->get([
  82. 'PRRE_IDRE AS NUMERO_REFERENCIA',
  83. 'PRRE_EMPR AS RAZON_SOCIAL',
  84. 'PRRE_CORR AS CORREO',
  85. 'PRRE_LADA AS LADA',
  86. 'PRRE_TELE AS TELEFONO',
  87. 'PRRE_XRFC AS RFC',
  88. 'PRRE_DIRE AS DIRECCION',
  89. 'PRRE_ESTA AS ESTADO',
  90. 'PRRE_USRE AS USUARIO_REGISTRA',
  91. 'PRRE_FERE AS FECHA_REGISTRA',
  92. 'PRRE_USMO AS USUARIO_MODIFICA',
  93. 'PRRE_FEMO AS FECHA_MODIFICA',
  94. ]);
  95. $arrContacts = DB::table('S002V01TPRCO')
  96. ->where('PRCO_NULI', '=', $line)
  97. ->where('PRCO_ESTA', '=', 'Activo')
  98. ->where('PRCO_NUPR', '=', $provider['NUMERO_PROVEEDOR'])
  99. ->get([
  100. 'PRCO_IDCP AS NUMERO_CONTACTO',
  101. 'PRCO_NOMB AS NOMBRE_CONTACTO',
  102. 'PRCO_TIPO AS TIPO_CONTACTO',
  103. 'PRCO_CALL AS CALLE',
  104. 'PRCO_NUEX AS NUMERO_EXTERIOR',
  105. 'PRCO_NUIN AS NUMERO_INTERIOR',
  106. 'PRCO_COPO AS CODIGO_POSTAL',
  107. 'PRCO_COLO AS COLONIA',
  108. 'PRCO_LOCA AS LOCALIDAD',
  109. 'PRCO_MUNI AS MUNICIPIO',
  110. 'PRCO_ENTI AS ENTIDAD',
  111. 'PRCO_PAIS AS PAIS',
  112. 'PRCO_LAD1 AS LADA1',
  113. 'PRCO_TEL1 AS TELEFONO1',
  114. 'PRCO_LAD2 AS LADA2',
  115. 'PRCO_TEL2 AS TELEFONO2',
  116. 'PRCO_COR1 AS CORREO1',
  117. 'PRCO_COR2 AS CORREO2',
  118. 'PRCO_OBSE AS OBSERVACIONES',
  119. 'PRCO_ESTA AS ESTADO',
  120. 'PRCO_USRE AS USUARIO_REGISTRA',
  121. 'PRCO_FERE AS FECHA_REGISTRA',
  122. 'PRCO_USMO AS USUARIO_MODIFICA',
  123. 'PRCO_FEMO AS FECHA_MODIFICA',
  124. ]);
  125. $arrConditions = DB::table('S002V01TPRCN')
  126. ->where('PRCN_NULI', '=', $line)
  127. ->where('PRCN_ESTA', '=', 'Activo')
  128. ->where('PRCN_NUPR', '=', $provider['NUMERO_PROVEEDOR'])
  129. ->get([
  130. 'PRCN_IDCM AS NUMERO_CONDICION',
  131. 'PRCN_TIPO AS TIPO_CONDICION',
  132. 'PRCN_INFO AS INFORMACION',
  133. 'PRCN_ESTA AS ESTADO',
  134. 'PRCN_USRE AS USUARIO_REGISTRA',
  135. 'PRCN_FERE AS FECHA_REGISTRA',
  136. 'PRCN_USMO AS USUARIO_MODIFICA',
  137. 'PRCN_FEMO AS FECHA_MODIFICA',
  138. ]);
  139. $arrCatalogs = DB::table('S002V01TPRCE')
  140. ->where('PRCE_NULI', '=', $line)
  141. ->where('PRCE_ESTA', '=', 'Activo')
  142. ->where('PRCE_NUPR', '=', $provider['NUMERO_PROVEEDOR'])
  143. ->get([
  144. 'PRCE_IDCE AS NUMERO_CATALAGO',
  145. 'PRCE_CATA AS CATALAGO',
  146. 'PRCE_DESC AS DESCRIPCION',
  147. 'PRCE_XURL AS URL_CATALAGO',
  148. 'PRCE_ESTA AS ESTADO',
  149. 'PRCE_USRE AS USUARIO_REGISTRA',
  150. 'PRCE_FERE AS FECHA_REGISTRA',
  151. 'PRCE_USMO AS USUARIO_MODIFICA',
  152. 'PRCE_FEMO AS FECHA_MODIFICA',
  153. ]);
  154. $arrPayment = json_decode($provider['METODO_PAGO']);
  155. $arrPaymentFormat = array();
  156. foreach ($arrPayment as $key => $payment) {
  157. $arrPaymentFormat[] = [
  158. 'C_FORMAPAGO' => $key,
  159. 'DESCRIPCION' => $payment,
  160. ];
  161. }
  162. $provider['REFERENCIAS'] = $arrReferences;
  163. $provider['CONTACTOS'] = $arrContacts;
  164. $provider['CONDICIONES'] = $arrConditions;
  165. $provider['CATALAGOS'] = $arrCatalogs;
  166. $provider['METODOS_PAGO'] = $arrPaymentFormat;
  167. $arrResponse[] = $provider;
  168. }
  169. } catch (\Throwable $th) {
  170. return $this->responseController->makeResponse(true, "ERR_PROVIDER_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  171. }
  172. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrResponse);
  173. }
  174. public function getProvidersActives($user, $line) {
  175. try {
  176. $arrProvider = DB::table('S002V01TPROV')
  177. ->where('PROV_ESTA', '=', 'Activo')
  178. ->where('PROV_NULI', '=', $line)
  179. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  180. ->get([
  181. 'PROV_NUPR',
  182. 'PROV_NOCO',
  183. 'PROV_NOMB',
  184. 'PROV_APPA',
  185. 'PROV_APMA',
  186. 'PROV_CORR',
  187. 'PROV_LAD1',
  188. 'PROV_TEL1',
  189. 'PROV_LAD2',
  190. 'PROV_TEL2',
  191. 'PROV_XRFC',
  192. 'PROV_XTAX',
  193. 'REFI_CRFI',
  194. 'REFI_DRFI',
  195. 'PROV_TIPO',
  196. 'PROV_TICO',
  197. 'PROV_SIWE',
  198. 'PROV_MEPA',
  199. 'PROV_CALL',
  200. 'PROV_NUEX',
  201. 'PROV_NUIN',
  202. 'PROV_COPO',
  203. 'PROV_COLO',
  204. 'PROV_MUNI',
  205. 'PROV_LOCA',
  206. 'PROV_ENTI',
  207. 'PROV_PAIS',
  208. 'PROV_INEX',
  209. 'PROV_USRE',
  210. 'PROV_FERE',
  211. 'PROV_USMO',
  212. 'PROV_FEMO',
  213. 'PROV_FEAR',
  214. ]);
  215. } catch (\Throwable $th) {
  216. return $this->responseController->makeResponse(true, "ERR_PROVIDER_GETACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  217. }
  218. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrProvider);
  219. }
  220. public function getProvidersByNumber($provider, $user, $line) {
  221. try {
  222. $arrProvider = DB::table('S002V01TPROV')
  223. ->where('PROV_NUPR', '=', $provider)
  224. ->where('PROV_NULI', '=', $line)
  225. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  226. ->first([
  227. 'PROV_NUPR',
  228. 'PROV_NOCO',
  229. 'PROV_NOMB',
  230. 'PROV_APPA',
  231. 'PROV_APMA',
  232. 'PROV_CORR',
  233. 'PROV_LAD1',
  234. 'PROV_TEL1',
  235. 'PROV_LAD2',
  236. 'PROV_TEL2',
  237. 'PROV_XRFC',
  238. 'PROV_XTAX',
  239. 'REFI_CRFI',
  240. 'REFI_DRFI',
  241. 'PROV_TIPO',
  242. 'PROV_TICO',
  243. 'PROV_SIWE',
  244. 'PROV_MEPA',
  245. 'PROV_CALL',
  246. 'PROV_NUEX',
  247. 'PROV_NUIN',
  248. 'PROV_COPO',
  249. 'PROV_COLO',
  250. 'PROV_MUNI',
  251. 'PROV_LOCA',
  252. 'PROV_ENTI',
  253. 'PROV_PAIS',
  254. 'PROV_INEX',
  255. 'PROV_USRE',
  256. 'PROV_FERE',
  257. 'PROV_USMO',
  258. 'PROV_FEMO',
  259. 'PROV_FEAR',
  260. ]);
  261. } catch (\Throwable $th) {
  262. return $this->responseController->makeResponse(true, "ERR_PROVIDER_GETBYNUMBER000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  263. }
  264. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrProvider);
  265. }
  266. public function updateProvider(Request $request) {
  267. $validator = Validator::make($request->all(), [
  268. 'line' => 'required|string',
  269. 'user' => 'required|string',
  270. 'obj_response' => 'required',
  271. ]);
  272. if ($validator->fails()) {
  273. return $this->responseController->makeResponse(
  274. true,
  275. "ERR_PROVIDER_MOD000: Se encontraron uno o más errores.",
  276. $this->responseController->makeErrors($validator->errors()->messages()),
  277. 401
  278. );
  279. }
  280. DB::beginTransaction();
  281. $requestData = $request->all();
  282. $line = $requestData['line'];
  283. try {
  284. $user = $this->encController->decrypt($request['user']);
  285. } catch (\Throwable $th) {
  286. DB::rollBack();
  287. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  288. }
  289. $arrInformationPersonal = $requestData['obj_response']['INFORMACION'];
  290. $arrReferences = $requestData['obj_response']['REFERENCIAS'];
  291. $arrContacts = $requestData['obj_response']['CONTACTOS'];
  292. $arrConditions = $requestData['obj_response']['CONDICIONES'];
  293. $arrPaymentMedia = $requestData['obj_response']['METODOS_PAGO'];
  294. $arrCatalogs = $requestData['obj_response']['CATALAGOS'];
  295. $numeroProveedor = $arrInformationPersonal['NUMERO_PROVEEDOR'];
  296. $now = $this->functionsController->now();
  297. $currentDate = $now->toDateTimeString();
  298. $arrPaymentTemp = array();
  299. foreach ($arrPaymentMedia as $payment) {
  300. $arrPaymentTemp[$payment['C_FORMAPAGO']] = $payment['DESCRIPCION'];
  301. }
  302. try {
  303. $strPayment = json_encode($arrPaymentTemp);
  304. } catch (\Throwable $th) {
  305. DB::rollBack();
  306. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD002: Ocurrió un error al obtener los datos del método de pago.", $th->getMessage(), 500);
  307. }
  308. try {
  309. $validateUpdateInformation = DB::table('S002V01TPROV')
  310. ->where('PROV_NUPR', '=', $numeroProveedor)
  311. ->where('PROV_NULI', '=', $line)
  312. ->update([
  313. 'PROV_NOCO' => $arrInformationPersonal['RAZON_SOCIAL'],
  314. 'PROV_NOMB' => $arrInformationPersonal['NOMBRE'],
  315. 'PROV_APPA' => $arrInformationPersonal['PRIMER_APELLIDO'],
  316. 'PROV_APMA' => $arrInformationPersonal['SEGUNDO_APELLIDO'] != '' ? $arrInformationPersonal['SEGUNDO_APELLIDO'] : null,
  317. 'PROV_CORR' => $arrInformationPersonal['CORREO'],
  318. 'PROV_LAD1' => $arrInformationPersonal['LADA1'],
  319. 'PROV_TEL1' => $arrInformationPersonal['TELEFONO1'],
  320. 'PROV_LAD2' => $arrInformationPersonal['LADA2'] != '' ? $arrInformationPersonal['LADA2'] : null,
  321. 'PROV_TEL2' => $arrInformationPersonal['TELEFONO2'] != '' ? $arrInformationPersonal['TELEFONO2'] : null,
  322. 'PROV_TICO' => $arrInformationPersonal['TIPO_CONTRIBUYENTE'],
  323. 'PROV_XRFC' => $arrInformationPersonal['RFC'],
  324. 'PROV_XTAX' => $arrInformationPersonal['TAXID'] != '' ? $arrInformationPersonal['TAXID'] : null,
  325. 'PROV_CRFI' => $arrInformationPersonal['REGIMEN_FISCAL'],
  326. 'PROV_TIPO' => $arrInformationPersonal['TIPO'],
  327. 'PROV_SIWE' => $arrInformationPersonal['SITIOWEB'],
  328. 'PROV_MEPA' => $strPayment,
  329. 'PROV_CALL' => $arrInformationPersonal['CALLE'],
  330. 'PROV_NUEX' => $arrInformationPersonal['EXTERIOR'],
  331. 'PROV_NUIN' => $arrInformationPersonal['INTERIOR'],
  332. 'PROV_COPO' => $arrInformationPersonal['CODIGO_POSTAL'],
  333. 'PROV_COLO' => $arrInformationPersonal['COLONIA'],
  334. 'PROV_LOCA' => $arrInformationPersonal['LOCALIDAD'] === 'Sin localidad' ? null : $arrInformationPersonal['LOCALIDAD'],
  335. 'PROV_MUNI' => $arrInformationPersonal['MUNICIPIO'],
  336. 'PROV_ENTI' => $arrInformationPersonal['ENTIDAD'],
  337. 'PROV_PAIS' => $arrInformationPersonal['PAIS'],
  338. 'PROV_USMO' => $user,
  339. 'PROV_FEMO' => $currentDate,
  340. 'PROV_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  341. ]);
  342. } catch (\Throwable $th) {
  343. DB::rollBack();
  344. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD003: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  345. }
  346. if (!$validateUpdateInformation) {
  347. DB::rollBack();
  348. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD004: Ocurrió un error al obtener el contenido.", [], 500);
  349. }
  350. foreach ($arrReferences as $references) {
  351. if ($references['ESTADO'] == 'Activo' || $references['ESTADO'] == 'Modificado') {
  352. try {
  353. $validateUpdateReference = DB::table('S002V01TPRRE')
  354. ->where('PRRE_IDRE', '=', $references['NUMERO_REFERENCIA'])
  355. ->where('PRRE_NUPR', '=', $numeroProveedor)
  356. ->where('PRRE_NULI', '=', $line)
  357. ->update([
  358. 'PRRE_EMPR' => $references['RAZON_SOCIAL'],
  359. 'PRRE_CORR' => $references['CORREO'],
  360. 'PRRE_LADA' => $references['LADA'],
  361. 'PRRE_TELE' => $references['TELEFONO'],
  362. 'PRRE_XRFC' => $references['RFC'],
  363. 'PRRE_DIRE' => $references['DIRECCION'],
  364. 'PRRE_USMO' => $user,
  365. 'PRRE_FEMO' => $currentDate,
  366. 'PRRE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  367. ]);
  368. } catch (\Throwable $th) {
  369. DB::rollBack();
  370. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD005: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  371. }
  372. if (!$validateUpdateReference) {
  373. DB::rollBack();
  374. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD006: Ocurrió un error al obtener el contenido. ", [], 500);
  375. }
  376. } else if ($references['ESTADO'] == 'Nuevo') {
  377. try {
  378. $validateInsertReference = DB::table('S002V01TPRRE')->insert([
  379. 'PRRE_NUPR' => $numeroProveedor,
  380. 'PRRE_EMPR' => $references['RAZON_SOCIAL'],
  381. 'PRRE_CORR' => $references['CORREO'],
  382. 'PRRE_LADA' => $references['LADA'],
  383. 'PRRE_TELE' => $references['TELEFONO'],
  384. 'PRRE_XRFC' => $references['RFC'],
  385. 'PRRE_DIRE' => $references['DIRECCION'],
  386. 'PRRE_NULI' => $line,
  387. 'PRRE_USRE' => $user,
  388. 'PRRE_FERE' => $currentDate,
  389. 'PRRE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  390. ]);
  391. } catch (\Throwable $th) {
  392. DB::rollBack();
  393. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD007: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  394. }
  395. if (!$validateInsertReference) {
  396. DB::rollBack();
  397. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD008: Ocurrió un error al obtener el contenido.", [], 500);
  398. }
  399. } else if ($references['ESTADO'] == 'Eliminado'){
  400. try {
  401. $validateUpdateReference = DB::table('S002V01TPRRE')
  402. ->where('PRRE_IDRE', '=', $references['NUMERO_REFERENCIA'])
  403. ->where('PRRE_NUPR', '=', $numeroProveedor)
  404. ->where('PRRE_NULI', '=', $line)
  405. ->update([
  406. 'PRRE_ESTA' => 'Eliminado',
  407. 'PRRE_USMO' => $user,
  408. 'PRRE_FEMO' => $currentDate,
  409. 'PRRE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  410. ]);
  411. } catch (\Throwable $th) {
  412. DB::rollBack();
  413. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD009: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  414. }
  415. if (!$validateUpdateReference) {
  416. DB::rollBack();
  417. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD010: Ocurrió un error al obtener el contenido.", [], 500);
  418. }
  419. }
  420. }
  421. foreach ($arrContacts as $contacts) {
  422. if ($contacts['ESTADO'] == 'Activo' || $contacts['ESTADO'] == 'Modificado') {
  423. try {
  424. $validateUpdateContact = DB::table('S002V01TPRCO')
  425. ->where('PRCO_IDCP', '=', $contacts['NUMERO_CONTACTO'])
  426. ->where('PRCO_NUPR', '=', $numeroProveedor)
  427. ->where('PRCO_NULI', '=', $line)
  428. ->update([
  429. 'PRCO_NOMB' => $contacts['NOMBRE_CONTACTO'],
  430. 'PRCO_TIPO' => $contacts['TIPO_CONTACTO'],
  431. 'PRCO_CALL' => $contacts['CALLE'],
  432. 'PRCO_NUEX' => $contacts['NUMERO_EXTERIOR'],
  433. 'PRCO_NUIN' => $contacts['NUMERO_INTERIOR'] != '' ? $contacts['NUMERO_INTERIOR'] : null,
  434. 'PRCO_COPO' => $contacts['CODIGO_POSTAL'],
  435. 'PRCO_COLO' => $contacts['COLONIA'],
  436. 'PRCO_LOCA' => $contacts['LOCALIDAD'],
  437. 'PRCO_MUNI' => $contacts['MUNICIPIO'],
  438. 'PRCO_ENTI' => $contacts['ENTIDAD'],
  439. 'PRCO_PAIS' => $contacts['PAIS'],
  440. 'PRCO_TEL1' => $contacts['TELEFONO1'],
  441. 'PRCO_TEL2' => $contacts['TELEFONO2'] != '' ? $contacts['TELEFONO2'] : null,
  442. 'PRCO_COR1' => $contacts['CORREO1'],
  443. 'PRCO_COR2' => $contacts['CORREO2'] != '' ? $contacts['CORREO2'] : null,
  444. 'PRCO_OBSE' => $contacts['OBSERVACIONES'],
  445. 'PRCO_USMO' => $user,
  446. 'PRCO_FEMO' => $currentDate,
  447. 'PRCO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  448. ]);
  449. } catch (\Throwable $th) {
  450. DB::rollBack();
  451. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD011: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  452. }
  453. if (!$validateUpdateContact) {
  454. DB::rollBack();
  455. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD012: Ocurrió un error al obtener el contenido.", [], 500);
  456. }
  457. } else if ($contacts['ESTADO'] == 'Nuevo') {
  458. try {
  459. $validateInsertContact = DB::table('S002V01TPRCO')->insert([
  460. 'PRCO_NUPR' => $numeroProveedor,
  461. 'PRCO_NOMB' => $contacts['NOMBRE_CONTACTO'],
  462. 'PRCO_TIPO' => $contacts['TIPO_CONTACTO'],
  463. 'PRCO_CALL' => $contacts['CALLE'],
  464. 'PRCO_NUEX' => $contacts['NUMERO_EXTERIOR'],
  465. 'PRCO_NUIN' => $contacts['NUMERO_INTERIOR'] != '' ? $contacts['NUMERO_INTERIOR'] : null,
  466. 'PRCO_COPO' => $contacts['CODIGO_POSTAL'],
  467. 'PRCO_COLO' => $contacts['COLONIA'],
  468. 'PRCO_LOCA' => $contacts['LOCALIDAD'],
  469. 'PRCO_MUNI' => $contacts['MUNICIPIO'],
  470. 'PRCO_ENTI' => $contacts['ENTIDAD'],
  471. 'PRCO_PAIS' => $contacts['PAIS'],
  472. 'PRCO_LAD1' => $contacts['LADA1'],
  473. 'PRCO_TEL1' => $contacts['TELEFONO1'],
  474. 'PRCO_LAD2' => $contacts['LADA2'] != '' ? $contacts['LADA2'] : null,
  475. 'PRCO_TEL2' => $contacts['TELEFONO2'] != '' ? $contacts['TELEFONO2'] : null,
  476. 'PRCO_COR1' => $contacts['CORREO1'],
  477. 'PRCO_COR2' => $contacts['CORREO2'] != '' ? $contacts['CORREO2'] : null,
  478. 'PRCO_OBSE' => $contacts['OBSERVACIONES'],
  479. 'PRCO_NULI' => $line,
  480. 'PRCO_USRE' => $user,
  481. 'PRCO_FERE' => $currentDate,
  482. 'PRCO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  483. ]);
  484. } catch (\Throwable $th) {
  485. DB::rollBack();
  486. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  487. }
  488. if (!$validateInsertContact) {
  489. DB::rollBack();
  490. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD014: Ocurrió un error al obtener el contenido.", [], 500);
  491. }
  492. } else if ($contacts['ESTADO'] == 'Eliminado'){
  493. try {
  494. $validateUpdateContact = DB::table('S002V01TPRCO')
  495. ->where('PRCO_IDCP', '=', $contacts['NUMERO_CONTACTO'])
  496. ->where('PRCO_NUPR', '=', $numeroProveedor)
  497. ->where('PRCO_NULI', '=', $line)
  498. ->update([
  499. 'PRCO_ESTA' => 'Eliminado',
  500. 'PRCO_USMO' => $user,
  501. 'PRCO_FEMO' => $currentDate,
  502. 'PRCO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  503. ]);
  504. } catch (\Throwable $th) {
  505. DB::rollBack();
  506. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD015: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  507. }
  508. if (!$validateUpdateContact) {
  509. DB::rollBack();
  510. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD016: Ocurrió un error al obtener el contenido.", [], 500);
  511. }
  512. }
  513. }
  514. foreach ($arrConditions as $conditions) {
  515. if ($conditions['ESTADO'] == 'Activo' || $conditions['ESTADO'] == 'Modificado') {
  516. try {
  517. $validateUpdateCondition = DB::table('S002V01TPRCN')
  518. ->where('PRCN_IDCM', '=', $conditions['NUMERO_CONDICION'])
  519. ->where('PRCN_NUPR', '=', $numeroProveedor)
  520. ->where('PRCN_NULI', '=', $line)
  521. ->update([
  522. 'PRCN_TIPO' => $conditions['TIPO_CONDICION'],
  523. 'PRCN_INFO' => $conditions['INFORMACION'],
  524. 'PRCN_USMO' => $user,
  525. 'PRCN_FEMO' => $currentDate,
  526. 'PRCN_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  527. ]);
  528. } catch (\Throwable $th) {
  529. DB::rollBack();
  530. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD017: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  531. }
  532. if (!$validateUpdateCondition) {
  533. DB::rollBack();
  534. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD018: Ocurrió un error al obtener el contenido.", [], 500);
  535. }
  536. } else if ($conditions['ESTADO'] == 'Nuevo'){
  537. try {
  538. $validateInsertCondition = DB::table('S002V01TPRCN')->insert([
  539. 'PRCN_NUPR' => $numeroProveedor,
  540. 'PRCN_TIPO' => $conditions['TIPO_CONDICION'],
  541. 'PRCN_INFO' => $conditions['INFORMACION'],
  542. 'PRCN_NULI' => $line,
  543. 'PRCN_USRE' => $user,
  544. 'PRCN_FERE' => $currentDate,
  545. 'PRCN_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  546. ]);
  547. } catch (\Throwable $th) {
  548. DB::rollBack();
  549. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD019: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  550. }
  551. if (!$validateInsertCondition) {
  552. DB::rollBack();
  553. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD020: Ocurrió un error al obtener el contenido.", [], 500);
  554. }
  555. } else if ($conditions['ESTADO'] == 'Eliminado'){
  556. try {
  557. $validateRegister = DB::table('S002V01TPRCN')
  558. ->where('PRCN_IDCM', '=', $conditions['NUMERO_CONDICION'])
  559. ->where('PRCN_NUPR', '=', $numeroProveedor)
  560. ->where('PRCN_NULI', '=', $line)
  561. ->exists();
  562. } catch (\Throwable $th) {
  563. DB::rollBack();
  564. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD021: Ocurrió un error al validar el registro.", $th->getMessage(), 500);
  565. }
  566. if ($validateRegister) {
  567. try {
  568. $validateUpdateConditions = DB::table('S002V01TPRCN')
  569. ->where('PRCN_IDCM', '=', $conditions['NUMERO_CONDICION'])
  570. ->where('PRCN_NUPR', '=', $numeroProveedor)
  571. ->where('PRCN_NULI', '=', $line)
  572. ->update([
  573. 'PRCN_ESTA' => 'Eliminado',
  574. 'PRCN_USMO' => $user,
  575. 'PRCN_FEMO' => $currentDate,
  576. 'PRCN_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  577. ]);
  578. } catch (\Throwable $th) {
  579. DB::rollBack();
  580. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD022: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  581. }
  582. if (!$validateUpdateConditions) {
  583. DB::rollBack();
  584. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD023: Ocurrió un error al obtener el contenido.", [], 500);
  585. }
  586. }
  587. }
  588. }
  589. foreach ($arrCatalogs as $catalogs) {
  590. if ($catalogs['ESTADO'] == 'Activo' || $catalogs['ESTADO'] == 'Modificado') {
  591. try {
  592. $validateUpdateCatalog = DB::table('S002V01TPRCE')
  593. ->where('PRCE_IDCE', '=', $catalogs['NUMERO_CATALAGO'])
  594. ->where('PRCE_NUPR', '=', $numeroProveedor)
  595. ->where('PRCE_NULI', '=', $line)
  596. ->update([
  597. 'PRCE_CATA' => $catalogs['CATALAGO'],
  598. 'PRCE_DESC' => $catalogs['DESCRIPCION'],
  599. 'PRCE_XURL' => $catalogs['URL_CATALAGO'],
  600. 'PRCE_USMO' => $user,
  601. 'PRCE_FEMO' => $currentDate,
  602. 'PRCE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  603. ]);
  604. } catch (\Throwable $th) {
  605. DB::rollBack();
  606. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD024: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  607. }
  608. if (!$validateUpdateCatalog) {
  609. DB::rollBack();
  610. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD025: Ocurrió un error al obtener el contenido.", [], 500);
  611. }
  612. } else if ($catalogs['ESTADO'] == 'Nuevo'){
  613. try {
  614. $validateInsertCatalog = DB::table('S002V01TPRCE')->insert([
  615. 'PRCE_NUPR' => $numeroProveedor,
  616. 'PRCE_CATA' => $catalogs['CATALAGO'],
  617. 'PRCE_DESC' => $catalogs['DESCRIPCION'],
  618. 'PRCE_XURL' => $catalogs['URL_CATALAGO'],
  619. 'PRCE_NULI' => $line,
  620. 'PRCE_USRE' => $user,
  621. 'PRCE_FERE' => $currentDate,
  622. 'PRCE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  623. ]);
  624. } catch (\Throwable $th) {
  625. DB::rollBack();
  626. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD026: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  627. }
  628. if (!$validateInsertCatalog) {
  629. DB::rollBack();
  630. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD027: Ocurrió un error al obtener el contenido.", [], 500);
  631. }
  632. } else if ($catalogs['ESTADO'] == 'Eliminado'){
  633. try {
  634. $validateExists = DB::table('S002V01TPRCE')
  635. ->where('PRCE_IDCE', '=', $catalogs['NUMERO_CATALAGO'])
  636. ->where('PRCE_NUPR', '=', $numeroProveedor)
  637. ->where('PRCE_NULI', '=', $line)
  638. ->exists();
  639. } catch (\Throwable $th) {
  640. DB::rollBack();
  641. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD028: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  642. }
  643. if ($validateExists) {
  644. try {
  645. $validateDelete = DB::table('S002V01TPRCE')
  646. ->where('PRCE_IDCE', '=', $catalogs['NUMERO_CATALAGO'])
  647. ->where('PRCE_NUPR', '=', $numeroProveedor)
  648. ->where('PRCE_NULI', '=', $line)
  649. ->update([
  650. 'PRCE_ESTA' => 'Eliminado',
  651. 'PRCE_USMO' => $user,
  652. 'PRCE_FEMO' => $currentDate,
  653. 'PRCE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  654. ]);
  655. } catch (\Throwable $th) {
  656. DB::rollBack();
  657. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD029: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  658. }
  659. if (!$validateDelete) {
  660. DB::rollBack();
  661. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD030: Ocurrió un error al obtener el contenido.", [], 500);
  662. }
  663. }
  664. }
  665. }
  666. $response = [ 'idProvider' => $numeroProveedor ];
  667. try {
  668. $getSubcontract = (array) DB::table('S002V01TPESU')
  669. ->where('PESU_NUPR', '=', $numeroProveedor)
  670. ->where('PESU_NULI', '=', $line)
  671. ->first();
  672. } catch (\Throwable $th) {
  673. DB::rollBack();
  674. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD031: Ocurrió un error al válidar si existe en subcontratista.", $th->getMessage(), 500);
  675. }
  676. if ( !empty($getSubcontract)) {
  677. try {
  678. $updateSubcontract = DB::table('S002V01TPESU')
  679. ->where('PESU_NUPR', '=', $numeroProveedor)
  680. ->where('PESU_NULI', '=', $line)
  681. ->update([
  682. 'PESU_RASO' => $arrInformationPersonal['RAZON_SOCIAL'],
  683. 'PESU_REFI' => $arrInformationPersonal['REGIMEN_FISCAL'],
  684. 'PESU_XRFC' => $arrInformationPersonal['RFC'] != '' ? $arrInformationPersonal['RFC'] : null,
  685. 'PESU_TIPO' => $arrInformationPersonal['TIPO_CONTRIBUYENTE'],
  686. 'PESU_CORR' => $arrInformationPersonal['CORREO'],
  687. 'PESU_EXTR' => $arrInformationPersonal['TIPO'] === 'Nacional' ? 'No' : 'Si',
  688. 'PESU_TAID' => $arrInformationPersonal['TAXID'] != '' ? $arrInformationPersonal['TAXID'] : null,
  689. 'PESU_CALL' => $arrInformationPersonal['CALLE'],
  690. 'PESU_NUEX' => $arrInformationPersonal['EXTERIOR'],
  691. 'PESU_NUIN' => $arrInformationPersonal['INTERIOR'],
  692. 'PESU_COLO' => $arrInformationPersonal['COLONIA'],
  693. 'PESU_CIUD' => $arrInformationPersonal['MUNICIPIO'],
  694. 'PESU_LOCA' => $arrInformationPersonal['LOCALIDAD'] === 'Sin localidad' ? null : $arrInformationPersonal['LOCALIDAD'],
  695. 'PESU_COPO' => $arrInformationPersonal['CODIGO_POSTAL'],
  696. 'PESU_ENFE' => $arrInformationPersonal['ENTIDAD'],
  697. 'PESU_IDPA' => $arrInformationPersonal['PAIS'],
  698. 'PESU_TEL1' => $arrInformationPersonal['TELEFONO1'],
  699. 'PESU_LAT1' => $arrInformationPersonal['LADA1'],
  700. 'PESU_TEL2' => $arrInformationPersonal['TELEFONO2'] != '' ? $arrInformationPersonal['TELEFONO2'] : null,
  701. 'PESU_LAT2' => $arrInformationPersonal['LADA2'] != '' ? $arrInformationPersonal['LADA2'] : null,
  702. 'PESU_USMO' => $user,
  703. 'PESU_FEMO' => $currentDate,
  704. ]
  705. );
  706. } catch (\Throwable $th) {
  707. DB::rollBack();
  708. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD032: Ocurrió un error al modificar el subcontratista.", $th->getMessage(), 500);
  709. }
  710. if ( !$updateSubcontract ) {
  711. DB::rollBack();
  712. return $this->responseController->makeResponse(true, "ERR_PROVIDER_MOD033: No se pudo modificar el subcontratista.", [], 500);
  713. }
  714. $response['subcontract'] = $getSubcontract;
  715. }
  716. DB::commit();
  717. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", $response);
  718. }
  719. public function registerProvider(Request $request) {
  720. $validator = Validator::make($request->all(), [
  721. 'line' => 'required|string',
  722. 'user' => 'required|string',
  723. 'obj_response' => 'required',
  724. ]);
  725. if ($validator->fails()) {
  726. return $this->responseController->makeResponse(
  727. true,
  728. "ERR_PROVIDER_REG000: Se encontraron uno o más errores.",
  729. $this->responseController->makeErrors($validator->errors()->messages()),
  730. 401
  731. );
  732. }
  733. DB::beginTransaction();
  734. $requestData = $request->all();
  735. $line = $requestData['line'];
  736. try {
  737. $user = $this->encController->decrypt($requestData['user']);
  738. } catch (\Throwable $th) {
  739. DB::rollBack();
  740. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  741. }
  742. $arrInformationPersonal = (array) $requestData['obj_response']['INFORMACION'];
  743. $arrReferences = (array) $requestData['obj_response']['REFERENCIAS'];
  744. $arrContacts = (array) $requestData['obj_response']['CONTACTOS'];
  745. $arrConditions = (array) $requestData['obj_response']['CONDICIONES'];
  746. $arrPaymentMedia = (array) $requestData['obj_response']['METODOS_PAGO'];
  747. $arrCatalogs = (array) $requestData['obj_response']['CATALAGOS'];
  748. $now = $this->functionsController->now();
  749. $currentDate = $now->toDateTimeString();
  750. $arrPaymentTemp = array();
  751. foreach ($arrPaymentMedia as $payment) {
  752. $arrPaymentTemp[$payment['MEPA_IDME']] = $payment['MEPA_NOMB'];
  753. }
  754. try {
  755. $strPayment = json_encode($arrPaymentTemp);
  756. } catch (\Throwable $th) {
  757. DB::rollBack();
  758. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG002: Ocurrió un error al obtener los métodos de pago del proveedor.", $th->getMessage(), 500);
  759. }
  760. $idSubcontract = null;
  761. if (!is_null($arrInformationPersonal['ID_SUBCONTRACT'])) {
  762. $idSubcontract = $arrInformationPersonal['ID_SUBCONTRACT'];
  763. try {
  764. $validateSubcontract = DB::table('S002V01TPESU')
  765. ->where('PESU_IDPS', '=', $idSubcontract)
  766. ->where('PESU_NULI', '=', $line)
  767. ->exists();
  768. } catch (\Throwable $th) {
  769. DB::rollBack();
  770. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG003: Ocurrió un error al validar que el subcontratista exista.", $th->getMessage(), 500);
  771. }
  772. if (!$validateSubcontract) {
  773. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG004: El subcontratista no existe.", [], 500);
  774. }
  775. }
  776. try {
  777. $idProdiver = DB::table('S002V01TPROV')->insertGetId([
  778. 'PROV_NOCO' => $arrInformationPersonal['RAZON_SOCIAL'],
  779. 'PROV_IDPS' => $idSubcontract,
  780. 'PROV_NOMB' => $arrInformationPersonal['NOMBRE'],
  781. 'PROV_APPA' => $arrInformationPersonal['PRIMER_APELLIDO'],
  782. 'PROV_APMA' => $arrInformationPersonal['SEGUNDO_APELLIDO'] != '' ? $arrInformationPersonal['SEGUNDO_APELLIDO'] : null,
  783. 'PROV_CORR' => $arrInformationPersonal['CORREO'],
  784. 'PROV_LAD1' => $arrInformationPersonal['LADA1'],
  785. 'PROV_TEL1' => $arrInformationPersonal['TELEFONO1'],
  786. 'PROV_LAD2' => $arrInformationPersonal['LADA2'],
  787. 'PROV_TEL2' => $arrInformationPersonal['TELEFONO2'] != '' ? $arrInformationPersonal['TELEFONO2'] : null,
  788. 'PROV_TICO' => $arrInformationPersonal['TIPO_CONTRIBUYENTE'],
  789. 'PROV_XRFC' => $arrInformationPersonal['RFC'],
  790. 'PROV_XTAX' => $arrInformationPersonal['TAXID'] != '' ? $arrInformationPersonal['TAXID'] : null,
  791. 'PROV_CRFI' => $arrInformationPersonal['REGIMEN_FISCAL'],
  792. 'PROV_TIPO' => $arrInformationPersonal['TIPO'],
  793. 'PROV_SIWE' => $arrInformationPersonal['SITIOWEB'],
  794. 'PROV_CALL' => $arrInformationPersonal['CALLE'],
  795. 'PROV_NUEX' => $arrInformationPersonal['EXTERIOR'],
  796. 'PROV_NUIN' => $arrInformationPersonal['INTERIOR'] != '' ? $arrInformationPersonal['INTERIOR'] : null,
  797. 'PROV_COPO' => $arrInformationPersonal['CODIGO_POSTAL'],
  798. 'PROV_COLO' => $arrInformationPersonal['COLONIA'],
  799. 'PROV_LOCA' => $arrInformationPersonal['LOCALIDAD'] === 'Sin localidad' ? null : $arrInformationPersonal['LOCALIDAD'],
  800. 'PROV_MUNI' => $arrInformationPersonal['MUNICIPIO'],
  801. 'PROV_ENTI' => $arrInformationPersonal['ENTIDAD'],
  802. 'PROV_PAIS' => $arrInformationPersonal['PAIS'],
  803. 'PROV_MEPA' => $strPayment,
  804. 'PROV_NULI' => $line,
  805. 'PROV_USRE' => $user,
  806. 'PROV_FERE' => $currentDate,
  807. 'PROV_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  808. ]);
  809. } catch (\Throwable $th) {
  810. DB::rollBack();
  811. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG005: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  812. }
  813. if ( !is_null($idSubcontract )) {
  814. try {
  815. $validateUpdateSubcontract = DB::table('S002V01TPESU')
  816. ->where('PESU_IDPS', '=', $idSubcontract)
  817. ->where('PESU_NULI', '=', $line)
  818. ->update([
  819. 'PESU_NUPR' => $idProdiver,
  820. 'PESU_USMO' => $user,
  821. 'PESU_FEMO' => $currentDate,
  822. 'PESU_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  823. ]);
  824. } catch (\Throwable $th) {
  825. DB::rollBack();
  826. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG006: Ocurrió un error enlazar el proveedor con el subcontratista.", $th->getMessage(), 500);
  827. }
  828. if (!$validateUpdateSubcontract) {
  829. DB::rollBack();
  830. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG007: No se pudo enlazar el proveedor con el subcontratista.", [], 500);
  831. }
  832. }
  833. foreach ($arrReferences as $references) {
  834. if ($references['ESTADO'] == 'Activo' || $references['ESTADO'] == 'Nuevo') {
  835. $insertReferences = [
  836. 'PRRE_NUPR' => $idProdiver,
  837. 'PRRE_EMPR' => $references['RAZON_SOCIAL'],
  838. 'PRRE_CORR' => $references['CORREO'],
  839. 'PRRE_LADA' => $references['LADA'],
  840. 'PRRE_TELE' => $references['TELEFONO'],
  841. 'PRRE_XRFC' => $references['RFC'],
  842. 'PRRE_DIRE' => $references['DIRECCION'],
  843. 'PRRE_NULI' => $line,
  844. 'PRRE_USRE' => $user,
  845. 'PRRE_FERE' => $currentDate,
  846. 'PRRE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  847. ];
  848. try {
  849. $resp = DB::table('S002V01TPRRE')->insert($insertReferences);
  850. if (!$resp) {
  851. DB::rollBack();
  852. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG008: Ocurrió un error al obtener el contenido.", [], 500);
  853. }
  854. } catch (\Throwable $th) {
  855. DB::rollBack();
  856. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG009: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  857. }
  858. }
  859. }
  860. foreach ($arrContacts as $contacts) {
  861. if ($contacts['ESTADO'] == 'Activo' || $contacts['ESTADO'] == 'Nuevo') {
  862. $insertContacts = [
  863. 'PRCO_NUPR' => $idProdiver,
  864. 'PRCO_NOMB' => $contacts['NOMBRE_CONTACTO'],
  865. 'PRCO_TIPO' => $contacts['TIPO_CONTACTO'],
  866. 'PRCO_CALL' => $contacts['CALLE'],
  867. 'PRCO_NUEX' => $contacts['NUMERO_EXTERIOR'],
  868. 'PRCO_NUIN' => $contacts['NUMERO_INTERIOR'] != '' ? $contacts['NUMERO_INTERIOR'] : null,
  869. 'PRCO_COPO' => $contacts['CODIGO_POSTAL'],
  870. 'PRCO_LOCA' => $contacts['LOCALIDAD'],
  871. 'PRCO_COLO' => $contacts['COLONIA'],
  872. 'PRCO_MUNI' => $contacts['MUNICIPIO'],
  873. 'PRCO_ENTI' => $contacts['ENTIDAD'],
  874. 'PRCO_PAIS' => $contacts['PAIS'],
  875. 'PRCO_LAD1' => $contacts['LADA1'],
  876. 'PRCO_TEL1' => $contacts['TELEFONO1'],
  877. 'PRCO_LAD2' => $contacts['LADA2'] != '' ? $contacts['LADA2'] : null,
  878. 'PRCO_TEL2' => $contacts['TELEFONO2'] != '' ? $contacts['TELEFONO2'] : null,
  879. 'PRCO_COR1' => $contacts['CORREO1'],
  880. 'PRCO_COR2' => $contacts['CORREO2'] != '' ? $contacts['CORREO2'] : null,
  881. 'PRCO_OBSE' => $contacts['OBSERVACIONES'],
  882. 'PRCO_NULI' => $line,
  883. 'PRCO_USRE' => $user,
  884. 'PRCO_FERE' => $currentDate,
  885. 'PRCO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  886. ];
  887. try {
  888. $resp = DB::table('S002V01TPRCO')->insert($insertContacts);
  889. if (!$resp) {
  890. DB::rollBack();
  891. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG010: Ocurrió un error al obtener el contenido.", [], 500);
  892. }
  893. } catch (\Throwable $th) {
  894. DB::rollBack();
  895. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG011: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  896. }
  897. }
  898. }
  899. foreach ($arrConditions as $conditions) {
  900. if ($conditions['ESTADO'] == 'Activo') {
  901. $insertConditions = [
  902. 'PRCN_NUPR' => $idProdiver,
  903. 'PRCN_TIPO' => $conditions['TIPO_CONDICION'],
  904. 'PRCN_INFO' => $conditions['INFORMACION'],
  905. 'PRCN_NULI' => $line,
  906. 'PRCN_USRE' => $user,
  907. 'PRCN_FERE' => $currentDate,
  908. 'PRCN_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  909. ];
  910. try {
  911. $resp = DB::table('S002V01TPRCN')->insert($insertConditions);
  912. if (!$resp) {
  913. DB::rollBack();
  914. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG012: Ocurrió un error al obtener el contenido.", [], 500);
  915. }
  916. } catch (\Throwable $th) {
  917. DB::rollBack();
  918. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  919. }
  920. }
  921. }
  922. foreach ($arrCatalogs as $catalogs) {
  923. if ($catalogs['ESTADO'] == 'Activo' || $catalogs['ESTADO'] == 'Nuevo') {
  924. $insertCatalogs = [
  925. 'PRCE_NUPR' => $idProdiver,
  926. 'PRCE_CATA' => $catalogs['CATALAGO'],
  927. 'PRCE_DESC' => $catalogs['DESCRIPCION'],
  928. 'PRCE_XURL' => $catalogs['URL_CATALAGO'],
  929. 'PRCE_NULI' => $line,
  930. 'PRCE_USRE' => $user,
  931. 'PRCE_FERE' => $currentDate,
  932. 'PRCE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  933. ];
  934. try {
  935. $resp = DB::table('S002V01TPRCE')->insert($insertCatalogs);
  936. if (!$resp) {
  937. DB::rollBack();
  938. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG014: Ocurrió un error al obtener el contenido.", [], 500);
  939. }
  940. } catch (\Throwable $th) {
  941. DB::rollBack();
  942. return $this->responseController->makeResponse(true, "ERR_PROVIDER_REG015: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  943. }
  944. }
  945. }
  946. $response = [ 'idProvider' => $idProdiver ];
  947. DB::commit();
  948. return $this->responseController->makeResponse(false, "EXITO: Registro Exitoso", $response);
  949. }
  950. public function deleteProvider(Request $request) {
  951. $validator = Validator::make($request->all(), [
  952. 'line' => 'required|string',
  953. 'user' => 'required|string',
  954. 'numero_proveedor' => 'required|string'
  955. ]);
  956. if ($validator->fails()) {
  957. return $this->responseController->makeResponse(
  958. true,
  959. "ERR_PROVIDER_DEL000: Se encontraron uno o más errores.",
  960. $this->responseController->makeErrors($validator->errors()->messages()),
  961. 401
  962. );
  963. }
  964. DB::beginTransaction();
  965. $requestData = $request->all();
  966. $now = $this->functionsController->now();
  967. $currentDate = $now->toDateTimeString();
  968. $line = $requestData['line'];
  969. try {
  970. $numeroProveedor = $this->encController->decrypt($requestData['numero_proveedor']);
  971. } catch (\Throwable $th) {
  972. DB::rollBack();
  973. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL001: Ocurrió un error al obtener el número del proveedor.", $th->getMessage(), 500);
  974. }
  975. try {
  976. $user = $this->encController->decrypt($requestData['user']);
  977. } catch (\Throwable $th) {
  978. DB::rollBack();
  979. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL002: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  980. }
  981. $update = [
  982. 'PROV_ESTA' => 'Eliminado',
  983. 'PROV_USMO' => $user,
  984. 'PROV_FEMO' => $currentDate,
  985. 'PROV_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  986. ];
  987. try {
  988. $resp = DB::table('S002V01TPROV')->where('PROV_NUPR', '=', $numeroProveedor)->where('PROV_NULI', '=', $line)->update($update);
  989. if (!$resp) {
  990. DB::rollBack();
  991. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL003: Ocurrió un error al obtener el contenido. ", [], 500);
  992. }
  993. } catch (\Throwable $th) {
  994. DB::rollBack();
  995. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL004: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  996. }
  997. try {
  998. $resp = DB::table('S002V01TPRRE')
  999. ->where('PRRE_NUPR', '=', $numeroProveedor)
  1000. ->where('PRRE_NULI', '=', $line)
  1001. ->update([
  1002. 'PRRE_ESTA' => 'Eliminado',
  1003. 'PRRE_USMO' => $user,
  1004. 'PRRE_FEMO' => $currentDate,
  1005. 'PRRE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1006. ]);
  1007. } catch (\Throwable $th) {
  1008. DB::rollBack();
  1009. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL006: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1010. }
  1011. try {
  1012. $resp = DB::table('S002V01TPRCO')
  1013. ->where('PRCO_NUPR', '=', $numeroProveedor)
  1014. ->where('PRCO_NULI', '=', $line)
  1015. ->update([
  1016. 'PRCO_ESTA' => 'Eliminado',
  1017. 'PRCO_USMO' => $user,
  1018. 'PRCO_FEMO' => $currentDate,
  1019. 'PRCO_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1020. ]);
  1021. } catch (\Throwable $th) {
  1022. DB::rollBack();
  1023. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL008: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1024. }
  1025. try {
  1026. $resp = DB::table('S002V01TPRCN')
  1027. ->where('PRCN_NUPR', '=', $numeroProveedor)
  1028. ->where('PRCN_NULI', '=', $line)
  1029. ->update([
  1030. 'PRCN_ESTA' => 'Eliminado',
  1031. 'PRCN_USMO' => $user,
  1032. 'PRCN_FEMO' => $currentDate,
  1033. 'PRCN_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1034. ]);
  1035. } catch (\Throwable $th) {
  1036. DB::rollBack();
  1037. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL010: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1038. }
  1039. try {
  1040. $resp = DB::table('S002V01TPRCE')
  1041. ->where('PRCE_NUPR', '=', $numeroProveedor)
  1042. ->where('PRCE_NULI', '=', $line)
  1043. ->update([
  1044. 'PRCE_ESTA' => 'Eliminado',
  1045. 'PRCE_USMO' => $user,
  1046. 'PRCE_FEMO' => $currentDate,
  1047. 'PRCE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1048. ]);
  1049. } catch (\Throwable $th) {
  1050. DB::rollBack();
  1051. return $this->responseController->makeResponse(true, "ERR_PROVIDER_DEL012: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1052. }
  1053. DB::commit();
  1054. return $this->responseController->makeResponse(false, "EXITO: Eliminación correcta",);
  1055. }
  1056. public function getProviderByArtitle(Request $request) {
  1057. $validator = Validator::make($request->all(), [
  1058. 'NUMERO_ARTICULO' => 'required|string',
  1059. 'NUMERO_LINEA' => 'required|string',
  1060. ]);
  1061. if ($validator->fails()) {
  1062. return $this->responseController->makeResponse(
  1063. true,
  1064. "ERR_PROVIDER_GETBYARTITLE000: Se encontraron uno o más errores.",
  1065. $this->responseController->makeErrors($validator->errors()->messages()),
  1066. 401
  1067. );
  1068. }
  1069. $response = $request->all();
  1070. $numeroArticulo = $this->encController->decrypt($response['NUMERO_ARTICULO']);
  1071. try {
  1072. $arrDescription = DB::table('S002V01TDEAR')
  1073. ->where('DEAR_ESTA', '=', 'Activo')
  1074. ->where('DEAR_IDAR', '=', $numeroArticulo)
  1075. ->join('S002V01TPROV', 'DEAR_NUPR', '=', 'PROV_NUPR')
  1076. ->get([
  1077. 'DEAR_IDDE AS NUMERO_DESCRIPTION',
  1078. 'PROV_NUPR AS NUMERO_PROVEEDOR',
  1079. 'PROV_NOCO AS RAZON_SOCIAL',
  1080. 'PROV_NOMB AS NOMBRE',
  1081. 'PROV_APPA AS PRIMER_APELLIDO',
  1082. 'PROV_APMA AS SEGUNDO_APELLIDO',
  1083. 'PROV_CORR AS CORREO',
  1084. 'PROV_LAD1 AS LADA1',
  1085. 'PROV_TEL1 AS TELEFONO1',
  1086. 'PROV_LAD2 AS LADA2',
  1087. 'PROV_TEL2 AS TELEFONO2',
  1088. 'PROV_TICO AS TIPO_CONTRIBUYENTE',
  1089. 'PROV_XRFC AS RFC',
  1090. 'PROV_XTAX AS TAXID',
  1091. 'PROV_CRFI AS REGIMEN_FISCAL',
  1092. 'PROV_TIPO AS TIPO',
  1093. 'PROV_SIWE AS SITIOWEB',
  1094. 'PROV_MEPA AS METODO_PAGO',
  1095. 'PROV_ESTA AS ESTADO',
  1096. 'PROV_USRE AS USUARIO_REGISTRA',
  1097. 'PROV_FERE AS FECHA_REGISTRA',
  1098. 'PROV_USMO AS USUARIO_MODIFICA',
  1099. 'PROV_FEMO AS FECHA_MODIFICA',
  1100. ]);
  1101. } catch (\Throwable $th) {
  1102. return $this->responseController->makeResponse(true, "ERR_PROVIDER_GETBYARTITLE001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1103. }
  1104. return $this->responseController->makeResponse(false, "ÉXITO", $arrDescription);
  1105. }
  1106. public function getArtitlesByProvider($encProvider, $user, $line) {
  1107. DB::beginTransaction();
  1108. // Se obtiene el número del proveedor
  1109. try {
  1110. $provider = $this->encController->decrypt($encProvider);
  1111. } catch (\Throwable $th) {
  1112. DB::rollBack();
  1113. return $this->responseController->makeResponse(
  1114. true,
  1115. "ERR_ARTITLES_PROVIDER_GET000: Ocurrió un error al obtener el número del proveedor.",
  1116. $th->getMessage(),
  1117. 500
  1118. );
  1119. }
  1120. // Verifica su existe el proveedor
  1121. try {
  1122. $validateExist = DB::table('S002V01TPROV')
  1123. ->where('PROV_NUPR', '=', $provider)
  1124. ->where('PROV_NULI', '=', $line)
  1125. ->exists();
  1126. } catch (\Throwable $th) {
  1127. DB::rollBack();
  1128. return $this->responseController->makeResponse(
  1129. true,
  1130. "ERR_ARTITLES_PROVIDER_GET001: Ocurrió un error al identificar el proveedor.",
  1131. $th->getMessage(),
  1132. 500
  1133. );
  1134. }
  1135. // Valida si existe el proveedor
  1136. if (!$validateExist) {
  1137. DB::rollBack();
  1138. return $this->responseController->makeResponse(
  1139. true,
  1140. "ERR_ARTITLES_PROVIDER_GET002: El proveedor no existe",
  1141. [],
  1142. 500
  1143. );
  1144. }
  1145. // Obtiene todos las descripciones de los artículos del proveedor
  1146. try {
  1147. $getDescriptionArtitles = DB::table('S002V01TDEAR')
  1148. ->where('DEAR_NUPR', '=', $provider)
  1149. ->where('DEAR_NULI', '=', $line)
  1150. ->where('DEAR_ESTA', '=', 'Activo')
  1151. ->get([
  1152. 'DEAR_IDDE', # Identificador de la descripción
  1153. 'DEAR_IMAG', # Imagenes de los artículos
  1154. 'DEAR_DESC', # Descripción del artículo
  1155. 'DEAR_CARA', # Características del artículo
  1156. 'DEAR_COWE', # Compra web
  1157. 'DEAR_IDUN', # Identificador del tipo de unidad
  1158. 'DEAR_IDAR', # Identificador del artículo principal
  1159. 'DEAR_USRE', # Usuario de registro
  1160. 'DEAR_FERE', # Fecha de registro
  1161. 'DEAR_USMO', # Usuario de modificación
  1162. 'DEAR_FEMO', # Fecha de modificación
  1163. ]);
  1164. } catch (\Throwable $th) {
  1165. DB::rollBack();
  1166. return $this->responseController->makeResponse(true, "ERR_ARTITLES_PROVIDER_GET003: El proveedor no existe", $th->getMessage(), 500);
  1167. }
  1168. // El resultado pasa a ser un arreglo
  1169. $arrDescriptionArtitles = json_decode(json_encode($getDescriptionArtitles), true);
  1170. $arrDescription = array();
  1171. foreach ($arrDescriptionArtitles as $keyDescription => $descriptionArtitle) {
  1172. // Obtiene las imagenes y las pasa a un arreglo
  1173. $arrImages = json_decode($descriptionArtitle['DEAR_IMAG']);
  1174. $arrUrlImage = array();
  1175. foreach ($arrImages as $keyImages => $images) {
  1176. $responseDocument = $this->documentManagementController->getPublicDocumentURL($images, $user, $line);
  1177. $arrResponseDocument = json_decode($responseDocument->original, true);
  1178. if ($arrResponseDocument['error']) {
  1179. return $this->responseController->makeResponse(true, "ERR_ARTITLES_PROVIDER_GET004: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1180. }
  1181. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  1182. }
  1183. $descriptionArtitle['DEAR_IMAG'] = $arrUrlImage;
  1184. // Obtiene la información principal del artículo
  1185. try {
  1186. $objArtitle = DB::table('S002V01TARTI')
  1187. ->where('ARTI_IDAR', '=', $descriptionArtitle['DEAR_IDAR'])
  1188. ->where('ARTI_NULI', '=', $line)
  1189. ->where('ARTI_ESTA', '=', 'Activo')
  1190. ->join('S002V01TFAMI', 'ARTI_COFA', '=', 'FAMI_COFA')
  1191. ->join('S002V01TSUBF', 'ARTI_COSU', '=', 'SUBF_COSU')
  1192. ->first([
  1193. 'ARTI_IDAR', # Identificador del artículo
  1194. 'ARTI_COFA', # Identificador de la familia del artículo
  1195. 'FAMI_NOFA', # Nombre de la familia del artículo
  1196. 'ARTI_COSU', # Identificador de la subfamilia del artículo
  1197. 'SUBF_NOSU', # Nombre de la subfamilia del artículo
  1198. 'ARTI_CODI', # Código de barras del artículo
  1199. 'ARTI_NOMB', # Nombre principal del artículo
  1200. // 'ARTI_USRE', # Usuario de registro
  1201. // 'ARTI_FERE', # Fecha de registro
  1202. // 'ARTI_USMO', # Usuario de modificación
  1203. // 'ARTI_FEMO', # Fecha de modificación
  1204. ]);
  1205. } catch (\Throwable $th) {
  1206. DB::rollBack();
  1207. return $this->responseController->makeResponse(true, "ERR_ARTITLES_PROVIDER_GET005: Ocurrió un error al obtener la información del artículo.", $th->getMessage(), 500);
  1208. }
  1209. // La información es guardada en el arreglo de respuesta
  1210. foreach ($objArtitle as $keyArtitle => $artitle) {
  1211. $descriptionArtitle[$keyArtitle] = $artitle;
  1212. }
  1213. // Se obtiene la unidad del artículo
  1214. try {
  1215. $objUnit = DB::table('S002V01TUNID')
  1216. ->where('UNID_IDUN', '=', $descriptionArtitle['DEAR_IDUN'])
  1217. ->where('UNID_NULI', '=', $line)
  1218. ->where('UNID_ESTA', '=', 'Activo')
  1219. ->first([
  1220. 'UNID_IDUN', # Identificador de la unidad
  1221. 'UNID_NOMB', # Nombre de la unidad
  1222. 'UNID_ACRO', # Acrónimo de la unidad
  1223. 'UNID_USRE', # Usuario de registro
  1224. 'UNID_FERE', # Fecha de registro
  1225. 'UNID_USMO', # Usuario de modificación
  1226. 'UNID_FEMO', # Fecha de modificación
  1227. ]);
  1228. } catch (\Throwable $th) {
  1229. DB::rollBack();
  1230. return $this->responseController->makeResponse(
  1231. true,
  1232. "ERR_ARTITLES_PROVIDER_GET006: Ocurrió un error al obtener el tipo de unidad.",
  1233. $th->getMessage(),
  1234. 500
  1235. );
  1236. }
  1237. // La información es guardada en el arreglo de respuesta
  1238. $descriptionArtitle['DEAR_IDUN'] = $objUnit;
  1239. // Se obtienen los detalles de la descripción
  1240. try {
  1241. $getDetailsDescription = DB::table('S002V01TINAR')
  1242. ->where('INAR_IDDE', '=', $descriptionArtitle['DEAR_IDDE'])
  1243. ->where('INAR_NULI', '=', $line)
  1244. ->where('INAR_ESTA', '=', 'Activo')
  1245. ->get([
  1246. 'INAR_IDIN', # Identificador de los detalles
  1247. 'INAR_CODI', # Código del artículo
  1248. 'INAR_MODE', # Módelo del artículo
  1249. 'INAR_COMO', # Tipo de moneda
  1250. 'INAR_PREC', # Precio unitario del artículo
  1251. 'INAR_MOMI', # Mónto mínimo
  1252. 'INAR_CARA', # Características
  1253. 'INAR_USRE', # Usuario de registro
  1254. 'INAR_FERE', # Fecha de registro
  1255. 'INAR_USMO', # Usuario de modificación
  1256. 'INAR_FEMO', # Fecha de modificación
  1257. ]);
  1258. } catch (\Throwable $th) {
  1259. DB::rollBack();
  1260. return $this->responseController->makeResponse(
  1261. true,
  1262. "ERR_ARTITLES_PROVIDER_GET007: Ocurrió un error al obtener los detalles de la descripción del artículo.",
  1263. $th->getMessage(),
  1264. 500
  1265. );
  1266. }
  1267. // La información es guardada en el arreglo de respuesta
  1268. $descriptionArtitle['DETAILS'] = $getDetailsDescription;
  1269. // Se almacen el arreglo de respuesta en el arreglo principal
  1270. $arrDescription[] = $descriptionArtitle;
  1271. }
  1272. DB::commit(); # Para guardar los cambios en la base de datos
  1273. return $this->responseController->makeResponse(false, "ÉXITO: Consulta exitosa", $arrDescription);
  1274. }
  1275. public function downloadArtitlesByProvider(Request $request) {
  1276. $validator = Validator::make($request->all(), [
  1277. 'PROVIDER' => 'required|string',
  1278. 'USER' => 'required|string',
  1279. 'LINE_NUMBER' => 'required|string',
  1280. 'DOWNLOAD' => 'required|array',
  1281. ]);
  1282. if ($validator->fails()) {
  1283. return $this->responseController->makeResponse(
  1284. true,
  1285. "ERR_DOWNLOAD_ARTITLE_DOW000: Se encontraron uno o más errores.",
  1286. $this->responseController->makeErrors($validator->errors()->messages()),
  1287. 401
  1288. );
  1289. }
  1290. $responseData = $request->all();
  1291. try {
  1292. $user = $this->encController->decrypt($responseData['USER']);
  1293. } catch (\Throwable $th) {
  1294. DB::rollBack();
  1295. return $this->responseController->makeResponse(true, "ERR_DOWNLOAD_ARTITLE_DOW001: No se pudo obtener los datos del usuario", $th->getMessage(), 500);
  1296. }
  1297. // Verifica su existe el proveedor
  1298. try {
  1299. $validateExist = DB::table('S002V01TPROV')
  1300. ->where('PROV_NUPR', '=', $responseData['PROVIDER'])
  1301. ->where('PROV_NULI', '=', $responseData['LINE_NUMBER'])
  1302. ->exists();
  1303. } catch (\Throwable $th) {
  1304. DB::rollBack();
  1305. return $this->responseController->makeResponse(
  1306. true,
  1307. "ERR_DOWNLOAD_ARTITLE_DOW002: Ocurrió un error al identificar el proveedor.",
  1308. $th->getMessage(),
  1309. 500
  1310. );
  1311. }
  1312. // Valida si existe el proveedor
  1313. if (!$validateExist) {
  1314. DB::rollBack();
  1315. return $this->responseController->makeResponse(true, "ERR_DOWNLOAD_ARTITLE_DOW003: El proveedor no existe", [], 500);
  1316. }
  1317. $arrDescriptionId = $responseData['DOWNLOAD'];
  1318. $arrDataArtitles = array();
  1319. foreach ($arrDescriptionId as $keyId => $idDescription) {
  1320. // Obtiene todos las descripciones de los artículos del proveedor
  1321. try {
  1322. $getDescriptionArtitles = DB::table('S002V01TDEAR')
  1323. ->where('DEAR_IDDE', '=', $idDescription)
  1324. ->where('DEAR_NUPR', '=', $responseData['PROVIDER'])
  1325. ->where('DEAR_NULI', '=', $responseData['LINE_NUMBER'])
  1326. ->where('DEAR_ESTA', '=', 'Activo')
  1327. ->first([
  1328. 'DEAR_IDDE', # Identificador de la descripción
  1329. 'DEAR_IMAG', # Imagenes de los artículos
  1330. 'DEAR_DESC', # Descripción del artículo
  1331. 'DEAR_CARA', # Características del artículo
  1332. 'DEAR_COWE', # Compra web
  1333. 'DEAR_IDUN', # Identificador del tipo de unidad
  1334. 'DEAR_IDAR', # Identificador del artículo principal
  1335. 'DEAR_USRE', # Usuario de registro
  1336. 'DEAR_FERE', # Fecha de registro
  1337. 'DEAR_USMO', # Usuario de modificación
  1338. 'DEAR_FEMO', # Fecha de modificación
  1339. ]);
  1340. } catch (\Throwable $th) {
  1341. DB::rollBack();
  1342. return $this->responseController->makeResponse(true, "ERR_DOWNLOAD_ARTITLE_DOW004: El proveedor no existe", $th->getMessage(), 500);
  1343. }
  1344. $arrDescriptionArtitles = (array) $getDescriptionArtitles;
  1345. // Obtiene la información principal del artículo
  1346. try {
  1347. $objArtitle = DB::table('S002V01TARTI')
  1348. ->where('ARTI_IDAR', '=', $arrDescriptionArtitles['DEAR_IDAR'])
  1349. ->where('ARTI_NULI', '=', $responseData['LINE_NUMBER'])
  1350. ->where('ARTI_ESTA', '=', 'Activo')
  1351. ->join('S002V01TFAMI', 'ARTI_COFA', '=', 'FAMI_COFA')
  1352. ->join('S002V01TSUBF', 'ARTI_COSU', '=', 'SUBF_COSU')
  1353. ->first([
  1354. 'ARTI_IDAR', # Identificador del artículo
  1355. 'ARTI_COFA', # Identificador de la familia del artículo
  1356. 'FAMI_NOFA', # Nombre de la familia del artículo
  1357. 'ARTI_COSU', # Identificador de la subfamilia del artículo
  1358. 'SUBF_NOSU', # Nombre de la subfamilia del artículo
  1359. 'ARTI_CODI', # Código de barras del artículo
  1360. 'ARTI_NOMB', # Nombre principal del artículo
  1361. ]);
  1362. } catch (\Throwable $th) {
  1363. DB::rollBack();
  1364. return $this->responseController->makeResponse(
  1365. true,
  1366. "ERR_DOWNLOAD_ARTITLE_DOW005: Ocurrió un error al obtener la información del artículo.",
  1367. $th->getMessage(),
  1368. 500
  1369. );
  1370. }
  1371. $objArtitle = (array) $objArtitle;
  1372. // La información es guardada en el arreglo de respuesta
  1373. foreach ($objArtitle as $keyArtitle => $artitle) {
  1374. $arrDescriptionArtitles[$keyArtitle] = $artitle;
  1375. }
  1376. // Se obtiene la unidad del artículo
  1377. try {
  1378. $objUnit = DB::table('S002V01TUNID')
  1379. ->where('UNID_IDUN', '=', $arrDescriptionArtitles['DEAR_IDUN'])
  1380. ->where('UNID_NULI', '=', $responseData['LINE_NUMBER'])
  1381. ->where('UNID_ESTA', '=', 'Activo')
  1382. ->first([
  1383. 'UNID_IDUN', # Identificador de la unidad
  1384. 'UNID_NOMB', # Nombre de la unidad
  1385. 'UNID_ACRO', # Acrónimo de la unidad
  1386. ]);
  1387. } catch (\Throwable $th) {
  1388. DB::rollBack();
  1389. return $this->responseController->makeResponse(
  1390. true,
  1391. "ERR_DOWNLOAD_ARTITLE_DOW006: Ocurrió un error al obtener el tipo de unidad.",
  1392. $th->getMessage(),
  1393. 500
  1394. );
  1395. }
  1396. // La información es guardada en el arreglo de respuesta
  1397. $arrDescriptionArtitles['DEAR_IDUN'] = $objUnit;
  1398. // Se obtienen los detalles de la descripción
  1399. try {
  1400. $getDetailsDescription = DB::table('S002V01TINAR')
  1401. ->where('INAR_IDDE', '=', $idDescription)
  1402. ->where('INAR_NULI', '=', $responseData['LINE_NUMBER'])
  1403. ->where('INAR_ESTA', '=', 'Activo')
  1404. ->get([
  1405. 'INAR_IDIN', # Identificador de los detalles
  1406. 'INAR_CODI', # Código del artículo
  1407. 'INAR_MODE', # Módelo del artículo
  1408. 'INAR_MONE', # Tipo de moneda
  1409. 'INAR_PREC', # Precio unitario del artículo
  1410. 'INAR_MOMI', # Mónto mínimo
  1411. 'INAR_CARA', # Características
  1412. 'INAR_USRE', # Usuario de registro
  1413. 'INAR_FERE', # Fecha de registro
  1414. 'INAR_USMO', # Usuario de modificación
  1415. 'INAR_FEMO', # Fecha de modificación
  1416. ]);
  1417. } catch (\Throwable $th) {
  1418. DB::rollBack();
  1419. return $this->responseController->makeResponse(
  1420. true,
  1421. "ERR_DOWNLOAD_ARTITLE_DOW007: Ocurrió un error al obtener los detalles de la descripción del artículo.",
  1422. $th->getMessage(),
  1423. 500
  1424. );
  1425. }
  1426. $arrDetailsDescription = json_decode(json_encode($getDetailsDescription), true);
  1427. $arrDescriptionArtitles['DETAILS'] = $arrDetailsDescription;
  1428. $arrDataArtitles[] = $arrDescriptionArtitles;
  1429. }
  1430. // Se inicializa el nombre del documento
  1431. $nameDocument = "CONTENT_ARTITLE_BY_".$responseData['PROVIDER'].".xlsx";
  1432. // Se crea el documento y se obtiene el base64 del documento
  1433. $base64Document = $this->createDocument($arrDataArtitles);
  1434. // Se guarda el documento y se genera el código del documento
  1435. $arrResponseDocument = $this->resourcesController->saveDocument($base64Document, 'GEAD', $nameDocument, 'IN', $responseData['LINE_NUMBER']);
  1436. if ( $arrResponseDocument['error'] ) {
  1437. DB::rollBack();
  1438. return $this->responseController->makeResponse(
  1439. true,
  1440. 'ERR_DOWNLOAD_ARTITLE_DOW008:'.$arrResponseDocument['msg'], $arrResponseDocument['response'],
  1441. 500
  1442. );
  1443. }
  1444. // Se obtiene el código del documento
  1445. $codeDocument = $arrResponseDocument['response'];
  1446. $now = $this->functionsController->now();
  1447. $currentDate = $now->toDateTimeString();
  1448. try {
  1449. $validaeInsert = DB::table('S002V01TPRDO')->insert([
  1450. 'PRDO_NUPR' => $responseData['PROVIDER'],
  1451. 'PRDO_CODU' => $codeDocument,
  1452. 'PRDO_TIPO' => 'IN',
  1453. 'PRDO_DESC' => 'GENERACIÓN DE DOCUMENTO DE ARTÍCULOS POR PROVEEDOR',
  1454. 'PRDO_NULI' => $responseData['LINE_NUMBER'],
  1455. 'PRDO_USRE' => $user,
  1456. 'PRDO_FERE' => $currentDate,
  1457. 'PRDO_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1458. ]);
  1459. } catch (\Throwable $th) {
  1460. DB::rollBack();
  1461. return $this->responseController->makeResponse(true, "ERR_DOWNLOAD_ARTITLE_DOW009: Ocurrió un error al registrar el documento.", $th->getMessage(), 500);
  1462. }
  1463. if (!$validaeInsert) {
  1464. DB::rollBack();
  1465. return $this->responseController->makeResponse(true, "ERR_DOWNLOAD_ARTITLE_DOW010: No se pudo registrar el documento en la base de datos", [], 500);
  1466. }
  1467. DB::commit(); # Para guardar los cambios en la base de datos
  1468. return $this->responseController->makeResponse(false, "ÉXITO: Se genero correctamente.", $codeDocument);
  1469. }
  1470. public function generateSheetProviderXLS($encProvider, $typeUser, $user, $line) {
  1471. try {
  1472. $idProvider = $this->encController->decrypt($encProvider);
  1473. } catch (\Throwable $th) {
  1474. DB::rollBack();
  1475. return $this->responseController->makeResponse(
  1476. true,
  1477. "ERR_PROVIDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  1478. $th->getMessage(),
  1479. 500
  1480. );
  1481. }
  1482. try {
  1483. $user = $this->encController->decrypt($user);
  1484. } catch (\Throwable $th) {
  1485. DB::rollBack();
  1486. return $this->responseController->makeResponse(
  1487. true,
  1488. "ERR_PROVIDER_SHEET001: Ocurrió un error al obtener el usuario.",
  1489. $th->getMessage(),
  1490. 500
  1491. );
  1492. }
  1493. if ($typeUser === 'P') {
  1494. try {
  1495. $arrProvider = (array) DB::table('S002V01TPROV')
  1496. ->where('PROV_NUPR', '=', $idProvider)
  1497. ->where('PROV_NULI', '=', $line)
  1498. ->where('REFI_NULI', '=', $line)
  1499. ->where('REFI_ESTA', '=', 'Activo')
  1500. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  1501. ->first([
  1502. 'PROV_NUPR',
  1503. 'PROV_IDPS',
  1504. 'PROV_NOCO',
  1505. 'PROV_NOMB',
  1506. 'PROV_APPA',
  1507. 'PROV_APMA',
  1508. 'PROV_CORR',
  1509. 'PROV_LAD1',
  1510. 'PROV_TEL1',
  1511. 'PROV_LAD2',
  1512. 'PROV_TEL2',
  1513. 'PROV_XRFC',
  1514. 'PROV_XTAX',
  1515. 'PROV_TIPO',
  1516. 'PROV_TICO',
  1517. 'PROV_SIWE',
  1518. 'PROV_MEPA',
  1519. 'PROV_CALL',
  1520. 'PROV_NUEX',
  1521. 'PROV_NUIN',
  1522. 'PROV_COPO',
  1523. 'PROV_COLO',
  1524. 'PROV_MUNI',
  1525. 'PROV_LOCA',
  1526. 'PROV_ENTI',
  1527. 'PROV_PAIS',
  1528. 'PROV_ESTA',
  1529. 'PROV_INEX',
  1530. 'PROV_USRE',
  1531. 'PROV_FERE',
  1532. 'PROV_USMO',
  1533. 'PROV_FEMO',
  1534. 'PROV_FEAR',
  1535. 'REFI_CRFI',
  1536. 'REFI_DRFI',
  1537. ]);
  1538. } catch (\Throwable $th) {
  1539. return $this->responseController->makeResponse(
  1540. true,
  1541. "ERR_PROVIDER_SHEET002: Ocurrió un error al obtener la información del proveedor.",
  1542. $th->getMessage(),
  1543. 500
  1544. );
  1545. }
  1546. } else if ($typeUser === 'S') {
  1547. try {
  1548. $arrProvider = (array) DB::table('S002V01TPROV')
  1549. ->where('PROV_IDPS', '=', $idProvider)
  1550. ->where('PROV_NULI', '=', $line)
  1551. ->where('REFI_NULI', '=', $line)
  1552. ->where('REFI_ESTA', '=', 'Activo')
  1553. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  1554. ->first([
  1555. 'PROV_NUPR',
  1556. 'PROV_IDPS',
  1557. 'PROV_NOCO',
  1558. 'PROV_NOMB',
  1559. 'PROV_APPA',
  1560. 'PROV_APMA',
  1561. 'PROV_CORR',
  1562. 'PROV_LAD1',
  1563. 'PROV_TEL1',
  1564. 'PROV_LAD2',
  1565. 'PROV_TEL2',
  1566. 'PROV_XRFC',
  1567. 'PROV_XTAX',
  1568. 'PROV_TIPO',
  1569. 'PROV_TICO',
  1570. 'PROV_SIWE',
  1571. 'PROV_MEPA',
  1572. 'PROV_CALL',
  1573. 'PROV_NUEX',
  1574. 'PROV_NUIN',
  1575. 'PROV_COPO',
  1576. 'PROV_COLO',
  1577. 'PROV_MUNI',
  1578. 'PROV_LOCA',
  1579. 'PROV_ENTI',
  1580. 'PROV_PAIS',
  1581. 'PROV_ESTA',
  1582. 'PROV_INEX',
  1583. 'PROV_USRE',
  1584. 'PROV_FERE',
  1585. 'PROV_USMO',
  1586. 'PROV_FEMO',
  1587. 'PROV_FEAR',
  1588. 'REFI_CRFI',
  1589. 'REFI_DRFI',
  1590. ]);
  1591. } catch (\Throwable $th) {
  1592. return $this->responseController->makeResponse(
  1593. true,
  1594. "ERR_PROVIDER_SHEET002: Ocurrió un error al obtener la información del proveedor.",
  1595. $th->getMessage(),
  1596. 500
  1597. );
  1598. }
  1599. }
  1600. if ( empty($arrProvider) ) {
  1601. return $this->responseController->makeResponse(
  1602. true,
  1603. "ERR_PROVIDER_SHEET003: El proveedor seleccionado no existe.",
  1604. [],
  1605. 500
  1606. );
  1607. }
  1608. if ($arrProvider['PROV_ESTA'] !== 'Activo') {
  1609. return $this->responseController->makeResponse(
  1610. true,
  1611. "ERR_PROVIDER_SHEET004: El proveedor seleccionado no se encuentra activo.",
  1612. [],
  1613. 500
  1614. );
  1615. }
  1616. try {
  1617. $arrReference = DB::table('S002V01TPRRE')
  1618. ->where('PRRE_NUPR', '=', $idProvider)
  1619. ->where('PRRE_NULI', '=', $line)
  1620. ->where('PRRE_ESTA', '=', 'Activo')
  1621. ->get([
  1622. 'PRRE_IDRE',
  1623. 'PRRE_EMPR',
  1624. 'PRRE_CORR',
  1625. 'PRRE_LADA',
  1626. 'PRRE_TELE',
  1627. 'PRRE_XRFC',
  1628. 'PRRE_DIRE',
  1629. ]);
  1630. $arrReference = json_decode( json_encode($arrReference), true );
  1631. } catch (\Throwable $th) {
  1632. return $this->responseController->makeResponse(
  1633. true,
  1634. "ERR_PROVIDER_SHEET005: Ocurrió un error al obtener las referencias del proveedor.",
  1635. $th->getMessage(),
  1636. 500
  1637. );
  1638. }
  1639. try {
  1640. $arrContact = DB::table('S002V01TPRCO')
  1641. ->where('PRCO_NUPR', '=', $idProvider)
  1642. ->where('PRCO_NULI', '=', $line)
  1643. ->where('PRCO_ESTA', '=', 'Activo')
  1644. ->get([
  1645. 'PRCO_IDCP',
  1646. 'PRCO_NOMB',
  1647. 'PRCO_TIPO',
  1648. 'PRCO_CALL',
  1649. 'PRCO_NUEX',
  1650. 'PRCO_NUIN',
  1651. 'PRCO_COPO',
  1652. 'PRCO_COLO',
  1653. 'PRCO_LOCA',
  1654. 'PRCO_MUNI',
  1655. 'PRCO_ENTI',
  1656. 'PRCO_PAIS',
  1657. 'PRCO_LAD1',
  1658. 'PRCO_TEL1',
  1659. 'PRCO_LAD2',
  1660. 'PRCO_TEL2',
  1661. 'PRCO_COR1',
  1662. 'PRCO_COR2',
  1663. 'PRCO_OBSE',
  1664. ]);
  1665. $arrContact = json_decode( json_encode($arrContact), true );
  1666. } catch (\Throwable $th) {
  1667. return $this->responseController->makeResponse(
  1668. true,
  1669. "ERR_PROVIDER_SHEET006: Ocurrió un error al obtener los contactos del proveedor.",
  1670. $th->getMessage(),
  1671. 500
  1672. );
  1673. }
  1674. try {
  1675. $arrCondition = DB::table('S002V01TPRCN')
  1676. ->where('PRCN_NUPR', '=', $idProvider)
  1677. ->where('PRCN_NULI', '=', $line)
  1678. ->where('PRCN_ESTA', '=', 'Activo')
  1679. ->get([
  1680. 'PRCN_IDCM',
  1681. 'PRCN_TIPO',
  1682. 'PRCN_INFO',
  1683. ]);
  1684. $arrCondition = json_decode( json_encode($arrCondition), true );
  1685. } catch (\Throwable $th) {
  1686. return $this->responseController->makeResponse(
  1687. true,
  1688. "ERR_PROVIDER_SHEET007: Ocurrió un error al obtener las condiciones del proveedor.",
  1689. $th->getMessage(),
  1690. 500
  1691. );
  1692. }
  1693. try {
  1694. $arrCatalog = DB::table('S002V01TPRCE')
  1695. ->where('PRCE_NUPR', '=', $idProvider)
  1696. ->where('PRCE_NULI', '=', $line)
  1697. ->where('PRCE_ESTA', '=', 'Activo')
  1698. ->get([
  1699. 'PRCE_IDCE',
  1700. 'PRCE_CATA',
  1701. 'PRCE_DESC',
  1702. 'PRCE_XURL',
  1703. ]);
  1704. $arrCatalog = json_decode( json_encode($arrCatalog), true );
  1705. } catch (\Throwable $th) {
  1706. return $this->responseController->makeResponse(
  1707. true,
  1708. "ERR_PROVIDER_SHEET008: Ocurrió un error al obtener los catálogos del proveedor.",
  1709. $th->getMessage(),
  1710. 500
  1711. );
  1712. }
  1713. try {
  1714. $arrPayment = json_decode($arrProvider['PROV_MEPA']);
  1715. } catch (\Throwable $th) {
  1716. return $this->responseController->makeResponse(
  1717. true,
  1718. "ERR_PROVIDER_SHEET009: El proveedor seleccionado no se encuentra activo.",
  1719. $th->getMessage(),
  1720. 500
  1721. );
  1722. }
  1723. $spreadsheet = new Spreadsheet();
  1724. $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrProvider['PROV_NUPR']);
  1725. $headerA1 = 'Número de Proveedor';
  1726. $contentA1 = $arrProvider['PROV_NUPR'];
  1727. $activeWorksheet->setCellValue("A1", $headerA1);
  1728. $activeWorksheet->setCellValue("B1", $contentA1);
  1729. $activeWorksheet->getStyle( "A1" )->getFont()->setBold(true);
  1730. $headerB1 = 'Número de Subcontratista';
  1731. $contentB1 = '';
  1732. if ( $arrProvider['PROV_IDPS'] === null || $arrProvider['PROV_IDPS'] === '' ) {
  1733. $contentB1 = 'Sin Subcontratista';
  1734. } else {
  1735. $contentB1 = $arrProvider['PROV_IDPS'];
  1736. }
  1737. $activeWorksheet->setCellValue("A2", $headerB1);
  1738. $activeWorksheet->setCellValue("B2", $contentB1);
  1739. $activeWorksheet->getStyle( "A2" )->getFont()->setBold(true);
  1740. $headerC1 = "Nombre Comercial";
  1741. $contentC1 = $arrProvider['PROV_NOCO'];
  1742. $activeWorksheet->setCellValue("A3", $headerC1);
  1743. $activeWorksheet->setCellValue("B3", $contentC1);
  1744. $activeWorksheet->getStyle( "A3" )->getFont()->setBold(true);
  1745. $headerD1 = 'Responsable';
  1746. $contentD1 = $arrProvider['PROV_NOMB'].' '.$arrProvider['PROV_APPA'].' '.$arrProvider['PROV_APMA'] === null ? '' : $arrProvider['PROV_APMA'];
  1747. $activeWorksheet->setCellValue("A4", $headerD1);
  1748. $activeWorksheet->setCellValue("B4", $contentD1);
  1749. $activeWorksheet->getStyle( "A4" )->getFont()->setBold(true);
  1750. $headerE1 = 'Correo electrónico';
  1751. $contentE1 = $arrProvider['PROV_CORR'];
  1752. $activeWorksheet->setCellValue("A5", $headerE1);
  1753. $activeWorksheet->setCellValue("B5", $contentE1);
  1754. $activeWorksheet->getStyle( "A5" )->getFont()->setBold(true);
  1755. $headerF1 = '';
  1756. $contentF1 = '';
  1757. if ($arrProvider['PROV_XRFC'] !== null && $arrProvider['PROV_XRFC'] !== '' && ($arrProvider['PROV_XTAX'] === '' || $arrProvider['PROV_XTAX'] === null)) {
  1758. $headerF1 = 'R.F.C';
  1759. $contentF1 = $arrProvider['PROV_XRFC'];
  1760. } else if ($arrProvider['PROV_XTAX'] !== null && $arrProvider['PROV_XTAX'] !== '' && ($arrProvider['PROV_XRFC'] === '' || $arrProvider['PROV_XRFC'] === null)) {
  1761. $headerF1 = 'TAX ID';
  1762. $contentF1 = $arrProvider['PROV_XTAX'];
  1763. } else {
  1764. $headerF1 = 'R.F.C / TAX ID';
  1765. $contentF1 = 'Sin contenido';
  1766. }
  1767. $activeWorksheet->setCellValue("A6", $headerF1);
  1768. $activeWorksheet->setCellValue("B6", $contentF1);
  1769. $activeWorksheet->getStyle( "A6" )->getFont()->setBold(true);
  1770. $headerF1 = 'Régimen fiscal';
  1771. $contentF1 = $arrProvider['REFI_DRFI'] . ' (' . $arrProvider['REFI_CRFI'] . ')';
  1772. $activeWorksheet->setCellValue("A7", "Régimen Fiscal");
  1773. $activeWorksheet->setCellValue("B7", $contentF1);
  1774. $activeWorksheet->getStyle( "A7" )->getFont()->setBold(true);
  1775. $headerH1 = 'Tipo de ciudadania';
  1776. $contentH1 = $arrProvider['PROV_TIPO'];
  1777. $activeWorksheet->setCellValue("A8", $headerH1);
  1778. $activeWorksheet->setCellValue("B8", $contentH1);
  1779. $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
  1780. $headerI1 = 'Tipo de contribuyente';
  1781. $contentI1 = $arrProvider['PROV_TICO'];
  1782. $activeWorksheet->setCellValue("A9", $headerI1);
  1783. $activeWorksheet->setCellValue("B9", $contentI1);
  1784. $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
  1785. $headerJ1 = 'Teléfono principal';
  1786. $contentJ1 = '('.$arrProvider['PROV_LAD1'] .') '. $arrProvider['PROV_TEL1'];
  1787. $activeWorksheet->setCellValue("A10", $headerJ1);
  1788. $activeWorksheet->setCellValue("B10", $contentJ1);
  1789. $activeWorksheet->getStyle( "A10" )->getFont()->setBold(true);
  1790. $headerK1 = 'Teléfono secundario';
  1791. $contentK1 = '';
  1792. if ($arrProvider['PROV_LAD2'] !== null && $arrProvider['PROV_LAD2'] !== '' && $arrProvider['PROV_TEL2'] !== null && $arrProvider['PROV_TEL2'] !== '') {
  1793. $contentK1 = '('.$arrProvider['PROV_LAD2'] .') '. $arrProvider['PROV_TEL2'];
  1794. } else {
  1795. $contentK1 = 'No aplica';
  1796. }
  1797. $activeWorksheet->setCellValue("A11", $headerK1);
  1798. $activeWorksheet->setCellValue("B11", $contentK1);
  1799. $activeWorksheet->getStyle( "A11" )->getFont()->setBold(true);
  1800. $headerL1 = 'Enlace de sitio web';
  1801. $contentL1 = '';
  1802. if ($arrProvider['PROV_SIWE'] !== null && $arrProvider['PROV_SIWE'] !== '') {
  1803. $contentL1 = $arrProvider['PROV_SIWE'];
  1804. } else {
  1805. $contentL1 = 'No aplica';
  1806. }
  1807. $activeWorksheet->setCellValue("A12", $headerL1);
  1808. $activeWorksheet->setCellValue("B12", $contentL1);
  1809. $activeWorksheet->getStyle( "A12" )->getFont()->setBold(true);
  1810. $headerM1 = 'Calle ';
  1811. $contentM1 = $arrProvider['PROV_CALL'];
  1812. $activeWorksheet->setCellValue("A13", $headerM1);
  1813. $activeWorksheet->setCellValue("B13", $contentM1);
  1814. $activeWorksheet->getStyle( "A13" )->getFont()->setBold(true);
  1815. $headerN1 = 'Número exterior';
  1816. $contentN1 = $arrProvider['PROV_NUEX'];
  1817. $activeWorksheet->setCellValue("A14", $headerN1);
  1818. $activeWorksheet->setCellValue("B14", $contentN1);
  1819. $activeWorksheet->getStyle( "A14" )->getFont()->setBold(true);
  1820. $headerO1 = 'Número interior';
  1821. $contentO1 = '';
  1822. if ($arrProvider['PROV_NUIN'] !== null && $arrProvider['PROV_NUIN'] !== '') {
  1823. $contentO1 = $arrProvider['PROV_NUIN'];
  1824. } else {
  1825. $contentO1 = 'No aplica';
  1826. }
  1827. $activeWorksheet->setCellValue("A15", $headerO1);
  1828. $activeWorksheet->setCellValue("B15", $contentO1);
  1829. $activeWorksheet->getStyle( "A15" )->getFont()->setBold(true);
  1830. $headerP1 = 'Código postal';
  1831. $contentP1 = $arrProvider['PROV_COPO'];
  1832. $activeWorksheet->setCellValue("A16", $headerP1);
  1833. $activeWorksheet->setCellValue("B16", $contentP1);
  1834. $activeWorksheet->getStyle( "A16" )->getFont()->setBold(true);
  1835. $headerQ1 = 'Colonia';
  1836. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  1837. try {
  1838. $arrColony = (array) DB::table('S002V01TCOLO')
  1839. ->where('COLO_NULI', '=', $line)
  1840. ->where('COLO_COCO', '=', $arrProvider['PROV_COLO'])
  1841. ->where('COLO_COPO', '=', $arrProvider['PROV_COPO'])
  1842. ->where('COLO_ESTA', '=', 'Activo')
  1843. ->first([ 'COLO_COCO', 'COLO_NOCO' ]);
  1844. } catch (\Throwable $th) {
  1845. return $this->responseController->makeResponse(
  1846. true,
  1847. "ERR_PROVIDER_SHEET010: Ocurrió un error al obtener la información de la colonia.",
  1848. $th->getMessage(),
  1849. 500
  1850. );
  1851. }
  1852. if ( empty($arrColony) ) {
  1853. return $this->responseController->makeResponse(
  1854. true,
  1855. "ERR_PROVIDER_SHEET011: No se encontró la colonia asociada al proveedor.",
  1856. [],
  1857. 500
  1858. );
  1859. }
  1860. $contentQ1 = $arrColony['COLO_NOCO'] . ' (' . $arrColony['COLO_COCO'] . ')';
  1861. } else {
  1862. $contentQ1 = $arrProvider['PROV_COLO'];
  1863. }
  1864. $activeWorksheet->setCellValue("A17", $headerQ1);
  1865. $activeWorksheet->setCellValue("B17", $contentQ1);
  1866. $activeWorksheet->getStyle( "A17" )->getFont()->setBold(true);
  1867. $headerR1 = 'Localidad';
  1868. $contentR1 = '';
  1869. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  1870. if ( !is_null($arrProvider['PROV_LOCA']) && !empty($arrProvider['PROV_LOCA']) ) {
  1871. try {
  1872. $arrLocate = (array) DB::table('S002V01TLOCA')
  1873. ->where('LOCA_NULI', '=', $line)
  1874. ->where('LOCA_COLO', '=', $arrProvider['PROV_LOCA'])
  1875. ->where('LOCA_COES', '=', $arrProvider['PROV_ENTI'])
  1876. ->where('LOCA_ESTA', '=', 'Activo')
  1877. ->first([ 'LOCA_COLO', 'LOCA_NOLO' ]);
  1878. } catch (\Throwable $th) {
  1879. return $this->responseController->makeResponse(
  1880. true,
  1881. "ERR_PROVIDER_SHEET012: Ocurrió un error al obtener la información de la localidad.",
  1882. $th->getMessage(),
  1883. 500
  1884. );
  1885. }
  1886. if ( empty($arrLocate) ) {
  1887. return $this->responseController->makeResponse(
  1888. true,
  1889. "ERR_PROVIDER_SHEET013: No se encontró la localidad asociada al proveedor.",
  1890. [],
  1891. 500
  1892. );
  1893. }
  1894. $contentR1 = $arrLocate['LOCA_NOLO'] . ' (' . $arrLocate['LOCA_NOLO'] . ')';
  1895. } else {
  1896. $contentR1 = 'Sin localidad';
  1897. }
  1898. } else {
  1899. if ( !is_null($arrProvider['PROV_LOCA']) && !empty($arrProvider['PROV_LOCA']) ) {
  1900. $contentR1 = $arrProvider['PROV_LOCA'];
  1901. } else {
  1902. $contentR1 = 'Sin localidad';
  1903. }
  1904. }
  1905. $activeWorksheet->setCellValue("A18", $headerR1);
  1906. $activeWorksheet->setCellValue("B18", $contentR1);
  1907. $activeWorksheet->getColumnDimension("R")->setAutoSize(true);
  1908. $activeWorksheet->getStyle( "A18" )->getFont()->setBold(true);
  1909. $headerS1 = 'Municipio';
  1910. $contentS1 = '';
  1911. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  1912. try {
  1913. $arrMunicipality = (array) DB::table('S002V01TMUNI')
  1914. ->where('MUNI_NULI', '=', $line)
  1915. ->where('MUNI_COMU', '=', $arrProvider['PROV_MUNI'])
  1916. ->where('MUNI_COES', '=', $arrProvider['PROV_ENTI'])
  1917. ->where('MUNI_ESTA', '=', 'Activo')
  1918. ->first([ 'MUNI_COMU', 'MUNI_NOMU' ]);
  1919. } catch (\Throwable $th) {
  1920. return $this->responseController->makeResponse(
  1921. true,
  1922. "ERR_PROVIDER_SHEET014: Ocurrió un error al obtener la información del municipio.",
  1923. $th->getMessage(),
  1924. 500
  1925. );
  1926. }
  1927. if ( empty($arrMunicipality) ) {
  1928. return $this->responseController->makeResponse(
  1929. true,
  1930. "ERR_PROVIDER_SHEET015: No se encontró el municipio asociada al proveedor.",
  1931. [],
  1932. 500
  1933. );
  1934. }
  1935. $contentS1 = $arrMunicipality['MUNI_NOMU'] . ' (' . $arrMunicipality['MUNI_COMU'] . ')';
  1936. } else {
  1937. $contentS1 = $arrProvider['PROV_MUNI'];
  1938. }
  1939. $activeWorksheet->setCellValue("A19", $headerS1);
  1940. $activeWorksheet->setCellValue("B19", $contentS1);
  1941. $activeWorksheet->getStyle( "A19" )->getFont()->setBold(true);
  1942. $headerT1 = 'Entidad Federativa';
  1943. $contentT1 = '';
  1944. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  1945. try {
  1946. $arrEntity = (array) DB::table('S002V01TESTA')
  1947. ->where('ESTA_NULI', '=', $line)
  1948. ->where('ESTA_COES', '=', $arrProvider['PROV_ENTI'])
  1949. ->where('ESTA_COPA', '=', $arrProvider['PROV_PAIS'])
  1950. ->where('ESTA_ESTA', '=', 'Activo')
  1951. ->first([ 'ESTA_COES', 'ESTA_NOES' ]);
  1952. } catch (\Throwable $th) {
  1953. return $this->responseController->makeResponse(
  1954. true,
  1955. "ERR_PROVIDER_SHEET016: Ocurrió un error al obtener la información de la entidad federativa.",
  1956. $th->getMessage(),
  1957. 500
  1958. );
  1959. }
  1960. if ( empty($arrEntity) ) {
  1961. return $this->responseController->makeResponse(
  1962. true,
  1963. "ERR_PROVIDER_SHEET017: No se encontró la entidad federativa asociada al proveedor.",
  1964. [],
  1965. 500
  1966. );
  1967. }
  1968. $contentT1 = $arrEntity['ESTA_NOES'] . ' (' . $arrEntity['ESTA_COES'] . ')';
  1969. } else {
  1970. $contentT1 = $arrProvider['PROV_ENTI'];
  1971. }
  1972. $activeWorksheet->setCellValue("A20", $headerT1);
  1973. $activeWorksheet->setCellValue("B20", $contentT1);
  1974. $activeWorksheet->getStyle( "A20" )->getFont()->setBold(true);
  1975. $headerU1 = 'País';
  1976. try {
  1977. $arrCountry = (array) DB::table('S002V01TPAIS')
  1978. ->where('PAIS_NULI', '=', $line)
  1979. ->where('PAIS_IDPA', '=', $arrProvider['PROV_PAIS'])
  1980. ->first([ 'PAIS_IDPA', 'PAIS_NOMB' ]);
  1981. } catch (\Throwable $th) {
  1982. return $this->responseController->makeResponse(
  1983. true,
  1984. "ERR_PROVIDER_SHEET018: Ocurrió un error al obtener la información del país.",
  1985. $th->getMessage(),
  1986. 500
  1987. );
  1988. }
  1989. if ( empty($arrCountry) ) {
  1990. return $this->responseController->makeResponse(
  1991. true,
  1992. "ERR_PROVIDER_SHEET019: No se encontró el país asociado al proveedor.",
  1993. [],
  1994. 500
  1995. );
  1996. }
  1997. $contentU1 = $arrCountry['PAIS_NOMB'] . ' (' . $arrCountry['PAIS_IDPA'] . ')';
  1998. $activeWorksheet->setCellValue("A21", $headerU1);
  1999. $activeWorksheet->setCellValue("B21", $contentU1);
  2000. $activeWorksheet->getStyle( "A21" )->getFont()->setBold(true);
  2001. $activeWorksheet->getColumnDimension("A")->setAutoSize(true);
  2002. $activeWorksheet->getColumnDimension("B")->setAutoSize(true);
  2003. $arrAlphabet = $this->resourcesController->arrAlphabet;
  2004. $spreadsheet->createSheet();
  2005. $spreadsheet->setActiveSheetIndex(1);
  2006. $activeWorksheetContact = $spreadsheet->getActiveSheet()->setTitle('Contactos');
  2007. $arrHeaderContact = array(
  2008. 'ID', // A
  2009. 'Contacto', // B
  2010. 'Tipo de Contacto', // C
  2011. 'Correo Electrónico Principal', // D
  2012. 'Correo Electrónico Secundario', // E
  2013. 'Teléfono Principal', // F
  2014. 'Teléfono Secundario', // G
  2015. 'Calle', // H
  2016. 'Número Exterior', // I
  2017. 'Numero Interior', // J
  2018. 'Código Postal', // K
  2019. 'Colonia', // L
  2020. 'Localidad', // M
  2021. 'Municipio', // N
  2022. 'Entidad Federativa', // O
  2023. 'País', // P
  2024. 'Observaciones' // Q
  2025. );
  2026. foreach ($arrContact as $key => $contact) {
  2027. $key = $key + 2;
  2028. $activeWorksheetContact->setCellValue("A".$key, $contact['PRCO_IDCP']);
  2029. $activeWorksheetContact->setCellValue("B".$key, $contact['PRCO_NOMB']);
  2030. $activeWorksheetContact->setCellValue("C".$key, $contact['PRCO_TIPO']);
  2031. $activeWorksheetContact->setCellValue("D".$key, $contact['PRCO_COR1']);
  2032. if ( !is_null( $contact['PRCO_COR2'] ) ) {
  2033. $activeWorksheetContact->setCellValue("E".$key, $contact['PRCO_COR2']);
  2034. } else {
  2035. $activeWorksheetContact->setCellValue("E".$key, 'No aplica' );
  2036. }
  2037. $activeWorksheetContact->setCellValue("F".$key, $contact['PRCO_LAD1'] . ' ' . $contact['PRCO_TEL1'] );
  2038. if ( !is_null( $contact['PRCO_LAD2'] ) && !is_null( $contact['PRCO_TEL2'] ) ) {
  2039. $activeWorksheetContact->setCellValue("G".$key, $contact['PRCO_LAD2'] . ' ' . $contact['PRCO_TEL2'] );
  2040. } else {
  2041. $activeWorksheetContact->setCellValue("G".$key, 'No aplica' );
  2042. }
  2043. $activeWorksheetContact->setCellValue("H".$key, $contact['PRCO_CALL'] );
  2044. $activeWorksheetContact->setCellValue("I".$key, $contact['PRCO_NUEX'] );
  2045. if ( !is_null( $contact['PRCO_NUIN'] ) ) {
  2046. $activeWorksheetContact->setCellValue("J".$key, $contact['PRCO_NUIN']);
  2047. } else {
  2048. $activeWorksheetContact->setCellValue("J".$key, 'No aplica' );
  2049. }
  2050. $activeWorksheetContact->setCellValue("K".$key, $contact['PRCO_COPO'] );
  2051. $activeWorksheetContact->setCellValue("L".$key, $contact['PRCO_COLO'] );
  2052. if ( !is_null($contact['PRCO_LOCA']) && $contact['PRCO_LOCA'] !== 'Sin localidad' ) {
  2053. $activeWorksheetContact->setCellValue("M".$key, $contact['PRCO_LOCA'] );
  2054. } else {
  2055. $activeWorksheetContact->setCellValue("M".$key, 'No aplica' );
  2056. }
  2057. $activeWorksheetContact->setCellValue("N".$key, $contact['PRCO_MUNI'] );
  2058. $activeWorksheetContact->setCellValue("O".$key, $contact['PRCO_ENTI'] );
  2059. $activeWorksheetContact->setCellValue("P".$key, $contact['PRCO_PAIS'] );
  2060. $activeWorksheetContact->setCellValue("Q".$key, $contact['PRCO_OBSE'] );
  2061. }
  2062. foreach ($arrHeaderContact as $keyHeaderContact => $headerContact) {
  2063. $activeWorksheetContact->setCellValue( $arrAlphabet[$keyHeaderContact]."1", $headerContact);
  2064. $activeWorksheetContact->getColumnDimension( $arrAlphabet[$keyHeaderContact] )->setAutoSize(true);
  2065. $activeWorksheetContact->getStyle( $arrAlphabet[$keyHeaderContact]."1" )->getFont()->setBold(true);
  2066. }
  2067. $spreadsheet->createSheet();
  2068. $spreadsheet->setActiveSheetIndex(2);
  2069. $activeWorksheetReference = $spreadsheet->getActiveSheet()->setTitle('Referencias');
  2070. $arrHeaderReference = array(
  2071. 'ID', // A
  2072. 'Empresa', // B
  2073. 'R.F.C.', // C
  2074. 'Correo', // D
  2075. 'Teléfono', // E
  2076. 'Dirección', // F
  2077. );
  2078. foreach ($arrReference as $key => $reference) {
  2079. $key = $key + 2;
  2080. $activeWorksheetReference->setCellValue("A".$key, $reference['PRRE_IDRE']);
  2081. $activeWorksheetReference->setCellValue("B".$key, $reference['PRRE_EMPR']);
  2082. $activeWorksheetReference->setCellValue("C".$key, $reference['PRRE_XRFC']);
  2083. $activeWorksheetReference->setCellValue("D".$key, $reference['PRRE_CORR']);
  2084. $activeWorksheetReference->setCellValue("E".$key, $reference['PRRE_LADA'] .' '. $reference['PRRE_TELE']);
  2085. $activeWorksheetReference->setCellValue("F".$key, $reference['PRRE_DIRE']);
  2086. }
  2087. foreach ($arrHeaderReference as $keyHeaderReference => $headerReference) {
  2088. $activeWorksheetReference->setCellValue( $arrAlphabet[$keyHeaderReference]."1", $headerReference);
  2089. $activeWorksheetReference->getColumnDimension( $arrAlphabet[$keyHeaderReference] )->setAutoSize(true);
  2090. $activeWorksheetReference->getStyle( $arrAlphabet[$keyHeaderReference]."1" )->getFont()->setBold(true);
  2091. }
  2092. $spreadsheet->createSheet();
  2093. $spreadsheet->setActiveSheetIndex(3);
  2094. $activeWorksheetCatalog = $spreadsheet->getActiveSheet()->setTitle('Catálogos');
  2095. $arrHeaderCatalog = array(
  2096. 'ID', // A
  2097. 'Catálogo', // B
  2098. 'Descripción', // C
  2099. 'URL', // D
  2100. );
  2101. foreach ($arrCatalog as $key => $catalog) {
  2102. $key = $key + 2;
  2103. $activeWorksheetCatalog->setCellValue("A".$key, $catalog['PRCE_IDCE']);
  2104. $activeWorksheetCatalog->setCellValue("B".$key, $catalog['PRCE_CATA']);
  2105. $activeWorksheetCatalog->setCellValue("C".$key, $catalog['PRCE_DESC']);
  2106. $activeWorksheetCatalog->setCellValue("D".$key, $catalog['PRCE_XURL']);
  2107. }
  2108. foreach ($arrHeaderCatalog as $keyHeaderCatalog => $headerCatalog) {
  2109. $activeWorksheetCatalog->setCellValue( $arrAlphabet[$keyHeaderCatalog]."1", $headerCatalog);
  2110. $activeWorksheetCatalog->getColumnDimension( $arrAlphabet[$keyHeaderCatalog] )->setAutoSize(true);
  2111. $activeWorksheetCatalog->getStyle( $arrAlphabet[$keyHeaderCatalog]."1" )->getFont()->setBold(true);
  2112. }
  2113. $spreadsheet->createSheet();
  2114. $spreadsheet->setActiveSheetIndex(4);
  2115. $activeWorksheetPayment = $spreadsheet->getActiveSheet()->setTitle('Métodos de Pago');
  2116. $arrHeaderPayment = array(
  2117. 'ID', // A
  2118. 'Método de Pago', // B
  2119. );
  2120. $cont = 2;
  2121. foreach ($arrPayment as $key => $payment) {
  2122. $activeWorksheetPayment->setCellValue("A".$cont, $key);
  2123. $activeWorksheetPayment->setCellValue("B".$cont, $payment);
  2124. $cont++;
  2125. }
  2126. foreach ($arrHeaderPayment as $keyHeaderPayment => $headerPayment) {
  2127. $activeWorksheetPayment->setCellValue( $arrAlphabet[$keyHeaderPayment]."1", $headerPayment);
  2128. $activeWorksheetPayment->getColumnDimension( $arrAlphabet[$keyHeaderPayment] )->setAutoSize(true);
  2129. $activeWorksheetPayment->getStyle( $arrAlphabet[$keyHeaderPayment]."1" )->getFont()->setBold(true);
  2130. }
  2131. $spreadsheet->createSheet();
  2132. $spreadsheet->setActiveSheetIndex(5);
  2133. $activeWorksheetCondition = $spreadsheet->getActiveSheet()->setTitle('Condiciones');
  2134. $arrHeaderCondition = array(
  2135. 'ID', // A
  2136. 'Tipo de Condición', // B
  2137. 'Información', // C
  2138. );
  2139. foreach ($arrCondition as $key => $condition) {
  2140. $key = $key + 2;
  2141. $activeWorksheetCondition->setCellValue("A".$key, $condition['PRCN_IDCM']);
  2142. $activeWorksheetCondition->setCellValue("B".$key, $condition['PRCN_TIPO']);
  2143. $activeWorksheetCondition->setCellValue("C".$key, $condition['PRCN_INFO']);
  2144. }
  2145. foreach ($arrHeaderCondition as $keyHeaderCondition => $headerCondition) {
  2146. $activeWorksheetCondition->setCellValue( $arrAlphabet[$keyHeaderCondition]."1", $headerCondition);
  2147. $activeWorksheetCondition->getColumnDimension( $arrAlphabet[$keyHeaderCondition] )->setAutoSize(true);
  2148. $activeWorksheetCondition->getStyle( $arrAlphabet[$keyHeaderCondition]."1" )->getFont()->setBold(true);
  2149. }
  2150. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2151. $como = 'GEAD'; // Código del módulo
  2152. $cldo = 'IN'; // Código de la clasificación
  2153. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2154. try {
  2155. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2156. ->where('AFAL_COMO', '=', $como)
  2157. ->where('AFAL_CLDO', '=', $cldo)
  2158. ->where('AFAL_NULI', '=', $line)
  2159. ->orderBy('AFAL_NUSE', 'desc')
  2160. ->first([ 'AFAL_NUSE' ]);
  2161. } catch (\Throwable $th) {
  2162. return $this->responseController->makeResponse(
  2163. true,
  2164. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2165. $th->getMessage(),
  2166. 500
  2167. );
  2168. }
  2169. $nuse = 1; // Secuencia del documento
  2170. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2171. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2172. }
  2173. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2174. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2175. $noar = 'ficha_de_proveedor_' . $arrProvider['PROV_NUPR'];
  2176. $exte = 'xlsx';
  2177. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  2178. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  2179. } else {
  2180. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  2181. }
  2182. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  2183. $tempFile = $filePath.$fileName;
  2184. if ( file_exists( $tempFile ) ) {
  2185. if ( !unlink( $tempFile ) ) {
  2186. return $this->responseController->makeResponse(
  2187. true,
  2188. "ERR_PROVIDER_SHEET021: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
  2189. [],
  2190. 500
  2191. );
  2192. }
  2193. }
  2194. try {
  2195. $writer = new Xlsx($spreadsheet);
  2196. ob_start();
  2197. $writer->save('php://output');
  2198. $base64 = base64_encode(ob_get_clean());
  2199. $validate = \File::put( $tempFile, base64_decode($base64));
  2200. } catch (\Throwable $th) {
  2201. return $this->responseController->makeResponse(
  2202. true,
  2203. "ERR_PROVIDER_SHEET022: Ocurrió un error al guardar el documento.",
  2204. $th->getMessage(),
  2205. 500
  2206. );
  2207. }
  2208. $ubic = Storage::putFile('files', new File($tempFile));
  2209. $ubic = str_replace("/", "\\", $ubic);
  2210. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  2211. $tama = filesize($ubic);
  2212. $usac = json_encode([$user]);
  2213. $now = $this->functionsController->now();
  2214. $currentDate = $now->toDateTimeString();
  2215. try {
  2216. $validateInsert = DB::table('S002V01TAFAL')->insert([
  2217. 'AFAL_NULI' => $line,
  2218. 'AFAL_COMO' => $como,
  2219. 'AFAL_CLDO' => $cldo,
  2220. 'AFAL_FECR' => $fecr,
  2221. 'AFAL_NUSE' => $nuse,
  2222. 'AFAL_NUVE' => $nuve,
  2223. 'AFAL_NOAR' => $noar,
  2224. 'AFAL_EXTE' => $exte,
  2225. 'AFAL_TAMA' => $tama,
  2226. 'AFAL_UBIC' => $ubic,
  2227. 'AFAL_USAC' => $usac,
  2228. 'AFAL_USRE' => $user,
  2229. 'AFAL_FERE' => $currentDate,
  2230. ]);
  2231. } catch (\Throwable $th) {
  2232. return $this->responseController->makeResponse(
  2233. true,
  2234. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  2235. $th->getMessage(),
  2236. 500
  2237. );
  2238. }
  2239. if ( !$validateInsert ) {
  2240. return $this->responseController->makeResponse(
  2241. true,
  2242. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  2243. [],
  2244. 500
  2245. );
  2246. }
  2247. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  2248. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  2249. }
  2250. public function generateSheetProviderPDF($encProvider, $typeUser, $user, $line) {
  2251. try {
  2252. $idProvider = $this->encController->decrypt($encProvider);
  2253. } catch (\Throwable $th) {
  2254. DB::rollBack();
  2255. return $this->responseController->makeResponse(
  2256. true,
  2257. "ERR_PROVIDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  2258. $th->getMessage(),
  2259. 500
  2260. );
  2261. }
  2262. try {
  2263. $user = $this->encController->decrypt($user);
  2264. } catch (\Throwable $th) {
  2265. DB::rollBack();
  2266. return $this->responseController->makeResponse(
  2267. true,
  2268. "ERR_PROVIDER_SHEET001: Ocurrió un error al obtener el usuario.",
  2269. $th->getMessage(),
  2270. 500
  2271. );
  2272. }
  2273. $arrProvider = [];
  2274. if ($typeUser === 'P') {
  2275. try {
  2276. $arrProvider = (array) DB::table('S002V01TPROV')
  2277. ->where('PROV_NUPR', '=', $idProvider)
  2278. ->where('PROV_NULI', '=', $line)
  2279. ->where('REFI_NULI', '=', $line)
  2280. ->where('REFI_ESTA', '=', 'Activo')
  2281. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  2282. ->first([
  2283. 'PROV_NUPR',
  2284. 'PROV_IDPS',
  2285. 'PROV_NOCO',
  2286. // 'PROV_CRFI',
  2287. 'PROV_NOMB',
  2288. 'PROV_APPA',
  2289. 'PROV_APMA',
  2290. 'PROV_CORR',
  2291. 'PROV_LAD1',
  2292. 'PROV_TEL1',
  2293. 'PROV_LAD2',
  2294. 'PROV_TEL2',
  2295. 'PROV_XRFC',
  2296. 'PROV_XTAX',
  2297. 'PROV_TIPO',
  2298. 'PROV_TICO',
  2299. 'PROV_SIWE',
  2300. 'PROV_MEPA',
  2301. 'PROV_CALL',
  2302. 'PROV_NUEX',
  2303. 'PROV_NUIN',
  2304. 'PROV_COPO',
  2305. 'PROV_COLO',
  2306. 'PROV_MUNI',
  2307. 'PROV_LOCA',
  2308. 'PROV_ENTI',
  2309. 'PROV_PAIS',
  2310. 'PROV_ESTA',
  2311. 'PROV_INEX',
  2312. 'PROV_USRE',
  2313. 'PROV_FERE',
  2314. 'PROV_USMO',
  2315. 'PROV_FEMO',
  2316. 'PROV_FEAR',
  2317. 'REFI_CRFI',
  2318. 'REFI_DRFI',
  2319. ]);
  2320. } catch (\Throwable $th) {
  2321. return $this->responseController->makeResponse(
  2322. true,
  2323. "ERR_PROVIDER_SHEET002: Ocurrió un error al obtener la información del proveedor.",
  2324. $th->getMessage(),
  2325. 500
  2326. );
  2327. }
  2328. } else if ($typeUser === 'S') {
  2329. try {
  2330. $arrProvider = (array) DB::table('S002V01TPROV')
  2331. ->where('PROV_IDPS', '=', $idProvider)
  2332. ->where('PROV_NULI', '=', $line)
  2333. ->where('REFI_NULI', '=', $line)
  2334. ->where('REFI_ESTA', '=', 'Activo')
  2335. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  2336. ->first([
  2337. 'PROV_NUPR',
  2338. 'PROV_IDPS',
  2339. 'PROV_NOCO',
  2340. // 'PROV_CRFI',
  2341. 'PROV_NOMB',
  2342. 'PROV_APPA',
  2343. 'PROV_APMA',
  2344. 'PROV_CORR',
  2345. 'PROV_LAD1',
  2346. 'PROV_TEL1',
  2347. 'PROV_LAD2',
  2348. 'PROV_TEL2',
  2349. 'PROV_XRFC',
  2350. 'PROV_XTAX',
  2351. 'PROV_TIPO',
  2352. 'PROV_TICO',
  2353. 'PROV_SIWE',
  2354. 'PROV_MEPA',
  2355. 'PROV_CALL',
  2356. 'PROV_NUEX',
  2357. 'PROV_NUIN',
  2358. 'PROV_COPO',
  2359. 'PROV_COLO',
  2360. 'PROV_MUNI',
  2361. 'PROV_LOCA',
  2362. 'PROV_ENTI',
  2363. 'PROV_PAIS',
  2364. 'PROV_ESTA',
  2365. 'PROV_INEX',
  2366. 'PROV_USRE',
  2367. 'PROV_FERE',
  2368. 'PROV_USMO',
  2369. 'PROV_FEMO',
  2370. 'PROV_FEAR',
  2371. 'REFI_CRFI',
  2372. 'REFI_DRFI',
  2373. ]);
  2374. } catch (\Throwable $th) {
  2375. return $this->responseController->makeResponse(
  2376. true,
  2377. "ERR_PROVIDER_SHEET002: Ocurrió un error al obtener la información del proveedor.",
  2378. $th->getMessage(),
  2379. 500
  2380. );
  2381. }
  2382. }
  2383. if ( empty($arrProvider) ) {
  2384. return $this->responseController->makeResponse(
  2385. true,
  2386. "ERR_PROVIDER_SHEET003: El proveedor seleccionado no existe.",
  2387. [],
  2388. 500
  2389. );
  2390. }
  2391. if ($arrProvider['PROV_ESTA'] !== 'Activo') {
  2392. return $this->responseController->makeResponse(
  2393. true,
  2394. "ERR_PROVIDER_SHEET004: El proveedor seleccionado no se encuentra activo.",
  2395. [],
  2396. 500
  2397. );
  2398. }
  2399. try {
  2400. $arrReference = DB::table('S002V01TPRRE')
  2401. ->where('PRRE_NUPR', '=', $idProvider)
  2402. ->where('PRRE_NULI', '=', $line)
  2403. ->where('PRRE_ESTA', '=', 'Activo')
  2404. ->get([
  2405. 'PRRE_IDRE',
  2406. 'PRRE_EMPR',
  2407. 'PRRE_CORR',
  2408. 'PRRE_LADA',
  2409. 'PRRE_TELE',
  2410. 'PRRE_XRFC',
  2411. 'PRRE_DIRE',
  2412. ]);
  2413. $arrReference = json_decode( json_encode($arrReference), true );
  2414. } catch (\Throwable $th) {
  2415. return $this->responseController->makeResponse(
  2416. true,
  2417. "ERR_PROVIDER_SHEET005: Ocurrió un error al obtener las referencias del proveedor.",
  2418. $th->getMessage(),
  2419. 500
  2420. );
  2421. }
  2422. try {
  2423. $arrContact = DB::table('S002V01TPRCO')
  2424. ->where('PRCO_NUPR', '=', $idProvider)
  2425. ->where('PRCO_NULI', '=', $line)
  2426. ->where('PRCO_ESTA', '=', 'Activo')
  2427. ->get([
  2428. 'PRCO_IDCP',
  2429. 'PRCO_NOMB',
  2430. 'PRCO_TIPO',
  2431. 'PRCO_CALL',
  2432. 'PRCO_NUEX',
  2433. 'PRCO_NUIN',
  2434. 'PRCO_COPO',
  2435. 'PRCO_COLO',
  2436. 'PRCO_LOCA',
  2437. 'PRCO_MUNI',
  2438. 'PRCO_ENTI',
  2439. 'PRCO_PAIS',
  2440. 'PRCO_LAD1',
  2441. 'PRCO_TEL1',
  2442. 'PRCO_LAD2',
  2443. 'PRCO_TEL2',
  2444. 'PRCO_COR1',
  2445. 'PRCO_COR2',
  2446. 'PRCO_OBSE',
  2447. ]);
  2448. $arrContact = json_decode( json_encode($arrContact), true );
  2449. } catch (\Throwable $th) {
  2450. return $this->responseController->makeResponse(
  2451. true,
  2452. "ERR_PROVIDER_SHEET006: Ocurrió un error al obtener los contactos del proveedor.",
  2453. $th->getMessage(),
  2454. 500
  2455. );
  2456. }
  2457. try {
  2458. $arrCondition = DB::table('S002V01TPRCN')
  2459. ->where('PRCN_NUPR', '=', $idProvider)
  2460. ->where('PRCN_NULI', '=', $line)
  2461. ->where('PRCN_ESTA', '=', 'Activo')
  2462. ->get([
  2463. 'PRCN_IDCM',
  2464. 'PRCN_TIPO',
  2465. 'PRCN_INFO',
  2466. ]);
  2467. $arrCondition = json_decode( json_encode($arrCondition), true );
  2468. } catch (\Throwable $th) {
  2469. return $this->responseController->makeResponse(
  2470. true,
  2471. "ERR_PROVIDER_SHEET007: Ocurrió un error al obtener las condiciones del proveedor.",
  2472. $th->getMessage(),
  2473. 500
  2474. );
  2475. }
  2476. try {
  2477. $arrCatalog = DB::table('S002V01TPRCE')
  2478. ->where('PRCE_NUPR', '=', $idProvider)
  2479. ->where('PRCE_NULI', '=', $line)
  2480. ->where('PRCE_ESTA', '=', 'Activo')
  2481. ->get([
  2482. 'PRCE_IDCE',
  2483. 'PRCE_CATA',
  2484. 'PRCE_DESC',
  2485. 'PRCE_XURL',
  2486. ]);
  2487. $arrCatalog = json_decode( json_encode($arrCatalog), true );
  2488. } catch (\Throwable $th) {
  2489. return $this->responseController->makeResponse(
  2490. true,
  2491. "ERR_PROVIDER_SHEET008: Ocurrió un error al obtener los catálogos del proveedor.",
  2492. $th->getMessage(),
  2493. 500
  2494. );
  2495. }
  2496. try {
  2497. $arrPayment = json_decode($arrProvider['PROV_MEPA']);
  2498. } catch (\Throwable $th) {
  2499. return $this->responseController->makeResponse(
  2500. true,
  2501. "ERR_PROVIDER_SHEET009: El proveedor seleccionado no se encuentra activo.",
  2502. $th->getMessage(),
  2503. 500
  2504. );
  2505. }
  2506. $arrProvider['CONDITION'] = $arrCondition;
  2507. $arrProvider['CATALOG'] = $arrCatalog;
  2508. $arrProvider['PROV_MEPA'] = $arrPayment;
  2509. $html = '<!DOCTYPE html>
  2510. <html lang="en">
  2511. <head>
  2512. <meta charset="UTF-8">
  2513. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2514. <title>Document</title>
  2515. <style>
  2516. body {
  2517. font-family: Arial, Helvetica, sans-serif;
  2518. font-size: 8pt;
  2519. }
  2520. .section-title {
  2521. margin: 20px 0;
  2522. font-size: 12pt;
  2523. }
  2524. table {
  2525. width: 100%;
  2526. }
  2527. thead tr th {
  2528. text-align: start;
  2529. padding: 0 16px;
  2530. height: 52px;
  2531. border-bottom-width: 1px;
  2532. border-bottom-style: solid;
  2533. border-bottom-color: #CCC;
  2534. }
  2535. tbody tr td {
  2536. padding: 0 16px;
  2537. height: 52px;
  2538. border-bottom-width: 1px;
  2539. border-bottom-style: solid;
  2540. border-bottom-color: #CCC;
  2541. }
  2542. p {
  2543. text-align: justify;
  2544. }
  2545. </style>
  2546. </head>
  2547. <body>
  2548. <div class="item">
  2549. <b>Número Proveedor:</b>
  2550. <span>'.$arrProvider['PROV_NUPR'].'</span>
  2551. </div>
  2552. <div class="item">
  2553. <b>Nombre Comercial: </b>
  2554. <span>'.$arrProvider['PROV_NOCO'].'</span>
  2555. </div>
  2556. <div class="item">
  2557. <b>Responsable: </b>
  2558. <span>'.$arrProvider['PROV_NOMB'].' '.$arrProvider['PROV_APPA'].' '.$arrProvider['PROV_APMA'].'</span>
  2559. </div>
  2560. <div class="item">
  2561. <b>Correo electrónico: </b>
  2562. <span>'.$arrProvider['PROV_CORR'].'</span>
  2563. </div>';
  2564. if ($arrProvider['PROV_XRFC'] !== null && $arrProvider['PROV_XRFC'] !== '' && ($arrProvider['PROV_XTAX'] === '' || $arrProvider['PROV_XTAX'] === null)) {
  2565. $html.='<div class="item">
  2566. <b>R.F.C: </b>
  2567. <span>'.$arrProvider['PROV_XRFC'].'</span>
  2568. </div>';
  2569. } else if ($arrProvider['PROV_XTAX'] !== null && $arrProvider['PROV_XTAX'] !== '' && ($arrProvider['PROV_XRFC'] === '' || $arrProvider['PROV_XRFC'] === null)) {
  2570. $html.='<div class="item">
  2571. <b>TAX ID: </b>
  2572. <span>'.$arrProvider['PROV_XTAX'].'</span>
  2573. </div>';
  2574. } else {
  2575. $html.='<div class="item">
  2576. <b>R.F.C / TAX ID: </b>
  2577. <span> Sin contenido </span>
  2578. </div>';
  2579. }
  2580. $html.='<div class="item">
  2581. <b>Régimen fiscal: </b>
  2582. <span>'.$arrProvider['REFI_DRFI'] . ' (' . $arrProvider['REFI_CRFI'] . ')'.'</span>
  2583. </div>
  2584. <div class="item">
  2585. <b>Tipo de ciudadania: </b>
  2586. <span>'.$arrProvider['PROV_TIPO'].'</span>
  2587. </div>
  2588. <div class="item">
  2589. <b>Tipo de contribuyente: </b>
  2590. <span>'.$arrProvider['PROV_TICO'].'</span>
  2591. </div>
  2592. <div class="item">
  2593. <b>Teléfono principal: </b>
  2594. <span>'.'('.$arrProvider['PROV_LAD1'] .') '. $arrProvider['PROV_TEL1'].'</span>
  2595. </div>';
  2596. if ($arrProvider['PROV_LAD2'] !== null && $arrProvider['PROV_LAD2'] !== '' && $arrProvider['PROV_TEL2'] !== null && $arrProvider['PROV_TEL2'] !== '') {
  2597. $html.='<div class="item">
  2598. <b>Teléfono secundario: </b>
  2599. <span>'.'('.$arrProvider['PROV_LAD2'] .') '. $arrProvider['PROV_TEL2'].'</span>
  2600. </div>';
  2601. } else {
  2602. $html.='<div class="item">
  2603. <b>Teléfono secundario: </b>
  2604. <span>No aplica</span>
  2605. </div>';
  2606. }
  2607. if ($arrProvider['PROV_SIWE'] !== null && $arrProvider['PROV_SIWE'] !== '') {
  2608. $html.='<div class="item">
  2609. <b>Enlace de sitio web: </b>
  2610. <span>'.$arrProvider['PROV_SIWE'].'</span>
  2611. </div>';
  2612. } else {
  2613. $html.='<div class="item">
  2614. <b>Enlace de sitio web: </b>
  2615. <span>No aplica</span>
  2616. </div>';
  2617. }
  2618. $address = $arrProvider['PROV_CALL'].' '.$arrProvider['PROV_NUEX'] . ' ';
  2619. if ($arrProvider['PROV_NUIN'] !== null && $arrProvider['PROV_NUIN'] !== '') {
  2620. $address .= $arrProvider['PROV_NUIN'] . ' ';
  2621. }
  2622. $address .= $arrProvider['PROV_COPO'] . ', ';
  2623. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  2624. try {
  2625. $arrColony = (array) DB::table('S002V01TCOLO')
  2626. ->where('COLO_NULI', '=', $line)
  2627. ->where('COLO_COCO', '=', $arrProvider['PROV_COLO'])
  2628. ->where('COLO_COPO', '=', $arrProvider['PROV_COPO'])
  2629. ->where('COLO_ESTA', '=', 'Activo')
  2630. ->first([ 'COLO_COCO', 'COLO_NOCO' ]);
  2631. } catch (\Throwable $th) {
  2632. return $this->responseController->makeResponse(
  2633. true,
  2634. "ERR_PROVIDER_SHEET010: Ocurrió un error al obtener la información de la colonia.",
  2635. $th->getMessage(),
  2636. 500
  2637. );
  2638. }
  2639. if ( empty($arrColony) ) {
  2640. return $this->responseController->makeResponse(
  2641. true,
  2642. "ERR_PROVIDER_SHEET011: No se encontró la colonia asociada al proveedor.",
  2643. [],
  2644. 500
  2645. );
  2646. }
  2647. $address .= $arrColony['COLO_NOCO'] . ', ';
  2648. } else {
  2649. $address .= $arrProvider['PROV_COLO'] . ', ';
  2650. }
  2651. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  2652. if ( !is_null($arrProvider['PROV_LOCA']) && !empty($arrProvider['PROV_LOCA']) ) {
  2653. try {
  2654. $arrLocate = (array) DB::table('S002V01TLOCA')
  2655. ->where('LOCA_NULI', '=', $line)
  2656. ->where('LOCA_COLO', '=', $arrProvider['PROV_LOCA'])
  2657. ->where('LOCA_COES', '=', $arrProvider['PROV_ENTI'])
  2658. ->where('LOCA_ESTA', '=', 'Activo')
  2659. ->first([ 'LOCA_COLO', 'LOCA_NOLO' ]);
  2660. } catch (\Throwable $th) {
  2661. return $this->responseController->makeResponse(
  2662. true,
  2663. "ERR_PROVIDER_SHEET012: Ocurrió un error al obtener la información de la localidad.",
  2664. $th->getMessage(),
  2665. 500
  2666. );
  2667. }
  2668. if ( empty($arrLocate) ) {
  2669. return $this->responseController->makeResponse(
  2670. true,
  2671. "ERR_PROVIDER_SHEET013: No se encontró la localidad asociada al proveedor.",
  2672. [],
  2673. 500
  2674. );
  2675. }
  2676. $address .= $arrLocate['LOCA_NOLO'] . ', ';
  2677. }
  2678. } else {
  2679. if ( !is_null($arrProvider['PROV_LOCA']) && !empty($arrProvider['PROV_LOCA']) ) {
  2680. $address .= $arrProvider['PROV_LOCA'] . ', ';
  2681. }
  2682. }
  2683. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  2684. try {
  2685. $arrMunicipality = (array) DB::table('S002V01TMUNI')
  2686. ->where('MUNI_NULI', '=', $line)
  2687. ->where('MUNI_COMU', '=', $arrProvider['PROV_MUNI'])
  2688. ->where('MUNI_COES', '=', $arrProvider['PROV_ENTI'])
  2689. ->where('MUNI_ESTA', '=', 'Activo')
  2690. ->first([ 'MUNI_COMU', 'MUNI_NOMU' ]);
  2691. } catch (\Throwable $th) {
  2692. return $this->responseController->makeResponse(
  2693. true,
  2694. "ERR_PROVIDER_SHEET014: Ocurrió un error al obtener la información del municipio.",
  2695. $th->getMessage(),
  2696. 500
  2697. );
  2698. }
  2699. if ( empty($arrMunicipality) ) {
  2700. return $this->responseController->makeResponse(
  2701. true,
  2702. "ERR_PROVIDER_SHEET015: No se encontró el municipio asociada al proveedor.",
  2703. [],
  2704. 500
  2705. );
  2706. }
  2707. $address .= $arrMunicipality['MUNI_NOMU'] . ', ';
  2708. } else {
  2709. $address .= $arrProvider['PROV_MUNI'] . ', ';
  2710. }
  2711. if ($arrProvider['PROV_PAIS'] === 'MEX') {
  2712. try {
  2713. $arrEntity = (array) DB::table('S002V01TESTA')
  2714. ->where('ESTA_NULI', '=', $line)
  2715. ->where('ESTA_COES', '=', $arrProvider['PROV_ENTI'])
  2716. ->where('ESTA_COPA', '=', $arrProvider['PROV_PAIS'])
  2717. ->where('ESTA_ESTA', '=', 'Activo')
  2718. ->first([ 'ESTA_COES', 'ESTA_NOES' ]);
  2719. } catch (\Throwable $th) {
  2720. return $this->responseController->makeResponse(
  2721. true,
  2722. "ERR_PROVIDER_SHEET016: Ocurrió un error al obtener la información de la entidad federativa.",
  2723. $th->getMessage(),
  2724. 500
  2725. );
  2726. }
  2727. if ( empty($arrEntity) ) {
  2728. return $this->responseController->makeResponse(
  2729. true,
  2730. "ERR_PROVIDER_SHEET017: No se encontró la entidad federativa asociada al proveedor.",
  2731. [],
  2732. 500
  2733. );
  2734. }
  2735. $address .= $arrEntity['ESTA_NOES'] . ', ';
  2736. } else {
  2737. $address .= $arrProvider['PROV_ENTI'] . ', ';
  2738. }
  2739. try {
  2740. $arrCountry = (array) DB::table('S002V01TPAIS')
  2741. ->where('PAIS_NULI', '=', $line)
  2742. ->where('PAIS_IDPA', '=', $arrProvider['PROV_PAIS'])
  2743. ->first([ 'PAIS_IDPA', 'PAIS_NOMB' ]);
  2744. } catch (\Throwable $th) {
  2745. return $this->responseController->makeResponse(
  2746. true,
  2747. "ERR_PROVIDER_SHEET018: Ocurrió un error al obtener la información del país.",
  2748. $th->getMessage(),
  2749. 500
  2750. );
  2751. }
  2752. if ( empty($arrCountry) ) {
  2753. return $this->responseController->makeResponse(
  2754. true,
  2755. "ERR_PROVIDER_SHEET019: No se encontró el país asociado al proveedor.",
  2756. [],
  2757. 500
  2758. );
  2759. }
  2760. $address .= $arrCountry['PAIS_NOMB'] . '.';
  2761. $html.='<div class="item">
  2762. <b>Dirección: </b>
  2763. <span>'.$address.'</span>
  2764. </div>';
  2765. if ( !empty($arrContact) ) {
  2766. $html.='<div class="section-title">
  2767. <b>Contactos</b>
  2768. </div>';
  2769. $html.='<table cellspacing="0" cellpadding="0">
  2770. <thead>
  2771. <tr>
  2772. <th>ID</th>
  2773. <th>Contacto</th>
  2774. <th>Tipo de Contacto</th>
  2775. <th>Correo Electrónico</th>
  2776. <th>Teléfono</th>
  2777. <th>Direcciones</th>
  2778. <th>Observaciones</th>
  2779. </tr>
  2780. </thead>
  2781. <tbody>';
  2782. foreach ($arrContact as $keyContact => $contact) {
  2783. $html.= '<tr>
  2784. <td>'.$contact['PRCO_IDCP'].'</td>
  2785. <td>'.$contact['PRCO_NOMB'].'</td>
  2786. <td>'.$contact['PRCO_TIPO'].'</td>
  2787. <td>'.$contact['PRCO_COR1'].'</td>
  2788. <td>'.$contact['PRCO_LAD1'].' '.$contact['PRCO_TEL1'].'</td>
  2789. <td>'.$contact['PRCO_CALL'].'</td>
  2790. <td>'.$contact['PRCO_OBSE'].'</td>
  2791. </tr>';
  2792. }
  2793. $html.= '</tbody>
  2794. </table>';
  2795. }
  2796. if ( !empty($arrReference) ) {
  2797. $html.='<div class="section-title">
  2798. <b>Referencias</b>
  2799. </div>';
  2800. $html.='<table cellspacing="0" cellpadding="0">
  2801. <thead>
  2802. <tr>
  2803. <th>ID</th>
  2804. <th>Empresa</th>
  2805. <th>R.F.C.</th>
  2806. <th>Correo Electrónico</th>
  2807. <th>Teléfono</th>
  2808. <th>Dirección</th>
  2809. </tr>
  2810. </thead>
  2811. <tbody>';
  2812. foreach ($arrReference as $keyReference => $reference) {
  2813. $html.= '<tr>
  2814. <td>'.$reference['PRRE_IDRE'].'</td>
  2815. <td>'.$reference['PRRE_EMPR'].'</td>
  2816. <td>'.$reference['PRRE_XRFC'].'</td>
  2817. <td>'.$reference['PRRE_CORR'].'</td>
  2818. <td>'.$reference['PRRE_LADA'].' '.$reference['PRRE_TELE'].'</td>
  2819. <td>'.$reference['PRRE_DIRE'].'</td>
  2820. </tr>';
  2821. }
  2822. $html.= '</tbody>
  2823. </table>';
  2824. }
  2825. if ( !empty($arrPayment) ) {
  2826. $html.='<div class="section-title">
  2827. <b>Métodos de Pago</b>
  2828. </div>';
  2829. $html.='<ol style="margin: 0;">';
  2830. foreach ($arrPayment as $keyPayment => $payment) {
  2831. $html.='<li>'.$payment.'</li>';
  2832. }
  2833. $html.='</ol>';
  2834. }
  2835. if ( !empty($arrCatalog) ) {
  2836. $html.='<div class="section-title">
  2837. <b>Catálogos</b>
  2838. </div>';
  2839. $html.='<table cellspacing="0" cellpadding="0">
  2840. <thead>
  2841. <tr>
  2842. <th>ID</th>
  2843. <th>Catálogo</th>
  2844. <th>Descripción</th>
  2845. <th>URL</th>
  2846. </tr>
  2847. </thead>
  2848. <tbody>';
  2849. foreach ($arrCatalog as $keyCatalog => $catalog) {
  2850. $html.= '<tr>
  2851. <td>'.$catalog['PRCE_IDCE'].'</td>
  2852. <td>'.$catalog['PRCE_CATA'].'</td>
  2853. <td>'.$catalog['PRCE_DESC'].'</td>
  2854. <td>'.$catalog['PRCE_XURL'].'</td>
  2855. </tr>';
  2856. }
  2857. $html.= '</tbody>
  2858. </table>';
  2859. }
  2860. if ( !empty($arrCondition) ) {
  2861. foreach ($arrCondition as $keyCondition => $condition) {
  2862. $html.='<div class="section-title">
  2863. <b>'.$condition['PRCN_TIPO'].'</b>
  2864. </div>';
  2865. $html.='<p>'.$condition['PRCN_INFO'].'</p>';
  2866. }
  2867. }
  2868. $html.='</body></html>';
  2869. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2870. $como = 'GEAD'; // Código del módulo
  2871. $cldo = 'IN'; // Código de la clasificación
  2872. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2873. try {
  2874. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2875. ->where('AFAL_COMO', '=', $como)
  2876. ->where('AFAL_CLDO', '=', $cldo)
  2877. ->where('AFAL_NULI', '=', $line)
  2878. ->orderBy('AFAL_NUSE', 'desc')
  2879. ->first([ 'AFAL_NUSE' ]);
  2880. } catch (\Throwable $th) {
  2881. return $this->responseController->makeResponse(
  2882. true,
  2883. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2884. $th->getMessage(),
  2885. 500
  2886. );
  2887. }
  2888. $nuse = 1; // Secuencia del documento
  2889. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2890. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2891. }
  2892. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2893. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2894. $noar = 'ficha_de_proveedor_' . $arrProvider['PROV_NUPR'];
  2895. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2896. $como = 'GEAD'; // Código del módulo
  2897. $cldo = 'IN'; // Código de la clasificación
  2898. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2899. try {
  2900. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2901. ->where('AFAL_COMO', '=', $como)
  2902. ->where('AFAL_CLDO', '=', $cldo)
  2903. ->where('AFAL_NULI', '=', $line)
  2904. ->orderBy('AFAL_NUSE', 'desc')
  2905. ->first([ 'AFAL_NUSE' ]);
  2906. } catch (\Throwable $th) {
  2907. return $this->responseController->makeResponse(
  2908. true,
  2909. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2910. $th->getMessage(),
  2911. 500
  2912. );
  2913. }
  2914. $nuse = 1; // Secuencia del documento
  2915. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2916. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2917. }
  2918. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2919. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2920. $noar = 'ficha_de_proveedor_' . $arrProvider['PROV_NUPR'];
  2921. $exte = 'pdf';
  2922. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  2923. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  2924. } else {
  2925. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  2926. }
  2927. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  2928. $tempFile = $filePath . $fileName;
  2929. $dompdf = new Dompdf();
  2930. $dompdf ->loadHtml($html);
  2931. $dompdf->setPaper('A4', 'portrait');
  2932. $dompdf->render();
  2933. $output = $dompdf->output();
  2934. file_put_contents($tempFile, $output);
  2935. $ubic = Storage::putFile('files', new File($tempFile));
  2936. $ubic = str_replace("/", "\\", $ubic);
  2937. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  2938. $tama = filesize($ubic);
  2939. $usac = json_encode([$user]);
  2940. $now = $this->functionsController->now();
  2941. $currentDate = $now->toDateTimeString();
  2942. try {
  2943. $validateInsert = DB::table('S002V01TAFAL')->insert([
  2944. 'AFAL_NULI' => $line,
  2945. 'AFAL_COMO' => $como,
  2946. 'AFAL_CLDO' => $cldo,
  2947. 'AFAL_FECR' => $fecr,
  2948. 'AFAL_NUSE' => $nuse,
  2949. 'AFAL_NUVE' => $nuve,
  2950. 'AFAL_NOAR' => $noar,
  2951. 'AFAL_EXTE' => $exte,
  2952. 'AFAL_TAMA' => $tama,
  2953. 'AFAL_UBIC' => $ubic,
  2954. 'AFAL_USAC' => $usac,
  2955. 'AFAL_USRE' => $user,
  2956. 'AFAL_FERE' => $currentDate,
  2957. ]);
  2958. } catch (\Throwable $th) {
  2959. return $this->responseController->makeResponse(
  2960. true,
  2961. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  2962. $th->getMessage(),
  2963. 500
  2964. );
  2965. }
  2966. if ( !$validateInsert ) {
  2967. return $this->responseController->makeResponse(
  2968. true,
  2969. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  2970. [],
  2971. 500
  2972. );
  2973. }
  2974. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  2975. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  2976. }
  2977. }