OrderController.php 157 KB

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