ArtitleController.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 10/10/2023
  5. Módulo: Gestión de Adquisiciones
  6. */
  7. namespace App\Http\Controllers;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Carbon;
  10. use Illuminate\Support\Facades\DB;
  11. use App\Http\Controllers\Controller;
  12. use Illuminate\Support\Facades\Validator;
  13. use App\Http\Controllers\ResponseController;
  14. use App\Http\Controllers\ResourcesController;
  15. use App\Http\Controllers\EncryptionController;
  16. use App\Http\Controllers\DocumentManagementController;
  17. use App\Http\Controllers\FunctionsController;
  18. class ArtitleController extends Controller {
  19. private $responseController;
  20. private $encController;
  21. private $resourcesController;
  22. private $documentManagementController;
  23. private $functionsController;
  24. public function __construct() {
  25. $this->responseController = new ResponseController();
  26. $this->encController = new EncryptionController();
  27. $this->resourcesController = new ResourcesController();
  28. $this->documentManagementController = new DocumentManagementController();
  29. $this->functionsController = new FunctionsController();
  30. }
  31. // Función para obtener las familias y las subfamilias activas
  32. public function getFamiliesAndSubfamilies ($user, $line) {
  33. try {
  34. $arrFamilias = DB::table('S002V01TFAMI')
  35. ->where('FAMI_ESTA', '=', 'Activo')
  36. ->where('FAMI_NULI', '=', $line)
  37. ->get([
  38. 'FAMI_COFA AS ID_FAMILIA',
  39. 'FAMI_NOFA AS FAMILIA',
  40. ]);
  41. } catch (\Throwable $th) {
  42. return $this->responseController->makeResponse(
  43. true,
  44. "ERR_ARTITLE_GETFAMILYS000: No se pudo realizar la consulta de las familias en la base.",
  45. $th->getMessage(),
  46. 500
  47. );
  48. }
  49. try {
  50. $arrSubfamilias = DB::table('S002V01TSUBF')
  51. ->where('SUBF_ESTA', '=', 'Activo')
  52. ->where('SUBF_NULI', '=', $line)
  53. ->get([
  54. 'SUBF_COSU AS ID_SUBFAMILIA',
  55. 'SUBF_NOSU AS SUBFAMILIA',
  56. 'SUBF_COFA AS ID_FAMILIA',
  57. ]);
  58. } catch (\Throwable $th) {
  59. return $this->responseController->makeResponse(
  60. true,
  61. "ERR_ARTITLE_GETFAMILYS001: No se pudo realizar la consulta de las subfamilias en la base.",
  62. $th->getMessage(),
  63. 500
  64. );
  65. }
  66. try {
  67. foreach ($arrFamilias as $keyFamilias => $familias) {
  68. $familias->SUBFAMILIAS = array();
  69. foreach ($arrSubfamilias as $keySubfamilias => $subfamilias) {
  70. if ($familias->ID_FAMILIA == $subfamilias->ID_FAMILIA) {
  71. $familias->SUBFAMILIAS[] = array(
  72. "ID_SUBFAMILIA" => $subfamilias->ID_SUBFAMILIA,
  73. "SUBFAMILIA" => $subfamilias->SUBFAMILIA,
  74. );
  75. }
  76. }
  77. }
  78. } catch (\Throwable $th) {
  79. return $this->responseController->makeResponse(
  80. true,
  81. "ERR_ARTITLE_GETFAMILYS002: Ocurrió un error al generar la respuesta de la consulta.",
  82. $th->getMessage(),
  83. 500
  84. );
  85. }
  86. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  87. }
  88. public function registerFamily(Request $request){
  89. $valitador = Validator::make($request->all(), [
  90. 'FAMILIA' => 'required|string|max:50',
  91. 'LINE' => 'required|integer',
  92. 'USER' => 'required|string'
  93. ]);
  94. if ($valitador->fails()) {
  95. return $this->responseController->makeResponse(
  96. true,
  97. "ERR_FAMILY_REG000: Se encontraron uno o más errores.",
  98. $this->responseController->makeErrors($valitador->errors()->messages()),
  99. 401
  100. );
  101. }
  102. DB::beginTransaction();
  103. $responseData = $request->all();
  104. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($responseData['USER'], $responseData['LINE']);
  105. if ($arrResponseCheckUser['error']) {
  106. DB::rollBack();
  107. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  108. }
  109. $usuario = $arrResponseCheckUser['response'];
  110. $now = $this->functionsController->now();
  111. $currentDate = $now->toDateTimeString();
  112. try {
  113. $validateInsert = DB::table('S002V01TFAMI')->insert([
  114. "FAMI_NOFA" => trim($responseData['FAMILIA']),
  115. "FAMI_USRE" => $usuario,
  116. "FAMI_NULI" => $responseData['LINE'],
  117. "FAMI_FERE" => $currentDate,
  118. "FAMI_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  119. ]);
  120. } catch (\Throwable $th) {
  121. DB::rollBack();
  122. return $this->responseController->makeResponse(true, "Ocurrió un error al ingresar los registros.", $th->getMessage(), 401);
  123. }
  124. if (!$validateInsert) {
  125. DB::rollBack();
  126. return $this->responseController->makeResponse(true, "No se pudo ingresar los datos a la base de datos.", [], 401);
  127. }
  128. DB::commit();
  129. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  130. }
  131. public function getUnits($user, $line) {
  132. try {
  133. $arrFamilias = DB::table('S002V01TUNID')
  134. ->where('UNID_NULI', '=', $line)
  135. ->get([
  136. 'UNID_IDUN AS ID_UNIDAD',
  137. 'UNID_NOMB AS UNIDAD',
  138. 'UNID_ESTA AS ESTADO',
  139. 'UNID_USRE AS USUARIO_REGISTRA',
  140. 'UNID_FERE AS FECHA_REGISTRA',
  141. 'UNID_USMO AS USUARIO_MODIFICA',
  142. 'UNID_FEMO AS FECHA_MODIFICA',
  143. ]);
  144. } catch (\Throwable $th) {
  145. return $this->responseController->makeResponse(
  146. true,
  147. "ERR_ARTITLE_GETUNITS000: No se pudo realizar la consulta a la base.",
  148. $th->getMessage(),
  149. 500
  150. );
  151. }
  152. return $this->responseController->makeResponse(false, "ÉXITO: Consulta exitosa", $arrFamilias);
  153. }
  154. public function getUnitsActives($user, $line) {
  155. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  156. if ($arrResponseCheckUser['error']) {
  157. DB::rollBack();
  158. return $this->responseController->makeResponse(true, 'ERR_UNITS_GETACTIVES000:'.$arrResponseCheckUser['msg'], [], 401);
  159. }
  160. try {
  161. $arrFamilias = DB::table('S002V01TUNID')
  162. ->where('UNID_NULI', '=', $line)
  163. ->where('UNID_ESTA', '=', 'Activo')
  164. ->get([
  165. 'UNID_IDUN AS ID_UNIDAD',
  166. 'UNID_NOMB AS UNIDAD',
  167. 'UNID_USRE AS USUARIO_REGISTRA',
  168. 'UNID_FERE AS FECHA_REGISTRA',
  169. 'UNID_USMO AS USUARIO_MODIFICA',
  170. 'UNID_FEMO AS FECHA_MODIFICA',
  171. ]);
  172. } catch (\Throwable $th) {
  173. return $this->responseController->makeResponse(
  174. true,
  175. "ERR_UNITS_GETACTIVES001: No se pudo realizar la consulta a la base.",
  176. $th->getMessage(),
  177. 500
  178. );
  179. }
  180. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  181. }
  182. public function registerUnit(Request $request){
  183. $valitador = Validator::make($request->all(), [
  184. 'UNIDAD' => 'required|string|max:50',
  185. 'LINE' => 'required|integer',
  186. 'USER' => 'required|string'
  187. ]);
  188. if ($valitador->fails()) {
  189. return $this->responseController->makeResponse(
  190. true,
  191. "ERR_UNITS_REG000: Se encontraron uno o más errores.",
  192. $this->responseController->makeErrors($valitador->errors()->messages()),
  193. 401
  194. );
  195. }
  196. DB::beginTransaction();
  197. $responseData = $request->all();
  198. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($responseData['USER'], $responseData['LINE']);
  199. if ($arrResponseCheckUser['error']) {
  200. DB::rollBack();
  201. return $this->responseController->makeResponse(true, 'ERR_UNITS_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  202. }
  203. $usuario = $arrResponseCheckUser['response'];
  204. $now = $this->functionsController->now();
  205. $currentDate = $now->toDateTimeString();
  206. try {
  207. $validateInsert = DB::table('S002V01TUNID')->insert([
  208. "UNID_NOMB" => trim($responseData['UNIDAD']),
  209. "UNID_USRE" => $usuario,
  210. "UNID_NULI" => $responseData['LINE'],
  211. "UNID_FERE" => $currentDate,
  212. "UNID_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  213. ]);
  214. } catch (\Throwable $th) {
  215. DB::rollBack();
  216. return $this->responseController->makeResponse(
  217. true,
  218. "ERR_UNITS_REG002: Ocurrió un error al ingresar los registros.",
  219. $th->getMessage(),
  220. 401
  221. );
  222. }
  223. if (!$validateInsert) {
  224. DB::rollBack();
  225. return $this->responseController->makeResponse(
  226. true,
  227. "ERR_UNITS_REG003: No se pudo ingresar los datos a la base de datos.",
  228. [],
  229. 401
  230. );
  231. }
  232. DB::commit();
  233. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  234. }
  235. public function registerSubfamily(Request $request){
  236. $valitador = Validator::make($request->all(), [
  237. 'ID_FAMILIA' => 'required|integer',
  238. 'SUBFAMILIA' => 'required|string|max:50',
  239. 'LINE' => 'required|integer',
  240. 'USER' => 'required|string'
  241. ]);
  242. if ($valitador->fails()) {
  243. return $this->responseController->makeResponse(
  244. true,
  245. "ERR_SUBFAMILY_REG000: Se encontraron uno o más errores.",
  246. $this->responseController->makeErrors($valitador->errors()->messages()),
  247. 401
  248. );
  249. }
  250. DB::beginTransaction();
  251. $responseData = $request->all();
  252. try {
  253. $validateExists = DB::table('S002V01TFAMI')
  254. ->where('FAMI_COFA', '=', trim($responseData['ID_FAMILIA']))
  255. ->where('FAMI_ESTA', '=', 'Activo')
  256. ->where('FAMI_NULI', '=', $responseData['LINE'])
  257. ->exists();
  258. } catch (\Throwable $th) {
  259. DB::rollBack();
  260. return $this->responseController->makeResponse(
  261. true,
  262. "ERR_SUBFAMILY_REG001: Ocurrió al verificar la Familia.",
  263. $th->getMessage(),
  264. 401
  265. );
  266. }
  267. if (!$validateExists) {
  268. return $this->responseController->makeResponse(
  269. true,
  270. "ERR_SUBFAMILY_REG002: La Familia seleccionada no existe.",
  271. [],
  272. 401
  273. );
  274. }
  275. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($responseData['USER'], $responseData['LINE']);
  276. if ($arrResponseCheckUser['error']) {
  277. DB::rollBack();
  278. return $this->responseController->makeResponse(true, 'ERR_SUBFAMILY_REG003:'.$arrResponseCheckUser['msg'], [], 401);
  279. }
  280. $user = $arrResponseCheckUser['response'];
  281. $now = $this->functionsController->now();
  282. $currentDate = $now->toDateTimeString();
  283. try {
  284. $validateInsert = DB::table('S002V01TSUBF')->insert([
  285. "SUBF_COFA" => $responseData['ID_FAMILIA'],
  286. "SUBF_NOSU" => $responseData['SUBFAMILIA'],
  287. "SUBF_USRE" => $user,
  288. "SUBF_NULI" => $responseData['LINE'],
  289. "SUBF_FERE" => $currentDate,
  290. "SUBF_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  291. ]);
  292. } catch (\Throwable $th) {
  293. DB::rollBack();
  294. return $this->responseController->makeResponse(
  295. true,
  296. "ERR_SUBFAMILY_REG004: Ocurrió un error al ingresar los registros.",
  297. $th->getMessage(),
  298. 401
  299. );
  300. }
  301. if (!$validateInsert) {
  302. DB::rollBack();
  303. return $this->responseController->makeResponse(
  304. true,
  305. "ERR_SUBFAMILY_REG005: No se pudo ingresar los datos a la base de datos.",
  306. [],
  307. 401
  308. );
  309. }
  310. DB::commit();
  311. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  312. }
  313. public function getArtitles($user, $line) {
  314. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  315. if ($arrResponseCheckUser['error']) {
  316. DB::rollBack();
  317. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_GET000:'.$arrResponseCheckUser['msg'], [], 401);
  318. }
  319. try {
  320. $getArtitle = DB::table('S002V01TARTI')
  321. ->where("ARTI_NULI", "=", $line)
  322. ->where("FAMI_NULI", "=", $line)
  323. ->where("SUBF_NULI", "=", $line)
  324. ->where("DEAR_NULI", "=", $line)
  325. ->where("PROV_NULI", "=", $line)
  326. ->where("UNID_NULI", "=", $line)
  327. ->where("ARTI_ESTA", "=", "Activo")
  328. ->where("FAMI_ESTA", "=", "Activo")
  329. ->where("SUBF_ESTA", "=", "Activo")
  330. ->where("DEAR_ESTA", "=", "Activo")
  331. ->where("PROV_ESTA", "=", "Activo")
  332. ->where("UNID_ESTA", "=", "Activo")
  333. ->join("S002V01TFAMI", "ARTI_COFA", "=", "FAMI_COFA")
  334. ->join("S002V01TSUBF", "ARTI_COSU", "=", "SUBF_COSU")
  335. ->join("S002V01TDEAR", "ARTI_IDAR", "=", "DEAR_IDAR")
  336. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  337. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  338. ->get([
  339. "DEAR_IDDE AS ID_DESC_ARTI",
  340. "ARTI_IDAR AS ID_ARTICULO",
  341. "ARTI_NOMB AS MODELO",
  342. "FAMI_COFA AS ID_FAMILIA",
  343. "FAMI_NOFA AS FAMILIA",
  344. "SUBF_COSU AS ID_SUBFAMILIA",
  345. "SUBF_NOSU AS SUBFAMILIA",
  346. "DEAR_DESC AS DESCRIPCION",
  347. "DEAR_CARA AS CARACTERISTICAS",
  348. "DEAR_COWE AS COMPRA_WEB",
  349. "DEAR_IDUN AS TIPO_UNIDAD",
  350. "DEAR_IMAG AS URL_IMAGEN",
  351. "PROV_NUPR AS ID_PROVEEDOR",
  352. "PROV_NOCO AS PROVEEDOR",
  353. ]);
  354. } catch (\Throwable $th) {
  355. return $this->responseController->makeResponse(
  356. true,
  357. "ERR_ARTITLE_GET001: No se pudo realizar la consulta a la base.",
  358. $th->getMessage(),
  359. 500
  360. );
  361. }
  362. try {
  363. foreach ($getArtitle as $artitle) {
  364. $arrImagen = json_decode($artitle->URL_IMAGEN);
  365. $arrUrlImage = array();
  366. foreach ($arrImagen as $key => $imagen) {
  367. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  368. if ($responseDocument['error']) {
  369. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET002: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  370. }
  371. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  372. }
  373. $artitle->URL_IMAGEN = $arrUrlImage;
  374. }
  375. } catch (\Throwable $th) {
  376. return $this->responseController->makeResponse(
  377. true,
  378. "ERR_ARTITLE_GET003: Ocurrió un error al obtener las imangenes de los artículos.",
  379. $th->getMessage(),
  380. 500
  381. );
  382. }
  383. $getArtitle = json_decode(json_encode($getArtitle), true);
  384. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getArtitle);
  385. }
  386. public function getArtitlesByProvider($artitle, $provider, $user, $line) {
  387. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  388. if ($arrResponseCheckUser['error']) {
  389. DB::rollBack();
  390. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_GETBYPROVIDER000:'.$arrResponseCheckUser['msg'], [], 401);
  391. }
  392. try {
  393. $idArtitle = $this->encController->decrypt($artitle);
  394. } catch (\Throwable $th) {
  395. return $this->responseController->makeResponse(
  396. true,
  397. "ERR_ARTITLE_GETBYPROVIDER001: No se pudo realizar la consulta a la base.",
  398. $th->getMessage(),
  399. 500
  400. );
  401. }
  402. try {
  403. $idProvider = $this->encController->decrypt($provider);
  404. } catch (\Throwable $th) {
  405. return $this->responseController->makeResponse(
  406. true,
  407. "ERR_ARTITLE_GETBYPROVIDER002: No se pudo realizar la consulta a la base.",
  408. $th->getMessage(),
  409. 500
  410. );
  411. }
  412. try {
  413. $objArtitle = (array) DB::table('S002V01TDEAR')
  414. ->where("ARTI_NULI", "=", $line)
  415. ->where("DEAR_IDDE", "=", $idArtitle)
  416. ->where("DEAR_NUPR", "=", $idProvider)
  417. ->join("S002V01TARTI", "ARTI_IDAR", "=", "DEAR_IDAR")
  418. ->join("S002V01TFAMI", "ARTI_COFA", "=", "FAMI_COFA")
  419. ->join("S002V01TSUBF", "ARTI_COSU", "=", "SUBF_COSU")
  420. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  421. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  422. ->first([
  423. "DEAR_IDDE AS ID_DESC_ARTI",
  424. "ARTI_IDAR AS ID_ARTICULO",
  425. "ARTI_NOMB AS MODELO",
  426. "FAMI_COFA AS ID_FAMILIA",
  427. "FAMI_NOFA AS FAMILIA",
  428. "SUBF_COSU AS ID_SUBFAMILIA",
  429. "SUBF_NOSU AS SUBFAMILIA",
  430. "DEAR_DESC AS DESCRIPCION",
  431. "DEAR_CARA AS CARACTERISTICAS",
  432. "DEAR_COWE AS COMPRA_WEB",
  433. "UNID_IDUN AS ID_UNIDAD",
  434. "UNID_NOMB AS UNIDAD",
  435. "DEAR_IMAG AS URL_IMAGEN",
  436. "PROV_NUPR AS ID_PROVEEDOR",
  437. "PROV_NOCO AS PROVEEDOR",
  438. ]);
  439. } catch (\Throwable $th) {
  440. return $this->responseController->makeResponse(
  441. true,
  442. "ERR_ARTITLE_GETBYPROVIDER003: No se pudo realizar la consulta a la base.",
  443. $th->getMessage(),
  444. 500
  445. );
  446. }
  447. if ( empty($objArtitle) ) {
  448. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER004: No se encontró el resultado deseado.", [], 500);
  449. }
  450. try {
  451. $objArtitle['URL_IMAGEN'] = json_decode($objArtitle['URL_IMAGEN']);
  452. $arrUrlImage = array();
  453. foreach ($objArtitle['URL_IMAGEN'] as $key => $encImage) {
  454. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($encImage, $user, $line);
  455. if ($responseDocument['error']) {
  456. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER005: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  457. }
  458. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  459. }
  460. $objArtitle['URL_IMAGEN'] = $arrUrlImage;
  461. } catch (\Throwable $th) {
  462. return $this->responseController->makeResponse(
  463. true,
  464. "ERR_ARTITLE_GETBYPROVIDER006: Ocurrió un error al obtner las imagenes de los artículos",
  465. $th->getMessage(),
  466. 500
  467. );
  468. }
  469. try {
  470. $arrInformation = DB::table('S002V01TINAR')
  471. ->where('INAR_ESTA', '=', 'Activo')
  472. ->where('INAR_NULI', '=', $line)
  473. ->where('INAR_IDDE', '=', $objArtitle['ID_DESC_ARTI'])
  474. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  475. ->get([
  476. 'INAR_IDIN AS NUMERO_INFORMACION',
  477. 'INAR_CODI AS CODIGO',
  478. 'INAR_MODE AS MODELO',
  479. 'CAMO_COMO AS MONEDA',
  480. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  481. 'INAR_PREC AS PRECIO',
  482. 'INAR_MOMI AS MONTO_MINIMO',
  483. 'INAR_CARA AS CARACTERISTICAS',
  484. ]);
  485. } catch (\Throwable $th) {
  486. return $this->responseController->makeResponse(
  487. true,
  488. "ERR_ARTITLE_GETBYPROVIDER007: No se pudo realizar la consulta a la base.",
  489. $th->getMessage(),
  490. 500
  491. );
  492. }
  493. $objArtitle['INFO_PRODUCTO'] = json_encode($arrInformation);
  494. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objArtitle);
  495. }
  496. public function getArticleById($idArticle, $user, $line) {
  497. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  498. if ($arrResponseCheckUser['error']) {
  499. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  500. }
  501. $idArticle = $this->encController->decrypt($idArticle);
  502. if (is_null($idArticle)) {
  503. return $this->responseController->makeResponse(true, 'El identificador del artículo no está encriptado correctamente.', [], 401);
  504. }
  505. try {
  506. $article = DB::table('S002V01TARTI')
  507. ->where([
  508. ['ARTI_NULI', '=', $line],
  509. ['ARTI_IDAR', '=', $idArticle],
  510. ['ARTI_ESTA', '=', 'Activo'],
  511. ])
  512. ->first([
  513. 'ARTI_IDAR AS ID_ARTICULO',
  514. 'ARTI_COFA AS FAMILIA',
  515. 'ARTI_COSU AS SUBFAMILIA',
  516. 'ARTI_CODI AS CODIGO',
  517. 'ARTI_NOMB AS ARTICULO',
  518. 'ARTI_ESTA AS ESTADO',
  519. ]);
  520. } catch (\Throwable $th) {
  521. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido del artículo #{$idArticle}.", $th->getMessage(), 500);
  522. }
  523. if (is_null($article) || empty((array)$article)) {
  524. return $this->responseController->makeResponse(true, "No existen datos del artículo #{$idArticle}.", [], 500);
  525. }
  526. try {
  527. $arrDescription = DB::table('S002V01TDEAR')
  528. ->where([
  529. ['DEAR_NULI', '=', $line],
  530. ['DEAR_IDAR', '=', $idArticle],
  531. ['DEAR_ESTA', '=', 'Activo'],
  532. ])
  533. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  534. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  535. ->get([
  536. 'DEAR_IDDE AS ID_DESCRIPCION',
  537. 'PROV_NUPR AS NUMERO_PROVEEDOR',
  538. 'PROV_NOCO AS PROVEEDOR',
  539. 'UNID_IDUN AS ID_UNIDAD',
  540. 'UNID_NOMB AS UNIDAD',
  541. 'DEAR_DESC AS DESCRIPCION',
  542. 'DEAR_CARA AS CARACTERISTICAS',
  543. 'DEAR_ESTA AS ESTADO',
  544. 'DEAR_IMAG AS ARCHIVOS',
  545. ]);
  546. } catch (\Throwable $th) {
  547. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido la descripción del artículo #{$idArticle}.", $th->getMessage(), 500);
  548. }
  549. foreach ($arrDescription as $description) {
  550. $images = json_decode($description->ARCHIVOS);
  551. $files = array();
  552. foreach ($images as $img) {
  553. $response = $this->documentManagementController->getFileByCode($img, $user, $line);
  554. if ($response['error']) {
  555. return $this->responseController->makeResponse(true, $response['msg'], $response['response'], 500);
  556. }
  557. $dataFile = $response['response'];
  558. $files[] = $dataFile;
  559. }
  560. $description->ARCHIVOS = $files;
  561. try {
  562. $arrDetails = DB::table('S002V01TINAR')
  563. ->where([
  564. ['INAR_NULI', '=', $line],
  565. ['INAR_IDDE', '=', $description->ID_DESCRIPCION],
  566. ['INAR_ESTA', '=', 'Activo'],
  567. ])
  568. ->get([
  569. 'INAR_IDIN AS ID_DETAILS',
  570. 'INAR_CODI AS CODIGO',
  571. 'INAR_MODE AS MODELO',
  572. 'INAR_COMO AS MONEDA',
  573. 'INAR_PREC AS PRECIO',
  574. 'INAR_MOMI AS MONTO_MINIMO',
  575. 'INAR_CARA AS CARACTERISTICAS',
  576. 'INAR_ESTA AS ESTADO',
  577. ]);
  578. } catch (\Throwable $th) {
  579. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido de los detalles de la descripción del artículo #{$idArticle}.", $th->getMessage(), 500);
  580. }
  581. $description->DETALLES = $arrDetails;
  582. }
  583. $article->DESCRIPCION_ARTICULO = $arrDescription;
  584. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $article);
  585. }
  586. public function getAllArtitles($user, $line) {
  587. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  588. if ($arrResponseCheckUser['error']) {
  589. DB::rollBack();
  590. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_GETALL000:'.$arrResponseCheckUser['msg'], [], 401);
  591. }
  592. try {
  593. $arrArtitle = DB::table('S002V01TARTI')
  594. ->where("ARTI_NULI", "=", $line)
  595. ->join("S002V01TFAMI", "ARTI_COFA", "=", "FAMI_COFA")
  596. ->join("S002V01TSUBF", "ARTI_COSU", "=", "SUBF_COSU")
  597. ->get([
  598. "ARTI_IDAR AS ID_ARTICULO",
  599. "ARTI_NOMB AS MODELO",
  600. "FAMI_COFA AS ID_FAMILIA",
  601. "FAMI_NOFA AS FAMILIA",
  602. "SUBF_COSU AS ID_SUBFAMILIA",
  603. "SUBF_NOSU AS SUBFAMILIA",
  604. "ARTI_ESTA AS ESTADO",
  605. "ARTI_USRE AS USUARIO_REGISTRA",
  606. "ARTI_FERE AS FECHA_REGISTRA",
  607. "ARTI_USMO AS USUARIO_MODIFICA",
  608. "ARTI_FEMO AS FECHA_MODIFICA",
  609. ]);
  610. $arrArtitle = json_decode(json_encode($arrArtitle), true);
  611. } catch (\Throwable $th) {
  612. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETALL001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  613. }
  614. $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrArtitle, $line);
  615. if ($responseCheckLatestUpdate['error']) {
  616. return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
  617. }
  618. $arrArtitle = $responseCheckLatestUpdate['response'];
  619. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArtitle);
  620. }
  621. public function registerArtitlesOld(Request $request) {
  622. $validator = Validator::make($request->all(), [
  623. 'CODIGO' => 'required|string',
  624. 'ARTICULO' => 'required|string',
  625. 'FAMILIA' => 'required|string',
  626. 'SUBFAMILIA' => 'required|string',
  627. 'INFORMATION' => 'required|array',
  628. 'USUARIO' => 'required|string',
  629. 'NUMERO_LINEA' => 'required|integer',
  630. ]);
  631. if ($validator->fails()) {
  632. return $this->responseController->makeResponse(
  633. true,
  634. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  635. $this->responseController->makeErrors($validator->errors()->messages()),
  636. 401
  637. );
  638. }
  639. DB::beginTransaction();
  640. $requestData = $request->all();
  641. foreach ($requestData['INFORMATION'] as $information) {
  642. $validator = Validator::make($information, [
  643. 'NO' => 'required|string',
  644. 'IMAGEN' => 'required|array',
  645. 'DESCRIPCION' => 'required|string',
  646. // 'CARACTERISTICAS' => '|string',
  647. 'TIPO_UNIDAD' => 'required|integer',
  648. 'PROVEEDOR' => 'required|string',
  649. 'COMPRA_WEB' => 'required|boolean',
  650. 'ESTADO' => 'required|string',
  651. 'DETAILS' => 'required|array',
  652. ]);
  653. if ($validator->fails()) {
  654. return $this->responseController->makeResponse(
  655. true,
  656. "ERR_ARTITLE_REG001: Se encontraron uno o más errores.",
  657. $this->responseController->makeErrors($validator->errors()->messages()),
  658. 401
  659. );
  660. }
  661. foreach ($information['DETAILS'] as $details) {
  662. $validator = Validator::make($details, [
  663. 'NO' => 'required|string',
  664. 'CODIGO' => 'required|string',
  665. 'MODELO' => 'required|string',
  666. 'MONEDA' => 'required|string',
  667. 'PRECIO' => 'required|string',
  668. 'MONTO_MINIMO' => 'required|string',
  669. 'ESTADO' => 'required|string',
  670. 'CARACTERISTICAS' => 'required|string',
  671. ]);
  672. if ($validator->fails()) {
  673. return $this->responseController->makeResponse(
  674. true,
  675. "ERR_ARTITLE_REG002: Se encontraron uno o más errores.",
  676. $this->responseController->makeErrors($validator->errors()->messages()),
  677. 401
  678. );
  679. }
  680. }
  681. }
  682. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  683. if ($arrResponseCheckUser['error']) {
  684. DB::rollBack();
  685. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG003:'.$arrResponseCheckUser['msg'], [], 401);
  686. }
  687. $usuario = $arrResponseCheckUser['response'];
  688. $now = $this->functionsController->now();
  689. $currentDate = $now->toDateTimeString();
  690. try {
  691. $idArtitle = DB::table('S002V01TARTI')->insertGetId([
  692. 'ARTI_CODI' => $requestData['CODIGO'],
  693. 'ARTI_COFA' => $requestData['FAMILIA'],
  694. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  695. 'ARTI_NOMB' => $requestData['ARTICULO'],
  696. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  697. 'ARTI_USRE' => $usuario,
  698. 'ARTI_FERE' => $currentDate,
  699. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  700. ]);
  701. } catch (\Throwable $th) {
  702. DB::rollBack();
  703. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG004: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  704. }
  705. foreach ($requestData['INFORMATION'] as $keyInformation => $information) {
  706. try {
  707. $arrCodeImages = array();
  708. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  709. $idFile = $this->encController->decrypt($encIdFile);
  710. $tempFile = DB::table('S002V01TARTE')->where([
  711. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  712. ['ARTE_IDAR', '=', $idFile],
  713. ])->first();
  714. if(is_null($tempFile)){
  715. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG005: El archivo consultado no está registrado', [], 404);
  716. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  717. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado está eliminado', [], 404);
  718. }
  719. $fileResponse = $this->documentManagementController->moveFinalFile(
  720. intval($requestData['NUMERO_LINEA']),
  721. 'GEAD',
  722. 'FO',
  723. $tempFile,
  724. $usuario,
  725. );
  726. if(!$fileResponse[0]){
  727. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: '.$fileResponse[1], [], 400);
  728. }
  729. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  730. }
  731. $jsonImages = json_encode($arrCodeImages);
  732. } catch (\Throwable $th) {
  733. DB::rollBack();
  734. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG008: Ocurrió un error al obtener la URL pública de las imágenes.", $th->getMessage(), 500);
  735. }
  736. try {
  737. $idDescription = DB::table('S002V01TDEAR')->insertGetId([
  738. 'DEAR_DESC' => $information['DESCRIPCION'],
  739. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  740. 'DEAR_COWE' => $information['COMPRA_WEB'],
  741. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  742. 'DEAR_IMAG' => $jsonImages,
  743. 'DEAR_NUPR' => $information['PROVEEDOR'],
  744. 'DEAR_IDAR' => $idArtitle,
  745. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  746. 'DEAR_USRE' => $usuario,
  747. 'DEAR_FERE' => $currentDate,
  748. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  749. ]);
  750. } catch (\Throwable $th) {
  751. DB::rollBack();
  752. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG009: Ocurrió un error al insertar los datos de la información del artículo.", $th->getMessage(), 500);
  753. }
  754. $arrDetails = $information['DETAILS'];
  755. foreach ($arrDetails as $keyDetails => $details) {
  756. $insertDetails = [
  757. 'INAR_IDDE' => $idDescription,
  758. 'INAR_CODI' => $details['CODIGO'],
  759. 'INAR_MODE' => $details['MODELO'],
  760. 'INAR_COMO' => $details['MONEDA'],
  761. 'INAR_PREC' => $details['PRECIO'],
  762. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  763. 'INAR_CARA' => $details['CARACTERISTICAS'],
  764. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  765. 'INAR_USRE' => $usuario,
  766. 'INAR_FERE' => $currentDate,
  767. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  768. ];
  769. try {
  770. $validateDetails = DB::table('S002V01TINAR')->insert($insertDetails);
  771. } catch (\Throwable $th) {
  772. DB::rollBack();
  773. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG010: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  774. }
  775. if (!$validateDetails) {
  776. DB::rollBack();
  777. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG011: No se pudo insertar los datos de los detalles.", [], 500);
  778. }
  779. }
  780. }
  781. DB::commit();
  782. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  783. }
  784. public function registerArticle (Request $request) {
  785. $validator = Validator::make($request->all(), [
  786. 'CODIGO' => 'required|string',
  787. 'ARTICULO' => 'required|string',
  788. 'FAMILIA' => 'required|string',
  789. 'SUBFAMILIA' => 'required|string',
  790. 'DESCRIPCION_ARTICULO' => 'required|array',
  791. 'USUARIO' => 'required|string',
  792. 'NUMERO_LINEA' => 'required|integer',
  793. ]);
  794. if ($validator->fails()) {
  795. return $this->responseController->makeResponse(
  796. true,
  797. "Se encontraron uno o más errores.",
  798. $this->responseController->makeErrors($validator->errors()->messages()),
  799. 401
  800. );
  801. }
  802. DB::beginTransaction();
  803. $requestData = $request->all();
  804. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  805. if ($arrResponseCheckUser['error']) {
  806. DB::rollBack();
  807. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  808. }
  809. $user = $arrResponseCheckUser['response'];
  810. try {
  811. $validateExists = DB::table("S002V01TFAMI")->where([
  812. ['FAMI_COFA', '=', $requestData['FAMILIA']],
  813. ['FAMI_NULI', '=', $requestData['NUMERO_LINEA']],
  814. ])->exists();
  815. } catch (\Throwable $th) {
  816. DB::rollBack();
  817. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la familia.", $th->getMessage(), 500);
  818. }
  819. if ($validateExists === false) {
  820. DB::rollBack();
  821. return $this->responseController->makeResponse(true, "La familia {$requestData['FAMILIA']} no existe.", [], 500);
  822. }
  823. unset($validateExists);
  824. try {
  825. $validateExists = DB::table('S002V01TSUBF')
  826. ->where([
  827. ['SUBF_NULI', '=', $requestData['NUMERO_LINEA']],
  828. ['SUBF_COFA', '=', $requestData['FAMILIA']],
  829. ['SUBF_COSU', '=', $requestData['SUBFAMILIA']],
  830. ])->exists();
  831. } catch (\Throwable $th) {
  832. DB::rollBack();
  833. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la subfamilia.", $th->getMessage(), 500);
  834. }
  835. if ($validateExists === false) {
  836. DB::rollBack();
  837. return $this->responseController->makeResponse(true, "La subfamilia {$requestData['SUBFAMILIA']} perteneciente a la familia {$requestData['FAMILIA']} no existe.", [], 500);
  838. }
  839. unset($validateExists);
  840. $now = $this->functionsController->now();
  841. $currentDate = $now->toDateTimeString();
  842. try {
  843. $idArticle = DB::table('S002V01TARTI')
  844. ->insertGetId([
  845. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  846. 'ARTI_COFA' => $requestData['FAMILIA'],
  847. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  848. 'ARTI_CODI' => $requestData['CODIGO'],
  849. 'ARTI_NOMB' => $requestData['ARTICULO'],
  850. 'ARTI_USRE' => $user,
  851. 'ARTI_FERE' => $currentDate,
  852. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  853. ]);
  854. } catch (\Throwable $th) {
  855. DB::rollBack();
  856. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el artículo.", $th->getMessage(), 500);
  857. }
  858. if ($idArticle <= 0) {
  859. DB::rollBack();
  860. return $this->responseController->makeResponse(true, "No se pudo registra el artículo.", [], 500);
  861. }
  862. foreach ($requestData['DESCRIPCION_ARTICULO'] as $descriptions) {
  863. try {
  864. $validateExists = DB::table('S002V01TUNID')
  865. ->where([
  866. ['UNID_NULI', '=', $requestData['NUMERO_LINEA']],
  867. ['UNID_IDUN', '=', $descriptions['ID_UNIDAD']],
  868. ])->exists();
  869. } catch (\Throwable $th) {
  870. DB::rollBack();
  871. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}).", $th->getMessage(), 500);
  872. }
  873. if ($validateExists === false) {
  874. DB::rollBack();
  875. return $this->responseController->makeResponse(true, "La unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}) no existe.", [], 500);
  876. }
  877. unset($validateExists);
  878. try {
  879. $validateExists = DB::table('S002V01TPROV')
  880. ->where([
  881. ['PROV_NULI', '=', $requestData['NUMERO_LINEA']],
  882. ['PROV_NUPR', '=', $descriptions['NUMERO_PROVEEDOR']],
  883. ])->exists();
  884. } catch (\Throwable $th) {
  885. DB::rollBack();
  886. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia del proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}).", $th->getMessage(), 500);
  887. }
  888. if ($validateExists === false) {
  889. DB::rollBack();
  890. return $this->responseController->makeResponse(true, "El proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}) no existe.", [], 500);
  891. }
  892. unset($validateExists);
  893. $arrImages = [];
  894. foreach ($descriptions['ARCHIVOS'] as $files) {
  895. $idFile = $this->encController->decrypt($files['ID']);
  896. if (is_null($idFile)) {
  897. DB::rollBack();
  898. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido del identificador del archivo temporal.", [], 500);
  899. }
  900. try {
  901. $tempFile = DB::table('S002V01TARTE')
  902. ->where([
  903. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  904. ['ARTE_IDAR', '=', $idFile],
  905. ])->first();
  906. } catch (\Throwable $th) {
  907. DB::rollBack();
  908. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener los archivos temporales.", $th->getMessage(), 500);
  909. }
  910. if (is_null($tempFile) || empty((array)$tempFile)) {
  911. DB::rollBack();
  912. return $this->responseController->makeResponse(true, "No se encontró el archivo temporal dentro de la base de datos.", [], 500);
  913. }
  914. if ($tempFile->ARTE_ESTA == 'Eliminado') {
  915. DB::rollBack();
  916. return $this->responseController->makeResponse(true, "El archivo consultado se encuentra eliminado.", [], 500);
  917. }
  918. $fileResponse = $this->documentManagementController->moveFinalFile(
  919. intval($requestData['NUMERO_LINEA']),
  920. 'GEAD',
  921. 'FO',
  922. $tempFile,
  923. $user,
  924. );
  925. if(!$fileResponse[0]){
  926. DB::rollBack();
  927. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  928. }
  929. $arrImages[] = $this->encController->encrypt($fileResponse[1]);
  930. }
  931. $images = json_encode($arrImages);
  932. try {
  933. $idDescription = DB::table('S002V01TDEAR')
  934. ->insertGetId([
  935. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  936. 'DEAR_IMAG' => $images,
  937. 'DEAR_DESC' => $descriptions['DESCRIPCION'],
  938. 'DEAR_CARA' => $descriptions['CARACTERISTICAS'],
  939. 'DEAR_COWE' => true,
  940. 'DEAR_IDUN' => $descriptions['ID_UNIDAD'],
  941. 'DEAR_NUPR' => $descriptions['NUMERO_PROVEEDOR'],
  942. 'DEAR_IDAR' => $idArticle,
  943. 'DEAR_USRE' => $user,
  944. 'DEAR_FERE' => $currentDate,
  945. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  946. ]);
  947. } catch (\Throwable $th) {
  948. DB::rollBack();
  949. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  950. }
  951. if ($idDescription <= 0) {
  952. DB::rollBack();
  953. return $this->responseController->makeResponse(true, "No se pudo registrar la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  954. }
  955. foreach ($descriptions['DETALLES'] as $details) {
  956. try {
  957. $validateExists = DB::table('S002V01TCAMO')
  958. ->where([
  959. ['CAMO_NULI', '=', $requestData['NUMERO_LINEA']],
  960. ['CAMO_COMO', '=', $details['MONEDA']],
  961. ])->exists();
  962. } catch (\Throwable $th) {
  963. DB::rollBack();
  964. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar la existencia de la moneda {$details['MONEDA']}.", $th->getMessage(), 500);
  965. }
  966. if ($validateExists === false) {
  967. DB::rollBack();
  968. return $this->responseController->makeResponse(true, "La moneda {$details['MONEDA']} no existe.", [], 500);
  969. }
  970. unset($validateExists);
  971. try {
  972. $validateInsert = DB::table('S002V01TINAR')
  973. ->insert([
  974. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  975. 'INAR_IDDE' => $idDescription,
  976. 'INAR_CODI' => $details['CODIGO'],
  977. 'INAR_MODE' => $details['MODELO'],
  978. 'INAR_COMO' => $details['MONEDA'],
  979. 'INAR_PREC' => $details['PRECIO'],
  980. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  981. 'INAR_CARA' => $details['CARACTERISTICAS'],
  982. 'INAR_USRE' => $user,
  983. 'INAR_FERE' => $currentDate,
  984. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  985. ]);
  986. } catch (\Throwable $th) {
  987. DB::rollBack();
  988. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar los detalles de la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  989. }
  990. if ($validateInsert === false) {
  991. DB::rollBack();
  992. return $this->responseController->makeResponse(true, "No se pudo registrar los detalles de descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  993. }
  994. }
  995. }
  996. DB::commit();
  997. return $this->responseController->makeResponse(false, "ÉXITO: Registro exitoso");
  998. }
  999. public function updateArticle (Request $request, $idArticle) {
  1000. $validator = Validator::make($request->all(), [
  1001. 'CODIGO' => 'required|string',
  1002. 'ARTICULO' => 'required|string',
  1003. 'FAMILIA' => 'required|string',
  1004. 'SUBFAMILIA' => 'required|string',
  1005. 'DESCRIPCION_ARTICULO' => 'required|array',
  1006. 'USUARIO' => 'required|string',
  1007. 'NUMERO_LINEA' => 'required|integer',
  1008. ]);
  1009. if ($validator->fails()) {
  1010. return $this->responseController->makeResponse(
  1011. true,
  1012. "Se encontraron uno o más errores.",
  1013. $this->responseController->makeErrors($validator->errors()->messages()),
  1014. 401
  1015. );
  1016. }
  1017. DB::beginTransaction();
  1018. $requestData = $request->all();
  1019. $idArticle = $this->encController->decrypt($idArticle);
  1020. if (is_null($idArticle)) {
  1021. DB::rollBack();
  1022. return $this->responseController->makeResponse(true, "El identificador del artículo no está encriptado correctamente.", [], 500);
  1023. }
  1024. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1025. if ($arrResponseCheckUser['error']) {
  1026. DB::rollBack();
  1027. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1028. }
  1029. $user = $arrResponseCheckUser['response'];
  1030. try {
  1031. $validateExists = DB::table("S002V01TFAMI")->where([
  1032. ['FAMI_COFA', '=', $requestData['FAMILIA']],
  1033. ['FAMI_NULI', '=', $requestData['NUMERO_LINEA']],
  1034. ])->exists();
  1035. } catch (\Throwable $th) {
  1036. DB::rollBack();
  1037. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la familia.", $th->getMessage(), 500);
  1038. }
  1039. if ($validateExists === false) {
  1040. DB::rollBack();
  1041. return $this->responseController->makeResponse(true, "La familia {$requestData['FAMILIA']} no existe.", [], 500);
  1042. }
  1043. unset($validateExists);
  1044. try {
  1045. $validateExists = DB::table('S002V01TSUBF')
  1046. ->where([
  1047. ['SUBF_NULI', '=', $requestData['NUMERO_LINEA']],
  1048. ['SUBF_COFA', '=', $requestData['FAMILIA']],
  1049. ['SUBF_COSU', '=', $requestData['SUBFAMILIA']],
  1050. ])->exists();
  1051. } catch (\Throwable $th) {
  1052. DB::rollBack();
  1053. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la subfamilia.", $th->getMessage(), 500);
  1054. }
  1055. if ($validateExists === false) {
  1056. DB::rollBack();
  1057. return $this->responseController->makeResponse(true, "La subfamilia {$requestData['SUBFAMILIA']} perteneciente a la familia {$requestData['FAMILIA']} no existe.", [], 500);
  1058. }
  1059. unset($validateExists);
  1060. $now = $this->functionsController->now();
  1061. $currentDate = $now->toDateTimeString();
  1062. try {
  1063. $validateUpdate = DB::table('S002V01TARTI')
  1064. ->where([
  1065. ['ARTI_IDAR', '=', $idArticle],
  1066. ['ARTI_NULI', '=', $requestData['NUMERO_LINEA']],
  1067. ['ARTI_ESTA', '=', 'Activo'],
  1068. ])
  1069. ->update([
  1070. 'ARTI_COFA' => $requestData['FAMILIA'],
  1071. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  1072. 'ARTI_CODI' => $requestData['CODIGO'],
  1073. 'ARTI_NOMB' => $requestData['ARTICULO'],
  1074. 'ARTI_USRE' => $user,
  1075. 'ARTI_FERE' => $currentDate,
  1076. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1077. ]);
  1078. } catch (\Throwable $th) {
  1079. DB::rollBack();
  1080. return $this->responseController->makeResponse(true, "Ocurrió un error al actualizar el artículo.", $th->getMessage(), 500);
  1081. }
  1082. if (!$validateUpdate) {
  1083. DB::rollBack();
  1084. return $this->responseController->makeResponse(true, "No se pudo modificar el artículo #{$idArticle}.", [], 500);
  1085. }
  1086. foreach ($requestData['DESCRIPCION_ARTICULO'] as $descriptions) {
  1087. try {
  1088. $validateExists = DB::table('S002V01TUNID')
  1089. ->where([
  1090. ['UNID_NULI', '=', $requestData['NUMERO_LINEA']],
  1091. ['UNID_IDUN', '=', $descriptions['ID_UNIDAD']],
  1092. ])->exists();
  1093. } catch (\Throwable $th) {
  1094. DB::rollBack();
  1095. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}).", $th->getMessage(), 500);
  1096. }
  1097. if ($validateExists === false) {
  1098. DB::rollBack();
  1099. return $this->responseController->makeResponse(true, "La unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}) no existe.", [], 500);
  1100. }
  1101. unset($validateExists);
  1102. try {
  1103. $validateExists = DB::table('S002V01TPROV')
  1104. ->where([
  1105. ['PROV_NULI', '=', $requestData['NUMERO_LINEA']],
  1106. ['PROV_NUPR', '=', $descriptions['NUMERO_PROVEEDOR']],
  1107. ])->exists();
  1108. } catch (\Throwable $th) {
  1109. DB::rollBack();
  1110. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia del proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}).", $th->getMessage(), 500);
  1111. }
  1112. if ($validateExists === false) {
  1113. DB::rollBack();
  1114. return $this->responseController->makeResponse(true, "El proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}) no existe.", [], 500);
  1115. }
  1116. unset($validateExists);
  1117. $arrImages = [];
  1118. foreach ($descriptions['ARCHIVOS'] as $files) {
  1119. if ($files['TYPE'] === 'R') {
  1120. $idFile = $this->encController->decrypt($files['ID']);
  1121. if (is_null($idFile)) {
  1122. DB::rollBack();
  1123. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido del identificador del archivo temporal.", [], 500);
  1124. }
  1125. try {
  1126. $tempFile = DB::table('S002V01TARTE')
  1127. ->where([
  1128. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  1129. ['ARTE_IDAR', '=', $idFile],
  1130. ])->first();
  1131. } catch (\Throwable $th) {
  1132. DB::rollBack();
  1133. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener los archivos temporales.", $th->getMessage(), 500);
  1134. }
  1135. if (is_null($tempFile) || empty((array)$tempFile)) {
  1136. DB::rollBack();
  1137. return $this->responseController->makeResponse(true, "No se encontró el archivo temporal dentro de la base de datos.", [], 500);
  1138. }
  1139. if ($tempFile->ARTE_ESTA == 'Eliminado') {
  1140. DB::rollBack();
  1141. return $this->responseController->makeResponse(true, "El archivo consultado se encuentra eliminado.", [], 500);
  1142. }
  1143. $fileResponse = $this->documentManagementController->moveFinalFile(
  1144. intval($requestData['NUMERO_LINEA']),
  1145. 'GEAD',
  1146. 'FO',
  1147. $tempFile,
  1148. $user,
  1149. );
  1150. if(!$fileResponse[0]){
  1151. DB::rollBack();
  1152. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  1153. }
  1154. $arrImages[] = $this->encController->encrypt($fileResponse[1]);
  1155. }
  1156. if ($files['TYPE'] === 'O') {
  1157. $idFile = $this->encController->encrypt($files['ID']);
  1158. $arrImages[] = $idFile;
  1159. }
  1160. if ($files['TYPE'] === 'OD') {
  1161. $idFile = $this->encController->encrypt($files['ID']);
  1162. $request = new Request([
  1163. 'id_user' => $requestData['USUARIO'],
  1164. 'id_file' => $idFile,
  1165. 'linea' => $requestData['NUMERO_LINEA'],
  1166. ]);
  1167. $responseData = $this->documentManagementController->deleteFile($request);
  1168. $responseData = json_decode($responseData->original, true);
  1169. if ($responseData['error']) {
  1170. DB::rollBack();
  1171. return $this->responseController->makeResponse(true, $responseData['msg'], $responseData['response'], 500);
  1172. }
  1173. }
  1174. }
  1175. $images = json_encode($arrImages);
  1176. try {
  1177. $valdateUpdate = DB::table('S002V01TDEAR')
  1178. ->where([
  1179. ['DEAR_NULI', '=', $requestData['NUMERO_LINEA']],
  1180. ['DEAR_IDDE', '=', $descriptions['ID_DESCRIPCION']],
  1181. ['DEAR_IDAR', '=', $idArticle],
  1182. ['DEAR_ESTA', '=', 'Activo'],
  1183. ])
  1184. ->update([
  1185. 'DEAR_IMAG' => $images,
  1186. 'DEAR_DESC' => $descriptions['DESCRIPCION'],
  1187. 'DEAR_CARA' => $descriptions['CARACTERISTICAS'],
  1188. 'DEAR_COWE' => true,
  1189. 'DEAR_IDUN' => $descriptions['ID_UNIDAD'],
  1190. 'DEAR_NUPR' => $descriptions['NUMERO_PROVEEDOR'],
  1191. 'DEAR_USMO' => $user,
  1192. 'DEAR_FEMO' => $currentDate,
  1193. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1194. ]);
  1195. } catch (\Throwable $th) {
  1196. DB::rollBack();
  1197. return $this->responseController->makeResponse(true, "Ocurrió un error al actualizar la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  1198. }
  1199. if (!$valdateUpdate) {
  1200. DB::rollBack();
  1201. return $this->responseController->makeResponse(true, "No se pudo actualizar la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  1202. }
  1203. foreach ($descriptions['DETALLES'] as $details) {
  1204. try {
  1205. $validateExists = DB::table('S002V01TCAMO')
  1206. ->where([
  1207. ['CAMO_NULI', '=', $requestData['NUMERO_LINEA']],
  1208. ['CAMO_COMO', '=', $details['MONEDA']],
  1209. ])->exists();
  1210. } catch (\Throwable $th) {
  1211. DB::rollBack();
  1212. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar la existencia de la moneda {$details['MONEDA']}.", $th->getMessage(), 500);
  1213. }
  1214. if ($validateExists === false) {
  1215. DB::rollBack();
  1216. return $this->responseController->makeResponse(true, "La moneda {$details['MONEDA']} no existe.", [], 500);
  1217. }
  1218. unset($validateExists);
  1219. try {
  1220. $validateUpdate = DB::table('S002V01TINAR')
  1221. ->where([
  1222. ['INAR_NULI', '=', $requestData['NUMERO_LINEA']],
  1223. ['INAR_IDIN', '=', $details['ID_DETAILS']],
  1224. ['INAR_IDDE', '=', $descriptions['ID_DESCRIPCION']],
  1225. ['INAR_ESTA', '=', 'Activo'],
  1226. ])
  1227. ->update([
  1228. 'INAR_CODI' => $details['CODIGO'],
  1229. 'INAR_MODE' => $details['MODELO'],
  1230. 'INAR_COMO' => $details['MONEDA'],
  1231. 'INAR_PREC' => $details['PRECIO'],
  1232. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1233. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1234. 'INAR_USMO' => $user,
  1235. 'INAR_FEMO' => $currentDate,
  1236. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1237. ]);
  1238. } catch (\Throwable $th) {
  1239. DB::rollBack();
  1240. return $this->responseController->makeResponse(true, "Ocurrió un error al modificar los detalles de la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  1241. }
  1242. if (!$validateUpdate) {
  1243. DB::rollBack();
  1244. return $this->responseController->makeResponse(true, "No se pudo modificar los detalles de descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  1245. }
  1246. }
  1247. }
  1248. DB::commit();
  1249. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1250. }
  1251. public function deleteArtitle(Request $request) {
  1252. $validator = Validator::make($request->all(), [
  1253. 'NUMERO_ARTITULO' => 'required|string',
  1254. 'NUMERO_LINEA' => 'required|integer',
  1255. 'USUARIO' => 'required|string',
  1256. ]);
  1257. if ($validator->fails()) {
  1258. return $this->responseController->makeResponse(
  1259. true,
  1260. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1261. $this->responseController->makeErrors($validator->errors()->messages()),
  1262. 401
  1263. );
  1264. }
  1265. DB::beginTransaction();
  1266. $requestData = $request->all();
  1267. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1268. if ($arrResponseCheckUser['error']) {
  1269. DB::rollBack();
  1270. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_DEL001:'.$arrResponseCheckUser['msg'], [], 401);
  1271. }
  1272. $usuario = $arrResponseCheckUser['response'];
  1273. try {
  1274. $artitleNumber = $this->encController->decrypt($requestData['NUMERO_ARTITULO']);
  1275. } catch (\Throwable $th) {
  1276. return $this->responseController->makeResponse(
  1277. true,
  1278. "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.",
  1279. $th->getMessage(),
  1280. 500
  1281. );
  1282. }
  1283. $now = $this->functionsController->now();
  1284. $currentDate = $now->toDateTimeString();
  1285. try {
  1286. $validateUpdate = DB::table('S002V01TARTI')
  1287. ->where('ARTI_IDAR', '=', $artitleNumber)
  1288. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  1289. ->update([
  1290. 'ARTI_ESTA' => 'Eliminado',
  1291. 'ARTI_USMO' => $usuario,
  1292. 'ARTI_FEMO' => $currentDate,
  1293. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1294. ]);
  1295. } catch (\Throwable $th) {
  1296. DB::rollBack();
  1297. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1298. }
  1299. if (!$validateUpdate) {
  1300. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1301. }
  1302. try {
  1303. $arrDescription = DB::table('S002V01TDEAR')
  1304. ->where('DEAR_IDAR', '=', $artitleNumber)
  1305. ->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1306. } catch (\Throwable $th) {
  1307. DB::rollBack();
  1308. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL005: Ocurrió un error al obtener los datos de la descripción del artículo", $th->getMessage(), 500);
  1309. }
  1310. foreach ($arrDescription as $keyDescription => $description) {
  1311. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1312. try {
  1313. $validateUpdate = DB::table('S002V01TDEAR')
  1314. ->where('DEAR_IDDE', '=', $numeroDescripcion)
  1315. ->where('DEAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1316. ->update([
  1317. 'DEAR_ESTA' => 'Eliminado',
  1318. 'DEAR_USMO' => $usuario,
  1319. 'DEAR_FEMO' => $currentDate,
  1320. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1321. ]);
  1322. } catch (\Throwable $th) {
  1323. DB::rollBack();
  1324. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1325. }
  1326. if (!$validateUpdate) {
  1327. DB::rollBack();
  1328. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1329. }
  1330. try {
  1331. $validateUpdate = DB::table('S002V01TINAR')
  1332. ->where('INAR_IDDE', '=', $numeroDescripcion)
  1333. ->where('INAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1334. ->update([
  1335. 'INAR_ESTA' => 'Eliminado',
  1336. 'INAR_USMO' => $usuario,
  1337. 'INAR_FEMO' => $currentDate,
  1338. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1339. ]);
  1340. } catch (\Throwable $th) {
  1341. DB::rollBack();
  1342. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL009: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1343. }
  1344. if (!$validateUpdate) {
  1345. DB::rollBack();
  1346. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL008: Ocurrió un error al modificar en la tabla.", [], 500);
  1347. }
  1348. }
  1349. DB::commit(); # Para guardar los cambios en la base de datos
  1350. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1351. }
  1352. public function generateArtitles(Request $request) {
  1353. $validator = Validator::make($request->all(), [
  1354. 'FILE_ZIP' => 'required',
  1355. 'NUMERO_LINEA' => 'required',
  1356. 'USUARIO' => 'required',
  1357. ]);
  1358. if ($validator->fails()) {
  1359. return $this->responseController->makeResponse(
  1360. true,
  1361. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1362. $this->responseController->makeErrors($validator->errors()->messages()),
  1363. 401
  1364. );
  1365. }
  1366. }
  1367. public function getArtitleByInformation($information, $user, $line) {
  1368. try {
  1369. $objInformation = (array) DB::table('S002V01TINAR')
  1370. ->where('INAR_IDIN', '=', $information)
  1371. ->where('INAR_ESTA', '=', 'Activo')
  1372. ->where('DEAR_ESTA', '=', 'Activo')
  1373. ->where('ARTI_ESTA', '=', 'Activo')
  1374. ->where('FAMI_ESTA', '=', 'Activo')
  1375. ->where('SUBF_ESTA', '=', 'Activo')
  1376. ->where('UNID_ESTA', '=', 'Activo')
  1377. ->where('PROV_ESTA', '=', 'Activo')
  1378. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1379. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1380. ->join('S002V01TFAMI', 'FAMI_COFA', '=', 'ARTI_COFA')
  1381. ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'ARTI_COSU')
  1382. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1383. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1384. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1385. ->first([
  1386. 'INAR_IDIN', // Identificador de Información del artículo
  1387. 'INAR_CODI', // Código del artículo
  1388. 'INAR_MODE', // Modelo del artículo
  1389. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1390. 'INAR_PREC', // Precio
  1391. 'INAR_CARA', // Características
  1392. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1393. 'DEAR_DESC', // Descripción del artículo
  1394. 'DEAR_CARA', // Características del artículo
  1395. 'DEAR_COWE', // Compra web
  1396. 'DEAR_IMAG', // Imagen
  1397. 'DEAR_IDUN', // Identificador de la unidad
  1398. 'UNID_NOMB', // Nombre de la unidad
  1399. 'UNID_ACRO', // Acrónimo de la familia
  1400. 'DEAR_NUPR', // Número del proveedor
  1401. 'ARTI_IDAR', // Identificador del artículo
  1402. 'ARTI_COFA', // Identificador de la familia
  1403. 'FAMI_NOFA', // Nombre de la familia
  1404. 'ARTI_COSU', // Identificador de la subfamilia
  1405. 'SUBF_NOSU', // Nombre de la subfamilia
  1406. 'ARTI_CODI', // Código del artículo
  1407. 'ARTI_NOMB', // Nombre del artículo
  1408. 'PROV_NOCO', // Nombre comercial
  1409. 'PROV_NOMB', // Nombre del proveedor
  1410. 'PROV_APPA', // Apellido paterno del proveedor
  1411. 'PROV_APMA', // Apellido materno del proveedor
  1412. 'PROV_CORR', // Correo electrónico
  1413. 'PROV_LAD1', // Lada 1
  1414. 'PROV_TEL1', // Teléfono 1
  1415. 'PROV_LAD2', // Lada 2
  1416. 'PROV_TEL2', // Teléfono 2
  1417. 'PROV_XRFC', // R.F.C
  1418. 'PROV_XTAX', // TAX ID
  1419. 'PROV_TIPO', // Tipo
  1420. 'PROV_SIWE', // Sitio Web
  1421. 'PROV_MEPA', // Metodos de pago
  1422. ]);
  1423. } catch (\Throwable $th) {
  1424. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1425. }
  1426. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1427. $arrUrlImage = array();
  1428. foreach ($objInformation['DEAR_IMAG'] as $key => $imagen) {
  1429. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  1430. if ($responseDocument['error']) {
  1431. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION001: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1432. }
  1433. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  1434. }
  1435. $objInformation['DEAR_IMAG'] = $arrUrlImage;
  1436. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1437. }
  1438. public function getManagementUnit ($user, $line) {
  1439. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1440. if ($arrResponseCheckUser['error']) {
  1441. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1442. }
  1443. try {
  1444. $arrUnits = DB::table('S002V01TUNID')
  1445. ->where('UNID_NULI', '=', $line)
  1446. ->where('UNID_ESTA', '=', 'Activo')
  1447. ->get([
  1448. 'UNID_IDUN AS ID_UNIDAD',
  1449. 'UNID_NOMB AS UNIDAD',
  1450. 'UNID_ACRO AS ACRONIMO',
  1451. ]);
  1452. $arrUnits = json_decode(json_encode($arrUnits), true);
  1453. } catch (\Throwable $th) {
  1454. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos de la unidad.', [], 500);
  1455. }
  1456. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnits);
  1457. }
  1458. public function createUnit (Request $request) {
  1459. $validator = Validator::make($request->all(), [
  1460. 'UNIDAD' => 'required|string',
  1461. 'ACRONIMO' => 'required|string',
  1462. 'USUARIO' => 'required|string',
  1463. 'NUMERO_LINEA' => 'required|integer',
  1464. ]);
  1465. if ($validator->fails()) {
  1466. return $this->responseController->makeResponse(
  1467. true,
  1468. "Se encontraron uno o más errores.",
  1469. $this->responseController->makeErrors($validator->errors()->messages()),
  1470. 401
  1471. );
  1472. }
  1473. $requestData = $request->all();
  1474. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1475. if ($arrResponseCheckUser['error']) {
  1476. DB::rollBack();
  1477. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1478. }
  1479. $user = $arrResponseCheckUser['response'];
  1480. $now = $this->functionsController->now();
  1481. $currentDate = $now->toDateTimeString();
  1482. try {
  1483. $validate = DB::table('S002V01TUNID')->insert([
  1484. 'UNID_NULI' => $requestData['NUMERO_LINEA'],
  1485. 'UNID_NOMB' => $requestData['UNIDAD'],
  1486. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1487. 'UNID_USRE' => $user,
  1488. 'UNID_FERE' => $currentDate,
  1489. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1490. ]);
  1491. } catch (\Throwable $th) {
  1492. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar la unidad.", $th->getMessage(), 500);
  1493. }
  1494. if (!$validate) {
  1495. return $this->responseController->makeResponse(true, "No se pudo registrar la unidad.", [], 500);
  1496. }
  1497. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1498. }
  1499. public function updateUnit (Request $request, $idUnit) {
  1500. $validator = Validator::make($request->all(), [
  1501. 'UNIDAD' => 'required|string',
  1502. 'ACRONIMO' => 'required|string',
  1503. 'USUARIO' => 'required|string',
  1504. 'NUMERO_LINEA' => 'required|integer',
  1505. ]);
  1506. if ($validator->fails()) {
  1507. return $this->responseController->makeResponse(
  1508. true,
  1509. "Se encontraron uno o más errores.",
  1510. $this->responseController->makeErrors($validator->errors()->messages()),
  1511. 401
  1512. );
  1513. }
  1514. $requestData = $request->all();
  1515. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1516. if ($arrResponseCheckUser['error']) {
  1517. DB::rollBack();
  1518. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1519. }
  1520. $user = $arrResponseCheckUser['response'];
  1521. $idUnit = $this->encController->encrypt($idUnit);
  1522. if (is_null($idUnit)) {
  1523. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1524. }
  1525. try {
  1526. $validateExists = DB::table('S002V01TUNID')
  1527. ->where('UNID_IDUN', '=', $idUnit)
  1528. ->where('UNID_ESTA', '=', 'Activo')
  1529. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1530. ->exists();
  1531. } catch (\Throwable $th) {
  1532. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1533. }
  1534. if (!$validateExists) {
  1535. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1536. }
  1537. $now = $this->functionsController->now();
  1538. $currentDate = $now->toDateTimeString();
  1539. try {
  1540. $validate = DB::table('S002V01TUNID')
  1541. ->where('UNID_IDUN', '=', $idUnit)
  1542. ->where('UNID_ESTA', '=', 'Activo')
  1543. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1544. ->update([
  1545. 'UNID_NOMB' => $requestData['UNIDAD'],
  1546. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1547. 'UNID_USMO' => $user,
  1548. 'UNID_FEMO' => $currentDate,
  1549. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1550. ]);
  1551. } catch (\Throwable $th) {
  1552. return $this->responseController->makeResponse(true, "IOcurrió un error al modificar la unidad.", $th->getMessage(), 500);
  1553. }
  1554. if (!$validate) {
  1555. return $this->responseController->makeResponse(true, "No se pudo modificar la unidad.", [], 500);
  1556. }
  1557. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1558. }
  1559. public function getUnitById ($idUnit, $user, $line) {
  1560. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1561. if ($arrResponseCheckUser['error']) {
  1562. DB::rollBack();
  1563. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1564. }
  1565. $user = $arrResponseCheckUser['response'];
  1566. $idUnit = $this->encController->decrypt($idUnit);
  1567. if (is_null($idUnit)) {
  1568. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1569. }
  1570. try {
  1571. $validateExists = DB::table('S002V01TUNID')
  1572. ->where('UNID_IDUN', '=', $idUnit)
  1573. ->where('UNID_ESTA', '=', 'Activo')
  1574. ->where('UNID_NULI', '=', $line)
  1575. ->exists();
  1576. } catch (\Throwable $th) {
  1577. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1578. }
  1579. if (!$validateExists) {
  1580. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1581. }
  1582. try {
  1583. $arrUnit = (array) DB::table('S002V01TUNID')
  1584. ->where('UNID_IDUN', '=', $idUnit)
  1585. ->where('UNID_ESTA', '=', 'Activo')
  1586. ->where('UNID_NULI', '=', $line)
  1587. ->first([
  1588. 'UNID_IDUN AS ID_UNIDAD',
  1589. 'UNID_NOMB AS UNIDAD',
  1590. 'UNID_ACRO AS ACRONIMO',
  1591. ]);
  1592. } catch (\Throwable $th) {
  1593. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener la información de la unidad.", $th->getMessage(), 500);
  1594. }
  1595. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnit);
  1596. }
  1597. public function deleteUnitById (Request $request, $idUnit) {
  1598. }
  1599. }