ProviderController.php 133 KB

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