ProviderController.php 143 KB

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