ArtitleController.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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 getArtitleById($encIdArtitle, $user, $line) {
  497. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  498. if ($arrResponseCheckUser['error']) {
  499. DB::rollBack();
  500. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_GETBYID000:'.$arrResponseCheckUser['msg'], [], 401);
  501. }
  502. try {
  503. $idArtitle = $this->encController->decrypt($encIdArtitle);
  504. } catch (\Throwable $th) {
  505. return $this->responseController->makeResponse(
  506. true,
  507. "ERR_ARTITLE_GETBYID001: Ocurrió un error al obtener el artículo.",
  508. $th->getMessage(),
  509. 500
  510. );
  511. }
  512. try {
  513. $arrArtitle = DB::table('S002V01TARTI')
  514. ->where('ARTI_IDAR', '=', $idArtitle)
  515. ->where('ARTI_ESTA', '=', 'Activo')
  516. ->where('ARTI_NULI', '=', $line)
  517. ->join("S002V01TFAMI", "ARTI_COFA", "=", "FAMI_COFA")
  518. ->join("S002V01TSUBF", "ARTI_COSU", "=", "SUBF_COSU")
  519. ->first([
  520. 'ARTI_IDAR AS NUMERO_ARTICULO',
  521. 'ARTI_CODI AS CODIGO',
  522. "FAMI_COFA AS ID_FAMILIA",
  523. "FAMI_NOFA AS FAMILIA",
  524. "SUBF_COSU AS ID_SUBFAMILIA",
  525. "SUBF_NOSU AS SUBFAMILIA",
  526. 'ARTI_NOMB AS ARTICULO',
  527. ]);
  528. } catch (\Throwable $th) {
  529. return $this->responseController->makeResponse(
  530. true,
  531. "ERR_ARTITLE_GETBYID002: No se pudo realizar la consulta a la base.",
  532. $th->getMessage(),
  533. 500
  534. );
  535. }
  536. try {
  537. $arrDescription = DB::table('S002V01TDEAR')
  538. ->where('DEAR_IDAR', '=', $idArtitle)
  539. ->where('DEAR_ESTA', '=', 'Activo')
  540. ->where('DEAR_NULI', '=', $line)
  541. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  542. ->get([
  543. 'DEAR_IDDE AS ID_DESCRIPCION',
  544. 'DEAR_DESC AS DESCRIPCION',
  545. 'DEAR_CARA AS CARACTERISTICAS',
  546. 'DEAR_COWE AS COMPRA_WEB',
  547. 'DEAR_IDUN AS TIPO_UNIDAD',
  548. 'DEAR_IMAG AS IMAGEN',
  549. 'DEAR_NUPR AS PROVEEDOR',
  550. 'DEAR_ESTA AS ESTADO',
  551. ]);
  552. } catch (\Throwable $th) {
  553. return $this->responseController->makeResponse(
  554. true,
  555. "ERR_ARTITLE_GETBYID003: No se pudo realizar la consulta a la base.",
  556. $th->getMessage(),
  557. 500
  558. );
  559. }
  560. if ( empty($arrDescription) ) {
  561. return $this->responseController->makeResponse(
  562. true,
  563. "ERR_ARTITLE_GETBYID004: No se encontró ninguna descripción.",
  564. [],
  565. 500
  566. );
  567. }
  568. // Se obtienen las URL de las imagenes de los artículos
  569. try {
  570. foreach ($arrDescription as $description) {
  571. $arrImagen = json_decode($description->IMAGEN);
  572. $arrUrlImage = array();
  573. foreach ($arrImagen as $key => $imagen) {
  574. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  575. if ($responseDocument['error']) {
  576. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYID005: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  577. }
  578. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  579. }
  580. $description->IMAGEN = $arrUrlImage;
  581. }
  582. } catch (\Throwable $th) {
  583. return $this->responseController->makeResponse(
  584. true,
  585. "ERR_ARTITLE_GETBYID006: Ocurrió un error al obtener las imágenes de los artículos.",
  586. [],
  587. 500
  588. );
  589. }
  590. foreach ($arrDescription as $description) {
  591. try {
  592. $arrDetails = DB::table('S002V01TINAR')
  593. ->where('INAR_IDDE', '=', $description->ID_DESCRIPCION)
  594. ->where('INAR_ESTA', '=', 'Activo')
  595. ->where('INAR_NULI', '=', $line)
  596. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  597. ->get([
  598. 'INAR_IDIN AS NUMERO_DETALLE',
  599. 'INAR_CODI AS CODIGO',
  600. 'INAR_MODE AS MODELO',
  601. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS MONEDA'),
  602. 'INAR_PREC AS PRECIO',
  603. 'INAR_MOMI AS MONTO_MINIMO',
  604. // 'INAR_CANT AS CANTIDAD',
  605. 'INAR_CARA AS CARACTERISTICAS',
  606. 'INAR_ESTA AS ESTADO',
  607. ]);
  608. } catch (\Throwable $th) {
  609. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYID007: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  610. }
  611. $description->DETALLES = $arrDetails;
  612. try {
  613. $objProdiver = DB::table('S002V01TPROV')
  614. ->where('PROV_NUPR', '=', $description->PROVEEDOR)
  615. ->where('PROV_ESTA', '=', 'Activo')
  616. ->where('PROV_NULI', '=', $line)
  617. ->first([
  618. 'PROV_NUPR',
  619. 'PROV_NOCO',
  620. 'PROV_NOMB',
  621. 'PROV_APPA',
  622. 'PROV_APMA',
  623. 'PROV_CORR',
  624. 'PROV_LAD1',
  625. 'PROV_TEL1',
  626. 'PROV_LAD2',
  627. 'PROV_TEL2',
  628. 'PROV_XRFC',
  629. 'PROV_XTAX',
  630. 'PROV_CRFI',
  631. 'PROV_TIPO',
  632. 'PROV_SIWE',
  633. 'PROV_MEPA',
  634. 'PROV_USRE',
  635. 'PROV_FERE',
  636. 'PROV_USMO',
  637. 'PROV_FEMO',
  638. ]);
  639. $description->PROVEEDOR = $objProdiver;
  640. } catch (\Throwable $th) {
  641. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYID008: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  642. }
  643. }
  644. $arrArtitle->INFORMACION = $arrDescription;
  645. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArtitle);
  646. }
  647. public function getAllArtitles($user, $line) {
  648. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  649. if ($arrResponseCheckUser['error']) {
  650. DB::rollBack();
  651. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_GETALL000:'.$arrResponseCheckUser['msg'], [], 401);
  652. }
  653. try {
  654. $arrArtitle = DB::table('S002V01TARTI')
  655. ->where("ARTI_NULI", "=", $line)
  656. ->join("S002V01TFAMI", "ARTI_COFA", "=", "FAMI_COFA")
  657. ->join("S002V01TSUBF", "ARTI_COSU", "=", "SUBF_COSU")
  658. ->get([
  659. "ARTI_IDAR AS ID_ARTICULO",
  660. "ARTI_NOMB AS MODELO",
  661. "FAMI_COFA AS ID_FAMILIA",
  662. "FAMI_NOFA AS FAMILIA",
  663. "SUBF_COSU AS ID_SUBFAMILIA",
  664. "SUBF_NOSU AS SUBFAMILIA",
  665. "ARTI_ESTA AS ESTADO",
  666. "ARTI_USRE AS USUARIO_REGISTRA",
  667. "ARTI_FERE AS FECHA_REGISTRA",
  668. "ARTI_USMO AS USUARIO_MODIFICA",
  669. "ARTI_FEMO AS FECHA_MODIFICA",
  670. ]);
  671. $arrArtitle = json_decode(json_encode($arrArtitle), true);
  672. } catch (\Throwable $th) {
  673. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETALL001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  674. }
  675. $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrArtitle, $line);
  676. if ($responseCheckLatestUpdate['error']) {
  677. return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
  678. }
  679. $arrArtitle = $responseCheckLatestUpdate['response'];
  680. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArtitle);
  681. }
  682. public function registerArtitlesOld(Request $request) {
  683. $validator = Validator::make($request->all(), [
  684. 'CODIGO' => 'required|string',
  685. 'ARTICULO' => 'required|string',
  686. 'FAMILIA' => 'required|string',
  687. 'SUBFAMILIA' => 'required|string',
  688. 'INFORMATION' => 'required|array',
  689. 'USUARIO' => 'required|string',
  690. 'NUMERO_LINEA' => 'required|integer',
  691. ]);
  692. if ($validator->fails()) {
  693. return $this->responseController->makeResponse(
  694. true,
  695. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  696. $this->responseController->makeErrors($validator->errors()->messages()),
  697. 401
  698. );
  699. }
  700. DB::beginTransaction();
  701. $requestData = $request->all();
  702. foreach ($requestData['INFORMATION'] as $information) {
  703. $validator = Validator::make($information, [
  704. 'NO' => 'required|string',
  705. 'IMAGEN' => 'required|array',
  706. 'DESCRIPCION' => 'required|string',
  707. // 'CARACTERISTICAS' => '|string',
  708. 'TIPO_UNIDAD' => 'required|integer',
  709. 'PROVEEDOR' => 'required|string',
  710. 'COMPRA_WEB' => 'required|boolean',
  711. 'ESTADO' => 'required|string',
  712. 'DETAILS' => 'required|array',
  713. ]);
  714. if ($validator->fails()) {
  715. return $this->responseController->makeResponse(
  716. true,
  717. "ERR_ARTITLE_REG001: Se encontraron uno o más errores.",
  718. $this->responseController->makeErrors($validator->errors()->messages()),
  719. 401
  720. );
  721. }
  722. foreach ($information['DETAILS'] as $details) {
  723. $validator = Validator::make($details, [
  724. 'NO' => 'required|string',
  725. 'CODIGO' => 'required|string',
  726. 'MODELO' => 'required|string',
  727. 'MONEDA' => 'required|string',
  728. 'PRECIO' => 'required|string',
  729. 'MONTO_MINIMO' => 'required|string',
  730. 'ESTADO' => 'required|string',
  731. 'CARACTERISTICAS' => 'required|string',
  732. ]);
  733. if ($validator->fails()) {
  734. return $this->responseController->makeResponse(
  735. true,
  736. "ERR_ARTITLE_REG002: Se encontraron uno o más errores.",
  737. $this->responseController->makeErrors($validator->errors()->messages()),
  738. 401
  739. );
  740. }
  741. }
  742. }
  743. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  744. if ($arrResponseCheckUser['error']) {
  745. DB::rollBack();
  746. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG003:'.$arrResponseCheckUser['msg'], [], 401);
  747. }
  748. $usuario = $arrResponseCheckUser['response'];
  749. $now = $this->functionsController->now();
  750. $currentDate = $now->toDateTimeString();
  751. try {
  752. $idArtitle = DB::table('S002V01TARTI')->insertGetId([
  753. 'ARTI_CODI' => $requestData['CODIGO'],
  754. 'ARTI_COFA' => $requestData['FAMILIA'],
  755. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  756. 'ARTI_NOMB' => $requestData['ARTICULO'],
  757. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  758. 'ARTI_USRE' => $usuario,
  759. 'ARTI_FERE' => $currentDate,
  760. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  761. ]);
  762. } catch (\Throwable $th) {
  763. DB::rollBack();
  764. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG004: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  765. }
  766. foreach ($requestData['INFORMATION'] as $keyInformation => $information) {
  767. try {
  768. $arrCodeImages = array();
  769. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  770. $idFile = $this->encController->decrypt($encIdFile);
  771. $tempFile = DB::table('S002V01TARTE')->where([
  772. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  773. ['ARTE_IDAR', '=', $idFile],
  774. ])->first();
  775. if(is_null($tempFile)){
  776. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG005: El archivo consultado no está registrado', [], 404);
  777. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  778. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado está eliminado', [], 404);
  779. }
  780. $fileResponse = $this->documentManagementController->moveFinalFile(
  781. intval($requestData['NUMERO_LINEA']),
  782. 'GEAD',
  783. 'FO',
  784. $tempFile,
  785. $usuario,
  786. );
  787. if(!$fileResponse[0]){
  788. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: '.$fileResponse[1], [], 400);
  789. }
  790. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  791. }
  792. $jsonImages = json_encode($arrCodeImages);
  793. } catch (\Throwable $th) {
  794. DB::rollBack();
  795. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG008: Ocurrió un error al obtener la URL pública de las imágenes.", $th->getMessage(), 500);
  796. }
  797. try {
  798. $idDescription = DB::table('S002V01TDEAR')->insertGetId([
  799. 'DEAR_DESC' => $information['DESCRIPCION'],
  800. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  801. 'DEAR_COWE' => $information['COMPRA_WEB'],
  802. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  803. 'DEAR_IMAG' => $jsonImages,
  804. 'DEAR_NUPR' => $information['PROVEEDOR'],
  805. 'DEAR_IDAR' => $idArtitle,
  806. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  807. 'DEAR_USRE' => $usuario,
  808. 'DEAR_FERE' => $currentDate,
  809. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  810. ]);
  811. } catch (\Throwable $th) {
  812. DB::rollBack();
  813. 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);
  814. }
  815. $arrDetails = $information['DETAILS'];
  816. foreach ($arrDetails as $keyDetails => $details) {
  817. $insertDetails = [
  818. 'INAR_IDDE' => $idDescription,
  819. 'INAR_CODI' => $details['CODIGO'],
  820. 'INAR_MODE' => $details['MODELO'],
  821. 'INAR_COMO' => $details['MONEDA'],
  822. 'INAR_PREC' => $details['PRECIO'],
  823. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  824. 'INAR_CARA' => $details['CARACTERISTICAS'],
  825. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  826. 'INAR_USRE' => $usuario,
  827. 'INAR_FERE' => $currentDate,
  828. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  829. ];
  830. try {
  831. $validateDetails = DB::table('S002V01TINAR')->insert($insertDetails);
  832. } catch (\Throwable $th) {
  833. DB::rollBack();
  834. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG010: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  835. }
  836. if (!$validateDetails) {
  837. DB::rollBack();
  838. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG011: No se pudo insertar los datos de los detalles.", [], 500);
  839. }
  840. }
  841. }
  842. DB::commit();
  843. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  844. }
  845. public function registerArticle (Request $request) {
  846. $validator = Validator::make($request->all(), [
  847. 'CODIGO' => 'required|string',
  848. 'ARTICULO' => 'required|string',
  849. 'FAMILIA' => 'required|string',
  850. 'SUBFAMILIA' => 'required|string',
  851. 'DESCRIPCION_ARTICULO' => 'required|array',
  852. 'USUARIO' => 'required|string',
  853. 'NUMERO_LINEA' => 'required|integer',
  854. ]);
  855. if ($validator->fails()) {
  856. return $this->responseController->makeResponse(
  857. true,
  858. "Se encontraron uno o más errores.",
  859. $this->responseController->makeErrors($validator->errors()->messages()),
  860. 401
  861. );
  862. }
  863. DB::beginTransaction();
  864. $requestData = $request->all();
  865. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  866. if ($arrResponseCheckUser['error']) {
  867. DB::rollBack();
  868. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  869. }
  870. $user = $arrResponseCheckUser['response'];
  871. try {
  872. $validateExists = DB::table("S002V01TFAMI")->where([
  873. ['FAMI_COFA', '=', $requestData['FAMILIA']],
  874. ['FAMI_NULI', '=', $requestData['NUMERO_LINEA']],
  875. ])->exists();
  876. } catch (\Throwable $th) {
  877. DB::rollBack();
  878. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la familia.", $th->getMessage(), 500);
  879. }
  880. if ($validateExists === false) {
  881. DB::rollBack();
  882. return $this->responseController->makeResponse(true, "La familia no existe.", [], 500);
  883. }
  884. unset($validateExists);
  885. try {
  886. $validateExists = DB::table('S002V01TSUBF')
  887. ->where([
  888. ['SUBF_NULI', '=', $requestData['NUMERO_LINEA']],
  889. ['SUBF_COFA', '=', $requestData['FAMILIA']],
  890. ['SUBF_COSU', '=', $requestData['SUBFAMILIA']],
  891. ])->exists();
  892. } catch (\Throwable $th) {
  893. DB::rollBack();
  894. return $this->responseController->makeResponse(true, "Ocurrió un error verificar la existencia de la subfamilia.", $th->getMessage(), 500);
  895. }
  896. if ($validateExists === false) {
  897. DB::rollBack();
  898. return $this->responseController->makeResponse(true, "La subfamilia no existe.", [], 500);
  899. }
  900. unset($validateExists);
  901. $now = $this->functionsController->now();
  902. $currentDate = $now->toDateTimeString();
  903. try {
  904. $idArticle = DB::table('S002V01TARTI')
  905. ->insertGetId([
  906. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  907. 'ARTI_COFA' => $requestData['FAMILIA'],
  908. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  909. 'ARTI_CODI' => $requestData['CODIGO'],
  910. 'ARTI_NOMB' => $requestData['ARTICULO'],
  911. 'ARTI_USRE' => $user,
  912. 'ARTI_FERE' => $currentDate,
  913. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  914. ]);
  915. } catch (\Throwable $th) {
  916. DB::rollBack();
  917. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el artículo.", $th->getMessage(), 500);
  918. }
  919. if ($idArticle <= 0) {
  920. DB::rollBack();
  921. return $this->responseController->makeResponse(true, "No se pudo registra el artículo.", [], 500);
  922. }
  923. foreach ($requestData['DESCRIPCION_ARTICULO'] as $keyDesc => $descriptions) {
  924. // codeFile
  925. foreach ($descriptions['ARCHIVOS'] as $files) {
  926. $idFile = $this->encController->decrypt($files['ID']);
  927. try {
  928. $tempFile = DB::table('S002V01TARTE')
  929. ->where([
  930. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  931. ['ARTE_IDAR', '=', $idFile],
  932. ])->first();
  933. } catch (\Throwable $th) {
  934. DB::rollBack();
  935. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener los archivos temporales.", $th->getMessage(), 500);
  936. }
  937. }
  938. ry {
  939. $arrCodeImages = array();
  940. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  941. $idFile = $this->encController->decrypt($encIdFile);
  942. $tempFile = DB::table('S002V01TARTE')->where([
  943. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  944. ['ARTE_IDAR', '=', $idFile],
  945. ])->first();
  946. if(is_null($tempFile)){
  947. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG005: El archivo consultado no está registrado', [], 404);
  948. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  949. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado está eliminado', [], 404);
  950. }
  951. $fileResponse = $this->documentManagementController->moveFinalFile(
  952. intval($requestData['NUMERO_LINEA']),
  953. 'GEAD',
  954. 'FO',
  955. $tempFile,
  956. $usuario,
  957. );
  958. if(!$fileResponse[0]){
  959. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: '.$fileResponse[1], [], 400);
  960. }
  961. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  962. }
  963. $jsonImages = json_encode($arrCodeImages);
  964. } catch (\Throwable $th) {
  965. DB::rollBack();
  966. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG008: Ocurrió un error al obtener la URL pública de las imágenes.", $th->getMessage(), 500);
  967. }
  968. try {
  969. $idDescription = DB::table('S002V01TDEAR')
  970. ->insertGetId([
  971. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  972. 'DEAR_IMAG' => $codeFile,
  973. 'DEAR_DESC' => $descriptions['DESCRIPCION'],
  974. 'DEAR_CARA' => $descriptions['CARACTERISTICAS'],
  975. 'DEAR_COWE' => true,
  976. 'DEAR_IDUN' => $descriptions['ID_UNIDAD'],
  977. 'DEAR_NUPR' => $descriptions['NUMERO_PROVEEDOR'],
  978. 'DEAR_IDAR' => $idArticle,
  979. 'DEAR_USRE' => $user,
  980. 'DEAR_FERE' => $currentDate,
  981. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  982. ]);
  983. } catch (\Throwable $th) {
  984. //throw $th;
  985. }
  986. }
  987. }
  988. public function updateArtitles(Request $request) {
  989. $validator = Validator::make($request->all(), [
  990. 'NO' => 'required|string',
  991. 'CODIGO' => 'required|string',
  992. 'ARTICULO' => 'required|string',
  993. 'FAMILIA' => 'required|string',
  994. 'SUBFAMILIA' => 'required|string',
  995. 'USUARIO' => 'required|string',
  996. 'NUMERO_LINEA' => 'required|integer',
  997. 'INFORMATION' => 'required',
  998. ]);
  999. if ($validator->fails()) {
  1000. return $this->responseController->makeResponse(
  1001. true,
  1002. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1003. $this->responseController->makeErrors($validator->errors()->messages()),
  1004. 401
  1005. );
  1006. }
  1007. DB::beginTransaction(); # Para impedir que las actualizaciones queden a incompletas
  1008. $requestData = $request->all();
  1009. foreach ($requestData['INFORMATION'] as $information) {
  1010. $validator = Validator::make($information, [
  1011. 'NO' => 'required|integer',
  1012. 'IMAGEN' => 'required|array',
  1013. 'DESCRIPCION' => 'required|string',
  1014. // 'CARACTERISTICAS' => '|string',
  1015. 'TIPO_UNIDAD' => 'required|integer',
  1016. 'PROVEEDOR' => 'required|string',
  1017. 'COMPRA_WEB' => 'required|boolean',
  1018. 'ESTADO' => 'required|string',
  1019. 'DETAILS' => 'required|array',
  1020. ]);
  1021. if ($validator->fails()) {
  1022. return $this->responseController->makeResponse(
  1023. true,
  1024. "ERR_ARTITLE_MOD001: Se encontraron uno o más errores.",
  1025. $this->responseController->makeErrors($validator->errors()->messages()),
  1026. 401
  1027. );
  1028. }
  1029. foreach ($information['DETAILS'] as $details) {
  1030. $validator = Validator::make($details, [
  1031. 'NO' => 'required|string',
  1032. 'CODIGO' => 'required|string',
  1033. 'MODELO' => 'required|string',
  1034. 'MONEDA' => 'required|string',
  1035. 'PRECIO' => 'required|string',
  1036. 'MONTO_MINIMO' => 'required|string',
  1037. 'ESTADO' => 'required|string',
  1038. 'CARACTERISTICAS' => 'required|string',
  1039. ]);
  1040. if ($validator->fails()) {
  1041. return $this->responseController->makeResponse(
  1042. true,
  1043. "ERR_ARTITLE_MOD002: Se encontraron uno o más errores.",
  1044. $this->responseController->makeErrors($validator->errors()->messages()),
  1045. 401
  1046. );
  1047. }
  1048. }
  1049. foreach ($information['IMAGEN'] as $key => $imagen) {
  1050. if (gettype($imagen) != 'string') {
  1051. return $this->responseController->makeResponse(
  1052. true,
  1053. "ERR_ARTITLE_MOD003: Se encontraron uno o más errores.",
  1054. "Se se obtuvieron los ID de los archivos.",
  1055. 401
  1056. );
  1057. }
  1058. }
  1059. }
  1060. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1061. if ($arrResponseCheckUser['error']) {
  1062. DB::rollBack();
  1063. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD004:'.$arrResponseCheckUser['msg'], [], 401);
  1064. }
  1065. $usuario = $arrResponseCheckUser['response'];
  1066. $now = $this->functionsController->now();
  1067. $currentDate = $now->toDateTimeString();
  1068. $numeroArticulo = $requestData['NO'];
  1069. try {
  1070. $validateUpdate = DB::table('S002V01TARTI')
  1071. ->where('ARTI_IDAR', '=', $numeroArticulo)
  1072. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  1073. ->update([
  1074. 'ARTI_CODI' => $requestData['CODIGO'],
  1075. 'ARTI_COFA' => $requestData['FAMILIA'],
  1076. 'ARTI_COSU' => $requestData['SUBFAMILIA'],
  1077. 'ARTI_NOMB' => $requestData['ARTICULO'],
  1078. 'ARTI_USMO' => $usuario,
  1079. 'ARTI_FEMO' => $currentDate,
  1080. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1081. ]);
  1082. } catch (\Throwable $th) {
  1083. DB::rollBack();
  1084. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD005: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1085. }
  1086. if (!$validateUpdate) {
  1087. DB::rollBack();
  1088. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD006: Ocurrió un error al modificar en la tabla.", [], 500);
  1089. }
  1090. $arrInformation = $requestData['INFORMATION'];
  1091. foreach ($arrInformation as $keyInformation => $information) {
  1092. // Número de ID de información
  1093. $numeroInformation = $information['NO'];
  1094. // Se verifica si la información ya está registrado o no
  1095. if ($information['ESTADO'] === 'Modificado' || $information['ESTADO'] === 'Activo') {
  1096. $arrCodeImages = array();
  1097. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  1098. $idFile = $this->encController->decrypt($encIdFile);
  1099. $arrCode = explode('=', $idFile);
  1100. if ( count($arrCode) == 3 ) {
  1101. $arrStrucuteCode = explode("-", $arrCode[0]);
  1102. $nameCode = explode(".", $arrCode[2]);
  1103. $validateImage = DB::table('S002V01TAFAL')->where([
  1104. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  1105. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  1106. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  1107. ['AFAL_NOAR', '=', $nameCode[0]],
  1108. ['AFAL_EXTE', '=', $nameCode[1]],
  1109. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  1110. if (!$validateImage) {
  1111. DB::rollBack();
  1112. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD007: : La imagen con el código $idFile no existe.", [], 500);
  1113. }
  1114. $arrCodeImages[] = $this->encController->encrypt($idFile);
  1115. } else {
  1116. $tempFile = DB::table('S002V01TARTE')->where([
  1117. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  1118. ['ARTE_IDAR', '=', $idFile],
  1119. ])->first();
  1120. if(is_null($tempFile)){
  1121. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD008: El archivo consultado no está registrado', $idFile, 404);
  1122. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  1123. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD009: El archivo consultado está eliminado', $tempFile, 404);
  1124. }
  1125. $fileResponse = $this->documentManagementController->moveFinalFile(
  1126. intval($requestData['NUMERO_LINEA']),
  1127. 'GEAD',
  1128. 'FO',
  1129. $tempFile,
  1130. $usuario,
  1131. );
  1132. if(!$fileResponse[0]){
  1133. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD010: ".$fileResponse[1], [], 400);
  1134. }
  1135. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  1136. // $arrCodeImages[] = $fileResponse[1];
  1137. }
  1138. }
  1139. $jsonImages = json_encode($arrCodeImages);
  1140. try {
  1141. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1142. 'DEAR_DESC' => $information['DESCRIPCION'],
  1143. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  1144. 'DEAR_COWE' => $information['COMPRA_WEB'],
  1145. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  1146. 'DEAR_IMAG' => $jsonImages,
  1147. 'DEAR_NUPR' => $information['PROVEEDOR'],
  1148. 'DEAR_USMO' => $usuario,
  1149. 'DEAR_FEMO' => $currentDate,
  1150. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1151. ]);
  1152. } catch (\Throwable $th) {
  1153. DB::rollBack();
  1154. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD011: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1155. }
  1156. if (!$validate) {
  1157. DB::rollBack();
  1158. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD012: Ocurrió un error al modificar en la tabla.", [], 500);
  1159. }
  1160. $arrDetails = $information['DETAILS'];
  1161. foreach ($arrDetails as $keyDetails => $details) {
  1162. $numeroDetails = $details['NO'];
  1163. if ( $details['ESTADO'] === 'Modificado' || $details['ESTADO'] === 'Activo') {
  1164. try {
  1165. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  1166. 'INAR_CODI' => $details['CODIGO'],
  1167. 'INAR_MODE' => $details['MODELO'],
  1168. 'INAR_COMO' => $details['MONEDA'],
  1169. 'INAR_PREC' => $details['PRECIO'],
  1170. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1171. // 'INAR_CANT' => $details['CANTIDAD'],
  1172. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1173. 'INAR_USMO' => $usuario,
  1174. 'INAR_FEMO' => $currentDate,
  1175. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1176. ]);
  1177. } catch (\Throwable $th) {
  1178. DB::rollBack();
  1179. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1180. }
  1181. if (!$validate) {
  1182. DB::rollBack();
  1183. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD014: Ocurrió un error al modificar en la tabla.", [], 500);
  1184. }
  1185. } else if ($details['ESTADO'] === 'Nuevo') {
  1186. try {
  1187. $validate = DB::table('S002V01TINAR')->insertGetId([
  1188. 'INAR_IDDE' => $numeroInformation,
  1189. 'INAR_CODI' => $details['CODIGO'],
  1190. 'INAR_MODE' => $details['MODELO'],
  1191. 'INAR_COMO' => $details['MONEDA'],
  1192. 'INAR_PREC' => $details['PRECIO'],
  1193. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1194. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1195. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1196. 'INAR_USRE' => $usuario,
  1197. 'INAR_FERE' => $currentDate,
  1198. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1199. ]);
  1200. } catch (\Throwable $th) {
  1201. DB::rollBack();
  1202. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD015: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1203. }
  1204. if (!$validate) {
  1205. DB::rollBack();
  1206. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD016: Ocurrió un error al modificar en la tabla.", [], 500);
  1207. }
  1208. } else if ($details['ESTADO'] === 'Eliminado') {
  1209. try {
  1210. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  1211. 'INAR_ESTA' => 'Eliminado',
  1212. 'INAR_USMO' => $usuario,
  1213. 'INAR_FEMO' => $currentDate,
  1214. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1215. ]);
  1216. } catch (\Throwable $th) {
  1217. DB::rollBack();
  1218. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD017: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1219. }
  1220. if (!$validate) {
  1221. DB::rollBack();
  1222. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD018: Ocurrió un error al modificar en la tabla.", [], 500);
  1223. }
  1224. }
  1225. }
  1226. } else if ($information['ESTADO'] === 'Nuevo') {
  1227. $arrCodeImages = array();
  1228. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  1229. $idFile = $this->encController->decrypt($encIdFile);
  1230. $arrCode = explode('=', $idFile);
  1231. if ( count($arrCode) == 3 ) {
  1232. $arrStrucuteCode = explode("-", $arrCode[0]);
  1233. $nameCode = explode(".", $arrCode[2]);
  1234. $validateImage = DB::table('S002V01TAFAL')->where([
  1235. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  1236. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  1237. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  1238. ['AFAL_NOAR', '=', $nameCode[0]],
  1239. ['AFAL_EXTE', '=', $nameCode[1]],
  1240. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  1241. if (!$validateImage) {
  1242. DB::rollBack();
  1243. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD019: La imagen con el código $idFile no existe.", [], 500);
  1244. }
  1245. $arrCodeImages[] = $this->encController->encrypt($idFile);
  1246. } else {
  1247. $tempFile = DB::table('S002V01TARTE')->where([
  1248. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  1249. ['ARTE_IDAR', '=', $idFile],
  1250. ])->first();
  1251. if(is_null($tempFile)){
  1252. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD020: El archivo consultado no está registrado', [], 404);
  1253. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  1254. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD021: El archivo consultado está eliminado', [], 404);
  1255. }
  1256. $fileResponse = $this->documentManagementController->moveFinalFile(
  1257. intval($requestData['NUMERO_LINEA']),
  1258. 'GEAD',
  1259. 'FO',
  1260. $tempFile,
  1261. $usuario,
  1262. );
  1263. if(!$fileResponse[0]){
  1264. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD022: '.$fileResponse[1], [], 400);
  1265. }
  1266. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  1267. }
  1268. }
  1269. $jsonImages = json_encode($arrCodeImages);
  1270. try {
  1271. $numeroInformation = DB::table('S002V01TDEAR')->insertGetId([
  1272. 'DEAR_DESC' => $information['DESCRIPCION'],
  1273. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  1274. 'DEAR_COWE' => $information['COMPRA_WEB'],
  1275. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  1276. 'DEAR_IMAG' => $jsonImages,
  1277. 'DEAR_NUPR' => $information['PROVEEDOR'],
  1278. 'DEAR_IDAR' => $numeroArticulo,
  1279. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  1280. 'DEAR_USRE' => $usuario,
  1281. 'DEAR_FERE' => $currentDate,
  1282. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1283. ]);
  1284. } catch (\Throwable $th) {
  1285. DB::rollBack();
  1286. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD023: Ocurrió un error al insertar los datos de la información del artículo.", $th->getMessage(), 500);
  1287. }
  1288. $arrDetails = $information['DETAILS'];
  1289. foreach ($arrDetails as $keyDetails => $details) {
  1290. try {
  1291. DB::table('S002V01TINAR')->insertGetId([
  1292. 'INAR_IDDE' => $numeroInformation,
  1293. 'INAR_CODI' => $details['CODIGO'],
  1294. 'INAR_MODE' => $details['MODELO'],
  1295. 'INAR_COMO' => $details['MONEDA'],
  1296. 'INAR_PREC' => $details['PRECIO'],
  1297. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1298. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1299. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1300. 'INAR_USRE' => $usuario,
  1301. 'INAR_FERE' => $currentDate,
  1302. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1303. ]);
  1304. } catch (\Throwable $th) {
  1305. DB::rollBack();
  1306. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD024: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  1307. }
  1308. }
  1309. } else if ($information['ESTADO'] === 'Eliminado') {
  1310. try {
  1311. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1312. 'DEAR_ESTA' => 'Eliminado',
  1313. 'DEAR_USMO' => $usuario,
  1314. 'DEAR_FEMO' => $currentDate,
  1315. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1316. ]);
  1317. } catch (\Throwable $th) {
  1318. DB::rollBack();
  1319. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD025: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1320. }
  1321. if (!$validate) {
  1322. DB::rollBack();
  1323. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD026: Ocurrió un error al modificar en la tabla.", [], 500);
  1324. }
  1325. }
  1326. }
  1327. DB::commit(); # Para guardar los cambios en la base de datos
  1328. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1329. }
  1330. public function deleteArtitle(Request $request) {
  1331. $validator = Validator::make($request->all(), [
  1332. 'NUMERO_ARTITULO' => 'required|string',
  1333. 'NUMERO_LINEA' => 'required|integer',
  1334. 'USUARIO' => 'required|string',
  1335. ]);
  1336. if ($validator->fails()) {
  1337. return $this->responseController->makeResponse(
  1338. true,
  1339. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1340. $this->responseController->makeErrors($validator->errors()->messages()),
  1341. 401
  1342. );
  1343. }
  1344. DB::beginTransaction();
  1345. $requestData = $request->all();
  1346. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1347. if ($arrResponseCheckUser['error']) {
  1348. DB::rollBack();
  1349. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_DEL001:'.$arrResponseCheckUser['msg'], [], 401);
  1350. }
  1351. $usuario = $arrResponseCheckUser['response'];
  1352. try {
  1353. $artitleNumber = $this->encController->decrypt($requestData['NUMERO_ARTITULO']);
  1354. } catch (\Throwable $th) {
  1355. return $this->responseController->makeResponse(
  1356. true,
  1357. "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.",
  1358. $th->getMessage(),
  1359. 500
  1360. );
  1361. }
  1362. $now = $this->functionsController->now();
  1363. $currentDate = $now->toDateTimeString();
  1364. try {
  1365. $validateUpdate = DB::table('S002V01TARTI')
  1366. ->where('ARTI_IDAR', '=', $artitleNumber)
  1367. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  1368. ->update([
  1369. 'ARTI_ESTA' => 'Eliminado',
  1370. 'ARTI_USMO' => $usuario,
  1371. 'ARTI_FEMO' => $currentDate,
  1372. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1373. ]);
  1374. } catch (\Throwable $th) {
  1375. DB::rollBack();
  1376. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1377. }
  1378. if (!$validateUpdate) {
  1379. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1380. }
  1381. try {
  1382. $arrDescription = DB::table('S002V01TDEAR')
  1383. ->where('DEAR_IDAR', '=', $artitleNumber)
  1384. ->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1385. } catch (\Throwable $th) {
  1386. DB::rollBack();
  1387. 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);
  1388. }
  1389. foreach ($arrDescription as $keyDescription => $description) {
  1390. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1391. try {
  1392. $validateUpdate = DB::table('S002V01TDEAR')
  1393. ->where('DEAR_IDDE', '=', $numeroDescripcion)
  1394. ->where('DEAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1395. ->update([
  1396. 'DEAR_ESTA' => 'Eliminado',
  1397. 'DEAR_USMO' => $usuario,
  1398. 'DEAR_FEMO' => $currentDate,
  1399. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1400. ]);
  1401. } catch (\Throwable $th) {
  1402. DB::rollBack();
  1403. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1404. }
  1405. if (!$validateUpdate) {
  1406. DB::rollBack();
  1407. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1408. }
  1409. try {
  1410. $validateUpdate = DB::table('S002V01TINAR')
  1411. ->where('INAR_IDDE', '=', $numeroDescripcion)
  1412. ->where('INAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1413. ->update([
  1414. 'INAR_ESTA' => 'Eliminado',
  1415. 'INAR_USMO' => $usuario,
  1416. 'INAR_FEMO' => $currentDate,
  1417. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1418. ]);
  1419. } catch (\Throwable $th) {
  1420. DB::rollBack();
  1421. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL009: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1422. }
  1423. if (!$validateUpdate) {
  1424. DB::rollBack();
  1425. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL008: Ocurrió un error al modificar en la tabla.", [], 500);
  1426. }
  1427. }
  1428. DB::commit(); # Para guardar los cambios en la base de datos
  1429. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1430. }
  1431. public function generateArtitles(Request $request) {
  1432. $validator = Validator::make($request->all(), [
  1433. 'FILE_ZIP' => 'required',
  1434. 'NUMERO_LINEA' => 'required',
  1435. 'USUARIO' => 'required',
  1436. ]);
  1437. if ($validator->fails()) {
  1438. return $this->responseController->makeResponse(
  1439. true,
  1440. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1441. $this->responseController->makeErrors($validator->errors()->messages()),
  1442. 401
  1443. );
  1444. }
  1445. }
  1446. public function getArtitleByInformation($information, $user, $line) {
  1447. try {
  1448. $objInformation = (array) DB::table('S002V01TINAR')
  1449. ->where('INAR_IDIN', '=', $information)
  1450. ->where('INAR_ESTA', '=', 'Activo')
  1451. ->where('DEAR_ESTA', '=', 'Activo')
  1452. ->where('ARTI_ESTA', '=', 'Activo')
  1453. ->where('FAMI_ESTA', '=', 'Activo')
  1454. ->where('SUBF_ESTA', '=', 'Activo')
  1455. ->where('UNID_ESTA', '=', 'Activo')
  1456. ->where('PROV_ESTA', '=', 'Activo')
  1457. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1458. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1459. ->join('S002V01TFAMI', 'FAMI_COFA', '=', 'ARTI_COFA')
  1460. ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'ARTI_COSU')
  1461. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1462. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1463. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1464. ->first([
  1465. 'INAR_IDIN', // Identificador de Información del artículo
  1466. 'INAR_CODI', // Código del artículo
  1467. 'INAR_MODE', // Modelo del artículo
  1468. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1469. 'INAR_PREC', // Precio
  1470. 'INAR_CARA', // Características
  1471. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1472. 'DEAR_DESC', // Descripción del artículo
  1473. 'DEAR_CARA', // Características del artículo
  1474. 'DEAR_COWE', // Compra web
  1475. 'DEAR_IMAG', // Imagen
  1476. 'DEAR_IDUN', // Identificador de la unidad
  1477. 'UNID_NOMB', // Nombre de la unidad
  1478. 'UNID_ACRO', // Acrónimo de la familia
  1479. 'DEAR_NUPR', // Número del proveedor
  1480. 'ARTI_IDAR', // Identificador del artículo
  1481. 'ARTI_COFA', // Identificador de la familia
  1482. 'FAMI_NOFA', // Nombre de la familia
  1483. 'ARTI_COSU', // Identificador de la subfamilia
  1484. 'SUBF_NOSU', // Nombre de la subfamilia
  1485. 'ARTI_CODI', // Código del artículo
  1486. 'ARTI_NOMB', // Nombre del artículo
  1487. 'PROV_NOCO', // Nombre comercial
  1488. 'PROV_NOMB', // Nombre del proveedor
  1489. 'PROV_APPA', // Apellido paterno del proveedor
  1490. 'PROV_APMA', // Apellido materno del proveedor
  1491. 'PROV_CORR', // Correo electrónico
  1492. 'PROV_LAD1', // Lada 1
  1493. 'PROV_TEL1', // Teléfono 1
  1494. 'PROV_LAD2', // Lada 2
  1495. 'PROV_TEL2', // Teléfono 2
  1496. 'PROV_XRFC', // R.F.C
  1497. 'PROV_XTAX', // TAX ID
  1498. 'PROV_TIPO', // Tipo
  1499. 'PROV_SIWE', // Sitio Web
  1500. 'PROV_MEPA', // Metodos de pago
  1501. ]);
  1502. } catch (\Throwable $th) {
  1503. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1504. }
  1505. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1506. $arrUrlImage = array();
  1507. foreach ($objInformation['DEAR_IMAG'] as $key => $imagen) {
  1508. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  1509. if ($responseDocument['error']) {
  1510. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION001: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1511. }
  1512. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  1513. }
  1514. $objInformation['DEAR_IMAG'] = $arrUrlImage;
  1515. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1516. }
  1517. public function getManagementUnit ($user, $line) {
  1518. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1519. if ($arrResponseCheckUser['error']) {
  1520. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1521. }
  1522. try {
  1523. $arrUnits = DB::table('S002V01TUNID')
  1524. ->where('UNID_NULI', '=', $line)
  1525. ->where('UNID_ESTA', '=', 'Activo')
  1526. ->get([
  1527. 'UNID_IDUN AS ID_UNIDAD',
  1528. 'UNID_NOMB AS UNIDAD',
  1529. 'UNID_ACRO AS ACRONIMO',
  1530. ]);
  1531. $arrUnits = json_decode(json_encode($arrUnits), true);
  1532. } catch (\Throwable $th) {
  1533. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener los datos de la unidad.', [], 500);
  1534. }
  1535. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnits);
  1536. }
  1537. public function createUnit (Request $request) {
  1538. $validator = Validator::make($request->all(), [
  1539. 'UNIDAD' => 'required|string',
  1540. 'ACRONIMO' => 'required|string',
  1541. 'USUARIO' => 'required|string',
  1542. 'NUMERO_LINEA' => 'required|integer',
  1543. ]);
  1544. if ($validator->fails()) {
  1545. return $this->responseController->makeResponse(
  1546. true,
  1547. "Se encontraron uno o más errores.",
  1548. $this->responseController->makeErrors($validator->errors()->messages()),
  1549. 401
  1550. );
  1551. }
  1552. $requestData = $request->all();
  1553. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1554. if ($arrResponseCheckUser['error']) {
  1555. DB::rollBack();
  1556. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1557. }
  1558. $user = $arrResponseCheckUser['response'];
  1559. $now = $this->functionsController->now();
  1560. $currentDate = $now->toDateTimeString();
  1561. try {
  1562. $validate = DB::table('S002V01TUNID')->insert([
  1563. 'UNID_NULI' => $requestData['NUMERO_LINEA'],
  1564. 'UNID_NOMB' => $requestData['UNIDAD'],
  1565. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1566. 'UNID_USRE' => $user,
  1567. 'UNID_FERE' => $currentDate,
  1568. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1569. ]);
  1570. } catch (\Throwable $th) {
  1571. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar la unidad.", $th->getMessage(), 500);
  1572. }
  1573. if (!$validate) {
  1574. return $this->responseController->makeResponse(true, "No se pudo registrar la unidad.", [], 500);
  1575. }
  1576. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1577. }
  1578. public function updateUnit (Request $request, $idUnit) {
  1579. $validator = Validator::make($request->all(), [
  1580. 'UNIDAD' => 'required|string',
  1581. 'ACRONIMO' => 'required|string',
  1582. 'USUARIO' => 'required|string',
  1583. 'NUMERO_LINEA' => 'required|integer',
  1584. ]);
  1585. if ($validator->fails()) {
  1586. return $this->responseController->makeResponse(
  1587. true,
  1588. "Se encontraron uno o más errores.",
  1589. $this->responseController->makeErrors($validator->errors()->messages()),
  1590. 401
  1591. );
  1592. }
  1593. $requestData = $request->all();
  1594. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1595. if ($arrResponseCheckUser['error']) {
  1596. DB::rollBack();
  1597. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  1598. }
  1599. $user = $arrResponseCheckUser['response'];
  1600. $idUnit = $this->encController->encrypt($idUnit);
  1601. if (is_null($idUnit)) {
  1602. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1603. }
  1604. try {
  1605. $validateExists = DB::table('S002V01TUNID')
  1606. ->where('UNID_IDUN', '=', $idUnit)
  1607. ->where('UNID_ESTA', '=', 'Activo')
  1608. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1609. ->exists();
  1610. } catch (\Throwable $th) {
  1611. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1612. }
  1613. if (!$validateExists) {
  1614. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1615. }
  1616. $now = $this->functionsController->now();
  1617. $currentDate = $now->toDateTimeString();
  1618. try {
  1619. $validate = DB::table('S002V01TUNID')
  1620. ->where('UNID_IDUN', '=', $idUnit)
  1621. ->where('UNID_ESTA', '=', 'Activo')
  1622. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  1623. ->update([
  1624. 'UNID_NOMB' => $requestData['UNIDAD'],
  1625. 'UNID_ACRO' => $requestData['ACRONIMO'],
  1626. 'UNID_USMO' => $user,
  1627. 'UNID_FEMO' => $currentDate,
  1628. 'UNID_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1629. ]);
  1630. } catch (\Throwable $th) {
  1631. return $this->responseController->makeResponse(true, "IOcurrió un error al modificar la unidad.", $th->getMessage(), 500);
  1632. }
  1633. if (!$validate) {
  1634. return $this->responseController->makeResponse(true, "No se pudo modificar la unidad.", [], 500);
  1635. }
  1636. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1637. }
  1638. public function getUnitById ($idUnit, $user, $line) {
  1639. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1640. if ($arrResponseCheckUser['error']) {
  1641. DB::rollBack();
  1642. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  1643. }
  1644. $user = $arrResponseCheckUser['response'];
  1645. $idUnit = $this->encController->decrypt($idUnit);
  1646. if (is_null($idUnit)) {
  1647. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el identificador de la unidad.", [], 500);
  1648. }
  1649. try {
  1650. $validateExists = DB::table('S002V01TUNID')
  1651. ->where('UNID_IDUN', '=', $idUnit)
  1652. ->where('UNID_ESTA', '=', 'Activo')
  1653. ->where('UNID_NULI', '=', $line)
  1654. ->exists();
  1655. } catch (\Throwable $th) {
  1656. return $this->responseController->makeResponse(true, "Ocurrió un error al verificar si la unidad está registrada.", $th->getMessage(), 500);
  1657. }
  1658. if (!$validateExists) {
  1659. return $this->responseController->makeResponse(true, "La unidad no existe.", [], 404);
  1660. }
  1661. try {
  1662. $arrUnit = (array) DB::table('S002V01TUNID')
  1663. ->where('UNID_IDUN', '=', $idUnit)
  1664. ->where('UNID_ESTA', '=', 'Activo')
  1665. ->where('UNID_NULI', '=', $line)
  1666. ->first([
  1667. 'UNID_IDUN AS ID_UNIDAD',
  1668. 'UNID_NOMB AS UNIDAD',
  1669. 'UNID_ACRO AS ACRONIMO',
  1670. ]);
  1671. } catch (\Throwable $th) {
  1672. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener la información de la unidad.", $th->getMessage(), 500);
  1673. }
  1674. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrUnit);
  1675. }
  1676. public function deleteUnitById (Request $request, $idUnit) {
  1677. }
  1678. public function registerDescriptionArtitle () {}
  1679. }