ArtitleController.php 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  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 $item => $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_PRIO' => $item + 1,
  944. 'DEAR_CAAR' => $descriptions['CANTIDAD_UNIDAD'],
  945. 'DEAR_USRE' => $user,
  946. 'DEAR_FERE' => $currentDate,
  947. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  948. ]);
  949. } catch (\Throwable $th) {
  950. DB::rollBack();
  951. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar la descripción del proveedor #{$descriptions['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  952. }
  953. if ($idDescription <= 0) {
  954. DB::rollBack();
  955. return $this->responseController->makeResponse(true, "No se pudo registrar la descripción del proveedor #{$descriptions['NUMERO_PROVEEDOR']}.", [], 500);
  956. }
  957. foreach ($descriptions['DETALLES'] as $details) {
  958. try {
  959. $validateExists = DB::table('S002V01TCAMO')
  960. ->where([
  961. ['CAMO_NULI', '=', $requestData['NUMERO_LINEA']],
  962. ['CAMO_COMO', '=', $details['MONEDA']],
  963. ])->exists();
  964. } catch (\Throwable $th) {
  965. DB::rollBack();
  966. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar la existencia de la moneda {$details['MONEDA']}.", $th->getMessage(), 500);
  967. }
  968. if ($validateExists === false) {
  969. DB::rollBack();
  970. return $this->responseController->makeResponse(true, "La moneda {$details['MONEDA']} no existe.", [], 500);
  971. }
  972. unset($validateExists);
  973. try {
  974. $validateInsert = DB::table('S002V01TINAR')
  975. ->insert([
  976. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  977. 'INAR_IDDE' => $idDescription,
  978. 'INAR_CODI' => $details['CODIGO'],
  979. 'INAR_MODE' => $details['MODELO'],
  980. 'INAR_COMO' => $details['MONEDA'],
  981. 'INAR_PREC' => $details['PRECIO'],
  982. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  983. 'INAR_CARA' => $details['CARACTERISTICAS'],
  984. 'INAR_USRE' => $user,
  985. 'INAR_FERE' => $currentDate,
  986. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  987. ]);
  988. } catch (\Throwable $th) {
  989. DB::rollBack();
  990. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar los detalles de la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  991. }
  992. if ($validateInsert === false) {
  993. DB::rollBack();
  994. return $this->responseController->makeResponse(true, "No se pudo registrar los detalles de descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  995. }
  996. }
  997. }
  998. DB::commit();
  999. return $this->responseController->makeResponse(false, "ÉXITO: Registro exitoso");
  1000. }
  1001. public function updateArticle (Request $request, $idArticle) {
  1002. $validator = Validator::make($request->all(), [
  1003. 'CODIGO' => 'required|string',
  1004. 'ARTICULO' => 'required|string',
  1005. 'FAMILIA' => 'required|string',
  1006. 'SUBFAMILIA' => 'required|string',
  1007. 'DESCRIPCION_ARTICULO' => 'required|array',
  1008. 'USUARIO' => 'required|string',
  1009. 'NUMERO_LINEA' => 'required|integer',
  1010. ]);
  1011. if ($validator->fails()) {
  1012. return $this->responseController->makeResponse(
  1013. true,
  1014. "Se encontraron uno o más errores.",
  1015. $this->responseController->makeErrors($validator->errors()->messages()),
  1016. 401
  1017. );
  1018. }
  1019. DB::beginTransaction();
  1020. $requestData = $request->all();
  1021. $idArticle = $this->encController->decrypt($idArticle);
  1022. if (is_null($idArticle)) {
  1023. DB::rollBack();
  1024. return $this->responseController->makeResponse(true, "El identificador del artículo no está encriptado correctamente.", [], 500);
  1025. }
  1026. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1027. if ($arrResponseCheckUser['error']) {
  1028. DB::rollBack();
  1029. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1030. }
  1031. $user = $arrResponseCheckUser['response'];
  1032. try {
  1033. $validateExists = DB::table("S002V01TFAMI")->where([
  1034. ['FAMI_COFA', '=', $requestData['FAMILIA']],
  1035. ['FAMI_NULI', '=', $requestData['NUMERO_LINEA']],
  1036. ])->exists();
  1037. } catch (\Throwable $th) {
  1038. DB::rollBack();
  1039. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la familia.", $th->getMessage(), 500);
  1040. }
  1041. if ($validateExists === false) {
  1042. DB::rollBack();
  1043. return $this->responseController->makeResponse(true, "La familia {$requestData['FAMILIA']} no existe.", [], 500);
  1044. }
  1045. unset($validateExists);
  1046. try {
  1047. $validateExists = DB::table('S002V01TSUBF')
  1048. ->where([
  1049. ['SUBF_NULI', '=', $requestData['NUMERO_LINEA']],
  1050. ['SUBF_COFA', '=', $requestData['FAMILIA']],
  1051. ['SUBF_COSU', '=', $requestData['SUBFAMILIA']],
  1052. ])->exists();
  1053. } catch (\Throwable $th) {
  1054. DB::rollBack();
  1055. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la subfamilia.", $th->getMessage(), 500);
  1056. }
  1057. if ($validateExists === false) {
  1058. DB::rollBack();
  1059. return $this->responseController->makeResponse(true, "La subfamilia {$requestData['SUBFAMILIA']} perteneciente a la familia {$requestData['FAMILIA']} no existe.", [], 500);
  1060. }
  1061. unset($validateExists);
  1062. $now = $this->functionsController->now();
  1063. $currentDate = $now->toDateTimeString();
  1064. try {
  1065. $validateUpdate = DB::table('S002V01TARTI')
  1066. ->where([
  1067. ['ARTI_IDAR', '=', $idArticle],
  1068. ['ARTI_NULI', '=', $requestData['NUMERO_LINEA']],
  1069. ['ARTI_ESTA', '=', 'Activo'],
  1070. ])
  1071. ->update([
  1072. 'ARTI_COFA' => $requestData['FAMILIA'],
  1073. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  1074. 'ARTI_CODI' => $requestData['CODIGO'],
  1075. 'ARTI_NOMB' => $requestData['ARTICULO'],
  1076. 'ARTI_USRE' => $user,
  1077. 'ARTI_FERE' => $currentDate,
  1078. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1079. ]);
  1080. } catch (\Throwable $th) {
  1081. DB::rollBack();
  1082. return $this->responseController->makeResponse(true, "Ocurrió un error al actualizar el artículo.", $th->getMessage(), 500);
  1083. }
  1084. if (!$validateUpdate) {
  1085. DB::rollBack();
  1086. return $this->responseController->makeResponse(true, "No se pudo modificar el artículo #{$idArticle}.", [], 500);
  1087. }
  1088. foreach ($requestData['DESCRIPCION_ARTICULO'] as $item => $descriptions) {
  1089. try {
  1090. $validateExists = DB::table('S002V01TUNID')
  1091. ->where([
  1092. ['UNID_NULI', '=', $requestData['NUMERO_LINEA']],
  1093. ['UNID_IDUN', '=', $descriptions['ID_UNIDAD']],
  1094. ])->exists();
  1095. } catch (\Throwable $th) {
  1096. DB::rollBack();
  1097. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}).", $th->getMessage(), 500);
  1098. }
  1099. if ($validateExists === false) {
  1100. DB::rollBack();
  1101. return $this->responseController->makeResponse(true, "La unidad {$descriptions['UNIDAD']} (#{$descriptions['ID_UNIDAD']}) no existe.", [], 500);
  1102. }
  1103. unset($validateExists);
  1104. try {
  1105. $validateExists = DB::table('S002V01TPROV')
  1106. ->where([
  1107. ['PROV_NULI', '=', $requestData['NUMERO_LINEA']],
  1108. ['PROV_NUPR', '=', $descriptions['NUMERO_PROVEEDOR']],
  1109. ])->exists();
  1110. } catch (\Throwable $th) {
  1111. DB::rollBack();
  1112. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia del proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}).", $th->getMessage(), 500);
  1113. }
  1114. if ($validateExists === false) {
  1115. DB::rollBack();
  1116. return $this->responseController->makeResponse(true, "El proveedor {$descriptions['PROVEEDOR']} (#{$descriptions['NUMERO_PROVEEDOR']}) no existe.", [], 500);
  1117. }
  1118. unset($validateExists);
  1119. $arrImages = [];
  1120. foreach ($descriptions['ARCHIVOS'] as $files) {
  1121. if ($files['TYPE'] === 'R') {
  1122. $idFile = $this->encController->decrypt($files['ID']);
  1123. if (is_null($idFile)) {
  1124. DB::rollBack();
  1125. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el contenido del identificador del archivo temporal.", [], 500);
  1126. }
  1127. try {
  1128. $tempFile = DB::table('S002V01TARTE')
  1129. ->where([
  1130. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  1131. ['ARTE_IDAR', '=', $idFile],
  1132. ])->first();
  1133. } catch (\Throwable $th) {
  1134. DB::rollBack();
  1135. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener los archivos temporales.", $th->getMessage(), 500);
  1136. }
  1137. if (is_null($tempFile) || empty((array)$tempFile)) {
  1138. DB::rollBack();
  1139. return $this->responseController->makeResponse(true, "No se encontró el archivo temporal dentro de la base de datos.", [], 500);
  1140. }
  1141. if ($tempFile->ARTE_ESTA == 'Eliminado') {
  1142. DB::rollBack();
  1143. return $this->responseController->makeResponse(true, "El archivo consultado se encuentra eliminado.", [], 500);
  1144. }
  1145. $fileResponse = $this->documentManagementController->moveFinalFile(
  1146. intval($requestData['NUMERO_LINEA']),
  1147. 'GEAD',
  1148. 'FO',
  1149. $tempFile,
  1150. $user,
  1151. );
  1152. if(!$fileResponse[0]){
  1153. DB::rollBack();
  1154. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  1155. }
  1156. $arrImages[] = $this->encController->encrypt($fileResponse[1]);
  1157. }
  1158. if ($files['TYPE'] === 'O') {
  1159. $idFile = $this->encController->encrypt($files['ID']);
  1160. $arrImages[] = $idFile;
  1161. }
  1162. if ($files['TYPE'] === 'OD') {
  1163. $idFile = $this->encController->encrypt($files['ID']);
  1164. $request = new Request([
  1165. 'id_user' => $requestData['USUARIO'],
  1166. 'id_file' => $idFile,
  1167. 'linea' => $requestData['NUMERO_LINEA'],
  1168. ]);
  1169. $responseData = $this->documentManagementController->deleteFile($request);
  1170. $responseData = json_decode($responseData->original, true);
  1171. if ($responseData['error']) {
  1172. DB::rollBack();
  1173. return $this->responseController->makeResponse(true, $responseData['msg'], $responseData['response'], 500);
  1174. }
  1175. }
  1176. }
  1177. $images = json_encode($arrImages);
  1178. try {
  1179. $valdateUpdate = DB::table('S002V01TDEAR')
  1180. ->where([
  1181. ['DEAR_NULI', '=', $requestData['NUMERO_LINEA']],
  1182. ['DEAR_IDDE', '=', $descriptions['ID_DESCRIPCION']],
  1183. ['DEAR_IDAR', '=', $idArticle],
  1184. ['DEAR_ESTA', '=', 'Activo'],
  1185. ])
  1186. ->update([
  1187. 'DEAR_IMAG' => $images,
  1188. 'DEAR_DESC' => $descriptions['DESCRIPCION'],
  1189. 'DEAR_CARA' => $descriptions['CARACTERISTICAS'],
  1190. 'DEAR_COWE' => true,
  1191. 'DEAR_IDUN' => $descriptions['ID_UNIDAD'],
  1192. 'DEAR_NUPR' => $descriptions['NUMERO_PROVEEDOR'],
  1193. 'DEAR_CAAR' => $descriptions['CANTIDAD_UNIDAD'],
  1194. 'DEAR_PRIO' => $item + 1,
  1195. 'DEAR_USMO' => $user,
  1196. 'DEAR_FEMO' => $currentDate,
  1197. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1198. ]);
  1199. } catch (\Throwable $th) {
  1200. DB::rollBack();
  1201. return $this->responseController->makeResponse(true, "Ocurrió un error al actualizar la descripción del proveedor #{$descriptions['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  1202. }
  1203. if (!$valdateUpdate) {
  1204. DB::rollBack();
  1205. return $this->responseController->makeResponse(true, "No se pudo actualizar la descripción del proveedor #{$descriptions['NUMERO_PROVEEDOR']}.", [], 500);
  1206. }
  1207. foreach ($descriptions['DETALLES'] as $details) {
  1208. try {
  1209. $validateExists = DB::table('S002V01TCAMO')
  1210. ->where([
  1211. ['CAMO_NULI', '=', $requestData['NUMERO_LINEA']],
  1212. ['CAMO_COMO', '=', $details['MONEDA']],
  1213. ])->exists();
  1214. } catch (\Throwable $th) {
  1215. DB::rollBack();
  1216. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar la existencia de la moneda {$details['MONEDA']}.", $th->getMessage(), 500);
  1217. }
  1218. if ($validateExists === false) {
  1219. DB::rollBack();
  1220. return $this->responseController->makeResponse(true, "La moneda {$details['MONEDA']} no existe.", [], 500);
  1221. }
  1222. unset($validateExists);
  1223. try {
  1224. $validateUpdate = DB::table('S002V01TINAR')
  1225. ->where([
  1226. ['INAR_NULI', '=', $requestData['NUMERO_LINEA']],
  1227. ['INAR_IDIN', '=', $details['ID_DETAILS']],
  1228. ['INAR_IDDE', '=', $descriptions['ID_DESCRIPCION']],
  1229. ['INAR_ESTA', '=', 'Activo'],
  1230. ])
  1231. ->update([
  1232. 'INAR_CODI' => $details['CODIGO'],
  1233. 'INAR_MODE' => $details['MODELO'],
  1234. 'INAR_COMO' => $details['MONEDA'],
  1235. 'INAR_PREC' => $details['PRECIO'],
  1236. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1237. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1238. 'INAR_USMO' => $user,
  1239. 'INAR_FEMO' => $currentDate,
  1240. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1241. ]);
  1242. } catch (\Throwable $th) {
  1243. DB::rollBack();
  1244. return $this->responseController->makeResponse(true, "Ocurrió un error al modificar los detalles de la descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", $th->getMessage(), 500);
  1245. }
  1246. if (!$validateUpdate) {
  1247. DB::rollBack();
  1248. return $this->responseController->makeResponse(true, "No se pudo modificar los detalles de descripción del proveedor #{$requestData['NUMERO_PROVEEDOR']}.", [], 500);
  1249. }
  1250. }
  1251. }
  1252. DB::commit();
  1253. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1254. }
  1255. public function deleteArtitle(Request $request) {
  1256. $validator = Validator::make($request->all(), [
  1257. 'NUMERO_ARTITULO' => 'required|string',
  1258. 'NUMERO_LINEA' => 'required|integer',
  1259. 'USUARIO' => 'required|string',
  1260. ]);
  1261. if ($validator->fails()) {
  1262. return $this->responseController->makeResponse(
  1263. true,
  1264. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1265. $this->responseController->makeErrors($validator->errors()->messages()),
  1266. 401
  1267. );
  1268. }
  1269. DB::beginTransaction();
  1270. $requestData = $request->all();
  1271. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1272. if ($arrResponseCheckUser['error']) {
  1273. DB::rollBack();
  1274. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_DEL001:'.$arrResponseCheckUser['msg'], [], 401);
  1275. }
  1276. $usuario = $arrResponseCheckUser['response'];
  1277. try {
  1278. $artitleNumber = $this->encController->decrypt($requestData['NUMERO_ARTITULO']);
  1279. } catch (\Throwable $th) {
  1280. return $this->responseController->makeResponse(
  1281. true,
  1282. "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.",
  1283. $th->getMessage(),
  1284. 500
  1285. );
  1286. }
  1287. $now = $this->functionsController->now();
  1288. $currentDate = $now->toDateTimeString();
  1289. try {
  1290. $validateUpdate = DB::table('S002V01TARTI')
  1291. ->where('ARTI_IDAR', '=', $artitleNumber)
  1292. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  1293. ->update([
  1294. 'ARTI_ESTA' => 'Eliminado',
  1295. 'ARTI_USMO' => $usuario,
  1296. 'ARTI_FEMO' => $currentDate,
  1297. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1298. ]);
  1299. } catch (\Throwable $th) {
  1300. DB::rollBack();
  1301. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1302. }
  1303. if (!$validateUpdate) {
  1304. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1305. }
  1306. try {
  1307. $arrDescription = DB::table('S002V01TDEAR')
  1308. ->where('DEAR_IDAR', '=', $artitleNumber)
  1309. ->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1310. } catch (\Throwable $th) {
  1311. DB::rollBack();
  1312. 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);
  1313. }
  1314. foreach ($arrDescription as $keyDescription => $description) {
  1315. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1316. try {
  1317. $validateUpdate = DB::table('S002V01TDEAR')
  1318. ->where('DEAR_IDDE', '=', $numeroDescripcion)
  1319. ->where('DEAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1320. ->update([
  1321. 'DEAR_ESTA' => 'Eliminado',
  1322. 'DEAR_USMO' => $usuario,
  1323. 'DEAR_FEMO' => $currentDate,
  1324. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1325. ]);
  1326. } catch (\Throwable $th) {
  1327. DB::rollBack();
  1328. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1329. }
  1330. if (!$validateUpdate) {
  1331. DB::rollBack();
  1332. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1333. }
  1334. try {
  1335. $validateUpdate = DB::table('S002V01TINAR')
  1336. ->where('INAR_IDDE', '=', $numeroDescripcion)
  1337. ->where('INAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1338. ->update([
  1339. 'INAR_ESTA' => 'Eliminado',
  1340. 'INAR_USMO' => $usuario,
  1341. 'INAR_FEMO' => $currentDate,
  1342. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1343. ]);
  1344. } catch (\Throwable $th) {
  1345. DB::rollBack();
  1346. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL009: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1347. }
  1348. if (!$validateUpdate) {
  1349. DB::rollBack();
  1350. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL008: Ocurrió un error al modificar en la tabla.", [], 500);
  1351. }
  1352. }
  1353. DB::commit(); # Para guardar los cambios en la base de datos
  1354. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1355. }
  1356. public function generateArtitles(Request $request) {
  1357. $validator = Validator::make($request->all(), [
  1358. 'FILE_ZIP' => 'required',
  1359. 'NUMERO_LINEA' => 'required',
  1360. 'USUARIO' => 'required',
  1361. ]);
  1362. if ($validator->fails()) {
  1363. return $this->responseController->makeResponse(
  1364. true,
  1365. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1366. $this->responseController->makeErrors($validator->errors()->messages()),
  1367. 401
  1368. );
  1369. }
  1370. }
  1371. public function getArtitleByInformation($information, $user, $line) {
  1372. try {
  1373. $objInformation = (array) DB::table('S002V01TINAR')
  1374. ->where('INAR_IDIN', '=', $information)
  1375. ->where('INAR_ESTA', '=', 'Activo')
  1376. ->where('DEAR_ESTA', '=', 'Activo')
  1377. ->where('ARTI_ESTA', '=', 'Activo')
  1378. ->where('FAMI_ESTA', '=', 'Activo')
  1379. ->where('SUBF_ESTA', '=', 'Activo')
  1380. ->where('UNID_ESTA', '=', 'Activo')
  1381. ->where('PROV_ESTA', '=', 'Activo')
  1382. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1383. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1384. ->join('S002V01TFAMI', 'FAMI_COFA', '=', 'ARTI_COFA')
  1385. ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'ARTI_COSU')
  1386. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1387. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1388. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1389. ->first([
  1390. 'INAR_IDIN', // Identificador de Información del artículo
  1391. 'INAR_CODI', // Código del artículo
  1392. 'INAR_MODE', // Modelo del artículo
  1393. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1394. 'INAR_PREC', // Precio
  1395. 'INAR_CARA', // Características
  1396. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1397. 'DEAR_DESC', // Descripción del artículo
  1398. 'DEAR_CARA', // Características del artículo
  1399. 'DEAR_COWE', // Compra web
  1400. 'DEAR_IMAG', // Imagen
  1401. 'DEAR_IDUN', // Identificador de la unidad
  1402. 'UNID_NOMB', // Nombre de la unidad
  1403. 'UNID_ACRO', // Acrónimo de la familia
  1404. 'DEAR_NUPR', // Número del proveedor
  1405. 'ARTI_IDAR', // Identificador del artículo
  1406. 'ARTI_COFA', // Identificador de la familia
  1407. 'FAMI_NOFA', // Nombre de la familia
  1408. 'ARTI_COSU', // Identificador de la subfamilia
  1409. 'SUBF_NOSU', // Nombre de la subfamilia
  1410. 'ARTI_CODI', // Código del artículo
  1411. 'ARTI_NOMB', // Nombre del artículo
  1412. 'PROV_NOCO', // Nombre comercial
  1413. 'PROV_NOMB', // Nombre del proveedor
  1414. 'PROV_APPA', // Apellido paterno del proveedor
  1415. 'PROV_APMA', // Apellido materno del proveedor
  1416. 'PROV_CORR', // Correo electrónico
  1417. 'PROV_LAD1', // Lada 1
  1418. 'PROV_TEL1', // Teléfono 1
  1419. 'PROV_LAD2', // Lada 2
  1420. 'PROV_TEL2', // Teléfono 2
  1421. 'PROV_XRFC', // R.F.C
  1422. 'PROV_XTAX', // TAX ID
  1423. 'PROV_TIPO', // Tipo
  1424. 'PROV_SIWE', // Sitio Web
  1425. 'PROV_MEPA', // Metodos de pago
  1426. ]);
  1427. } catch (\Throwable $th) {
  1428. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1429. }
  1430. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1431. $arrUrlImage = array();
  1432. foreach ($objInformation['DEAR_IMAG'] as $key => $imagen) {
  1433. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  1434. if ($responseDocument['error']) {
  1435. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION001: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1436. }
  1437. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  1438. }
  1439. $objInformation['DEAR_IMAG'] = $arrUrlImage;
  1440. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1441. }
  1442. public function getManagementUnit ($user, $line) {
  1443. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1444. if ($arrResponseCheckUser['error']) {
  1445. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1446. }
  1447. try {
  1448. $arrUnits = DB::table('S002V01TUNID')
  1449. ->where('UNID_NULI', '=', $line)
  1450. ->where('UNID_ESTA', '=', 'Activo')
  1451. ->get([
  1452. 'UNID_IDUN AS ID_UNIDAD',
  1453. 'UNID_NOMB AS UNIDAD',
  1454. 'UNID_ACRO AS ACRONIMO',
  1455. ]);
  1456. $arrUnits = json_decode(json_encode($arrUnits), true);
  1457. } catch (\Throwable $th) {
  1458. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos de la unidad.', [], 500);
  1459. }
  1460. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnits);
  1461. }
  1462. public function createUnit (Request $request) {
  1463. $validator = Validator::make($request->all(), [
  1464. 'UNIDAD' => 'required|string',
  1465. 'ACRONIMO' => 'required|string',
  1466. 'USUARIO' => 'required|string',
  1467. 'NUMERO_LINEA' => 'required|integer',
  1468. ]);
  1469. if ($validator->fails()) {
  1470. return $this->responseController->makeResponse(
  1471. true,
  1472. "Se encontraron uno o más errores.",
  1473. $this->responseController->makeErrors($validator->errors()->messages()),
  1474. 401
  1475. );
  1476. }
  1477. $requestData = $request->all();
  1478. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1479. if ($arrResponseCheckUser['error']) {
  1480. DB::rollBack();
  1481. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1482. }
  1483. $user = $arrResponseCheckUser['response'];
  1484. $now = $this->functionsController->now();
  1485. $currentDate = $now->toDateTimeString();
  1486. try {
  1487. $validate = DB::table('S002V01TUNID')->insert([
  1488. 'UNID_NULI' => $requestData['NUMERO_LINEA'],
  1489. 'UNID_NOMB' => $requestData['UNIDAD'],
  1490. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1491. 'UNID_USRE' => $user,
  1492. 'UNID_FERE' => $currentDate,
  1493. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1494. ]);
  1495. } catch (\Throwable $th) {
  1496. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar la unidad.", $th->getMessage(), 500);
  1497. }
  1498. if (!$validate) {
  1499. return $this->responseController->makeResponse(true, "No se pudo registrar la unidad.", [], 500);
  1500. }
  1501. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1502. }
  1503. public function updateUnit (Request $request, $idUnit) {
  1504. $validator = Validator::make($request->all(), [
  1505. 'UNIDAD' => 'required|string',
  1506. 'ACRONIMO' => 'required|string',
  1507. 'USUARIO' => 'required|string',
  1508. 'NUMERO_LINEA' => 'required|integer',
  1509. ]);
  1510. if ($validator->fails()) {
  1511. return $this->responseController->makeResponse(
  1512. true,
  1513. "Se encontraron uno o más errores.",
  1514. $this->responseController->makeErrors($validator->errors()->messages()),
  1515. 401
  1516. );
  1517. }
  1518. $requestData = $request->all();
  1519. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1520. if ($arrResponseCheckUser['error']) {
  1521. DB::rollBack();
  1522. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1523. }
  1524. $user = $arrResponseCheckUser['response'];
  1525. $idUnit = $this->encController->encrypt($idUnit);
  1526. if (is_null($idUnit)) {
  1527. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1528. }
  1529. try {
  1530. $validateExists = DB::table('S002V01TUNID')
  1531. ->where('UNID_IDUN', '=', $idUnit)
  1532. ->where('UNID_ESTA', '=', 'Activo')
  1533. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1534. ->exists();
  1535. } catch (\Throwable $th) {
  1536. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1537. }
  1538. if (!$validateExists) {
  1539. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1540. }
  1541. $now = $this->functionsController->now();
  1542. $currentDate = $now->toDateTimeString();
  1543. try {
  1544. $validate = DB::table('S002V01TUNID')
  1545. ->where('UNID_IDUN', '=', $idUnit)
  1546. ->where('UNID_ESTA', '=', 'Activo')
  1547. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1548. ->update([
  1549. 'UNID_NOMB' => $requestData['UNIDAD'],
  1550. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1551. 'UNID_USMO' => $user,
  1552. 'UNID_FEMO' => $currentDate,
  1553. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1554. ]);
  1555. } catch (\Throwable $th) {
  1556. return $this->responseController->makeResponse(true, "IOcurrió un error al modificar la unidad.", $th->getMessage(), 500);
  1557. }
  1558. if (!$validate) {
  1559. return $this->responseController->makeResponse(true, "No se pudo modificar la unidad.", [], 500);
  1560. }
  1561. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1562. }
  1563. public function getUnitById ($idUnit, $user, $line) {
  1564. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1565. if ($arrResponseCheckUser['error']) {
  1566. DB::rollBack();
  1567. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1568. }
  1569. $user = $arrResponseCheckUser['response'];
  1570. $idUnit = $this->encController->decrypt($idUnit);
  1571. if (is_null($idUnit)) {
  1572. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1573. }
  1574. try {
  1575. $validateExists = DB::table('S002V01TUNID')
  1576. ->where('UNID_IDUN', '=', $idUnit)
  1577. ->where('UNID_ESTA', '=', 'Activo')
  1578. ->where('UNID_NULI', '=', $line)
  1579. ->exists();
  1580. } catch (\Throwable $th) {
  1581. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1582. }
  1583. if (!$validateExists) {
  1584. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1585. }
  1586. try {
  1587. $arrUnit = (array) DB::table('S002V01TUNID')
  1588. ->where('UNID_IDUN', '=', $idUnit)
  1589. ->where('UNID_ESTA', '=', 'Activo')
  1590. ->where('UNID_NULI', '=', $line)
  1591. ->first([
  1592. 'UNID_IDUN AS ID_UNIDAD',
  1593. 'UNID_NOMB AS UNIDAD',
  1594. 'UNID_ACRO AS ACRONIMO',
  1595. ]);
  1596. } catch (\Throwable $th) {
  1597. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener la información de la unidad.", $th->getMessage(), 500);
  1598. }
  1599. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnit);
  1600. }
  1601. public function deleteUnitById (Request $request, $idUnit) {
  1602. }
  1603. }