OrderController.php 155 KB

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