OrderController.php 152 KB

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