OrderController.php 153 KB

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