OrderController.php 154 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 11/04/2023
  5. Módulo: Gestión de Adquisiciones
  6. */
  7. namespace App\Http\Controllers;
  8. use App\Http\Controllers\Controller;
  9. use App\Http\Controllers\ResponseController;
  10. use App\Http\Controllers\EncryptionController;
  11. use App\Http\Controllers\ResourcesController;
  12. use App\Http\Controllers\FunctionsController;
  13. use App\Http\Controllers\DocumentManagementController;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Validator;
  17. use Illuminate\Database\Query\JoinClause;
  18. use Illuminate\Support\Facades\Storage;
  19. use Illuminate\Http\File;
  20. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  21. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  22. use Dompdf\Dompdf;
  23. class OrderController extends Controller {
  24. private $responseController;
  25. private $encController;
  26. private $resourcesController;
  27. private $functionsController;
  28. private $documentManagementController;
  29. public function __construct(){
  30. $this->responseController = new ResponseController();
  31. $this->encController = new EncryptionController();
  32. $this->resourcesController = new ResourcesController();
  33. $this->functionsController = new FunctionsController();
  34. $this->arrUrlImage = new FunctionsController();
  35. $this->documentManagementController = new DocumentManagementController();
  36. }
  37. public function getOrders($user, $line) {
  38. try {
  39. $arrOrders = DB::table('S002V01TORCO')
  40. ->where('ORCO_NULI', '=', $line)
  41. ->where('DESP_NULI', '=', $line)
  42. ->where('PROV_NULI', '=', $line)
  43. ->where('LINE_NULI', '=', $line)
  44. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  45. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  46. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  47. ->get([
  48. 'ORCO_NUOR', // Número de Orden
  49. 'LINE_IDLI', // Identificador de línea de solicitud de compra
  50. 'PROV_NUPR', // Número de Proveedor
  51. 'PROV_NOCO', // Nombre Comercial del Proveedor
  52. 'PROV_TIPO', // Tipo de Nacionalidad
  53. 'DESP_IDDE', // Número de Despacho
  54. 'DESP_NODE', // Nombre del Despacho
  55. 'DESP_NOMB', // Nombre del Despacho
  56. 'ORCO_ESTA', // Estado
  57. 'ORCO_USRE', // Usuario Registra
  58. 'ORCO_FERE', // Fecha Registra
  59. 'ORCO_USMO', // Usuario Modifica
  60. 'ORCO_FEMO', // Fecha Modifica
  61. ]);
  62. } catch ( \Throwable $th ) {
  63. return $this->responseController->makeResponse(
  64. true,
  65. "ERR_ORDER_GET000: Ocurrió un error al momento de obtener las órdenes de compra.",
  66. $th->getMessage(),
  67. 500
  68. );
  69. }
  70. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrOrders);
  71. }
  72. public function createOrder(Request $request){
  73. $validator = Validator::make($request->all(), [
  74. 'NUMERO_LINEA' => 'required|string',
  75. 'NUMERO_SOLICITUD' => 'required|string',
  76. 'DESPACHO' => 'required|integer',
  77. 'USUARIO' => 'required|string',
  78. ]);
  79. if ($validator->fails()) {
  80. return $this->responseController->makeResponse(
  81. true,
  82. "ERR_ORDER_REG000: Se encontraron uno o más errores.",
  83. $this->responseController->makeErrors($validator->errors()->messages()),
  84. 401
  85. );
  86. }
  87. DB::beginTransaction();
  88. $requestData = $request->all();
  89. try {
  90. $user = $this->encController->decrypt($requestData['USUARIO']);
  91. } catch (\Throwable $th) {
  92. DB::rollBack();
  93. return $this->responseController->makeResponse(true, "ERR_ORDER_REG001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  94. }
  95. $now = $this->functionsController->now();
  96. $currentDate = $now->toDateTimeString();
  97. try {
  98. $idOrder = DB::table('S002V01TORCO')->insertGetId([
  99. 'ORCO_NULI' => $requestData['NUMERO_LINEA'],
  100. 'ORCO_IDLI' => $requestData['NUMERO_SOLICITUD'],
  101. 'ORCO_IDDE' => $requestData['DESPACHO'],
  102. 'ORCO_USRE' => $user,
  103. 'ORCO_FERE' => $currentDate,
  104. 'ORCO_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  105. ]);
  106. } catch (\Throwable $th) {
  107. DB::rollBack();
  108. return $this->responseController->makeResponse(true, "ERR_ORDER_REG002: Ocurrió un error al registrar la orden de compra.", $th->getMessage(), 500);
  109. }
  110. if (!$idOrder) {
  111. DB::rollBack();
  112. return $this->responseController->makeResponse(true, "ERR_ORDER_REG003: No se pudo registrar la orden de compra.", [], 401);
  113. }
  114. try {
  115. $validateUpdate = DB::table('S002V01TLINE')
  116. ->where('LINE_IDLI', '=', $requestData['NUMERO_SOLICITUD'])
  117. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  118. ->update([
  119. 'LINE_ESTA' => 'En OC',
  120. 'LINE_USMO' => $user,
  121. 'LINE_FEMO' => $currentDate,
  122. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  123. ]);
  124. } catch (\Throwable $th) {
  125. DB::rollBack();
  126. return $this->responseController->makeResponse(true, "ERR_ORDER_REG004: Ocurrió un error al modificar la línea de solitud de compra.", $th->getMessage(), 500);
  127. }
  128. if (!$validateUpdate) {
  129. DB::rollBack();
  130. return $this->responseController->makeResponse(true, "ERR_ORDER_REG005: No se pudo modificar la línea de solicitud de compra.", [], 401);
  131. }
  132. try {
  133. $valdiateInsert = DB::table('S002V01THIOR')
  134. ->insert([
  135. 'HIOR_NULI' => $requestData['NUMERO_LINEA'],
  136. 'HIOR_NUOR' => $idOrder,
  137. 'HIOR_POEN' => 10,
  138. 'HIOR_USRE' => $user,
  139. 'HIOR_FERE' => $currentDate,
  140. 'HIOR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  141. ]);
  142. } catch (\Throwable $th) {
  143. DB::rollBack();
  144. return $this->responseController->makeResponse(true, "ERR_ORDER_REG006: Ocurrió un error al insertar el registro en el historial.", $th->getMessage(), 500);
  145. }
  146. if (!$valdiateInsert) {
  147. DB::rollBack();
  148. return $this->responseController->makeResponse(true, "ERR_ORDER_REG007: No se pudo insertar el registro en el HISTORIAL.", [], 401);
  149. }
  150. DB::commit();
  151. return $this->responseController->makeResponse(false, "ÉXITO: Generación de Órdenes Exitosas");
  152. }
  153. public function getOrderByNumber($order, $provider, $user, $line){
  154. try {
  155. $order = $this->encController->decrypt($order);
  156. } catch (\Throwable $th) {
  157. DB::rollBack();
  158. return $this->responseController->makeResponse(true, "ERR_ORDER_GET000: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  159. }
  160. try {
  161. $provider = $this->encController->decrypt($provider);
  162. } catch (\Throwable $th) {
  163. DB::rollBack();
  164. return $this->responseController->makeResponse(true, "ERR_ORDER_GET001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  165. }
  166. try {
  167. $getOrders = (array) DB::table('S002V01TORCO')
  168. ->where('ORCO_NUOR', '=', $order)
  169. ->where('ORCO_NULI', '=', $line)
  170. ->where('DESP_NULI', '=', $line)
  171. ->where('LINE_NULI', '=', $line)
  172. ->where('PROV_NULI', '=', $line)
  173. ->where('LINE_ESTA', '!=', 'Cancelado')
  174. ->where('DESP_ESTA', '=', 'Activo')
  175. ->where('PROV_ESTA', '=', 'Activo')
  176. ->join('S002V01TLINE', 'ORCO_IDLI', '=', 'LINE_IDLI')
  177. ->join('S002V01TDESP', 'ORCO_IDDE', '=', 'DESP_IDDE')
  178. ->join('S002V01TPROV', 'LINE_NUPR', '=', 'PROV_NUPR')
  179. ->first([
  180. 'ORCO_NUOR',
  181. 'ORCO_ESTA',
  182. 'ORCO_USRE',
  183. 'ORCO_FERE',
  184. 'ORCO_USMO',
  185. 'ORCO_FEMO',
  186. 'ORCO_FEAR',
  187. 'LINE_IDLI',
  188. 'LINE_OTPR',
  189. 'LINE_OTCO',
  190. 'DESP_IDDE',
  191. 'DESP_NODE',
  192. 'DESP_NOMB',
  193. 'DESP_APPA',
  194. 'DESP_APMA',
  195. 'DESP_LADA',
  196. 'DESP_TELE',
  197. 'DESP_CORR',
  198. 'DESP_CALL',
  199. 'DESP_NUEX',
  200. 'DESP_NUIN',
  201. 'DESP_COPO',
  202. 'DESP_LOCA',
  203. 'DESP_COLO',
  204. 'DESP_MUNI',
  205. 'DESP_ENTI',
  206. 'DESP_PAIS',
  207. 'DESP_COME',
  208. 'PROV_NUPR',
  209. 'PROV_NOCO',
  210. 'PROV_NOMB',
  211. 'PROV_APPA',
  212. 'PROV_APMA',
  213. 'PROV_CORR',
  214. 'PROV_LAD1',
  215. 'PROV_TEL1',
  216. 'PROV_LAD2',
  217. 'PROV_TEL2',
  218. 'PROV_XRFC',
  219. 'PROV_XTAX',
  220. 'PROV_CRFI',
  221. 'PROV_TIPO',
  222. 'PROV_TICO',
  223. 'PROV_SIWE',
  224. 'PROV_MEPA',
  225. 'PROV_CALL',
  226. 'PROV_NUEX',
  227. 'PROV_NUIN',
  228. 'PROV_COPO',
  229. 'PROV_COLO',
  230. 'PROV_MUNI',
  231. 'PROV_LOCA',
  232. 'PROV_ENTI',
  233. 'PROV_PAIS',
  234. ]);
  235. } catch ( \Throwable $th ) {
  236. return $this->responseController->makeResponse(
  237. true,
  238. "ERR_ORDER_GET002: Ocurrió un error al momento de obtener las órdenes de compra.",
  239. $th->getMessage(),
  240. 500
  241. );
  242. }
  243. if ( empty($getOrders) || is_null($getOrders) ) {
  244. return $this->responseController->makeResponse( true, "ERR_ORDER_GET003: No se pudo obtener los datos de las órdenes de compra", [], 500);
  245. }
  246. try {
  247. $getArtitles = DB::table('S002V01TARSE')
  248. ->where('ARSE_IDLI', '=', $getOrders['LINE_IDLI'])
  249. ->where('ARSE_ESTA', '=', 'Activo')
  250. ->where('ARSE_NULI', '=', $line)
  251. ->where('ARTI_ESTA', '=', 'Activo')
  252. ->where('ARTI_NULI', '=', $line)
  253. ->where('FAMI_ESTA', '=', 'Activo')
  254. ->where('FAMI_NULI', '=', $line)
  255. ->where('SUBF_ESTA', '=', 'Activo')
  256. ->where('SUBF_NULI', '=', $line)
  257. ->where('DEAR_ESTA', '=', 'Activo')
  258. ->where('DEAR_NULI', '=', $line)
  259. ->where('INAR_ESTA', '=', 'Activo')
  260. ->where('INAR_NULI', '=', $line)
  261. ->where('UNID_ESTA', '=', 'Activo')
  262. ->where('UNID_NULI', '=', $line)
  263. ->join('S002V01TARTI', 'ARSE_IDAR', '=', 'ARTI_IDAR')
  264. ->join('S002V01TINAR', 'ARSE_IDIN', '=', 'INAR_IDIN')
  265. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  266. ->join('S002V01TFAMI', 'ARTI_COFA', '=', 'FAMI_COFA')
  267. ->join('S002V01TSUBF', 'ARTI_COSU', '=', 'SUBF_COSU')
  268. ->join('S002V01TUNID', 'DEAR_IDUN', '=', 'UNID_IDUN')
  269. ->get([
  270. 'ARSE_IDAS',
  271. 'ARSE_CANT',
  272. 'ARSE_PRTO',
  273. 'FAMI_COFA',
  274. 'FAMI_NOFA',
  275. 'SUBF_COSU',
  276. 'SUBF_NOSU',
  277. 'ARTI_IDAR',
  278. 'ARTI_CODI',
  279. 'ARTI_NOMB',
  280. 'DEAR_IDDE',
  281. 'DEAR_IMAG',
  282. 'DEAR_DESC',
  283. 'DEAR_CARA',
  284. 'DEAR_COWE',
  285. 'INAR_IDIN',
  286. 'INAR_CODI',
  287. 'INAR_MODE',
  288. 'INAR_COMO',
  289. 'INAR_PREC',
  290. 'INAR_MOMI',
  291. 'INAR_CARA',
  292. 'UNID_IDUN',
  293. 'UNID_NOMB',
  294. 'UNID_ACRO',
  295. ]);
  296. $arrArtitles = json_decode(json_encode($getArtitles), true);
  297. } catch (\Throwable $th) {
  298. return $this->responseController->makeResponse(
  299. true,
  300. "ERR_ORDER_GET004: Ocurrió un error al momento de obtener los artículos de las órdenes de compra.",
  301. $th->getMessage(),
  302. 500
  303. );
  304. }
  305. if (empty($arrArtitles) || is_null($arrArtitles)) {
  306. return $this->responseController->makeResponse( true, "ERR_ORDER_GET005: No se pudo obtener los artículos de las órdenes de compra.", [], 500);
  307. }
  308. foreach ($arrArtitles as $keyArtitles => $artitles) {
  309. $arrImageArtitle = json_decode($artitles['DEAR_IMAG']);
  310. $arrUrlImage = array();
  311. foreach ($arrImageArtitle as $key => $imagen) {
  312. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  313. $arrResponseDocument = json_decode($responseDocument->original, true);
  314. if ($arrResponseDocument['error']) {
  315. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  316. }
  317. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  318. }
  319. $arrArtitles[$keyArtitles]['DEAR_IMAG'] = $arrUrlImage;
  320. }
  321. try {
  322. $getHistoryOrder = DB::table('S002V01THIOR')
  323. ->where('HIOR_NUOR', '=', $order)
  324. ->where('HIOR_NULI', '=', $line)
  325. ->get([
  326. 'HIOR_IDHO',
  327. 'HIOR_ESOR',
  328. 'HIOR_DESC',
  329. 'HIOR_EVID',
  330. 'HIOR_POEN',
  331. 'HIOR_USRE',
  332. 'HIOR_FERE',
  333. 'HIOR_USMO',
  334. 'HIOR_FEMO',
  335. ]);
  336. $arrHistoryOrder = json_decode(json_encode($getHistoryOrder), true);
  337. } catch (\Throwable $th) {
  338. return $this->responseController->makeResponse(
  339. true,
  340. "ERR_ORDER_GET006: Ocurrió un error al momento de obtener el historial de la orden de compra.",
  341. $th->getMessage(),
  342. 500
  343. );
  344. }
  345. if (empty($arrHistoryOrder) || is_null($arrHistoryOrder)) {
  346. return $this->responseController->makeResponse( true, "ERR_ORDER_GET007: No se pudo obtener el historial de la orden de compra.", [], 500);
  347. }
  348. foreach ($arrHistoryOrder as $keyHistoryOrder => $historyOrder) {
  349. if ( !is_null($historyOrder['HIOR_EVID']) ) {
  350. $arrEvidence = json_decode($historyOrder['HIOR_EVID']);
  351. $arrUrlImage = array();
  352. foreach ($arrEvidence as $key => $imagen) {
  353. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  354. $arrResponseDocument = json_decode($responseDocument->original, true);
  355. if ($arrResponseDocument['error']) {
  356. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  357. }
  358. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  359. }
  360. $historyOrder['HIOR_EVID'] = $arrUrlImage;
  361. }
  362. $arrHistoryOrder[$keyHistoryOrder] = $historyOrder;
  363. }
  364. $getOrders['ARTI'] = $arrArtitles;
  365. $getOrders['HIST'] = $arrHistoryOrder;
  366. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getOrders);
  367. }
  368. public function getLastSateOrder($order, $user, $line) {
  369. try {
  370. $arrOrderState = (array) DB::table('S002V01THIOR')
  371. ->where('HIOR_NUOR', '=', $order)
  372. ->where('HIOR_NULI', '=', $line)
  373. ->where('HIOR_ESTA', '=', 'Activo')
  374. ->orderBy('HIOR_FEAR', 'DESC')
  375. ->first([
  376. 'HIOR_IDHO',
  377. 'HIOR_NULI',
  378. 'HIOR_NUOR',
  379. 'HIOR_ESOR',
  380. 'HIOR_DESC',
  381. 'HIOR_EVID',
  382. 'HIOR_POEN',
  383. 'HIOR_ESTA',
  384. 'HIOR_USRE',
  385. 'HIOR_FERE',
  386. 'HIOR_USMO',
  387. 'HIOR_FEMO',
  388. 'HIOR_FEAR',
  389. ]);
  390. } catch (\Throwable $th) {
  391. return $this->responseController->makeResponse(
  392. true,
  393. "ERR_ORDER_GETHISTORY000: Ocurrió un error al obtener el historial de las órdenes de compra",
  394. $th->getMessage(),
  395. 500
  396. );
  397. }
  398. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrOrderState);
  399. }
  400. public function updateStateHistory(Request $request) {
  401. $validator = Validator::make($request->all(), [
  402. 'ESTADO' => 'required|string',
  403. 'DESCRIPCION' => 'required|string',
  404. 'EVIDENCIA' => 'required|array',
  405. 'PORCENTAJE' => 'required|string',
  406. 'NUMERO_ORDEN' => 'required|string',
  407. 'USUARIO' => 'required|string',
  408. 'NUMERO_LINEA' => 'required|string',
  409. ]);
  410. if ($validator->fails()) {
  411. return $this->responseController->makeResponse(
  412. true,
  413. "ERR_ORDERSTATE_REG000: Se encontraron uno o más errores.",
  414. $this->responseController->makeErrors($validator->errors()->messages()),
  415. 401
  416. );
  417. }
  418. DB::beginTransaction();
  419. $requestData = $request->all();
  420. try {
  421. $user = $this->encController->decrypt($requestData['USUARIO']);
  422. } catch (\Throwable $th) {
  423. DB::rollBack();
  424. return $this->responseController->makeResponse(
  425. true,
  426. "ERR_ORDERSTATE_REG001: Ocurrió un error al obtener el usuario.",
  427. $th->getMessage(),
  428. 500
  429. );
  430. }
  431. $arrCodeEvidence = array();
  432. foreach ($requestData['EVIDENCIA'] as $keyEvidence => $evidence) {
  433. $idFile = $this->encController->decrypt($evidence);
  434. $tempFile = DB::table('S002V01TARTE')->where([
  435. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  436. ['ARTE_IDAR', '=', $idFile],
  437. ])->first();
  438. if(is_null($tempFile)){
  439. return $this->responseController->makeResponse(true, 'ERR_ORDERSTATE_REG002: El archivo consultado no está registrado', [], 404);
  440. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  441. return $this->responseController->makeResponse(true, 'ERR_ORDERSTATE_REG003: El archivo consultado está eliminado', [], 404);
  442. }
  443. $fileResponse = $this->documentManagementController->moveFinalFile(
  444. intval($requestData['NUMERO_LINEA']),
  445. 'GEAD',
  446. 'FO',
  447. $tempFile,
  448. $user,
  449. );
  450. if(!$fileResponse[0]){
  451. return $this->responseController->makeResponse(true, 'ERR_ORDERSTATE_REG004: '.$fileResponse[1], [], 400);
  452. }
  453. $arrCodeEvidence[] = $this->encController->encrypt($fileResponse[1]);
  454. }
  455. $jsonEvidence = json_encode($arrCodeEvidence);
  456. $now = $this->functionsController->now();
  457. $currentDate = $now->toDateTimeString();
  458. $arrInsert = [
  459. 'HIOR_NUOR' => $requestData['NUMERO_ORDEN'],
  460. 'HIOR_ESOR' => $requestData['ESTADO'],
  461. 'HIOR_DESC' => $requestData['DESCRIPCION'],
  462. 'HIOR_EVID' => $jsonEvidence,
  463. 'HIOR_POEN' => $requestData['PORCENTAJE'],
  464. 'HIOR_NULI' => $requestData['NUMERO_LINEA'],
  465. 'HIOR_USRE' => $user,
  466. 'HIOR_FERE' => $currentDate,
  467. 'HIOR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  468. ];
  469. try {
  470. $validateInsert = DB::table('S002V01THIOR')->insert($arrInsert);
  471. } catch (\Throwable $th) {
  472. DB::rollBack();
  473. return $this->responseController->makeResponse(true, "ERR_ORDERSTATE_REG005: Ocurrió un error al momento de insertar los datos.", $th->getMessage(), 500);
  474. }
  475. if ( !$validateInsert ) {
  476. DB::rollBack();
  477. return $this->responseController->makeResponse(true, "ERR_ORDERSTATE_REG006: No se pudo insertar los datos a la tabla.", [], 500);
  478. }
  479. try {
  480. $validateUpdate = DB::table('S002V01TORCO')
  481. ->where('ORCO_NUOR', '=', $requestData['NUMERO_ORDEN'])
  482. ->where('ORCO_NULI', '=', $requestData['NUMERO_LINEA'])
  483. ->update([
  484. 'ORCO_ESTA' => $requestData['ESTADO'],
  485. 'ORCO_USMO' => $user,
  486. 'ORCO_FEMO' => $currentDate,
  487. ]);
  488. } catch (\Throwable $th) {
  489. DB::rollBack();
  490. return $this->responseController->makeResponse(true, "ERR_ORDERSTATE_REG007: Ocurrió un error al momento de modificar los datos.", $th->getMessage(), 500);
  491. }
  492. if ( !$validateUpdate ) {
  493. DB::rollBack();
  494. return $this->responseController->makeRespÑonse(true, "ERR_ORDERSTATE_REG008: No se pudo modificar los datos a la tabla.", [], 500);
  495. }
  496. DB::commit();
  497. return $this->responseController->makeResponse(false, "ÉXITO: Modificación de Estado Exitoso");
  498. }
  499. public function reorderArtitles(Request $request) {
  500. $validator = Validator::make($request->all(), [
  501. 'ORDEN' => 'required|string',
  502. 'DESCRIPCION' => 'required|string',
  503. 'USUARIO' => 'required|string',
  504. 'NUMERO_LINEA' => 'required|string',
  505. ]);
  506. if ($validator->fails()) {
  507. return $this->responseController->makeResponse(
  508. true,
  509. "ERR_REORDER_REG000: Se encontraron uno o más errores.",
  510. $this->responseController->makeErrors($validator->errors()->messages()),
  511. 401
  512. );
  513. }
  514. DB::beginTransaction();
  515. $requestData = $request->all();
  516. try {
  517. $user = $this->encController->decrypt($requestData['USUARIO']);
  518. } catch (\Throwable $th) {
  519. DB::rollBack();
  520. return $this->responseController->makeResponse(true, "ERR_REORDER_REG001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  521. }
  522. try {
  523. $order = $this->encController->decrypt($requestData['ORDEN']);
  524. } catch (\Throwable $th) {
  525. DB::rollBack();
  526. return $this->responseController->makeResponse(true, "ERR_REORDER_REG002: Ocurrió un error al obtener el número de orden.", $th->getMessage(), 500);
  527. }
  528. $now = $this->functionsController->now();
  529. $currentDate = $now->toDateTimeString();
  530. try {
  531. $idRegisterLine = DB::table('S002V01TLINE')->insertGetId([
  532. // 'LINE_DESC' => $request['DESCRIPCION'],
  533. 'LINE_NULI' => $request['NUMERO_LINEA'],
  534. 'LINE_USRE' => $user,
  535. 'LINE_FERE' => $currentDate,
  536. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  537. ]);
  538. } catch (\Throwable $th) {
  539. DB::rollBack();
  540. return $this->responseController->makeResponse(true, "ERR_REORDER_REG003: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
  541. }
  542. if ( !$idRegisterLine ) {
  543. DB::rollBack();
  544. return $this->responseController->makeResponse(true, "ERR_REORDER_REG004: Ocurrió un error al hacer la inserción en la base.", [], 500);
  545. }
  546. try {
  547. $arrArtitles = DB::table('S002V01TORCO')
  548. ->where('ORCO_NUOR', '=', $order)
  549. ->join('S002V01TARSE', function (JoinClause $join) {
  550. $join->on('ARSE_IDLI', '=', 'ORCO_IDLI')
  551. ->on('ARSE_NUPR', '=', 'ORCO_NUPR');
  552. })
  553. ->get([
  554. 'ARSE_IDAR', // Identificador del artículo
  555. 'ARSE_NUPR', // Número del proveedor
  556. 'ARSE_IDIN', // Identificador de la información del artículo
  557. 'ARSE_CANT', // Cantidad
  558. 'ARSE_PRTO', // Precio total
  559. ]);
  560. } catch (\Throwable $th) {
  561. DB::rollBack();
  562. return $this->responseController->makeResponse(true, "ERR_REORDER_REG005: No se pudo obtener la información de la orden.", $th->getMessage(), 500);
  563. }
  564. if ( $arrArtitles->isEmpty() ) {
  565. DB::rollBack();
  566. return $this->responseController->makeResponse(true, "ERR_REORDER_REG006: La orden no tiene artículos.", [], 500);
  567. }
  568. foreach ($arrArtitles as $keyArtitle => $artitle) {
  569. try {
  570. $validateInsert = DB::table('S002V01TARSE')->insert([
  571. 'ARSE_IDAS' => $keyArtitle + 1,
  572. 'ARSE_IDLI' => $idRegisterLine,
  573. 'ARSE_IDAR' => $artitle->ARSE_IDAR,
  574. 'ARSE_NUPR' => $artitle->ARSE_NUPR,
  575. 'ARSE_IDIN' => $artitle->ARSE_IDIN,
  576. 'ARSE_CANT' => $artitle->ARSE_CANT,
  577. 'ARSE_PRTO' => $artitle->ARSE_PRTO,
  578. 'ARSE_NULI' => $request['NUMERO_LINEA'],
  579. 'ARSE_USRE' => $user,
  580. 'ARSE_FERE' => $currentDate,
  581. 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  582. ]);
  583. } catch (\Throwable $th) {
  584. DB::rollBack();
  585. return $this->responseController->makeResponse(true, "ERR_REORDER_REG007: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
  586. }
  587. if ( !$validateInsert ) {
  588. DB::rollBack();
  589. return $this->responseController->makeResponse(true, "ERR_REORDER_REG008: Ocurrió un error al hacer la inserción en la base.", [], 500);
  590. }
  591. }
  592. DB::commit();
  593. return $this->responseController->makeResponse(false, "ÉXITO: Artículos Reordenados Exitosamente");
  594. }
  595. public function generateSheetAcquisitionXLS($encOrderNumber, $user, $line) {
  596. try {
  597. $idOrder = $this->encController->decrypt($encOrderNumber);
  598. } catch (\Throwable $th) {
  599. DB::rollBack();
  600. return $this->responseController->makeResponse(
  601. true,
  602. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  603. $th->getMessage(),
  604. 500
  605. );
  606. }
  607. try {
  608. $user = $this->encController->decrypt($user);
  609. } catch (\Throwable $th) {
  610. DB::rollBack();
  611. return $this->responseController->makeResponse(
  612. true,
  613. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  614. $th->getMessage(),
  615. 500
  616. );
  617. }
  618. try {
  619. $arrOrder = (array) DB::table('S002V01TORCO')
  620. ->where('ORCO_NUOR', '=', $idOrder)
  621. ->where('ORCO_NULI', '=', $line)
  622. ->where('LINE_NULI', '=', $line)
  623. ->where('DESP_NULI', '=', $line)
  624. ->where('PROV_NULI', '=', $line)
  625. ->where('DESP_ESTA', '=', 'Activo')
  626. ->where('PROV_ESTA', '=', 'Activo')
  627. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  628. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  629. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  630. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  631. ->first([
  632. 'ORCO_NUOR',
  633. 'ORCO_ESTA',
  634. 'LINE_IDLI',
  635. 'LINE_OTPR',
  636. 'LINE_OTCO',
  637. 'LINE_ESTA',
  638. 'DESP_IDDE',
  639. 'DESP_NODE',
  640. 'DESP_NOMB',
  641. 'DESP_APPA',
  642. 'DESP_APMA',
  643. 'DESP_LADA',
  644. 'DESP_TELE',
  645. 'DESP_CORR',
  646. 'DESP_CALL',
  647. 'DESP_NUEX',
  648. 'DESP_NUIN',
  649. 'DESP_COPO',
  650. 'DESP_COLO',
  651. 'DESP_LOCA',
  652. 'DESP_MUNI',
  653. 'DESP_ENTI',
  654. 'DESP_PAIS',
  655. 'DESP_COME',
  656. 'PROV_NUPR',
  657. 'PROV_IDPS',
  658. 'PROV_NOCO',
  659. 'PROV_NOMB',
  660. 'PROV_APPA',
  661. 'PROV_APMA',
  662. 'PROV_CORR',
  663. 'PROV_LAD1',
  664. 'PROV_TEL1',
  665. 'PROV_LAD2',
  666. 'PROV_TEL2',
  667. 'PROV_XRFC',
  668. 'PROV_XTAX',
  669. 'PROV_TIPO',
  670. 'PROV_TICO',
  671. 'PROV_SIWE',
  672. 'PROV_MEPA',
  673. 'PROV_CALL',
  674. 'PROV_NUEX',
  675. 'PROV_NUIN',
  676. 'PROV_COPO',
  677. 'PROV_COLO',
  678. 'PROV_MUNI',
  679. 'PROV_LOCA',
  680. 'PROV_ENTI',
  681. 'PROV_PAIS',
  682. 'REFI_CRFI',
  683. 'REFI_DRFI',
  684. ]);
  685. } catch (\Throwable $th) {
  686. return $this->responseController->makeResponse(
  687. true,
  688. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  689. $th->getMessage(),
  690. 500
  691. );
  692. }
  693. try {
  694. $arrArtitle = DB::table('S002V01TARSE')
  695. ->where('ARSE_NULI', '=', $line)
  696. ->where('INAR_NULI', '=', $line)
  697. ->where('CAMO_NULI', '=', $line)
  698. ->where('DEAR_NULI', '=', $line)
  699. ->where('UNID_NULI', '=', $line)
  700. ->where('ARTI_NULI', '=', $line)
  701. ->where('FAMI_NULI', '=', $line)
  702. ->where('SUBF_NULI', '=', $line)
  703. ->where('ARSE_ESTA', '=', 'Activo')
  704. ->where('INAR_ESTA', '=', 'Activo')
  705. ->where('CAMO_ESTA', '=', 'Activo')
  706. ->where('DEAR_ESTA', '=', 'Activo')
  707. ->where('UNID_ESTA', '=', 'Activo')
  708. ->where('ARTI_ESTA', '=', 'Activo')
  709. ->where('FAMI_ESTA', '=', 'Activo')
  710. ->where('SUBF_ESTA', '=', 'Activo')
  711. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  712. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  713. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  714. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  715. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  716. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  717. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  718. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  719. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  720. ->get([
  721. 'ARSE_IDAS',
  722. 'ARSE_IDLI',
  723. 'ARSE_CANT',
  724. 'ARSE_PRTO',
  725. 'INAR_IDIN',
  726. 'INAR_CODI',
  727. 'INAR_MODE',
  728. 'INAR_PREC',
  729. 'INAR_MOMI',
  730. 'INAR_CARA',
  731. 'CAMO_COMO',
  732. 'CAMO_DESC',
  733. 'CAMO_DECI',
  734. 'CAMO_POVA',
  735. 'CAMO_FEIN',
  736. 'CAMO_FEFI',
  737. 'DEAR_IDDE',
  738. 'DEAR_IMAG',
  739. 'DEAR_DESC',
  740. 'DEAR_CARA',
  741. 'DEAR_COWE',
  742. 'UNID_IDUN',
  743. 'UNID_NOMB',
  744. 'UNID_ACRO',
  745. 'ARTI_IDAR',
  746. 'ARTI_CODI',
  747. 'ARTI_NOMB',
  748. 'FAMI_COFA',
  749. 'FAMI_NOFA',
  750. 'SUBF_COSU',
  751. 'SUBF_NOSU',
  752. ]);
  753. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  754. } catch (\Throwable $th) {
  755. return $this->responseController->makeResponse(
  756. true,
  757. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  758. $th->getMessage(),
  759. 500
  760. );
  761. }
  762. $spreadsheet = new Spreadsheet();
  763. $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrOrder['ORCO_NUOR']);
  764. $headerA1 = 'Número de orden';
  765. $contentB1 = $arrOrder['ORCO_NUOR'];
  766. $activeWorksheet->setCellValue("A1", $headerA1);
  767. $activeWorksheet->setCellValue("B1", $contentB1);
  768. $activeWorksheet->getStyle( "A1" )->getFont()->setBold(true);
  769. $headerA2 = 'Estado de la orden';
  770. $contentB2 = $arrOrder['ORCO_ESTA'];
  771. $activeWorksheet->setCellValue("A2", $headerA2);
  772. $activeWorksheet->setCellValue("B2", $contentB2);
  773. $activeWorksheet->getStyle( "A2" )->getFont()->setBold(true);
  774. $headerA3 = 'Numero de línea de solicitud';
  775. $contentB3 = $arrOrder['LINE_IDLI'];
  776. $activeWorksheet->setCellValue("A3", $headerA3);
  777. $activeWorksheet->setCellValue("B3", $contentB3);
  778. $activeWorksheet->getStyle( "A3" )->getFont()->setBold(true);
  779. $headerA4 = '';
  780. if ( !is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  781. $headerA4 = 'Orden de Trabajo Preventivo';
  782. $contentB4 = $arrOrder['LINE_OTPR'];
  783. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && !is_null( $arrOrder['LINE_OTCO'] ) ) {
  784. $headerA4 = 'Orden de Trabajo Correctivo';
  785. $contentB4 = $arrOrder['LINE_OTCO'];
  786. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  787. $headerA4 = 'Orden de Trabajo';
  788. $contentB4 = 'No aplica';
  789. } else {
  790. $headerA4 = 'Orden de Trabajo';
  791. $contentB4 = 'No aplica';
  792. }
  793. $activeWorksheet->setCellValue("A4", $headerA4 );
  794. $activeWorksheet->setCellValue("B4", $contentB4 );
  795. $activeWorksheet->getStyle( "A4" )->getFont()->setBold(true);
  796. $headerA5 = 'ID Despacho';
  797. $contentB5 = $arrOrder['DESP_IDDE'];
  798. $activeWorksheet->setCellValue("A5", $headerA5 );
  799. $activeWorksheet->setCellValue("B5", $contentB5 );
  800. $activeWorksheet->getStyle( "A5" )->getFont()->setBold(true);
  801. $headerA6 = 'Despacho';
  802. $contentB6 = $arrOrder['DESP_NODE'];
  803. $activeWorksheet->setCellValue("A6", $headerA6 );
  804. $activeWorksheet->setCellValue("B6", $contentB6 );
  805. $activeWorksheet->getStyle( "A6" )->getFont()->setBold(true);
  806. $headerA7 = 'Responsable del despacho';
  807. $contentB7 = $arrOrder['DESP_NOMB'] . ' ' . $arrOrder['DESP_APPA'] . ' ' . $arrOrder['DESP_APMA'];
  808. $activeWorksheet->setCellValue("A7", $headerA7 );
  809. $activeWorksheet->setCellValue("B7", $contentB7 );
  810. $activeWorksheet->getStyle( "A7" )->getFont()->setBold(true);
  811. $headerA8 = 'Teléfono del despacho';
  812. $contentB8 = $arrOrder['DESP_LADA'] . ' ' . $arrOrder['DESP_TELE'];
  813. $activeWorksheet->setCellValue("A8", $headerA8 );
  814. $activeWorksheet->setCellValue("B8", $contentB8 );
  815. $activeWorksheet->getStyle( "A8" )->getFont()->setBold(true);
  816. $headerA9 = 'Correo electrónico del despacho';
  817. $contentB9 = $arrOrder['DESP_CORR'];
  818. $activeWorksheet->setCellValue("A9", $headerA9 );
  819. $activeWorksheet->setCellValue("B9", $contentB9 );
  820. $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
  821. $headerA10 = 'Calle del despacho';
  822. $contentB10 = $arrOrder['DESP_CALL'];
  823. $activeWorksheet->setCellValue("A10", $headerA10 );
  824. $activeWorksheet->setCellValue("B10", $contentB10 );
  825. $activeWorksheet->getStyle( "A10" )->getFont()->setBold(true);
  826. $headerA11 = 'Número exterior';
  827. $contentB11 = $arrOrder['DESP_NUEX'];
  828. $activeWorksheet->setCellValue("A11", $headerA11 );
  829. $activeWorksheet->setCellValue("B11", $contentB11 );
  830. $activeWorksheet->getStyle( "A11" )->getFont()->setBold(true);
  831. $headerA12 = 'Número interior';
  832. if ( !is_null($arrOrder['DESP_NUIN']) ) {
  833. $contentB12 = $arrOrder['DESP_NUIN'];
  834. } else {
  835. $contentB12 = 'No aplica';
  836. }
  837. $activeWorksheet->setCellValue("A12", $headerA12 );
  838. $activeWorksheet->setCellValue("B12", $contentB12 );
  839. $activeWorksheet->getStyle( "A12" )->getFont()->setBold(true);
  840. $headerA13 = 'Código postal';
  841. $contentB13 = $arrOrder['DESP_COPO'];
  842. $activeWorksheet->setCellValue("A13", $headerA13 );
  843. $activeWorksheet->setCellValue("B13", $contentB13 );
  844. $activeWorksheet->getStyle( "A13" )->getFont()->setBold(true);
  845. $headerA14 = 'Colonia';
  846. $contentB14 = $arrOrder['DESP_COLO'];
  847. $activeWorksheet->setCellValue("A14", $headerA14 );
  848. $activeWorksheet->setCellValue("B14", $contentB14 );
  849. $activeWorksheet->getStyle( "A14" )->getFont()->setBold(true);
  850. $headerA15 = 'Localidad';
  851. if ( !is_null($arrOrder['DESP_LOCA']) && !empty($arrOrder['DESP_LOCA']) ) {
  852. $contentB15 = $arrOrder['DESP_LOCA'];
  853. } else {
  854. $contentB15 = 'No aplica';
  855. }
  856. $activeWorksheet->setCellValue("A15", $headerA15 );
  857. $activeWorksheet->setCellValue("B15", $contentB15 );
  858. $activeWorksheet->getStyle( "A15" )->getFont()->setBold(true);
  859. $headerA16 = 'Municipio';
  860. $contentB16 = $arrOrder['DESP_MUNI'];
  861. $activeWorksheet->setCellValue("A16", $headerA16 );
  862. $activeWorksheet->setCellValue("B16", $contentB16 );
  863. $activeWorksheet->getStyle( "A16" )->getFont()->setBold(true);
  864. $headerA17 = 'Entidad Federativa';
  865. $contentB17 = $arrOrder['DESP_ENTI'];
  866. $activeWorksheet->setCellValue("A17", $headerA17 );
  867. $activeWorksheet->setCellValue("B17", $contentB17 );
  868. $activeWorksheet->getStyle( "A17" )->getFont()->setBold(true);
  869. $headerA18 = 'País';
  870. $contentB18 = $arrOrder['DESP_PAIS'];
  871. $activeWorksheet->setCellValue("A18", $headerA18 );
  872. $activeWorksheet->setCellValue("B18", $contentB18 );
  873. $activeWorksheet->getStyle( "A18" )->getFont()->setBold(true);
  874. $headerA19 = 'Número de proveedor';
  875. $contentB19 = $arrOrder['PROV_NUPR'];
  876. $activeWorksheet->setCellValue("A19", $headerA19 );
  877. $activeWorksheet->setCellValue("B19", $contentB19 );
  878. $activeWorksheet->getStyle( "A19" )->getFont()->setBold(true);
  879. $headerA20 = 'Número de subcontratista';
  880. $contentB20 = $arrOrder['PROV_IDPS'];
  881. $activeWorksheet->setCellValue("A20", $headerA20 );
  882. $activeWorksheet->setCellValue("B20", $contentB20 );
  883. $activeWorksheet->getStyle( "A20" )->getFont()->setBold(true);
  884. $headerA21 = 'Nombre comercial del proveedor';
  885. $contentB21 = $arrOrder['PROV_NOCO'];
  886. $activeWorksheet->setCellValue("A21", $headerA21 );
  887. $activeWorksheet->setCellValue("B21", $contentB21 );
  888. $activeWorksheet->getStyle( "A21" )->getFont()->setBold(true);
  889. $headerA22 = 'Referencia fiscal del proveedor';
  890. $contentB22 = $arrOrder['REFI_DRFI'] . ' (' . $arrOrder['REFI_CRFI'] . ')';
  891. $activeWorksheet->setCellValue("A22", $headerA22 );
  892. $activeWorksheet->setCellValue("B22", $contentB22 );
  893. $activeWorksheet->getStyle( "A22" )->getFont()->setBold(true);
  894. $headerA23 = 'Responsable del proveedor';
  895. $contentB23 = $arrOrder['PROV_NOMB'] . ' ' . $arrOrder['PROV_APPA'] . ' ' . $arrOrder['PROV_APMA'];
  896. $activeWorksheet->setCellValue("A23", $headerA23 );
  897. $activeWorksheet->setCellValue("B23", $contentB23 );
  898. $activeWorksheet->getStyle( "A23" )->getFont()->setBold(true);
  899. $headerA24 = 'Correo electrónico del proveedor';
  900. $contentB24 = $arrOrder['PROV_CORR'];
  901. $activeWorksheet->setCellValue("A24", $headerA24 );
  902. $activeWorksheet->setCellValue("B24", $contentB24 );
  903. $activeWorksheet->getStyle( "A24" )->getFont()->setBold(true);
  904. $headerA25 = 'Teléfono del proveedor';
  905. $contentB25 = $arrOrder['PROV_LAD1'] . ' ' . $arrOrder['PROV_TEL1'];
  906. $activeWorksheet->setCellValue("A25", $headerA25 );
  907. $activeWorksheet->setCellValue("B25", $contentB25 );
  908. $activeWorksheet->getStyle( "A25" )->getFont()->setBold(true);
  909. $headerA26 = '';
  910. $contentB26 = '';
  911. if ( !is_null( $arrOrder['PROV_XRFC'] ) && is_null( $arrOrder['PROV_XRFC'] )) {
  912. $headerA26 = 'R.F.C. del proveedor';
  913. $contentB26 = $arrOrder['PROV_XRFC'];
  914. } else if ( is_null( $arrOrder['PROV_XRFC'] ) && !is_null( $arrOrder['PROV_XRFC'] )) {
  915. $headerA26 = 'TAX ID. del proveedor';
  916. $contentB26 = $arrOrder['PROV_XTAX'];
  917. } else {
  918. $headerA26 = 'R.F.C. / TAX ID';
  919. $contentB26 = 'No aplica';
  920. }
  921. $activeWorksheet->setCellValue("A26", $headerA26 );
  922. $activeWorksheet->setCellValue("B26", $contentB26 );
  923. $activeWorksheet->getStyle( "A26" )->getFont()->setBold(true);
  924. $activeWorksheet->getColumnDimension("A")->setAutoSize(true);
  925. $activeWorksheet->getColumnDimension("B")->setAutoSize(true);
  926. $arrAlphabet = $this->resourcesController->arrAlphabet;
  927. $spreadsheet->createSheet();
  928. $spreadsheet->setActiveSheetIndex(1);
  929. $activeWorksheetArtitle = $spreadsheet->getActiveSheet()->setTitle('Artículos de la orden');
  930. $arrHeaderArtitle = array(
  931. /* A */ 'ID Artículo',
  932. /* B */ 'Código del artíulo',
  933. /* C */ 'Artículo',
  934. /* D */ 'Familia',
  935. /* E */ 'Subfamilia',
  936. /* F */ 'Descripción',
  937. /* G */ 'Características',
  938. /* H */ 'Unidad',
  939. /* I */ 'Código',
  940. /* J */ 'Modelo',
  941. /* K */ 'Precio Unitario',
  942. /* L */ 'Cantidad',
  943. /* M */ 'Precio Total',
  944. /* N */ 'No. de selección',
  945. );
  946. foreach ($arrArtitle as $key => $artitle) {
  947. $key = $key + 2;
  948. $activeWorksheetArtitle->setCellValue("A".$key, $artitle['ARTI_IDAR']);
  949. $activeWorksheetArtitle->setCellValue("B".$key, $artitle['ARTI_CODI']);
  950. $activeWorksheetArtitle->setCellValue("C".$key, $artitle['ARTI_NOMB']);
  951. $activeWorksheetArtitle->setCellValue("D".$key, $artitle['FAMI_NOFA'] . ' (' . $artitle['FAMI_COFA'] . ')');
  952. $activeWorksheetArtitle->setCellValue("E".$key, $artitle['SUBF_NOSU'] . ' (' . $artitle['SUBF_COSU'] . ')');
  953. $activeWorksheetArtitle->setCellValue("F".$key, $artitle['DEAR_DESC']);
  954. $activeWorksheetArtitle->setCellValue("G".$key, $artitle['DEAR_CARA']);
  955. $activeWorksheetArtitle->setCellValue("H".$key, $artitle['UNID_NOMB'] . ' (' . $artitle['UNID_IDUN'] . ')');
  956. $activeWorksheetArtitle->setCellValue("I".$key, $artitle['INAR_CODI']);
  957. $activeWorksheetArtitle->setCellValue("J".$key, $artitle['INAR_MODE']);
  958. $activeWorksheetArtitle->setCellValue("K".$key, '$'. $artitle['INAR_PREC'] . ' ' . $artitle['CAMO_COMO'] );
  959. $activeWorksheetArtitle->setCellValue("L".$key, $artitle['ARSE_CANT']);
  960. $activeWorksheetArtitle->setCellValue("M".$key, '$'. $artitle['ARSE_PRTO'] . ' ' . $artitle['CAMO_COMO'] );
  961. $activeWorksheetArtitle->setCellValue("N".$key, $artitle['ARSE_IDAS']);
  962. }
  963. foreach ($arrHeaderArtitle as $keyHeaderArtitle => $headerArtitle) {
  964. $activeWorksheetArtitle->setCellValue( $arrAlphabet[$keyHeaderArtitle]."1", $headerArtitle);
  965. $activeWorksheetArtitle->getColumnDimension( $arrAlphabet[$keyHeaderArtitle] )->setAutoSize(true);
  966. $activeWorksheetArtitle->getStyle( $arrAlphabet[$keyHeaderArtitle]."1" )->getFont()->setBold(true);
  967. }
  968. $nuli = $this->resourcesController->formatSecuence($line, 2);
  969. $como = 'GEAD'; // Código del módulo
  970. $cldo = 'IN'; // Código de la clasificación
  971. $fecr = date('ymd'); // Fecha en la se carga el archivo
  972. try {
  973. $arrSecuence = (array) DB::table('S002V01TAFAL')
  974. ->where('AFAL_COMO', '=', $como)
  975. ->where('AFAL_CLDO', '=', $cldo)
  976. ->where('AFAL_NULI', '=', $line)
  977. ->orderBy('AFAL_NUSE', 'desc')
  978. ->first([ 'AFAL_NUSE' ]);
  979. } catch (\Throwable $th) {
  980. return $this->responseController->makeResponse(
  981. true,
  982. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  983. $th->getMessage(),
  984. 500
  985. );
  986. }
  987. $nuse = 1; // Secuencia del documento
  988. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  989. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  990. }
  991. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  992. $nuve = $this->resourcesController->formatSecuence('1', 2);
  993. $noar = 'ficha_de_adquisición_' . $arrOrder['ORCO_NUOR'];
  994. $exte = 'xlsx';
  995. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  996. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  997. } else {
  998. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  999. }
  1000. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  1001. $tempFile = $filePath.$fileName;
  1002. if ( file_exists( $tempFile ) ) {
  1003. if ( !unlink( $tempFile ) ) {
  1004. return $this->responseController->makeResponse(
  1005. true,
  1006. "ERR_PROVIDER_SHEET021: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
  1007. [],
  1008. 500
  1009. );
  1010. }
  1011. }
  1012. try {
  1013. $writer = new Xlsx($spreadsheet);
  1014. ob_start();
  1015. $writer->save('php://output');
  1016. $base64 = base64_encode(ob_get_clean());
  1017. $validate = \File::put( $tempFile, base64_decode($base64));
  1018. } catch (\Throwable $th) {
  1019. return $this->responseController->makeResponse(
  1020. true,
  1021. "ERR_PROVIDER_SHEET022: Ocurrió un error al guardar el documento.",
  1022. $th->getMessage(),
  1023. 500
  1024. );
  1025. }
  1026. $ubic = Storage::putFile('files', new File($tempFile));
  1027. $ubic = str_replace("/", "\\", $ubic);
  1028. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  1029. $tama = filesize($ubic);
  1030. $usac = json_encode([$user]);
  1031. $now = $this->functionsController->now();
  1032. $currentDate = $now->toDateTimeString();
  1033. try {
  1034. $validateInsert = DB::table('S002V01TAFAL')->insert([
  1035. 'AFAL_NULI' => $line,
  1036. 'AFAL_COMO' => $como,
  1037. 'AFAL_CLDO' => $cldo,
  1038. 'AFAL_FECR' => $fecr,
  1039. 'AFAL_NUSE' => $nuse,
  1040. 'AFAL_NUVE' => $nuve,
  1041. 'AFAL_NOAR' => $noar,
  1042. 'AFAL_EXTE' => $exte,
  1043. 'AFAL_TAMA' => $tama,
  1044. 'AFAL_UBIC' => $ubic,
  1045. 'AFAL_USAC' => $usac,
  1046. 'AFAL_USRE' => $user,
  1047. 'AFAL_FERE' => $currentDate,
  1048. ]);
  1049. } catch (\Throwable $th) {
  1050. return $this->responseController->makeResponse(
  1051. true,
  1052. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  1053. $th->getMessage(),
  1054. 500
  1055. );
  1056. }
  1057. if ( !$validateInsert ) {
  1058. return $this->responseController->makeResponse(
  1059. true,
  1060. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  1061. [],
  1062. 500
  1063. );
  1064. }
  1065. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  1066. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  1067. }
  1068. public function generateSheetAcquisitionPDF($encOrderNumber, $user, $line) {
  1069. try {
  1070. $idOrder = $this->encController->decrypt($encOrderNumber);
  1071. } catch (\Throwable $th) {
  1072. DB::rollBack();
  1073. return $this->responseController->makeResponse(
  1074. true,
  1075. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  1076. $th->getMessage(),
  1077. 500
  1078. );
  1079. }
  1080. try {
  1081. $user = $this->encController->decrypt($user);
  1082. } catch (\Throwable $th) {
  1083. DB::rollBack();
  1084. return $this->responseController->makeResponse(
  1085. true,
  1086. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  1087. $th->getMessage(),
  1088. 500
  1089. );
  1090. }
  1091. try {
  1092. $arrOrder = (array) DB::table('S002V01TORCO')
  1093. ->where('ORCO_NUOR', '=', $idOrder)
  1094. ->where('ORCO_NULI', '=', $line)
  1095. ->where('LINE_NULI', '=', $line)
  1096. ->where('DESP_NULI', '=', $line)
  1097. ->where('PROV_NULI', '=', $line)
  1098. ->where('DESP_ESTA', '=', 'Activo')
  1099. ->where('PROV_ESTA', '=', 'Activo')
  1100. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  1101. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  1102. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  1103. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  1104. ->first([
  1105. 'ORCO_NUOR',
  1106. 'ORCO_ESTA',
  1107. 'LINE_IDLI',
  1108. 'LINE_OTPR',
  1109. 'LINE_OTCO',
  1110. 'LINE_ESTA',
  1111. 'DESP_IDDE',
  1112. 'DESP_NODE',
  1113. 'DESP_NOMB',
  1114. 'DESP_APPA',
  1115. 'DESP_APMA',
  1116. 'DESP_LADA',
  1117. 'DESP_TELE',
  1118. 'DESP_CORR',
  1119. 'DESP_CALL',
  1120. 'DESP_NUEX',
  1121. 'DESP_NUIN',
  1122. 'DESP_COPO',
  1123. 'DESP_COLO',
  1124. 'DESP_LOCA',
  1125. 'DESP_MUNI',
  1126. 'DESP_ENTI',
  1127. 'DESP_PAIS',
  1128. 'DESP_COME',
  1129. 'PROV_NUPR',
  1130. 'PROV_IDPS',
  1131. 'PROV_NOCO',
  1132. 'PROV_NOMB',
  1133. 'PROV_APPA',
  1134. 'PROV_APMA',
  1135. 'PROV_CORR',
  1136. 'PROV_LAD1',
  1137. 'PROV_TEL1',
  1138. 'PROV_LAD2',
  1139. 'PROV_TEL2',
  1140. 'PROV_XRFC',
  1141. 'PROV_XTAX',
  1142. 'PROV_TIPO',
  1143. 'PROV_TICO',
  1144. 'PROV_SIWE',
  1145. 'PROV_MEPA',
  1146. 'PROV_CALL',
  1147. 'PROV_NUEX',
  1148. 'PROV_NUIN',
  1149. 'PROV_COPO',
  1150. 'PROV_COLO',
  1151. 'PROV_MUNI',
  1152. 'PROV_LOCA',
  1153. 'PROV_ENTI',
  1154. 'PROV_PAIS',
  1155. 'REFI_CRFI',
  1156. 'REFI_DRFI',
  1157. ]);
  1158. } catch (\Throwable $th) {
  1159. return $this->responseController->makeResponse(
  1160. true,
  1161. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  1162. $th->getMessage(),
  1163. 500
  1164. );
  1165. }
  1166. try {
  1167. $arrArtitle = DB::table('S002V01TARSE')
  1168. ->where('ARSE_NULI', '=', $line)
  1169. ->where('INAR_NULI', '=', $line)
  1170. ->where('CAMO_NULI', '=', $line)
  1171. ->where('DEAR_NULI', '=', $line)
  1172. ->where('UNID_NULI', '=', $line)
  1173. ->where('ARTI_NULI', '=', $line)
  1174. ->where('FAMI_NULI', '=', $line)
  1175. ->where('SUBF_NULI', '=', $line)
  1176. ->where('ARSE_ESTA', '=', 'Activo')
  1177. ->where('INAR_ESTA', '=', 'Activo')
  1178. ->where('CAMO_ESTA', '=', 'Activo')
  1179. ->where('DEAR_ESTA', '=', 'Activo')
  1180. ->where('UNID_ESTA', '=', 'Activo')
  1181. ->where('ARTI_ESTA', '=', 'Activo')
  1182. ->where('FAMI_ESTA', '=', 'Activo')
  1183. ->where('SUBF_ESTA', '=', 'Activo')
  1184. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  1185. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  1186. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  1187. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  1188. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  1189. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  1190. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  1191. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  1192. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  1193. ->get([
  1194. 'ARSE_IDAS',
  1195. 'ARSE_IDLI',
  1196. 'ARSE_CANT',
  1197. 'ARSE_PRTO',
  1198. 'INAR_IDIN',
  1199. 'INAR_CODI',
  1200. 'INAR_MODE',
  1201. 'INAR_PREC',
  1202. 'INAR_MOMI',
  1203. 'INAR_CARA',
  1204. 'CAMO_COMO',
  1205. 'CAMO_DESC',
  1206. 'CAMO_DECI',
  1207. 'CAMO_POVA',
  1208. 'CAMO_FEIN',
  1209. 'CAMO_FEFI',
  1210. 'DEAR_IDDE',
  1211. 'DEAR_IMAG',
  1212. 'DEAR_DESC',
  1213. 'DEAR_CARA',
  1214. 'DEAR_COWE',
  1215. 'UNID_IDUN',
  1216. 'UNID_NOMB',
  1217. 'UNID_ACRO',
  1218. 'ARTI_IDAR',
  1219. 'ARTI_CODI',
  1220. 'ARTI_NOMB',
  1221. 'FAMI_COFA',
  1222. 'FAMI_NOFA',
  1223. 'SUBF_COSU',
  1224. 'SUBF_NOSU',
  1225. ]);
  1226. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  1227. } catch (\Throwable $th) {
  1228. return $this->responseController->makeResponse(
  1229. true,
  1230. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  1231. $th->getMessage(),
  1232. 500
  1233. );
  1234. }
  1235. $html = '<!DOCTYPE html>
  1236. <html lang="en">
  1237. <head>
  1238. <meta charset="UTF-8">
  1239. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1240. <title>Document</title>
  1241. <style>
  1242. body {
  1243. font-family: Arial, Helvetica, sans-serif;
  1244. font-size: 8pt;
  1245. }
  1246. .section-title {
  1247. margin: 20px 0;
  1248. font-size: 12pt;
  1249. }
  1250. table {
  1251. width: 100%;
  1252. font-size: 8pt;
  1253. }
  1254. thead tr th {
  1255. text-align: start;
  1256. padding: 0 16px;
  1257. height: 52px;
  1258. border-bottom-width: 1px;
  1259. border-bottom-style: solid;
  1260. border-bottom-color: #CCC;
  1261. }
  1262. tbody tr td {
  1263. padding: 0 16px;
  1264. height: 52px;
  1265. border-bottom-width: 1px;
  1266. border-bottom-style: solid;
  1267. border-bottom-color: #CCC;
  1268. }
  1269. p {
  1270. text-align: justify;
  1271. }
  1272. </style>
  1273. </head>
  1274. <body>
  1275. <div class="item">
  1276. <b>Número de Orden de Compra: </b>
  1277. <span>'.$arrOrder['ORCO_NUOR'].'</span>
  1278. </div>
  1279. <div class="item">
  1280. <b>Estado de la orden: </b>
  1281. <span>'.$arrOrder['ORCO_ESTA'].'</span>
  1282. </div>
  1283. <div class="item">
  1284. <b>Numero de línea de solicitud: </b>
  1285. <span>'.$arrOrder['LINE_IDLI'].'</span>
  1286. </div>
  1287. ';
  1288. if ( !is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  1289. $html.='<div class="item">
  1290. <b>Orden de Trabajo Preventivo: </b>
  1291. <span>'.$arrOrder['LINE_OTPR'].'</span>
  1292. </div>';
  1293. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && !is_null( $arrOrder['LINE_OTCO'] ) ) {
  1294. $html.='<div class="item">
  1295. <b>Orden de Trabajo Correctivo: </b>
  1296. <span>'.$arrOrder['LINE_OTCO'].'</span>
  1297. </div>';
  1298. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  1299. $html.='<div class="item">
  1300. <b>Orden de Trabajo: </b>
  1301. <span>No aplica</span>
  1302. </div>';
  1303. } else {
  1304. $html.='<div class="item">
  1305. <b>Orden de Trabajo: </b>
  1306. <span>No aplica</span>
  1307. </div>';
  1308. }
  1309. $html.='<div class="item">
  1310. <b>ID Despacho: </b>
  1311. <span>'.$arrOrder['DESP_IDDE'].'</span>
  1312. </div>
  1313. <div class="item">
  1314. <b>Despacho: </b>
  1315. <span>'.$arrOrder['DESP_NODE'].'</span>
  1316. </div>
  1317. <div class="item">
  1318. <b>Responsable del despacho: </b>
  1319. <span>'.$arrOrder['DESP_NOMB'] . ' ' . $arrOrder['DESP_APPA'] . ' ' . $arrOrder['DESP_APMA'].'</span>
  1320. </div>
  1321. <div class="item">
  1322. <b>Teléfono del despacho: </b>
  1323. <span>'.$arrOrder['DESP_LADA'] . ' ' . $arrOrder['DESP_TELE'].'</span>
  1324. </div>
  1325. <div class="item">
  1326. <b>Correo electrónico del despacho: </b>
  1327. <span>'.$arrOrder['DESP_CORR'].'</span>
  1328. </div>
  1329. <div class="item">
  1330. <b>Calle del despacho: </b>
  1331. <span>'.$arrOrder['DESP_CALL'].'</span>
  1332. </div>
  1333. <div class="item">
  1334. <b>Número exterior: </b>
  1335. <span>'.$arrOrder['DESP_NUEX'].'</span>
  1336. </div>
  1337. ';
  1338. if ( !is_null($arrOrder['DESP_NUIN']) ) {
  1339. $html.='<div class="item">
  1340. <b>Número interior: </b>
  1341. <span>'.$arrOrder['DESP_NUIN'].'</span>
  1342. </div>';
  1343. } else {
  1344. $html.='<div class="item">
  1345. <b>Número interior: </b>
  1346. <span>No aplica</span>
  1347. </div>';
  1348. }
  1349. $html.='<div class="item">
  1350. <b>Código postal: </b>
  1351. <span>'.$arrOrder['DESP_COPO'].'</span>
  1352. </div>
  1353. <div class="item">
  1354. <b>Colonia: </b>
  1355. <span>'.$arrOrder['DESP_COLO'].'</span>
  1356. </div>
  1357. ';
  1358. if ( !is_null($arrOrder['DESP_LOCA']) && !empty($arrOrder['DESP_LOCA']) ) {
  1359. $html.='<div class="item">
  1360. <b>Localidad: </b>
  1361. <span>'.$arrOrder['DESP_LOCA'].'</span>
  1362. </div>';
  1363. } else {
  1364. $html.='<div class="item">
  1365. <b>Localidad: </b>
  1366. <span>No aplica</span>
  1367. </div>';
  1368. }
  1369. $html.='<div class="item">
  1370. <b>Municipio: </b>
  1371. <span>'.$arrOrder['DESP_MUNI'].'</span>
  1372. </div>
  1373. <div class="item">
  1374. <b>Entidad Federativa: </b>
  1375. <span>'.$arrOrder['DESP_ENTI'].'</span>
  1376. </div>
  1377. <div class="item">
  1378. <b>País: </b>
  1379. <span>'.$arrOrder['DESP_PAIS'].'</span>
  1380. </div>
  1381. <div class="item">
  1382. <b>Número de proveedor: </b>
  1383. <span>'.$arrOrder['PROV_NUPR'].'</span>
  1384. </div>
  1385. <div class="item">
  1386. <b>Número de subcontratista: </b>
  1387. <span>'.$arrOrder['PROV_IDPS'].'</span>
  1388. </div>
  1389. <div class="item">
  1390. <b>Nombre comercial del proveedor: </b>
  1391. <span>'.$arrOrder['PROV_NOCO'].'</span>
  1392. </div>
  1393. <div class="item">
  1394. <b>Referencia fiscal del proveedor: </b>
  1395. <span>'.$arrOrder['REFI_DRFI'] . ' (' . $arrOrder['REFI_CRFI'] . ')'.'</span>
  1396. </div>
  1397. <div class="item">
  1398. <b>Responsable del proveedor: </b>
  1399. <span>'.$arrOrder['PROV_NOMB'] . ' ' . $arrOrder['PROV_APPA'] . ' ' . $arrOrder['PROV_APMA'].'</span>
  1400. </div>
  1401. <div class="item">
  1402. <b>Correo electrónico del proveedor: </b>
  1403. <span>'.$arrOrder['PROV_CORR'].'</span>
  1404. </div>
  1405. <div class="item">
  1406. <b>Teléfono del proveedor: </b>
  1407. <span>'.$arrOrder['PROV_LAD1'] . ' ' . $arrOrder['PROV_TEL1'].'</span>
  1408. </div>
  1409. ';
  1410. if ( !is_null( $arrOrder['PROV_XRFC'] ) && is_null( $arrOrder['PROV_XRFC'] )) {
  1411. $html.='<div class="item">
  1412. <b>R.F.C. del proveedor: </b>
  1413. <span>'.$arrOrder['PROV_XRFC'].'</span>
  1414. </div>';
  1415. } else if ( is_null( $arrOrder['PROV_XRFC'] ) && !is_null( $arrOrder['PROV_XRFC'] )) {
  1416. $html.='<div class="item">
  1417. <b>TAX ID. del proveedor: </b>
  1418. <span>'.$arrOrder['PROV_XTAX'].'</span>
  1419. </div>';
  1420. } else {
  1421. $html.='<div class="item">
  1422. <b>R.F.C. / TAX ID: </b>
  1423. <span>No aplica</span>
  1424. </div>';
  1425. }
  1426. if ( !empty($arrArtitle) ) {
  1427. $html.='
  1428. <div style="page-break-after:always;"></div>
  1429. <div class="section-title">
  1430. <b>Artículos</b>
  1431. </div>';
  1432. $html.='<table cellspacing="0" cellpadding="0">
  1433. <thead>
  1434. <tr>
  1435. <th>ID Artículo</th>
  1436. <th>Código del artíulo</th>
  1437. <th>Artículo</th>
  1438. <th>Familia</th>
  1439. <th>Subfamilia</th>
  1440. <!-- <th>Descripción</th> -->
  1441. <!-- <th>Características</th> -->
  1442. <th>Unidad</th>
  1443. <th>Código</th>
  1444. <th>Modelo</th>
  1445. <th>Precio Unitario</th>
  1446. <th>Cantidad</th>
  1447. <th>Precio Total</th>
  1448. <th>No. de selección</th>
  1449. </tr>
  1450. </thead>
  1451. <tbody>';
  1452. foreach ($arrArtitle as $keyArtitle => $artitle) {
  1453. $html.= '<tr>
  1454. <td>'.$artitle['ARTI_IDAR'].'</td>
  1455. <td>'.$artitle['ARTI_CODI'].'</td>
  1456. <td>'.$artitle['ARTI_NOMB'].'</td>
  1457. <td>'.$artitle['FAMI_NOFA'] . ' (' . $artitle['FAMI_COFA'] . ')'.'</td>
  1458. <td>'.$artitle['SUBF_NOSU'] . ' (' . $artitle['SUBF_COSU'] . ')'.'</td>
  1459. <!-- <td>'.$artitle['DEAR_DESC'].'</td> -->
  1460. <!-- <td>'.$artitle['DEAR_CARA'].'</td> -->
  1461. <td>'.$artitle['UNID_NOMB'] . ' (' . $artitle['UNID_IDUN'] . ')'.'</td>
  1462. <td>'.$artitle['INAR_CODI'].'</td>
  1463. <td>'.$artitle['INAR_MODE'].'</td>
  1464. <td>'.'$'. $artitle['INAR_PREC'] . ' ' . $artitle['CAMO_COMO'] .'</td>
  1465. <td>'.$artitle['ARSE_CANT'].'</td>
  1466. <td>'.'$'. $artitle['ARSE_PRTO'] . ' ' . $artitle['CAMO_COMO'] .'</td>
  1467. <td>'.$artitle['ARSE_IDAS'].'</td>
  1468. </tr>';
  1469. }
  1470. $html.= '</tbody>
  1471. </table>';
  1472. }
  1473. $html.='</body></html>';
  1474. // return $html;
  1475. $nuli = $this->resourcesController->formatSecuence($line, 2);
  1476. $como = 'GEAD'; // Código del módulo
  1477. $cldo = 'IN'; // Código de la clasificación
  1478. $fecr = date('ymd'); // Fecha en la se carga el archivo
  1479. try {
  1480. $arrSecuence = (array) DB::table('S002V01TAFAL')
  1481. ->where('AFAL_COMO', '=', $como)
  1482. ->where('AFAL_CLDO', '=', $cldo)
  1483. ->where('AFAL_NULI', '=', $line)
  1484. ->orderBy('AFAL_NUSE', 'desc')
  1485. ->first([ 'AFAL_NUSE' ]);
  1486. } catch (\Throwable $th) {
  1487. return $this->responseController->makeResponse(
  1488. true,
  1489. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  1490. $th->getMessage(),
  1491. 500
  1492. );
  1493. }
  1494. $nuse = 1; // Secuencia del documento
  1495. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  1496. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  1497. }
  1498. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  1499. $nuve = $this->resourcesController->formatSecuence('1', 2);
  1500. $noar = 'ficha_de_adquisición_' . $arrOrder['ORCO_NUOR'];
  1501. $nuli = $this->resourcesController->formatSecuence($line, 2);
  1502. $como = 'GEAD'; // Código del módulo
  1503. $cldo = 'IN'; // Código de la clasificación
  1504. $fecr = date('ymd'); // Fecha en la se carga el archivo
  1505. try {
  1506. $arrSecuence = (array) DB::table('S002V01TAFAL')
  1507. ->where('AFAL_COMO', '=', $como)
  1508. ->where('AFAL_CLDO', '=', $cldo)
  1509. ->where('AFAL_NULI', '=', $line)
  1510. ->orderBy('AFAL_NUSE', 'desc')
  1511. ->first([ 'AFAL_NUSE' ]);
  1512. } catch (\Throwable $th) {
  1513. return $this->responseController->makeResponse(
  1514. true,
  1515. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  1516. $th->getMessage(),
  1517. 500
  1518. );
  1519. }
  1520. $nuse = 1; // Secuencia del documento
  1521. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  1522. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  1523. }
  1524. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  1525. $nuve = $this->resourcesController->formatSecuence('1', 2);
  1526. $noar = 'ficha_de_adquisición_' . $arrOrder['ORCO_NUOR'];
  1527. $exte = 'pdf';
  1528. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  1529. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  1530. } else {
  1531. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  1532. }
  1533. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  1534. $tempFile = $filePath . $fileName;
  1535. $dompdf = new Dompdf();
  1536. $dompdf ->loadHtml($html);
  1537. $dompdf->setPaper('A4', 'landscape');
  1538. $dompdf->render();
  1539. $output = $dompdf->output();
  1540. file_put_contents($tempFile, $output);
  1541. $ubic = Storage::putFile('files', new File($tempFile));
  1542. $ubic = str_replace("/", "\\", $ubic);
  1543. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  1544. $tama = filesize($ubic);
  1545. $usac = json_encode([$user]);
  1546. $now = $this->functionsController->now();
  1547. $currentDate = $now->toDateTimeString();
  1548. try {
  1549. $validateInsert = DB::table('S002V01TAFAL')->insert([
  1550. 'AFAL_NULI' => $line,
  1551. 'AFAL_COMO' => $como,
  1552. 'AFAL_CLDO' => $cldo,
  1553. 'AFAL_FECR' => $fecr,
  1554. 'AFAL_NUSE' => $nuse,
  1555. 'AFAL_NUVE' => $nuve,
  1556. 'AFAL_NOAR' => $noar,
  1557. 'AFAL_EXTE' => $exte,
  1558. 'AFAL_TAMA' => $tama,
  1559. 'AFAL_UBIC' => $ubic,
  1560. 'AFAL_USAC' => $usac,
  1561. 'AFAL_USRE' => $user,
  1562. 'AFAL_FERE' => $currentDate,
  1563. ]);
  1564. } catch (\Throwable $th) {
  1565. return $this->responseController->makeResponse(
  1566. true,
  1567. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  1568. $th->getMessage(),
  1569. 500
  1570. );
  1571. }
  1572. if ( !$validateInsert ) {
  1573. return $this->responseController->makeResponse(
  1574. true,
  1575. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  1576. [],
  1577. 500
  1578. );
  1579. }
  1580. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  1581. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  1582. }
  1583. public function generateSheetDivisaXLS($encOrderNumber, $user, $line) {
  1584. try {
  1585. $idOrder = $this->encController->decrypt($encOrderNumber);
  1586. } catch (\Throwable $th) {
  1587. DB::rollBack();
  1588. return $this->responseController->makeResponse(
  1589. true,
  1590. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  1591. $th->getMessage(),
  1592. 500
  1593. );
  1594. }
  1595. try {
  1596. $user = $this->encController->decrypt($user);
  1597. } catch (\Throwable $th) {
  1598. DB::rollBack();
  1599. return $this->responseController->makeResponse(
  1600. true,
  1601. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  1602. $th->getMessage(),
  1603. 500
  1604. );
  1605. }
  1606. try {
  1607. $arrOrder = (array) DB::table('S002V01TORCO')
  1608. ->where('ORCO_NUOR', '=', $idOrder)
  1609. ->where('ORCO_NULI', '=', $line)
  1610. ->where('LINE_NULI', '=', $line)
  1611. ->where('DESP_NULI', '=', $line)
  1612. ->where('PROV_NULI', '=', $line)
  1613. ->where('DESP_ESTA', '=', 'Activo')
  1614. ->where('PROV_ESTA', '=', 'Activo')
  1615. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  1616. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  1617. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  1618. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  1619. ->first([
  1620. 'ORCO_NUOR',
  1621. 'ORCO_ESTA',
  1622. 'LINE_IDLI',
  1623. 'LINE_OTPR',
  1624. 'LINE_OTCO',
  1625. 'LINE_ESTA',
  1626. 'DESP_IDDE',
  1627. 'DESP_NODE',
  1628. 'DESP_NOMB',
  1629. 'DESP_APPA',
  1630. 'DESP_APMA',
  1631. 'DESP_LADA',
  1632. 'DESP_TELE',
  1633. 'DESP_CORR',
  1634. 'DESP_CALL',
  1635. 'DESP_NUEX',
  1636. 'DESP_NUIN',
  1637. 'DESP_COPO',
  1638. 'DESP_COLO',
  1639. 'DESP_LOCA',
  1640. 'DESP_MUNI',
  1641. 'DESP_ENTI',
  1642. 'DESP_PAIS',
  1643. 'DESP_COME',
  1644. 'PROV_NUPR',
  1645. 'PROV_IDPS',
  1646. 'PROV_NOCO',
  1647. 'PROV_NOMB',
  1648. 'PROV_APPA',
  1649. 'PROV_APMA',
  1650. 'PROV_CORR',
  1651. 'PROV_LAD1',
  1652. 'PROV_TEL1',
  1653. 'PROV_LAD2',
  1654. 'PROV_TEL2',
  1655. 'PROV_XRFC',
  1656. 'PROV_XTAX',
  1657. 'PROV_TIPO',
  1658. 'PROV_TICO',
  1659. 'PROV_SIWE',
  1660. 'PROV_MEPA',
  1661. 'PROV_CALL',
  1662. 'PROV_NUEX',
  1663. 'PROV_NUIN',
  1664. 'PROV_COPO',
  1665. 'PROV_COLO',
  1666. 'PROV_MUNI',
  1667. 'PROV_LOCA',
  1668. 'PROV_ENTI',
  1669. 'PROV_PAIS',
  1670. 'REFI_CRFI',
  1671. 'REFI_DRFI',
  1672. ]);
  1673. } catch (\Throwable $th) {
  1674. return $this->responseController->makeResponse(
  1675. true,
  1676. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  1677. $th->getMessage(),
  1678. 500
  1679. );
  1680. }
  1681. try {
  1682. $arrArtitle = DB::table('S002V01TARSE')
  1683. ->where('ARSE_NULI', '=', $line)
  1684. ->where('INAR_NULI', '=', $line)
  1685. ->where('CAMO_NULI', '=', $line)
  1686. ->where('DEAR_NULI', '=', $line)
  1687. ->where('UNID_NULI', '=', $line)
  1688. ->where('ARTI_NULI', '=', $line)
  1689. ->where('FAMI_NULI', '=', $line)
  1690. ->where('SUBF_NULI', '=', $line)
  1691. ->where('ARSE_ESTA', '=', 'Activo')
  1692. ->where('INAR_ESTA', '=', 'Activo')
  1693. ->where('CAMO_ESTA', '=', 'Activo')
  1694. ->where('DEAR_ESTA', '=', 'Activo')
  1695. ->where('UNID_ESTA', '=', 'Activo')
  1696. ->where('ARTI_ESTA', '=', 'Activo')
  1697. ->where('FAMI_ESTA', '=', 'Activo')
  1698. ->where('SUBF_ESTA', '=', 'Activo')
  1699. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  1700. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  1701. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  1702. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  1703. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  1704. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  1705. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  1706. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  1707. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  1708. ->get([
  1709. 'ARSE_IDAS',
  1710. 'ARSE_IDLI',
  1711. 'ARSE_CANT',
  1712. 'ARSE_PRTO',
  1713. 'INAR_IDIN',
  1714. 'INAR_CODI',
  1715. 'INAR_MODE',
  1716. 'INAR_PREC',
  1717. 'INAR_MOMI',
  1718. 'INAR_CARA',
  1719. 'CAMO_COMO',
  1720. 'CAMO_DESC',
  1721. 'CAMO_DECI',
  1722. 'CAMO_POVA',
  1723. 'CAMO_FEIN',
  1724. 'CAMO_FEFI',
  1725. 'DEAR_IDDE',
  1726. 'DEAR_IMAG',
  1727. 'DEAR_DESC',
  1728. 'DEAR_CARA',
  1729. 'DEAR_COWE',
  1730. 'UNID_IDUN',
  1731. 'UNID_NOMB',
  1732. 'UNID_ACRO',
  1733. 'ARTI_IDAR',
  1734. 'ARTI_CODI',
  1735. 'ARTI_NOMB',
  1736. 'FAMI_COFA',
  1737. 'FAMI_NOFA',
  1738. 'SUBF_COSU',
  1739. 'SUBF_NOSU',
  1740. ]);
  1741. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  1742. } catch (\Throwable $th) {
  1743. return $this->responseController->makeResponse(
  1744. true,
  1745. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  1746. $th->getMessage(),
  1747. 500
  1748. );
  1749. }
  1750. try {
  1751. $arrInvoice = DB::table('S002V01TFALS')
  1752. ->where('FALS_IDLI', '=', $arrOrder['LINE_IDLI'])
  1753. ->where('FALS_NULI', '=', $line)
  1754. ->where('DLSC_NULI', '=', $line)
  1755. ->where('FALS_ESTA', '=', 'Activo')
  1756. ->where('DLSC_ESTA', '=', 'Activo')
  1757. ->where('DLSC_TIPO', '=', 'Cotización')
  1758. ->orWhere('DLSC_TIPO', '=', 'Orden')
  1759. ->join('S002V01TDLSC', 'DLSC_IDFA', '=', 'FALS_IDFA')
  1760. ->get([
  1761. 'FALS_IDFA',
  1762. 'FALS_CODO',
  1763. 'FALS_UUID',
  1764. 'FALS_VERS',
  1765. 'FALS_FEEM',
  1766. 'FALS_RFCE',
  1767. 'FALS_RFCR',
  1768. 'FALS_FOLI',
  1769. 'FALS_SERI',
  1770. 'FALS_FOPA',
  1771. 'FALS_MEPA',
  1772. 'FALS_TICA',
  1773. 'FALS_MONE',
  1774. 'FALS_COPA',
  1775. 'DLSC_IDDO',
  1776. 'DLSC_CODO',
  1777. 'DLSC_TIPO',
  1778. 'DLSC_TIAR',
  1779. 'DLSC_DESC',
  1780. ]);
  1781. $arrInvoice = json_decode( json_encode( $arrInvoice ), true );
  1782. } catch (\Throwable $th) {
  1783. return $this->responseController->makeResponse(
  1784. true,
  1785. "ERR_ORDER_SHEET003: Ocurrió un error al obtener la información de las facturas.",
  1786. $th->getMessage(),
  1787. 500
  1788. );
  1789. }
  1790. if ( empty($arrInvoice) ) {
  1791. return $this->responseController->makeResponse(
  1792. true,
  1793. "ERR_ORDER_SHEET004: La orden de compra no tiene ninguna factura registrada.",
  1794. [],
  1795. 500
  1796. );
  1797. }
  1798. $arrInvoiceOrder = array();
  1799. $arrInvoiceCotizacion = array();
  1800. foreach ($arrInvoice as $keyInvoice => $invoice) {
  1801. if ( $invoice['DLSC_TIPO'] === 'Orden') {
  1802. $arrInvoiceOrder[] = $invoice;
  1803. }
  1804. if ( $invoice['DLSC_TIPO'] === 'Cotización') {
  1805. $arrInvoiceCotizacion[] = $invoice;
  1806. }
  1807. }
  1808. unset($arrInvoice);
  1809. if ( !empty($arrInvoiceOrder) ) {
  1810. $idMax = 0;
  1811. foreach ($arrInvoiceOrder as $keyInvoiceOrder => $invoiceOrder) {
  1812. if ( $invoiceOrder['FALS_IDFA'] > $idMax ) {
  1813. $idMax = $invoiceOrder['FALS_IDFA'];
  1814. $arrInvoice = $invoiceOrder;
  1815. }
  1816. }
  1817. } else {
  1818. $idMax = 0;
  1819. foreach ($arrInvoiceCotizacion as $keyInvoiceCotizacion => $invoiceCotizacion) {
  1820. if ( $invoiceCotizacion['FALS_IDFA'] > $idMax ) {
  1821. $idMax = $invoiceCotizacion['FALS_IDFA'];
  1822. $arrInvoice = $invoiceCotizacion;
  1823. }
  1824. }
  1825. }
  1826. $spreadsheet = new Spreadsheet();
  1827. $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrOrder['ORCO_NUOR']);
  1828. $headerA1 = 'Número de orden';
  1829. $contentB1 = $arrOrder['ORCO_NUOR'];
  1830. $activeWorksheet->setCellValue("A1", $headerA1);
  1831. $activeWorksheet->setCellValue("B1", $contentB1);
  1832. $activeWorksheet->getStyle( "A1" )->getFont()->setBold(true);
  1833. $headerA2 = 'Estado de la orden';
  1834. $contentB2 = $arrOrder['ORCO_ESTA'];
  1835. $activeWorksheet->setCellValue("A2", $headerA2);
  1836. $activeWorksheet->setCellValue("B2", $contentB2);
  1837. $activeWorksheet->getStyle( "A2" )->getFont()->setBold(true);
  1838. $headerA3 = 'Numero de línea de solicitud';
  1839. $contentB3 = $arrOrder['LINE_IDLI'];
  1840. $activeWorksheet->setCellValue("A3", $headerA3);
  1841. $activeWorksheet->setCellValue("B3", $contentB3);
  1842. $activeWorksheet->getStyle( "A3" )->getFont()->setBold(true);
  1843. $headerA4 = '';
  1844. if ( !is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  1845. $headerA4 = 'Orden de Trabajo Preventivo';
  1846. $contentB4 = $arrOrder['LINE_OTPR'];
  1847. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && !is_null( $arrOrder['LINE_OTCO'] ) ) {
  1848. $headerA4 = 'Orden de Trabajo Correctivo';
  1849. $contentB4 = $arrOrder['LINE_OTCO'];
  1850. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  1851. $headerA4 = 'Orden de Trabajo';
  1852. $contentB4 = 'No aplica';
  1853. } else {
  1854. $headerA4 = 'Orden de Trabajo';
  1855. $contentB4 = 'No aplica';
  1856. }
  1857. $activeWorksheet->setCellValue("A4", $headerA4 );
  1858. $activeWorksheet->setCellValue("B4", $contentB4 );
  1859. $activeWorksheet->getStyle( "A4" )->getFont()->setBold(true);
  1860. $headerA5 = 'ID Despacho';
  1861. $contentB5 = $arrOrder['DESP_IDDE'];
  1862. $activeWorksheet->setCellValue("A5", $headerA5 );
  1863. $activeWorksheet->setCellValue("B5", $contentB5 );
  1864. $activeWorksheet->getStyle( "A5" )->getFont()->setBold(true);
  1865. $headerA6 = 'Despacho';
  1866. $contentB6 = $arrOrder['DESP_NODE'];
  1867. $activeWorksheet->setCellValue("A6", $headerA6 );
  1868. $activeWorksheet->setCellValue("B6", $contentB6 );
  1869. $activeWorksheet->getStyle( "A6" )->getFont()->setBold(true);
  1870. $headerA7 = 'Responsable del despacho';
  1871. $contentB7 = $arrOrder['DESP_NOMB'] . ' ' . $arrOrder['DESP_APPA'] . ' ' . $arrOrder['DESP_APMA'];
  1872. $activeWorksheet->setCellValue("A7", $headerA7 );
  1873. $activeWorksheet->setCellValue("B7", $contentB7 );
  1874. $activeWorksheet->getStyle( "A7" )->getFont()->setBold(true);
  1875. $headerA8 = 'Teléfono del despacho';
  1876. $contentB8 = $arrOrder['DESP_LADA'] . ' ' . $arrOrder['DESP_TELE'];
  1877. $activeWorksheet->setCellValue("A8", $headerA8 );
  1878. $activeWorksheet->setCellValue("B8", $contentB8 );
  1879. $activeWorksheet->getStyle( "A8" )->getFont()->setBold(true);
  1880. $headerA9 = 'Correo electrónico del despacho';
  1881. $contentB9 = $arrOrder['DESP_CORR'];
  1882. $activeWorksheet->setCellValue("A9", $headerA9 );
  1883. $activeWorksheet->setCellValue("B9", $contentB9 );
  1884. $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
  1885. $headerA10 = 'Calle del despacho';
  1886. $contentB10 = $arrOrder['DESP_CALL'];
  1887. $activeWorksheet->setCellValue("A10", $headerA10 );
  1888. $activeWorksheet->setCellValue("B10", $contentB10 );
  1889. $activeWorksheet->getStyle( "A10" )->getFont()->setBold(true);
  1890. $headerA11 = 'Número exterior';
  1891. $contentB11 = $arrOrder['DESP_NUEX'];
  1892. $activeWorksheet->setCellValue("A11", $headerA11 );
  1893. $activeWorksheet->setCellValue("B11", $contentB11 );
  1894. $activeWorksheet->getStyle( "A11" )->getFont()->setBold(true);
  1895. $headerA12 = 'Número interior';
  1896. if ( !is_null($arrOrder['DESP_NUIN']) ) {
  1897. $contentB12 = $arrOrder['DESP_NUIN'];
  1898. } else {
  1899. $contentB12 = 'No aplica';
  1900. }
  1901. $activeWorksheet->setCellValue("A12", $headerA12 );
  1902. $activeWorksheet->setCellValue("B12", $contentB12 );
  1903. $activeWorksheet->getStyle( "A12" )->getFont()->setBold(true);
  1904. $headerA13 = 'Código postal';
  1905. $contentB13 = $arrOrder['DESP_COPO'];
  1906. $activeWorksheet->setCellValue("A13", $headerA13 );
  1907. $activeWorksheet->setCellValue("B13", $contentB13 );
  1908. $activeWorksheet->getStyle( "A13" )->getFont()->setBold(true);
  1909. $headerA14 = 'Colonia';
  1910. $contentB14 = $arrOrder['DESP_COLO'];
  1911. $activeWorksheet->setCellValue("A14", $headerA14 );
  1912. $activeWorksheet->setCellValue("B14", $contentB14 );
  1913. $activeWorksheet->getStyle( "A14" )->getFont()->setBold(true);
  1914. $headerA15 = 'Localidad';
  1915. if ( !is_null($arrOrder['DESP_LOCA']) && !empty($arrOrder['DESP_LOCA']) ) {
  1916. $contentB15 = $arrOrder['DESP_LOCA'];
  1917. } else {
  1918. $contentB15 = 'No aplica';
  1919. }
  1920. $activeWorksheet->setCellValue("A15", $headerA15 );
  1921. $activeWorksheet->setCellValue("B15", $contentB15 );
  1922. $activeWorksheet->getStyle( "A15" )->getFont()->setBold(true);
  1923. $headerA16 = 'Municipio';
  1924. $contentB16 = $arrOrder['DESP_MUNI'];
  1925. $activeWorksheet->setCellValue("A16", $headerA16 );
  1926. $activeWorksheet->setCellValue("B16", $contentB16 );
  1927. $activeWorksheet->getStyle( "A16" )->getFont()->setBold(true);
  1928. $headerA17 = 'Entidad Federativa';
  1929. $contentB17 = $arrOrder['DESP_ENTI'];
  1930. $activeWorksheet->setCellValue("A17", $headerA17 );
  1931. $activeWorksheet->setCellValue("B17", $contentB17 );
  1932. $activeWorksheet->getStyle( "A17" )->getFont()->setBold(true);
  1933. $headerA18 = 'País';
  1934. $contentB18 = $arrOrder['DESP_PAIS'];
  1935. $activeWorksheet->setCellValue("A18", $headerA18 );
  1936. $activeWorksheet->setCellValue("B18", $contentB18 );
  1937. $activeWorksheet->getStyle( "A18" )->getFont()->setBold(true);
  1938. $headerA19 = 'Número de proveedor';
  1939. $contentB19 = $arrOrder['PROV_NUPR'];
  1940. $activeWorksheet->setCellValue("A19", $headerA19 );
  1941. $activeWorksheet->setCellValue("B19", $contentB19 );
  1942. $activeWorksheet->getStyle( "A19" )->getFont()->setBold(true);
  1943. $headerA20 = 'Número de subcontratista';
  1944. $contentB20 = $arrOrder['PROV_IDPS'];
  1945. $activeWorksheet->setCellValue("A20", $headerA20 );
  1946. $activeWorksheet->setCellValue("B20", $contentB20 );
  1947. $activeWorksheet->getStyle( "A20" )->getFont()->setBold(true);
  1948. $headerA21 = 'Nombre comercial del proveedor';
  1949. $contentB21 = $arrOrder['PROV_NOCO'];
  1950. $activeWorksheet->setCellValue("A21", $headerA21 );
  1951. $activeWorksheet->setCellValue("B21", $contentB21 );
  1952. $activeWorksheet->getStyle( "A21" )->getFont()->setBold(true);
  1953. $headerA22 = 'Referencia fiscal del proveedor';
  1954. $contentB22 = $arrOrder['REFI_DRFI'] . ' (' . $arrOrder['REFI_CRFI'] . ')';
  1955. $activeWorksheet->setCellValue("A22", $headerA22 );
  1956. $activeWorksheet->setCellValue("B22", $contentB22 );
  1957. $activeWorksheet->getStyle( "A22" )->getFont()->setBold(true);
  1958. $headerA23 = 'Responsable del proveedor';
  1959. $contentB23 = $arrOrder['PROV_NOMB'] . ' ' . $arrOrder['PROV_APPA'] . ' ' . $arrOrder['PROV_APMA'];
  1960. $activeWorksheet->setCellValue("A23", $headerA23 );
  1961. $activeWorksheet->setCellValue("B23", $contentB23 );
  1962. $activeWorksheet->getStyle( "A23" )->getFont()->setBold(true);
  1963. $headerA24 = 'Correo electrónico del proveedor';
  1964. $contentB24 = $arrOrder['PROV_CORR'];
  1965. $activeWorksheet->setCellValue("A24", $headerA24 );
  1966. $activeWorksheet->setCellValue("B24", $contentB24 );
  1967. $activeWorksheet->getStyle( "A24" )->getFont()->setBold(true);
  1968. $headerA25 = 'Teléfono del proveedor';
  1969. $contentB25 = $arrOrder['PROV_LAD1'] . ' ' . $arrOrder['PROV_TEL1'];
  1970. $activeWorksheet->setCellValue("A25", $headerA25 );
  1971. $activeWorksheet->setCellValue("B25", $contentB25 );
  1972. $activeWorksheet->getStyle( "A25" )->getFont()->setBold(true);
  1973. $headerA26 = '';
  1974. $contentB26 = '';
  1975. if ( !is_null( $arrOrder['PROV_XRFC'] ) && is_null( $arrOrder['PROV_XRFC'] )) {
  1976. $headerA26 = 'R.F.C. del proveedor';
  1977. $contentB26 = $arrOrder['PROV_XRFC'];
  1978. } else if ( is_null( $arrOrder['PROV_XRFC'] ) && !is_null( $arrOrder['PROV_XRFC'] )) {
  1979. $headerA26 = 'TAX ID. del proveedor';
  1980. $contentB26 = $arrOrder['PROV_XTAX'];
  1981. } else {
  1982. $headerA26 = 'R.F.C. / TAX ID';
  1983. $contentB26 = 'No aplica';
  1984. }
  1985. $activeWorksheet->setCellValue("A26", $headerA26 );
  1986. $activeWorksheet->setCellValue("B26", $contentB26 );
  1987. $activeWorksheet->getStyle( "A26" )->getFont()->setBold(true);
  1988. $activeWorksheet->getColumnDimension("A")->setAutoSize(true);
  1989. $activeWorksheet->getColumnDimension("B")->setAutoSize(true);
  1990. $arrAlphabet = $this->resourcesController->arrAlphabet;
  1991. $spreadsheet->createSheet();
  1992. $spreadsheet->setActiveSheetIndex(1);
  1993. $activeWorksheetArtitle = $spreadsheet->getActiveSheet()->setTitle('Artículos de la orden');
  1994. $arrHeaderArtitle = array(
  1995. /* A */ 'ID Artículo',
  1996. /* B */ 'Código del artíulo',
  1997. /* C */ 'Artículo',
  1998. /* D */ 'Familia',
  1999. /* E */ 'Subfamilia',
  2000. /* F */ 'Unidad',
  2001. /* G */ 'Código',
  2002. /* H */ 'Modelo',
  2003. /* I */ 'Precio Unitario',
  2004. /* J */ 'Cantidad',
  2005. /* K */ 'Precio Total',
  2006. /* L */ 'Moneda Local',
  2007. /* M */ 'Tipo de cambio',
  2008. /* N */ 'Precio Local',
  2009. );
  2010. foreach ($arrArtitle as $key => $artitle) {
  2011. $key = $key + 2;
  2012. $activeWorksheetArtitle->setCellValue("A".$key, $artitle['ARTI_IDAR']);
  2013. $activeWorksheetArtitle->setCellValue("B".$key, $artitle['ARTI_CODI']);
  2014. $activeWorksheetArtitle->setCellValue("C".$key, $artitle['ARTI_NOMB']);
  2015. $activeWorksheetArtitle->setCellValue("D".$key, $artitle['FAMI_NOFA'] . ' (' . $artitle['FAMI_COFA'] . ')');
  2016. $activeWorksheetArtitle->setCellValue("E".$key, $artitle['SUBF_NOSU'] . ' (' . $artitle['SUBF_COSU'] . ')');
  2017. $activeWorksheetArtitle->setCellValue("F".$key, $artitle['UNID_NOMB'] . ' (' . $artitle['UNID_IDUN'] . ')');
  2018. $activeWorksheetArtitle->setCellValue("G".$key, $artitle['INAR_CODI']);
  2019. $activeWorksheetArtitle->setCellValue("H".$key, $artitle['INAR_MODE']);
  2020. $activeWorksheetArtitle->setCellValue("I".$key, '$'. $artitle['INAR_PREC'] . ' ' . $artitle['CAMO_COMO'] );
  2021. $activeWorksheetArtitle->setCellValue("J".$key, $artitle['ARSE_CANT']);
  2022. $activeWorksheetArtitle->setCellValue("K".$key, '$'. $artitle['ARSE_PRTO'] . ' ' . $artitle['CAMO_COMO'] );
  2023. $activeWorksheetArtitle->setCellValue("L".$key, 'MXN');
  2024. $activeWorksheetArtitle->setCellValue("M".$key, $arrInvoice['FALS_TICA']);
  2025. $activeWorksheetArtitle->setCellValue("N".$key, '$'.($arrInvoice['FALS_TICA'] * $artitle['INAR_PREC']) . ' MXN' );
  2026. }
  2027. foreach ($arrHeaderArtitle as $keyHeaderArtitle => $headerArtitle) {
  2028. $activeWorksheetArtitle->setCellValue( $arrAlphabet[$keyHeaderArtitle]."1", $headerArtitle);
  2029. $activeWorksheetArtitle->getColumnDimension( $arrAlphabet[$keyHeaderArtitle] )->setAutoSize(true);
  2030. $activeWorksheetArtitle->getStyle( $arrAlphabet[$keyHeaderArtitle]."1" )->getFont()->setBold(true);
  2031. }
  2032. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2033. $como = 'GEAD'; // Código del módulo
  2034. $cldo = 'IN'; // Código de la clasificación
  2035. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2036. try {
  2037. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2038. ->where('AFAL_COMO', '=', $como)
  2039. ->where('AFAL_CLDO', '=', $cldo)
  2040. ->where('AFAL_NULI', '=', $line)
  2041. ->orderBy('AFAL_NUSE', 'desc')
  2042. ->first([ 'AFAL_NUSE' ]);
  2043. } catch (\Throwable $th) {
  2044. return $this->responseController->makeResponse(
  2045. true,
  2046. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2047. $th->getMessage(),
  2048. 500
  2049. );
  2050. }
  2051. $nuse = 1; // Secuencia del documento
  2052. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2053. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2054. }
  2055. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2056. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2057. $noar = 'ficha_de_divisa_' . $arrOrder['ORCO_NUOR'];
  2058. $exte = 'xlsx';
  2059. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  2060. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  2061. } else {
  2062. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  2063. }
  2064. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  2065. $tempFile = $filePath.$fileName;
  2066. if ( file_exists( $tempFile ) ) {
  2067. if ( !unlink( $tempFile ) ) {
  2068. return $this->responseController->makeResponse(
  2069. true,
  2070. "ERR_PROVIDER_SHEET021: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
  2071. [],
  2072. 500
  2073. );
  2074. }
  2075. }
  2076. try {
  2077. $writer = new Xlsx($spreadsheet);
  2078. ob_start();
  2079. $writer->save('php://output');
  2080. $base64 = base64_encode(ob_get_clean());
  2081. $validate = \File::put( $tempFile, base64_decode($base64));
  2082. } catch (\Throwable $th) {
  2083. return $this->responseController->makeResponse(
  2084. true,
  2085. "ERR_PROVIDER_SHEET022: Ocurrió un error al guardar el documento.",
  2086. $th->getMessage(),
  2087. 500
  2088. );
  2089. }
  2090. $ubic = Storage::putFile('files', new File($tempFile));
  2091. $ubic = str_replace("/", "\\", $ubic);
  2092. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  2093. $tama = filesize($ubic);
  2094. $usac = json_encode([$user]);
  2095. $now = $this->functionsController->now();
  2096. $currentDate = $now->toDateTimeString();
  2097. try {
  2098. $validateInsert = DB::table('S002V01TAFAL')->insert([
  2099. 'AFAL_NULI' => $line,
  2100. 'AFAL_COMO' => $como,
  2101. 'AFAL_CLDO' => $cldo,
  2102. 'AFAL_FECR' => $fecr,
  2103. 'AFAL_NUSE' => $nuse,
  2104. 'AFAL_NUVE' => $nuve,
  2105. 'AFAL_NOAR' => $noar,
  2106. 'AFAL_EXTE' => $exte,
  2107. 'AFAL_TAMA' => $tama,
  2108. 'AFAL_UBIC' => $ubic,
  2109. 'AFAL_USAC' => $usac,
  2110. 'AFAL_USRE' => $user,
  2111. 'AFAL_FERE' => $currentDate,
  2112. ]);
  2113. } catch (\Throwable $th) {
  2114. return $this->responseController->makeResponse(
  2115. true,
  2116. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  2117. $th->getMessage(),
  2118. 500
  2119. );
  2120. }
  2121. if ( !$validateInsert ) {
  2122. return $this->responseController->makeResponse(
  2123. true,
  2124. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  2125. [],
  2126. 500
  2127. );
  2128. }
  2129. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  2130. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  2131. }
  2132. public function generateSheetDivisaPDF($encOrderNumber, $user, $line) {
  2133. try {
  2134. $idOrder = $this->encController->decrypt($encOrderNumber);
  2135. } catch (\Throwable $th) {
  2136. DB::rollBack();
  2137. return $this->responseController->makeResponse(
  2138. true,
  2139. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  2140. $th->getMessage(),
  2141. 500
  2142. );
  2143. }
  2144. try {
  2145. $user = $this->encController->decrypt($user);
  2146. } catch (\Throwable $th) {
  2147. DB::rollBack();
  2148. return $this->responseController->makeResponse(
  2149. true,
  2150. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  2151. $th->getMessage(),
  2152. 500
  2153. );
  2154. }
  2155. try {
  2156. $arrOrder = (array) DB::table('S002V01TORCO')
  2157. ->where('ORCO_NUOR', '=', $idOrder)
  2158. ->where('ORCO_NULI', '=', $line)
  2159. ->where('LINE_NULI', '=', $line)
  2160. ->where('DESP_NULI', '=', $line)
  2161. ->where('PROV_NULI', '=', $line)
  2162. ->where('DESP_ESTA', '=', 'Activo')
  2163. ->where('PROV_ESTA', '=', 'Activo')
  2164. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  2165. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  2166. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  2167. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  2168. ->first([
  2169. 'ORCO_NUOR',
  2170. 'ORCO_ESTA',
  2171. 'LINE_IDLI',
  2172. 'LINE_OTPR',
  2173. 'LINE_OTCO',
  2174. 'LINE_ESTA',
  2175. 'DESP_IDDE',
  2176. 'DESP_NODE',
  2177. 'DESP_NOMB',
  2178. 'DESP_APPA',
  2179. 'DESP_APMA',
  2180. 'DESP_LADA',
  2181. 'DESP_TELE',
  2182. 'DESP_CORR',
  2183. 'DESP_CALL',
  2184. 'DESP_NUEX',
  2185. 'DESP_NUIN',
  2186. 'DESP_COPO',
  2187. 'DESP_COLO',
  2188. 'DESP_LOCA',
  2189. 'DESP_MUNI',
  2190. 'DESP_ENTI',
  2191. 'DESP_PAIS',
  2192. 'DESP_COME',
  2193. 'PROV_NUPR',
  2194. 'PROV_IDPS',
  2195. 'PROV_NOCO',
  2196. 'PROV_NOMB',
  2197. 'PROV_APPA',
  2198. 'PROV_APMA',
  2199. 'PROV_CORR',
  2200. 'PROV_LAD1',
  2201. 'PROV_TEL1',
  2202. 'PROV_LAD2',
  2203. 'PROV_TEL2',
  2204. 'PROV_XRFC',
  2205. 'PROV_XTAX',
  2206. 'PROV_TIPO',
  2207. 'PROV_TICO',
  2208. 'PROV_SIWE',
  2209. 'PROV_MEPA',
  2210. 'PROV_CALL',
  2211. 'PROV_NUEX',
  2212. 'PROV_NUIN',
  2213. 'PROV_COPO',
  2214. 'PROV_COLO',
  2215. 'PROV_MUNI',
  2216. 'PROV_LOCA',
  2217. 'PROV_ENTI',
  2218. 'PROV_PAIS',
  2219. 'REFI_CRFI',
  2220. 'REFI_DRFI',
  2221. ]);
  2222. } catch (\Throwable $th) {
  2223. return $this->responseController->makeResponse(
  2224. true,
  2225. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  2226. $th->getMessage(),
  2227. 500
  2228. );
  2229. }
  2230. try {
  2231. $arrArtitle = DB::table('S002V01TARSE')
  2232. ->where('ARSE_NULI', '=', $line)
  2233. ->where('INAR_NULI', '=', $line)
  2234. ->where('CAMO_NULI', '=', $line)
  2235. ->where('DEAR_NULI', '=', $line)
  2236. ->where('UNID_NULI', '=', $line)
  2237. ->where('ARTI_NULI', '=', $line)
  2238. ->where('FAMI_NULI', '=', $line)
  2239. ->where('SUBF_NULI', '=', $line)
  2240. ->where('ARSE_ESTA', '=', 'Activo')
  2241. ->where('INAR_ESTA', '=', 'Activo')
  2242. ->where('CAMO_ESTA', '=', 'Activo')
  2243. ->where('DEAR_ESTA', '=', 'Activo')
  2244. ->where('UNID_ESTA', '=', 'Activo')
  2245. ->where('ARTI_ESTA', '=', 'Activo')
  2246. ->where('FAMI_ESTA', '=', 'Activo')
  2247. ->where('SUBF_ESTA', '=', 'Activo')
  2248. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  2249. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  2250. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  2251. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  2252. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  2253. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  2254. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  2255. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  2256. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  2257. ->get([
  2258. 'ARSE_IDAS',
  2259. 'ARSE_IDLI',
  2260. 'ARSE_CANT',
  2261. 'ARSE_PRTO',
  2262. 'INAR_IDIN',
  2263. 'INAR_CODI',
  2264. 'INAR_MODE',
  2265. 'INAR_PREC',
  2266. 'INAR_MOMI',
  2267. 'INAR_CARA',
  2268. 'CAMO_COMO',
  2269. 'CAMO_DESC',
  2270. 'CAMO_DECI',
  2271. 'CAMO_POVA',
  2272. 'CAMO_FEIN',
  2273. 'CAMO_FEFI',
  2274. 'DEAR_IDDE',
  2275. 'DEAR_IMAG',
  2276. 'DEAR_DESC',
  2277. 'DEAR_CARA',
  2278. 'DEAR_COWE',
  2279. 'UNID_IDUN',
  2280. 'UNID_NOMB',
  2281. 'UNID_ACRO',
  2282. 'ARTI_IDAR',
  2283. 'ARTI_CODI',
  2284. 'ARTI_NOMB',
  2285. 'FAMI_COFA',
  2286. 'FAMI_NOFA',
  2287. 'SUBF_COSU',
  2288. 'SUBF_NOSU',
  2289. ]);
  2290. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  2291. } catch (\Throwable $th) {
  2292. return $this->responseController->makeResponse(
  2293. true,
  2294. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  2295. $th->getMessage(),
  2296. 500
  2297. );
  2298. }
  2299. try {
  2300. $arrInvoice = DB::table('S002V01TFALS')
  2301. ->where('FALS_IDLI', '=', $arrOrder['LINE_IDLI'])
  2302. ->where('FALS_NULI', '=', $line)
  2303. ->where('DLSC_NULI', '=', $line)
  2304. ->where('FALS_ESTA', '=', 'Activo')
  2305. ->where('DLSC_ESTA', '=', 'Activo')
  2306. ->where('DLSC_TIPO', '=', 'Cotización')
  2307. ->orWhere('DLSC_TIPO', '=', 'Orden')
  2308. ->join('S002V01TDLSC', 'DLSC_IDFA', '=', 'FALS_IDFA')
  2309. ->get([
  2310. 'FALS_IDFA',
  2311. 'FALS_CODO',
  2312. 'FALS_UUID',
  2313. 'FALS_VERS',
  2314. 'FALS_FEEM',
  2315. 'FALS_RFCE',
  2316. 'FALS_RFCR',
  2317. 'FALS_FOLI',
  2318. 'FALS_SERI',
  2319. 'FALS_FOPA',
  2320. 'FALS_MEPA',
  2321. 'FALS_TICA',
  2322. 'FALS_MONE',
  2323. 'FALS_COPA',
  2324. 'DLSC_IDDO',
  2325. 'DLSC_CODO',
  2326. 'DLSC_TIPO',
  2327. 'DLSC_TIAR',
  2328. 'DLSC_DESC',
  2329. ]);
  2330. $arrInvoice = json_decode( json_encode( $arrInvoice ), true );
  2331. } catch (\Throwable $th) {
  2332. return $this->responseController->makeResponse(
  2333. true,
  2334. "ERR_ORDER_SHEET003: Ocurrió un error al obtener la información de las facturas.",
  2335. $th->getMessage(),
  2336. 500
  2337. );
  2338. }
  2339. if ( empty($arrInvoice) ) {
  2340. return $this->responseController->makeResponse(
  2341. true,
  2342. "ERR_ORDER_SHEET004: La orden de compra no tiene ninguna factura registrada.",
  2343. [],
  2344. 500
  2345. );
  2346. }
  2347. $arrInvoiceOrder = array();
  2348. $arrInvoiceCotizacion = array();
  2349. foreach ($arrInvoice as $keyInvoice => $invoice) {
  2350. if ( $invoice['DLSC_TIPO'] === 'Orden') {
  2351. $arrInvoiceOrder[] = $invoice;
  2352. }
  2353. if ( $invoice['DLSC_TIPO'] === 'Cotización') {
  2354. $arrInvoiceCotizacion[] = $invoice;
  2355. }
  2356. }
  2357. unset($arrInvoice);
  2358. if ( !empty($arrInvoiceOrder) ) {
  2359. $idMax = 0;
  2360. foreach ($arrInvoiceOrder as $keyInvoiceOrder => $invoiceOrder) {
  2361. if ( $invoiceOrder['FALS_IDFA'] > $idMax ) {
  2362. $idMax = $invoiceOrder['FALS_IDFA'];
  2363. $arrInvoice = $invoiceOrder;
  2364. }
  2365. }
  2366. } else {
  2367. $idMax = 0;
  2368. foreach ($arrInvoiceCotizacion as $keyInvoiceCotizacion => $invoiceCotizacion) {
  2369. if ( $invoiceCotizacion['FALS_IDFA'] > $idMax ) {
  2370. $idMax = $invoiceCotizacion['FALS_IDFA'];
  2371. $arrInvoice = $invoiceCotizacion;
  2372. }
  2373. }
  2374. }
  2375. $html = '<!DOCTYPE html>
  2376. <html lang="en">
  2377. <head>
  2378. <meta charset="UTF-8">
  2379. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2380. <title>Document</title>
  2381. <style>
  2382. body {
  2383. font-family: Arial, Helvetica, sans-serif;
  2384. font-size: 8pt;
  2385. }
  2386. .section-title {
  2387. margin: 20px 0;
  2388. font-size: 12pt;
  2389. }
  2390. table {
  2391. width: 100%;
  2392. font-size: 8pt;
  2393. }
  2394. thead tr th {
  2395. text-align: start;
  2396. padding: 0 16px;
  2397. height: 52px;
  2398. border-bottom-width: 1px;
  2399. border-bottom-style: solid;
  2400. border-bottom-color: #CCC;
  2401. }
  2402. tbody tr td {
  2403. padding: 0 16px;
  2404. height: 52px;
  2405. border-bottom-width: 1px;
  2406. border-bottom-style: solid;
  2407. border-bottom-color: #CCC;
  2408. }
  2409. p {
  2410. text-align: justify;
  2411. }
  2412. </style>
  2413. </head>
  2414. <body>
  2415. <div class="item">
  2416. <b>Número de Orden de Compra: </b>
  2417. <span>'.$arrOrder['ORCO_NUOR'].'</span>
  2418. </div>
  2419. <div class="item">
  2420. <b>Estado de la orden: </b>
  2421. <span>'.$arrOrder['ORCO_ESTA'].'</span>
  2422. </div>
  2423. <div class="item">
  2424. <b>Numero de línea de solicitud: </b>
  2425. <span>'.$arrOrder['LINE_IDLI'].'</span>
  2426. </div>
  2427. ';
  2428. if ( !is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  2429. $html.='<div class="item">
  2430. <b>Orden de Trabajo Preventivo: </b>
  2431. <span>'.$arrOrder['LINE_OTPR'].'</span>
  2432. </div>';
  2433. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && !is_null( $arrOrder['LINE_OTCO'] ) ) {
  2434. $html.='<div class="item">
  2435. <b>Orden de Trabajo Correctivo: </b>
  2436. <span>'.$arrOrder['LINE_OTCO'].'</span>
  2437. </div>';
  2438. } else if ( is_null( $arrOrder['LINE_OTPR'] ) && is_null( $arrOrder['LINE_OTCO'] ) ) {
  2439. $html.='<div class="item">
  2440. <b>Orden de Trabajo: </b>
  2441. <span>No aplica</span>
  2442. </div>';
  2443. } else {
  2444. $html.='<div class="item">
  2445. <b>Orden de Trabajo: </b>
  2446. <span>No aplica</span>
  2447. </div>';
  2448. }
  2449. $html.='<div class="item">
  2450. <b>ID Despacho: </b>
  2451. <span>'.$arrOrder['DESP_IDDE'].'</span>
  2452. </div>
  2453. <div class="item">
  2454. <b>Despacho: </b>
  2455. <span>'.$arrOrder['DESP_NODE'].'</span>
  2456. </div>
  2457. <div class="item">
  2458. <b>Responsable del despacho: </b>
  2459. <span>'.$arrOrder['DESP_NOMB'] . ' ' . $arrOrder['DESP_APPA'] . ' ' . $arrOrder['DESP_APMA'].'</span>
  2460. </div>
  2461. <div class="item">
  2462. <b>Teléfono del despacho: </b>
  2463. <span>'.$arrOrder['DESP_LADA'] . ' ' . $arrOrder['DESP_TELE'].'</span>
  2464. </div>
  2465. <div class="item">
  2466. <b>Correo electrónico del despacho: </b>
  2467. <span>'.$arrOrder['DESP_CORR'].'</span>
  2468. </div>
  2469. <div class="item">
  2470. <b>Calle del despacho: </b>
  2471. <span>'.$arrOrder['DESP_CALL'].'</span>
  2472. </div>
  2473. <div class="item">
  2474. <b>Número exterior: </b>
  2475. <span>'.$arrOrder['DESP_NUEX'].'</span>
  2476. </div>
  2477. ';
  2478. if ( !is_null($arrOrder['DESP_NUIN']) ) {
  2479. $html.='<div class="item">
  2480. <b>Número interior: </b>
  2481. <span>'.$arrOrder['DESP_NUIN'].'</span>
  2482. </div>';
  2483. } else {
  2484. $html.='<div class="item">
  2485. <b>Número interior: </b>
  2486. <span>No aplica</span>
  2487. </div>';
  2488. }
  2489. $html.='<div class="item">
  2490. <b>Código postal: </b>
  2491. <span>'.$arrOrder['DESP_COPO'].'</span>
  2492. </div>
  2493. <div class="item">
  2494. <b>Colonia: </b>
  2495. <span>'.$arrOrder['DESP_COLO'].'</span>
  2496. </div>
  2497. ';
  2498. if ( !is_null($arrOrder['DESP_LOCA']) && !empty($arrOrder['DESP_LOCA']) ) {
  2499. $html.='<div class="item">
  2500. <b>Localidad: </b>
  2501. <span>'.$arrOrder['DESP_LOCA'].'</span>
  2502. </div>';
  2503. } else {
  2504. $html.='<div class="item">
  2505. <b>Localidad: </b>
  2506. <span>No aplica</span>
  2507. </div>';
  2508. }
  2509. $html.='<div class="item">
  2510. <b>Municipio: </b>
  2511. <span>'.$arrOrder['DESP_MUNI'].'</span>
  2512. </div>
  2513. <div class="item">
  2514. <b>Entidad Federativa: </b>
  2515. <span>'.$arrOrder['DESP_ENTI'].'</span>
  2516. </div>
  2517. <div class="item">
  2518. <b>País: </b>
  2519. <span>'.$arrOrder['DESP_PAIS'].'</span>
  2520. </div>
  2521. <div class="item">
  2522. <b>Número de proveedor: </b>
  2523. <span>'.$arrOrder['PROV_NUPR'].'</span>
  2524. </div>
  2525. <div class="item">
  2526. <b>Número de subcontratista: </b>
  2527. <span>'.$arrOrder['PROV_IDPS'].'</span>
  2528. </div>
  2529. <div class="item">
  2530. <b>Nombre comercial del proveedor: </b>
  2531. <span>'.$arrOrder['PROV_NOCO'].'</span>
  2532. </div>
  2533. <div class="item">
  2534. <b>Referencia fiscal del proveedor: </b>
  2535. <span>'.$arrOrder['REFI_DRFI'] . ' (' . $arrOrder['REFI_CRFI'] . ')'.'</span>
  2536. </div>
  2537. <div class="item">
  2538. <b>Responsable del proveedor: </b>
  2539. <span>'.$arrOrder['PROV_NOMB'] . ' ' . $arrOrder['PROV_APPA'] . ' ' . $arrOrder['PROV_APMA'].'</span>
  2540. </div>
  2541. <div class="item">
  2542. <b>Correo electrónico del proveedor: </b>
  2543. <span>'.$arrOrder['PROV_CORR'].'</span>
  2544. </div>
  2545. <div class="item">
  2546. <b>Teléfono del proveedor: </b>
  2547. <span>'.$arrOrder['PROV_LAD1'] . ' ' . $arrOrder['PROV_TEL1'].'</span>
  2548. </div>
  2549. ';
  2550. if ( !is_null( $arrOrder['PROV_XRFC'] ) && is_null( $arrOrder['PROV_XRFC'] )) {
  2551. $html.='<div class="item">
  2552. <b>R.F.C. del proveedor: </b>
  2553. <span>'.$arrOrder['PROV_XRFC'].'</span>
  2554. </div>';
  2555. } else if ( is_null( $arrOrder['PROV_XRFC'] ) && !is_null( $arrOrder['PROV_XRFC'] )) {
  2556. $html.='<div class="item">
  2557. <b>TAX ID. del proveedor: </b>
  2558. <span>'.$arrOrder['PROV_XTAX'].'</span>
  2559. </div>';
  2560. } else {
  2561. $html.='<div class="item">
  2562. <b>R.F.C. / TAX ID: </b>
  2563. <span>No aplica</span>
  2564. </div>';
  2565. }
  2566. if ( !empty($arrArtitle) ) {
  2567. $html.='
  2568. <div style="page-break-after:always;"></div>
  2569. <div class="section-title">
  2570. <b>Artículos</b>
  2571. </div>';
  2572. $html.='<table cellspacing="0" cellpadding="0">
  2573. <thead>
  2574. <tr>
  2575. <th>ID</th>
  2576. <th>Código del artíulo</th>
  2577. <th>Artículo</th>
  2578. <th>Familia</th>
  2579. <th>Subfamilia</th>
  2580. <th>Unidad</th>
  2581. <th>Código</th>
  2582. <th>Modelo</th>
  2583. <th>Precio Unitario</th>
  2584. <th>Cantidad</th>
  2585. <th>Precio Total</th>
  2586. <th>Moneda Local</th>
  2587. <th>Tipo de cambio</th>
  2588. <th>Precio Local</th>
  2589. </tr>
  2590. </thead>
  2591. <tbody>';
  2592. foreach ($arrArtitle as $keyArtitle => $artitle) {
  2593. $html.= '<tr>
  2594. <td>'.$artitle['ARTI_IDAR'] . '</td>
  2595. <td>'.$artitle['ARTI_CODI'] . '</td>
  2596. <td>'.$artitle['ARTI_NOMB'] . '</td>
  2597. <td>'.$artitle['FAMI_NOFA'] . ' (' . $artitle['FAMI_COFA'] . ')' . '</td>
  2598. <td>'.$artitle['SUBF_NOSU'] . ' (' . $artitle['SUBF_COSU'] . ')' . '</td>
  2599. <td>'.$artitle['UNID_NOMB'] . ' (' . $artitle['UNID_IDUN'] . ')' . '</td>
  2600. <td>'.$artitle['INAR_CODI'] . '</td>
  2601. <td>'.$artitle['INAR_MODE'] . '</td>
  2602. <td>'.'$'. $artitle['INAR_PREC'] . ' ' . $artitle['CAMO_COMO'] . '</td>
  2603. <td>'.$artitle['ARSE_CANT'] . '</td>
  2604. <td>'.'$'. $artitle['ARSE_PRTO'] . ' ' . $artitle['CAMO_COMO'] . '</td>
  2605. <td>'.'MXN' . '</td>
  2606. <td>'.$arrInvoice['FALS_TICA'] . '</td>
  2607. <td>'.'$'.($arrInvoice['FALS_TICA'] * $artitle['INAR_PREC']) . ' MXN' . '</td>
  2608. </tr>';
  2609. }
  2610. $html.= '</tbody>
  2611. </table>';
  2612. }
  2613. $html.='</body></html>';
  2614. // return $html;
  2615. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2616. $como = 'GEAD'; // Código del módulo
  2617. $cldo = 'IN'; // Código de la clasificación
  2618. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2619. try {
  2620. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2621. ->where('AFAL_COMO', '=', $como)
  2622. ->where('AFAL_CLDO', '=', $cldo)
  2623. ->where('AFAL_NULI', '=', $line)
  2624. ->orderBy('AFAL_NUSE', 'desc')
  2625. ->first([ 'AFAL_NUSE' ]);
  2626. } catch (\Throwable $th) {
  2627. return $this->responseController->makeResponse(
  2628. true,
  2629. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2630. $th->getMessage(),
  2631. 500
  2632. );
  2633. }
  2634. $nuse = 1; // Secuencia del documento
  2635. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2636. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2637. }
  2638. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2639. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2640. $noar = 'ficha_de_divisa_' . $arrOrder['ORCO_NUOR'];
  2641. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2642. $como = 'GEAD'; // Código del módulo
  2643. $cldo = 'IN'; // Código de la clasificación
  2644. $fecr = date('ymd'); // Fecha en la se carga el archivo
  2645. try {
  2646. $arrSecuence = (array) DB::table('S002V01TAFAL')
  2647. ->where('AFAL_COMO', '=', $como)
  2648. ->where('AFAL_CLDO', '=', $cldo)
  2649. ->where('AFAL_NULI', '=', $line)
  2650. ->orderBy('AFAL_NUSE', 'desc')
  2651. ->first([ 'AFAL_NUSE' ]);
  2652. } catch (\Throwable $th) {
  2653. return $this->responseController->makeResponse(
  2654. true,
  2655. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  2656. $th->getMessage(),
  2657. 500
  2658. );
  2659. }
  2660. $nuse = 1; // Secuencia del documento
  2661. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  2662. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  2663. }
  2664. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  2665. $nuve = $this->resourcesController->formatSecuence('1', 2);
  2666. $noar = 'ficha_de_divisa_' . $arrOrder['ORCO_NUOR'];
  2667. $exte = 'pdf';
  2668. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  2669. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  2670. } else {
  2671. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  2672. }
  2673. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  2674. $tempFile = $filePath . $fileName;
  2675. $dompdf = new Dompdf();
  2676. $dompdf ->loadHtml($html);
  2677. $dompdf->setPaper('A4', 'landscape');
  2678. $dompdf->render();
  2679. $output = $dompdf->output();
  2680. file_put_contents($tempFile, $output);
  2681. $ubic = Storage::putFile('files', new File($tempFile));
  2682. $ubic = str_replace("/", "\\", $ubic);
  2683. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  2684. $tama = filesize($ubic);
  2685. $usac = json_encode([$user]);
  2686. $now = $this->functionsController->now();
  2687. $currentDate = $now->toDateTimeString();
  2688. try {
  2689. $validateInsert = DB::table('S002V01TAFAL')->insert([
  2690. 'AFAL_NULI' => $line,
  2691. 'AFAL_COMO' => $como,
  2692. 'AFAL_CLDO' => $cldo,
  2693. 'AFAL_FECR' => $fecr,
  2694. 'AFAL_NUSE' => $nuse,
  2695. 'AFAL_NUVE' => $nuve,
  2696. 'AFAL_NOAR' => $noar,
  2697. 'AFAL_EXTE' => $exte,
  2698. 'AFAL_TAMA' => $tama,
  2699. 'AFAL_UBIC' => $ubic,
  2700. 'AFAL_USAC' => $usac,
  2701. 'AFAL_USRE' => $user,
  2702. 'AFAL_FERE' => $currentDate,
  2703. ]);
  2704. } catch (\Throwable $th) {
  2705. return $this->responseController->makeResponse(
  2706. true,
  2707. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  2708. $th->getMessage(),
  2709. 500
  2710. );
  2711. }
  2712. if ( !$validateInsert ) {
  2713. return $this->responseController->makeResponse(
  2714. true,
  2715. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  2716. [],
  2717. 500
  2718. );
  2719. }
  2720. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  2721. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  2722. }
  2723. public function generateSheetInvoiceXLS($encOrderNumber, $user, $line) {
  2724. try {
  2725. $idOrder = $this->encController->decrypt($encOrderNumber);
  2726. } catch (\Throwable $th) {
  2727. DB::rollBack();
  2728. return $this->responseController->makeResponse(
  2729. true,
  2730. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  2731. $th->getMessage(),
  2732. 500
  2733. );
  2734. }
  2735. try {
  2736. $user = $this->encController->decrypt($user);
  2737. } catch (\Throwable $th) {
  2738. DB::rollBack();
  2739. return $this->responseController->makeResponse(
  2740. true,
  2741. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  2742. $th->getMessage(),
  2743. 500
  2744. );
  2745. }
  2746. try {
  2747. $arrOrder = (array) DB::table('S002V01TORCO')
  2748. ->where('ORCO_NUOR', '=', $idOrder)
  2749. ->where('ORCO_NULI', '=', $line)
  2750. ->where('LINE_NULI', '=', $line)
  2751. ->where('DESP_NULI', '=', $line)
  2752. ->where('PROV_NULI', '=', $line)
  2753. ->where('DESP_ESTA', '=', 'Activo')
  2754. ->where('PROV_ESTA', '=', 'Activo')
  2755. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  2756. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  2757. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  2758. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  2759. ->first([
  2760. 'ORCO_NUOR',
  2761. 'ORCO_ESTA',
  2762. 'LINE_IDLI',
  2763. 'LINE_OTPR',
  2764. 'LINE_OTCO',
  2765. 'LINE_ESTA',
  2766. 'DESP_IDDE',
  2767. 'DESP_NODE',
  2768. 'DESP_NOMB',
  2769. 'DESP_APPA',
  2770. 'DESP_APMA',
  2771. 'DESP_LADA',
  2772. 'DESP_TELE',
  2773. 'DESP_CORR',
  2774. 'DESP_CALL',
  2775. 'DESP_NUEX',
  2776. 'DESP_NUIN',
  2777. 'DESP_COPO',
  2778. 'DESP_COLO',
  2779. 'DESP_LOCA',
  2780. 'DESP_MUNI',
  2781. 'DESP_ENTI',
  2782. 'DESP_PAIS',
  2783. 'DESP_COME',
  2784. 'PROV_NUPR',
  2785. 'PROV_IDPS',
  2786. 'PROV_NOCO',
  2787. 'PROV_NOMB',
  2788. 'PROV_APPA',
  2789. 'PROV_APMA',
  2790. 'PROV_CORR',
  2791. 'PROV_LAD1',
  2792. 'PROV_TEL1',
  2793. 'PROV_LAD2',
  2794. 'PROV_TEL2',
  2795. 'PROV_XRFC',
  2796. 'PROV_XTAX',
  2797. 'PROV_TIPO',
  2798. 'PROV_TICO',
  2799. 'PROV_SIWE',
  2800. 'PROV_MEPA',
  2801. 'PROV_CALL',
  2802. 'PROV_NUEX',
  2803. 'PROV_NUIN',
  2804. 'PROV_COPO',
  2805. 'PROV_COLO',
  2806. 'PROV_MUNI',
  2807. 'PROV_LOCA',
  2808. 'PROV_ENTI',
  2809. 'PROV_PAIS',
  2810. 'REFI_CRFI',
  2811. 'REFI_DRFI',
  2812. ]);
  2813. } catch (\Throwable $th) {
  2814. return $this->responseController->makeResponse(
  2815. true,
  2816. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  2817. $th->getMessage(),
  2818. 500
  2819. );
  2820. }
  2821. try {
  2822. $arrArtitle = DB::table('S002V01TARSE')
  2823. ->where('ARSE_NULI', '=', $line)
  2824. ->where('INAR_NULI', '=', $line)
  2825. ->where('CAMO_NULI', '=', $line)
  2826. ->where('DEAR_NULI', '=', $line)
  2827. ->where('UNID_NULI', '=', $line)
  2828. ->where('ARTI_NULI', '=', $line)
  2829. ->where('FAMI_NULI', '=', $line)
  2830. ->where('SUBF_NULI', '=', $line)
  2831. ->where('ARSE_ESTA', '=', 'Activo')
  2832. ->where('INAR_ESTA', '=', 'Activo')
  2833. ->where('CAMO_ESTA', '=', 'Activo')
  2834. ->where('DEAR_ESTA', '=', 'Activo')
  2835. ->where('UNID_ESTA', '=', 'Activo')
  2836. ->where('ARTI_ESTA', '=', 'Activo')
  2837. ->where('FAMI_ESTA', '=', 'Activo')
  2838. ->where('SUBF_ESTA', '=', 'Activo')
  2839. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  2840. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  2841. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  2842. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  2843. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  2844. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  2845. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  2846. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  2847. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  2848. ->get([
  2849. 'ARSE_IDAS',
  2850. 'ARSE_IDLI',
  2851. 'ARSE_CANT',
  2852. 'ARSE_PRTO',
  2853. 'INAR_IDIN',
  2854. 'INAR_CODI',
  2855. 'INAR_MODE',
  2856. 'INAR_PREC',
  2857. 'INAR_MOMI',
  2858. 'INAR_CARA',
  2859. 'CAMO_COMO',
  2860. 'CAMO_DESC',
  2861. 'CAMO_DECI',
  2862. 'CAMO_POVA',
  2863. 'CAMO_FEIN',
  2864. 'CAMO_FEFI',
  2865. 'DEAR_IDDE',
  2866. 'DEAR_IMAG',
  2867. 'DEAR_DESC',
  2868. 'DEAR_CARA',
  2869. 'DEAR_COWE',
  2870. 'UNID_IDUN',
  2871. 'UNID_NOMB',
  2872. 'UNID_ACRO',
  2873. 'ARTI_IDAR',
  2874. 'ARTI_CODI',
  2875. 'ARTI_NOMB',
  2876. 'FAMI_COFA',
  2877. 'FAMI_NOFA',
  2878. 'SUBF_COSU',
  2879. 'SUBF_NOSU',
  2880. ]);
  2881. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  2882. } catch (\Throwable $th) {
  2883. return $this->responseController->makeResponse(
  2884. true,
  2885. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  2886. $th->getMessage(),
  2887. 500
  2888. );
  2889. }
  2890. try {
  2891. $arrInvoice = DB::table('S002V01TFALS')
  2892. ->where('FALS_IDLI', '=', $arrOrder['LINE_IDLI'])
  2893. ->where('FALS_NULI', '=', $line)
  2894. ->where('DLSC_NULI', '=', $line)
  2895. ->where('FALS_ESTA', '=', 'Activo')
  2896. ->where('DLSC_ESTA', '=', 'Activo')
  2897. ->where('DLSC_TIPO', '=', 'Cotización')
  2898. ->orWhere('DLSC_TIPO', '=', 'Orden')
  2899. ->join('S002V01TDLSC', 'DLSC_IDFA', '=', 'FALS_IDFA')
  2900. ->get([
  2901. 'FALS_IDFA',
  2902. 'FALS_CODO',
  2903. 'FALS_UUID',
  2904. 'FALS_VERS',
  2905. 'FALS_FEEM',
  2906. 'FALS_RFCE',
  2907. 'FALS_RFCR',
  2908. 'FALS_FOLI',
  2909. 'FALS_SERI',
  2910. 'FALS_FOPA',
  2911. 'FALS_MEPA',
  2912. 'FALS_TICA',
  2913. 'FALS_MONE',
  2914. 'FALS_COPA',
  2915. 'FALS_CAAR',
  2916. 'FALS_PRTO',
  2917. 'DLSC_IDDO',
  2918. 'DLSC_CODO',
  2919. 'DLSC_TIPO',
  2920. 'DLSC_TIAR',
  2921. 'DLSC_DESC',
  2922. ]);
  2923. $arrInvoice = json_decode( json_encode( $arrInvoice ), true );
  2924. } catch (\Throwable $th) {
  2925. return $this->responseController->makeResponse(
  2926. true,
  2927. "ERR_ORDER_SHEET003: Ocurrió un error al obtener la información de las facturas.",
  2928. $th->getMessage(),
  2929. 500
  2930. );
  2931. }
  2932. if ( empty($arrInvoice) ) {
  2933. return $this->responseController->makeResponse(
  2934. true,
  2935. "ERR_ORDER_SHEET004: La orden de compra no tiene ninguna factura registrada.",
  2936. [],
  2937. 500
  2938. );
  2939. }
  2940. $arrAlphabet = $this->resourcesController->arrAlphabet;
  2941. $spreadsheet = new Spreadsheet();
  2942. $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrOrder['ORCO_NUOR']);
  2943. $activeWorksheet->setCellValue("B2", 'Número de orden de compra:' );
  2944. $activeWorksheet->setCellValue("C2", $arrOrder['ORCO_NUOR'] );
  2945. $activeWorksheet->getStyle( "B2" )->getFont()->setBold(true);
  2946. $arrHeaderInvoice = array(
  2947. /* A */ 'ID Factura',
  2948. /* B */ 'Tipo de Factura',
  2949. /* C */ 'UUID',
  2950. /* D */ 'Versión',
  2951. /* E */ 'Fecha de Emisión',
  2952. /* F */ 'R.F.C. Emisor',
  2953. /* G */ 'R.F.C. Receptor',
  2954. /* H */ 'Folio',
  2955. /* I */ 'Serie',
  2956. /* J */ 'Forma de Pago',
  2957. /* K */ 'Método de Pago',
  2958. /* L */ 'Tipo de Cambio',
  2959. /* M */ 'Moneda',
  2960. /* N */ 'Descripción',
  2961. /* O */ 'Cantidad de artículos',
  2962. /* P */ 'Precio Total',
  2963. );
  2964. foreach ($arrInvoice as $keyInvoice => $invoice) {
  2965. $key = $keyInvoice + 5;
  2966. $activeWorksheet->setCellValue("A".$key, $invoice['FALS_IDFA']);
  2967. if ($invoice['DLSC_TIPO'] === 'Cotización') {
  2968. $activeWorksheet->setCellValue("B".$key, 'Factura de Cotización');
  2969. } else if ($invoice['DLSC_TIPO'] === 'Orden') {
  2970. $activeWorksheet->setCellValue("B".$key, 'Factura de Orden de Compra');
  2971. } else if ($invoice['DLSC_TIPO'] === 'Abono') {
  2972. $activeWorksheet->setCellValue("B".$key, 'Factura de Abono');
  2973. } else {
  2974. $activeWorksheet->setCellValue("B".$key, 'No aplica');
  2975. }
  2976. $activeWorksheet->setCellValue("C".$key, $invoice['FALS_UUID']);
  2977. $activeWorksheet->setCellValue("D".$key, $invoice['FALS_VERS']);
  2978. $activeWorksheet->setCellValue("E".$key, $invoice['FALS_FEEM']);
  2979. $activeWorksheet->setCellValue("F".$key, $invoice['FALS_RFCE']);
  2980. $activeWorksheet->setCellValue("G".$key, $invoice['FALS_RFCR']);
  2981. $activeWorksheet->setCellValue("H".$key, $invoice['FALS_FOLI']);
  2982. $activeWorksheet->setCellValue("I".$key, $invoice['FALS_SERI']);
  2983. $activeWorksheet->setCellValue("J".$key, $invoice['FALS_FOPA']);
  2984. $activeWorksheet->setCellValue("K".$key, $invoice['FALS_MEPA']);
  2985. $activeWorksheet->setCellValue("L".$key, $invoice['FALS_TICA']);
  2986. $activeWorksheet->setCellValue("M".$key, $invoice['FALS_MONE']);
  2987. $activeWorksheet->setCellValue("N".$key, $invoice['DLSC_DESC']);
  2988. $activeWorksheet->setCellValue("O".$key, $invoice['FALS_CAAR']);
  2989. $activeWorksheet->setCellValue("P".$key, $invoice['FALS_PRTO']);
  2990. }
  2991. foreach ($arrHeaderInvoice as $keyHeaderInvoice => $headerInvoice) {
  2992. $activeWorksheet->setCellValue( $arrAlphabet[$keyHeaderInvoice]."4", $headerInvoice);
  2993. $activeWorksheet->getColumnDimension( $arrAlphabet[$keyHeaderInvoice] )->setAutoSize(true);
  2994. $activeWorksheet->getStyle( $arrAlphabet[$keyHeaderInvoice]."4" )->getFont()->setBold(true);
  2995. }
  2996. $nuli = $this->resourcesController->formatSecuence($line, 2);
  2997. $como = 'GEAD'; // Código del módulo
  2998. $cldo = 'IN'; // Código de la clasificación
  2999. $fecr = date('ymd'); // Fecha en la se carga el archivo
  3000. try {
  3001. $arrSecuence = (array) DB::table('S002V01TAFAL')
  3002. ->where('AFAL_COMO', '=', $como)
  3003. ->where('AFAL_CLDO', '=', $cldo)
  3004. ->where('AFAL_NULI', '=', $line)
  3005. ->orderBy('AFAL_NUSE', 'desc')
  3006. ->first([ 'AFAL_NUSE' ]);
  3007. } catch (\Throwable $th) {
  3008. return $this->responseController->makeResponse(
  3009. true,
  3010. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  3011. $th->getMessage(),
  3012. 500
  3013. );
  3014. }
  3015. $nuse = 1; // Secuencia del documento
  3016. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  3017. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  3018. }
  3019. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  3020. $nuve = $this->resourcesController->formatSecuence('1', 2);
  3021. $noar = 'ficha_de_facturación_' . $arrOrder['ORCO_NUOR'];
  3022. $exte = 'xlsx';
  3023. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  3024. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  3025. } else {
  3026. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  3027. }
  3028. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  3029. $tempFile = $filePath.$fileName;
  3030. if ( file_exists( $tempFile ) ) {
  3031. if ( !unlink( $tempFile ) ) {
  3032. return $this->responseController->makeResponse(
  3033. true,
  3034. "ERR_PROVIDER_SHEET021: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
  3035. [],
  3036. 500
  3037. );
  3038. }
  3039. }
  3040. try {
  3041. $writer = new Xlsx($spreadsheet);
  3042. ob_start();
  3043. $writer->save('php://output');
  3044. $base64 = base64_encode(ob_get_clean());
  3045. $validate = \File::put( $tempFile, base64_decode($base64));
  3046. } catch (\Throwable $th) {
  3047. return $this->responseController->makeResponse(
  3048. true,
  3049. "ERR_PROVIDER_SHEET022: Ocurrió un error al guardar el documento.",
  3050. $th->getMessage(),
  3051. 500
  3052. );
  3053. }
  3054. $ubic = Storage::putFile('files', new File($tempFile));
  3055. $ubic = str_replace("/", "\\", $ubic);
  3056. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  3057. $tama = filesize($ubic);
  3058. $usac = json_encode([$user]);
  3059. $now = $this->functionsController->now();
  3060. $currentDate = $now->toDateTimeString();
  3061. try {
  3062. $validateInsert = DB::table('S002V01TAFAL')->insert([
  3063. 'AFAL_NULI' => $line,
  3064. 'AFAL_COMO' => $como,
  3065. 'AFAL_CLDO' => $cldo,
  3066. 'AFAL_FECR' => $fecr,
  3067. 'AFAL_NUSE' => $nuse,
  3068. 'AFAL_NUVE' => $nuve,
  3069. 'AFAL_NOAR' => $noar,
  3070. 'AFAL_EXTE' => $exte,
  3071. 'AFAL_TAMA' => $tama,
  3072. 'AFAL_UBIC' => $ubic,
  3073. 'AFAL_USAC' => $usac,
  3074. 'AFAL_USRE' => $user,
  3075. 'AFAL_FERE' => $currentDate,
  3076. ]);
  3077. } catch (\Throwable $th) {
  3078. return $this->responseController->makeResponse(
  3079. true,
  3080. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  3081. $th->getMessage(),
  3082. 500
  3083. );
  3084. }
  3085. if ( !$validateInsert ) {
  3086. return $this->responseController->makeResponse(
  3087. true,
  3088. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  3089. [],
  3090. 500
  3091. );
  3092. }
  3093. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  3094. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  3095. }
  3096. public function generateSheetInvoicePDF($encOrderNumber, $user, $line) {
  3097. try {
  3098. $idOrder = $this->encController->decrypt($encOrderNumber);
  3099. } catch (\Throwable $th) {
  3100. DB::rollBack();
  3101. return $this->responseController->makeResponse(
  3102. true,
  3103. "ERR_ORDER_SHEET000: Ocurrió un error al obtener el número del proveedor.",
  3104. $th->getMessage(),
  3105. 500
  3106. );
  3107. }
  3108. try {
  3109. $user = $this->encController->decrypt($user);
  3110. } catch (\Throwable $th) {
  3111. DB::rollBack();
  3112. return $this->responseController->makeResponse(
  3113. true,
  3114. "ERR_ORDER_SHEET001: Ocurrió un error al obtener el usuario.",
  3115. $th->getMessage(),
  3116. 500
  3117. );
  3118. }
  3119. try {
  3120. $arrOrder = (array) DB::table('S002V01TORCO')
  3121. ->where('ORCO_NUOR', '=', $idOrder)
  3122. ->where('ORCO_NULI', '=', $line)
  3123. ->where('LINE_NULI', '=', $line)
  3124. ->where('DESP_NULI', '=', $line)
  3125. ->where('PROV_NULI', '=', $line)
  3126. ->where('DESP_ESTA', '=', 'Activo')
  3127. ->where('PROV_ESTA', '=', 'Activo')
  3128. ->join('S002V01TLINE', 'LINE_IDLI', '=', 'ORCO_IDLI')
  3129. ->join('S002V01TDESP', 'DESP_IDDE', '=', 'ORCO_IDDE')
  3130. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  3131. ->join('S002V01TREFI', 'REFI_CRFI', '=', 'PROV_CRFI')
  3132. ->first([
  3133. 'ORCO_NUOR',
  3134. 'ORCO_ESTA',
  3135. 'LINE_IDLI',
  3136. 'LINE_OTPR',
  3137. 'LINE_OTCO',
  3138. 'LINE_ESTA',
  3139. 'DESP_IDDE',
  3140. 'DESP_NODE',
  3141. 'DESP_NOMB',
  3142. 'DESP_APPA',
  3143. 'DESP_APMA',
  3144. 'DESP_LADA',
  3145. 'DESP_TELE',
  3146. 'DESP_CORR',
  3147. 'DESP_CALL',
  3148. 'DESP_NUEX',
  3149. 'DESP_NUIN',
  3150. 'DESP_COPO',
  3151. 'DESP_COLO',
  3152. 'DESP_LOCA',
  3153. 'DESP_MUNI',
  3154. 'DESP_ENTI',
  3155. 'DESP_PAIS',
  3156. 'DESP_COME',
  3157. 'PROV_NUPR',
  3158. 'PROV_IDPS',
  3159. 'PROV_NOCO',
  3160. 'PROV_NOMB',
  3161. 'PROV_APPA',
  3162. 'PROV_APMA',
  3163. 'PROV_CORR',
  3164. 'PROV_LAD1',
  3165. 'PROV_TEL1',
  3166. 'PROV_LAD2',
  3167. 'PROV_TEL2',
  3168. 'PROV_XRFC',
  3169. 'PROV_XTAX',
  3170. 'PROV_TIPO',
  3171. 'PROV_TICO',
  3172. 'PROV_SIWE',
  3173. 'PROV_MEPA',
  3174. 'PROV_CALL',
  3175. 'PROV_NUEX',
  3176. 'PROV_NUIN',
  3177. 'PROV_COPO',
  3178. 'PROV_COLO',
  3179. 'PROV_MUNI',
  3180. 'PROV_LOCA',
  3181. 'PROV_ENTI',
  3182. 'PROV_PAIS',
  3183. 'REFI_CRFI',
  3184. 'REFI_DRFI',
  3185. ]);
  3186. } catch (\Throwable $th) {
  3187. return $this->responseController->makeResponse(
  3188. true,
  3189. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  3190. $th->getMessage(),
  3191. 500
  3192. );
  3193. }
  3194. try {
  3195. $arrArtitle = DB::table('S002V01TARSE')
  3196. ->where('ARSE_NULI', '=', $line)
  3197. ->where('INAR_NULI', '=', $line)
  3198. ->where('CAMO_NULI', '=', $line)
  3199. ->where('DEAR_NULI', '=', $line)
  3200. ->where('UNID_NULI', '=', $line)
  3201. ->where('ARTI_NULI', '=', $line)
  3202. ->where('FAMI_NULI', '=', $line)
  3203. ->where('SUBF_NULI', '=', $line)
  3204. ->where('ARSE_ESTA', '=', 'Activo')
  3205. ->where('INAR_ESTA', '=', 'Activo')
  3206. ->where('CAMO_ESTA', '=', 'Activo')
  3207. ->where('DEAR_ESTA', '=', 'Activo')
  3208. ->where('UNID_ESTA', '=', 'Activo')
  3209. ->where('ARTI_ESTA', '=', 'Activo')
  3210. ->where('FAMI_ESTA', '=', 'Activo')
  3211. ->where('SUBF_ESTA', '=', 'Activo')
  3212. ->where('ARSE_IDLI', '=', $arrOrder['LINE_IDLI'])
  3213. ->where('ARSE_NUPR', '=', $arrOrder['PROV_NUPR'])
  3214. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  3215. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  3216. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  3217. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  3218. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  3219. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  3220. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  3221. ->get([
  3222. 'ARSE_IDAS',
  3223. 'ARSE_IDLI',
  3224. 'ARSE_CANT',
  3225. 'ARSE_PRTO',
  3226. 'INAR_IDIN',
  3227. 'INAR_CODI',
  3228. 'INAR_MODE',
  3229. 'INAR_PREC',
  3230. 'INAR_MOMI',
  3231. 'INAR_CARA',
  3232. 'CAMO_COMO',
  3233. 'CAMO_DESC',
  3234. 'CAMO_DECI',
  3235. 'CAMO_POVA',
  3236. 'CAMO_FEIN',
  3237. 'CAMO_FEFI',
  3238. 'DEAR_IDDE',
  3239. 'DEAR_IMAG',
  3240. 'DEAR_DESC',
  3241. 'DEAR_CARA',
  3242. 'DEAR_COWE',
  3243. 'UNID_IDUN',
  3244. 'UNID_NOMB',
  3245. 'UNID_ACRO',
  3246. 'ARTI_IDAR',
  3247. 'ARTI_CODI',
  3248. 'ARTI_NOMB',
  3249. 'FAMI_COFA',
  3250. 'FAMI_NOFA',
  3251. 'SUBF_COSU',
  3252. 'SUBF_NOSU',
  3253. ]);
  3254. $arrArtitle = json_decode( json_encode( $arrArtitle ), true );
  3255. } catch (\Throwable $th) {
  3256. return $this->responseController->makeResponse(
  3257. true,
  3258. "ERR_ORDER_SHEET002: Ocurrió un error al obtener la información de la orden de compra.",
  3259. $th->getMessage(),
  3260. 500
  3261. );
  3262. }
  3263. try {
  3264. $arrInvoice = DB::table('S002V01TFALS')
  3265. ->where('FALS_IDLI', '=', $arrOrder['LINE_IDLI'])
  3266. ->where('FALS_NULI', '=', $line)
  3267. ->where('DLSC_NULI', '=', $line)
  3268. ->where('FALS_ESTA', '=', 'Activo')
  3269. ->where('DLSC_ESTA', '=', 'Activo')
  3270. ->where('DLSC_TIPO', '=', 'Cotización')
  3271. ->orWhere('DLSC_TIPO', '=', 'Orden')
  3272. ->join('S002V01TDLSC', 'DLSC_IDFA', '=', 'FALS_IDFA')
  3273. ->get([
  3274. 'FALS_IDFA',
  3275. 'FALS_CODO',
  3276. 'FALS_UUID',
  3277. 'FALS_VERS',
  3278. 'FALS_FEEM',
  3279. 'FALS_RFCE',
  3280. 'FALS_RFCR',
  3281. 'FALS_FOLI',
  3282. 'FALS_SERI',
  3283. 'FALS_FOPA',
  3284. 'FALS_MEPA',
  3285. 'FALS_TICA',
  3286. 'FALS_MONE',
  3287. 'FALS_COPA',
  3288. 'FALS_CAAR',
  3289. 'FALS_PRTO',
  3290. 'DLSC_IDDO',
  3291. 'DLSC_CODO',
  3292. 'DLSC_TIPO',
  3293. 'DLSC_TIAR',
  3294. 'DLSC_DESC',
  3295. ]);
  3296. $arrInvoice = json_decode( json_encode( $arrInvoice ), true );
  3297. } catch (\Throwable $th) {
  3298. return $this->responseController->makeResponse(
  3299. true,
  3300. "ERR_ORDER_SHEET003: Ocurrió un error al obtener la información de las facturas.",
  3301. $th->getMessage(),
  3302. 500
  3303. );
  3304. }
  3305. if ( empty($arrInvoice) ) {
  3306. return $this->responseController->makeResponse(
  3307. true,
  3308. "ERR_ORDER_SHEET004: La orden de compra no tiene ninguna factura registrada.",
  3309. [],
  3310. 500
  3311. );
  3312. }
  3313. $html = '<!DOCTYPE html>
  3314. <html lang="en">
  3315. <head>
  3316. <meta charset="UTF-8">
  3317. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  3318. <title>Document</title>
  3319. <style>
  3320. body {
  3321. font-family: Arial, Helvetica, sans-serif;
  3322. font-size: 8pt;
  3323. }
  3324. .section-title {
  3325. margin: 20px 0;
  3326. font-size: 12pt;
  3327. }
  3328. table {
  3329. width: 100%;
  3330. font-size: 8pt;
  3331. }
  3332. thead tr th {
  3333. text-align: start;
  3334. padding: 0 16px;
  3335. height: 52px;
  3336. border-bottom-width: 1px;
  3337. border-bottom-style: solid;
  3338. border-bottom-color: #CCC;
  3339. }
  3340. tbody tr td {
  3341. padding: 0 16px;
  3342. height: 52px;
  3343. border-bottom-width: 1px;
  3344. border-bottom-style: solid;
  3345. border-bottom-color: #CCC;
  3346. }
  3347. p {
  3348. text-align: justify;
  3349. }
  3350. </style>
  3351. </head>
  3352. <body>
  3353. <div class="item">
  3354. <b>Número de Orden de Compra: </b>
  3355. <span>'.$arrOrder['ORCO_NUOR'].'</span>
  3356. </div>';
  3357. $html.='<table cellspacing="0" cellpadding="0">
  3358. <thead>
  3359. <tr>
  3360. <th>ID Factura</th>
  3361. <th>Tipo de Factura</th>
  3362. <th>UUID</th>
  3363. <!-- <th>Versión</th> -->
  3364. <th>Fecha de Emisión</th>
  3365. <th>R.F.C. Emisor</th>
  3366. <th>R.F.C. Receptor</th>
  3367. <!-- <th>Folio</th> -->
  3368. <!-- <th>Serie</th> -->
  3369. <!-- <th>Forma de Pago</th> -->
  3370. <!-- <th>Método de Pago</th> -->
  3371. <th>Tipo de Cambio</th>
  3372. <!-- <th>Moneda</th> -->
  3373. <th>Descripción</th>
  3374. <th>Cantidad de artículos</th>
  3375. <th>Precio Total</th>
  3376. </tr>
  3377. </thead>
  3378. <tbody>';
  3379. foreach ($arrInvoice as $keyInvoice => $invoice) {
  3380. $html.= '<tr>';
  3381. $html.= '<td>'.$invoice['FALS_IDFA'] . '</td>';
  3382. if ($invoice['DLSC_TIPO'] === 'Cotización') {
  3383. $html.= '<td>Factura de Cotización</td>';
  3384. } else if ($invoice['DLSC_TIPO'] === 'Orden') {
  3385. $html.= '<td>Factura de Orden de Compra</td>';
  3386. } else if ($invoice['DLSC_TIPO'] === 'Abono') {
  3387. $html.= '<td>Factura de Abono</td>';
  3388. } else {
  3389. $html.= '<td>No aplica</td>';
  3390. }
  3391. $html.= '<td>'.$invoice['FALS_UUID'].'</td>';
  3392. // $html.= '<td>'.$invoice['FALS_VERS'].'</td>';
  3393. $html.= '<td>'.$invoice['FALS_FEEM'].'</td>';
  3394. $html.= '<td>'.$invoice['FALS_RFCE'].'</td>';
  3395. $html.= '<td>'.$invoice['FALS_RFCR'].'</td>';
  3396. // $html.= '<td>'.$invoice['FALS_FOLI'].'</td>';
  3397. // $html.= '<td>'.$invoice['FALS_SERI'].'</td>';
  3398. // $html.= '<td>'.$invoice['FALS_FOPA'].'</td>';
  3399. // $html.= '<td>'.$invoice['FALS_MEPA'].'</td>';
  3400. $html.= '<td>'.$invoice['FALS_TICA'].'</td>';
  3401. // $html.= '<td>'.$invoice['FALS_MONE'].'</td>';
  3402. $html.= '<td>'.$invoice['DLSC_DESC'].'</td>';
  3403. $html.= '<td>'.$invoice['FALS_CAAR'].'</td>';
  3404. $html.= '<td>$'.$invoice['FALS_PRTO']. ' '. $invoice['FALS_MONE'] . '</td>';
  3405. $html.= '</tr>';
  3406. }
  3407. $html.= '</tbody>
  3408. </table>';
  3409. $html.='</body></html>';
  3410. $nuli = $this->resourcesController->formatSecuence($line, 2);
  3411. $como = 'GEAD'; // Código del módulo
  3412. $cldo = 'IN'; // Código de la clasificación
  3413. $fecr = date('ymd'); // Fecha en la se carga el archivo
  3414. try {
  3415. $arrSecuence = (array) DB::table('S002V01TAFAL')
  3416. ->where('AFAL_COMO', '=', $como)
  3417. ->where('AFAL_CLDO', '=', $cldo)
  3418. ->where('AFAL_NULI', '=', $line)
  3419. ->orderBy('AFAL_NUSE', 'desc')
  3420. ->first([ 'AFAL_NUSE' ]);
  3421. } catch (\Throwable $th) {
  3422. return $this->responseController->makeResponse(
  3423. true,
  3424. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  3425. $th->getMessage(),
  3426. 500
  3427. );
  3428. }
  3429. $nuse = 1; // Secuencia del documento
  3430. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  3431. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  3432. }
  3433. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  3434. $nuve = $this->resourcesController->formatSecuence('1', 2);
  3435. $noar = 'ficha_de_divisa_' . $arrOrder['ORCO_NUOR'];
  3436. $nuli = $this->resourcesController->formatSecuence($line, 2);
  3437. $como = 'GEAD'; // Código del módulo
  3438. $cldo = 'IN'; // Código de la clasificación
  3439. $fecr = date('ymd'); // Fecha en la se carga el archivo
  3440. try {
  3441. $arrSecuence = (array) DB::table('S002V01TAFAL')
  3442. ->where('AFAL_COMO', '=', $como)
  3443. ->where('AFAL_CLDO', '=', $cldo)
  3444. ->where('AFAL_NULI', '=', $line)
  3445. ->orderBy('AFAL_NUSE', 'desc')
  3446. ->first([ 'AFAL_NUSE' ]);
  3447. } catch (\Throwable $th) {
  3448. return $this->responseController->makeResponse(
  3449. true,
  3450. "ERR_PROVIDER_SHEET020: Ocurrió un error al obtener la información de la secuencia.",
  3451. $th->getMessage(),
  3452. 500
  3453. );
  3454. }
  3455. $nuse = 1; // Secuencia del documento
  3456. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  3457. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  3458. }
  3459. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  3460. $nuve = $this->resourcesController->formatSecuence('1', 2);
  3461. $noar = 'ficha_de_facturación_' . $arrOrder['ORCO_NUOR'];
  3462. $exte = 'pdf';
  3463. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  3464. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  3465. } else {
  3466. $filePath = $this->functionsController->getApiURI().'public_files/'; // API QA
  3467. }
  3468. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  3469. $tempFile = $filePath . $fileName;
  3470. $dompdf = new Dompdf();
  3471. $dompdf ->loadHtml($html);
  3472. $dompdf->setPaper('A4', 'landscape');
  3473. $dompdf->render();
  3474. $output = $dompdf->output();
  3475. file_put_contents($tempFile, $output);
  3476. $ubic = Storage::putFile('files', new File($tempFile));
  3477. $ubic = str_replace("/", "\\", $ubic);
  3478. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  3479. $tama = filesize($ubic);
  3480. $usac = json_encode([$user]);
  3481. $now = $this->functionsController->now();
  3482. $currentDate = $now->toDateTimeString();
  3483. try {
  3484. $validateInsert = DB::table('S002V01TAFAL')->insert([
  3485. 'AFAL_NULI' => $line,
  3486. 'AFAL_COMO' => $como,
  3487. 'AFAL_CLDO' => $cldo,
  3488. 'AFAL_FECR' => $fecr,
  3489. 'AFAL_NUSE' => $nuse,
  3490. 'AFAL_NUVE' => $nuve,
  3491. 'AFAL_NOAR' => $noar,
  3492. 'AFAL_EXTE' => $exte,
  3493. 'AFAL_TAMA' => $tama,
  3494. 'AFAL_UBIC' => $ubic,
  3495. 'AFAL_USAC' => $usac,
  3496. 'AFAL_USRE' => $user,
  3497. 'AFAL_FERE' => $currentDate,
  3498. ]);
  3499. } catch (\Throwable $th) {
  3500. return $this->responseController->makeResponse(
  3501. true,
  3502. "ERR_PROVIDER_SHEET023: Ocurrió un error guardar los datos a la tabla final de archivos.",
  3503. $th->getMessage(),
  3504. 500
  3505. );
  3506. }
  3507. if ( !$validateInsert ) {
  3508. return $this->responseController->makeResponse(
  3509. true,
  3510. "ERR_PROVIDER_SHEET024: No se pudo guardar la ficha del proveedor en la base de datos.",
  3511. [],
  3512. 500
  3513. );
  3514. }
  3515. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  3516. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  3517. }
  3518. }