ProviderController.php 137 KB

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