ArtitleController.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 02/05/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(true, "ERR_ARTITLE_GETFAMILYS000: No se pudo realizar la consulta de las familias en la base.", $th->getMessage(), 500);
  43. }
  44. try {
  45. $arrSubfamilias = DB::table('S002V01TSUBF')
  46. ->where('SUBF_ESTA', '=', 'Activo')
  47. ->where('SUBF_NULI', '=', $line)
  48. ->get([
  49. 'SUBF_COSU AS ID_SUBFAMILIA',
  50. 'SUBF_NOSU AS SUBFAMILIA',
  51. 'SUBF_COFA AS ID_FAMILIA',
  52. ]);
  53. } catch (\Throwable $th) {
  54. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETFAMILYS001: No se pudo realizar la consulta de las subfamilias en la base.", $th->getMessage(), 500);
  55. }
  56. $arrFamilasAndSubfamilias = array();
  57. foreach ($arrFamilias as $keyFamilias => $familias) {
  58. $familias->SUBFAMILIAS = array();
  59. foreach ($arrSubfamilias as $keySubfamilias => $subfamilias) {
  60. if ($familias->ID_FAMILIA == $subfamilias->ID_FAMILIA) {
  61. $familias->SUBFAMILIAS[] = array(
  62. "ID_SUBFAMILIA" => $subfamilias->ID_SUBFAMILIA,
  63. "SUBFAMILIA" => $subfamilias->SUBFAMILIA,
  64. );
  65. }
  66. }
  67. }
  68. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  69. }
  70. public function registerFamily(Request $request){
  71. $valitador = Validator::make($request->all(), [
  72. 'FAMILIA' => 'required|string|max:50',
  73. 'LINE' => 'required|integer',
  74. 'USER' => 'required|string'
  75. ]);
  76. if ($valitador->fails()) {
  77. return $this->responseController->makeResponse(
  78. true,
  79. "ERR_FAMILY_REG000: Se encontraron uno o más errores.",
  80. $this->responseController->makeErrors($valitador->errors()->messages()),
  81. 401
  82. );
  83. }
  84. DB::beginTransaction();
  85. $response = $request->all();
  86. try {
  87. $usuario = $this->encController->decrypt($response['USER']);
  88. } catch (\Throwable $th) {
  89. DB::rollBack();
  90. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  91. }
  92. $now = $this->functionsController->now();
  93. $currentDate = $now->toDateTimeString();
  94. $arrInsert = [
  95. "FAMI_NOFA" => trim($response['FAMILIA']),
  96. "FAMI_USRE" => $usuario,
  97. "FAMI_NULI" => $response['LINE'],
  98. "FAMI_FERE" => $currentDate,
  99. "FAMI_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  100. ];
  101. try {
  102. $valid = DB::table('S002V01TFAMI')->insert($arrInsert);
  103. } catch (\Throwable $th) {
  104. DB::rollBack();
  105. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG002: Ocurrió un error al ingresar los registros.", $th->getMessage(), 401);
  106. }
  107. if (!$valid) {
  108. DB::rollBack();
  109. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG003: No se pudo ingresar los datos a la base de datos.", [], 401);
  110. }
  111. DB::commit();
  112. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  113. }
  114. public function getUnits($user, $line) {
  115. try {
  116. $arrFamilias = DB::table('S002V01TUNID')
  117. ->where('UNID_NULI', '=', $line)
  118. ->get([
  119. 'UNID_IDUN AS ID_UNIDAD',
  120. 'UNID_NOMB AS UNIDAD',
  121. 'UNID_ESTA AS ESTADO',
  122. 'UNID_USRE AS USUARIO_REGISTRA',
  123. 'UNID_FERE AS FECHA_REGISTRA',
  124. 'UNID_USMO AS USUARIO_MODIFICA',
  125. 'UNID_FEMO AS FECHA_MODIFICA',
  126. ]);
  127. } catch (\Throwable $th) {
  128. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETUNITS000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  129. }
  130. return $this->responseController->makeResponse(false, "ÉXITO", $arrFamilias);
  131. }
  132. public function getUnitsActives($user, $line) {
  133. try {
  134. $arrFamilias = DB::table('S002V01TUNID')
  135. ->where('UNID_NULI', '=', $line)
  136. ->where('UNID_ESTA', '=', 'Activo')
  137. ->get([
  138. 'UNID_IDUN AS ID_UNIDAD',
  139. 'UNID_NOMB AS UNIDAD',
  140. 'UNID_USRE AS USUARIO_REGISTRA',
  141. 'UNID_FERE AS FECHA_REGISTRA',
  142. 'UNID_USMO AS USUARIO_MODIFICA',
  143. 'UNID_FEMO AS FECHA_MODIFICA',
  144. ]);
  145. } catch (\Throwable $th) {
  146. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETUNITACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  147. }
  148. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  149. }
  150. public function registerUnit(Request $request){
  151. $valitador = Validator::make($request->all(), [
  152. 'UNIDAD' => 'required|string|max:50',
  153. 'LINE' => 'required|integer',
  154. 'USER' => 'required|string'
  155. ]);
  156. if ($valitador->fails()) {
  157. return $this->responseController->makeResponse(
  158. true,
  159. "ERR_ARTITLE_REGUNIT000: Se encontraron uno o más errores.",
  160. $this->responseController->makeErrors($valitador->errors()->messages()),
  161. 401
  162. );
  163. }
  164. DB::beginTransaction();
  165. $response = $request->all();
  166. try {
  167. $usuario = $this->encController->decrypt($response['USER']);
  168. } catch (\Throwable $th) {
  169. DB::rollBack();
  170. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  171. }
  172. $now = $this->functionsController->now();
  173. $currentDate = $now->toDateTimeString();
  174. $arrInsert = [
  175. "UNID_NOMB" => trim($response['UNIDAD']),
  176. "UNID_USRE" => $usuario,
  177. "UNID_NULI" => $response['LINE'],
  178. "UNID_FERE" => $currentDate,
  179. "UNID_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  180. ];
  181. try {
  182. $valid = DB::table('S002V01TUNID')->insert($arrInsert);
  183. } catch (\Throwable $th) {
  184. DB::rollBack();
  185. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT002: Ocurrió un error al ingresar los registros.", $th->getMessage(), 401);
  186. }
  187. if (!$valid) {
  188. DB::rollBack();
  189. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT003: No se pudo ingresar los datos a la base de datos.", [], 401);
  190. }
  191. DB::commit();
  192. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  193. }
  194. public function registerSubfamily(Request $request){
  195. $valitador = Validator::make($request->all(), [
  196. 'ID_FAMILIA' => 'required|integer',
  197. 'SUBFAMILIA' => 'required|string|max:50',
  198. 'LINE' => 'required|integer',
  199. 'USER' => 'required|string'
  200. ]);
  201. if ($valitador->fails()) {
  202. return $this->responseController->makeResponse(
  203. true,
  204. "ERR_SUBFAMILY_REG000: Se encontraron uno o más errores.",
  205. $this->responseController->makeErrors($valitador->errors()->messages()),
  206. 401
  207. );
  208. }
  209. DB::beginTransaction();
  210. $response = $request->all();
  211. try {
  212. $exist = DB::table('S002V01TFAMI')
  213. ->where('FAMI_COFA', '=', trim($response['ID_FAMILIA']))
  214. ->where('FAMI_ESTA', '=', 'Activo')
  215. ->where('FAMI_NULI', '=', $response['LINE'])
  216. ->exists();
  217. } catch (\Throwable $th) {
  218. DB::rollBack();
  219. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG002: Ocurrió al verificar la Familia.", $th->getMessage(), 401);
  220. }
  221. if (!$exist) {
  222. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG003: La Familia seleccionada no existe.", [], 401);
  223. }
  224. try {
  225. $user = $this->encController->decrypt($response['USER']);
  226. } catch (\Throwable $th) {
  227. DB::rollBack();
  228. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  229. }
  230. $now = $this->functionsController->now();
  231. $currentDate = $now->toDateTimeString();
  232. $arrInsert = [
  233. "SUBF_COFA" => $response['ID_FAMILIA'],
  234. "SUBF_NOSU" => $response['SUBFAMILIA'],
  235. "SUBF_USRE" => $user,
  236. "SUBF_NULI" => $response['LINE'],
  237. "SUBF_FERE" => $currentDate,
  238. "SUBF_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  239. ];
  240. try {
  241. $valid = DB::table('S002V01TSUBF')->insert($arrInsert);
  242. } catch (\Throwable $th) {
  243. DB::rollBack();
  244. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG004: Ocurrió un error al ingresar los registros.", [], 401);
  245. }
  246. if (!$valid) {
  247. DB::rollBack();
  248. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG005: No se pudo ingresar los datos a la base de datos.", [], 401);
  249. }
  250. DB::commit();
  251. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  252. }
  253. public function getArtitles($user, $line) {
  254. try {
  255. $getArtitle = DB::table('S002V01TARTI')
  256. ->where("ARTI_NULI", "=", $line)
  257. ->where("FAMI_NULI", "=", $line)
  258. ->where("SUBF_NULI", "=", $line)
  259. ->where("DEAR_NULI", "=", $line)
  260. ->where("PROV_NULI", "=", $line)
  261. ->where("UNID_NULI", "=", $line)
  262. ->where("ARTI_ESTA", "=", "Activo")
  263. ->where("FAMI_ESTA", "=", "Activo")
  264. ->where("SUBF_ESTA", "=", "Activo")
  265. ->where("DEAR_ESTA", "=", "Activo")
  266. ->where("PROV_ESTA", "=", "Activo")
  267. ->where("UNID_ESTA", "=", "Activo")
  268. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_COFA")
  269. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_COSU")
  270. ->join("S002V01TDEAR", "ARTI_IDAR", "=", "DEAR_IDAR")
  271. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  272. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  273. ->get([
  274. "DEAR_IDDE AS ID_DESC_ARTI",
  275. "ARTI_IDAR AS ID_ARTICULO",
  276. "ARTI_NOMB AS MODELO",
  277. "FAMI_COFA AS ID_FAMILIA",
  278. "FAMI_NOFA AS FAMILIA",
  279. "SUBF_COSU AS ID_SUBFAMILIA",
  280. "SUBF_NOSU AS SUBFAMILIA",
  281. "DEAR_DESC AS DESCRIPCION",
  282. "DEAR_CARA AS CARACTERISTICAS",
  283. "DEAR_COWE AS COMPRA_WEB",
  284. "DEAR_IDUN AS TIPO_UNIDAD",
  285. "DEAR_IMAG AS URL_IMAGEN",
  286. "PROV_NUPR AS ID_PROVEEDOR",
  287. "PROV_NOCO AS PROVEEDOR",
  288. ]);
  289. } catch (\Throwable $th) {
  290. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  291. }
  292. foreach ($getArtitle as $artitle) {
  293. $arrImagen = json_decode($artitle->URL_IMAGEN);
  294. $arrUrlImage = array();
  295. foreach ($arrImagen as $key => $imagen) {
  296. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  297. $arrResponseDocument = json_decode($responseDocument->original, true);
  298. if ($arrResponseDocument['error']) {
  299. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  300. }
  301. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  302. }
  303. $artitle->URL_IMAGEN = $arrUrlImage;
  304. }
  305. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getArtitle);
  306. }
  307. // public function getArtitlesByProvider(Request $request) {
  308. public function getArtitlesByProvider($artitle, $provider, $user, $line) {
  309. $idArtitle = $this->encController->decrypt( $artitle );
  310. $idProvider = $this->encController->decrypt( $provider );
  311. try {
  312. $objArtitle = (array) DB::table('S002V01TDEAR')
  313. ->where("ARTI_NULI", "=", $line)
  314. ->where("DEAR_IDDE", "=", $idArtitle)
  315. ->where("DEAR_NUPR", "=", $idProvider)
  316. ->join("S002V01TARTI", "ARTI_IDAR", "=", "DEAR_IDAR")
  317. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_COFA")
  318. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_COSU")
  319. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  320. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  321. ->first([
  322. "DEAR_IDDE AS ID_DESC_ARTI",
  323. "ARTI_IDAR AS ID_ARTICULO",
  324. // "ARTI_CODI AS CODIGO",
  325. "ARTI_NOMB AS MODELO",
  326. "FAMI_COFA AS ID_FAMILIA",
  327. "FAMI_NOFA AS FAMILIA",
  328. "SUBF_COSU AS ID_SUBFAMILIA",
  329. "SUBF_NOSU AS SUBFAMILIA",
  330. "DEAR_DESC AS DESCRIPCION",
  331. "DEAR_CARA AS CARACTERISTICAS",
  332. "DEAR_COWE AS COMPRA_WEB",
  333. "UNID_IDUN AS ID_UNIDAD",
  334. "UNID_NOMB AS UNIDAD",
  335. // "DEAR_INPR AS INFO_PRODUCTO",
  336. "DEAR_IMAG AS URL_IMAGEN",
  337. "PROV_NUPR AS ID_PROVEEDOR",
  338. "PROV_NOCO AS PROVEEDOR",
  339. ]);
  340. } catch (\Throwable $th) {
  341. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  342. }
  343. if ( empty($objArtitle) ) {
  344. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER002: No se encontró el resultado deseado.", [], 500);
  345. }
  346. $objArtitle['URL_IMAGEN'] = json_decode($objArtitle['URL_IMAGEN']);
  347. $arrUrlImage = array();
  348. foreach ($objArtitle['URL_IMAGEN'] as $key => $encImage) {
  349. $responseDocument = $this->documentManagementController->getPublicDocumentURL($encImage, $user, $line);
  350. $arrResponseDocument = json_decode($responseDocument->original, true);
  351. if ($arrResponseDocument['error']) {
  352. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  353. }
  354. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  355. }
  356. $objArtitle['URL_IMAGEN'] = $arrUrlImage;
  357. try {
  358. $arrInformation = DB::table('S002V01TINAR')
  359. ->where('INAR_ESTA', '=', 'Activo')
  360. ->where('INAR_NULI', '=', $line)
  361. ->where('INAR_IDDE', '=', $objArtitle['ID_DESC_ARTI'])
  362. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  363. ->get([
  364. 'INAR_IDIN AS NUMERO_INFORMACION',
  365. 'INAR_CODI AS CODIGO',
  366. 'INAR_MODE AS MODELO',
  367. // DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS MONEDA'),
  368. 'CAMO_COMO AS MONEDA',
  369. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  370. 'INAR_PREC AS PRECIO',
  371. 'INAR_MOMI AS MONTO_MINIMO',
  372. 'INAR_CARA AS CARACTERISTICAS',
  373. ]);
  374. } catch (\Throwable $th) {
  375. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER003: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  376. }
  377. $objArtitle['INFO_PRODUCTO'] = json_encode($arrInformation);
  378. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objArtitle);
  379. }
  380. public function getArtitleById($encIdArtitle, $user, $line) {
  381. $idArtitle = $this->encController->decrypt($encIdArtitle);
  382. try {
  383. $arrArtitle = DB::table('S002V01TARTI')
  384. ->where('ARTI_IDAR', '=', $idArtitle)
  385. ->where('ARTI_ESTA', '=', 'Activo')
  386. ->where('ARTI_NULI', '=', $line)
  387. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_COFA")
  388. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_COSU")
  389. ->first([
  390. 'ARTI_IDAR AS NUMERO_ARTICULO',
  391. 'ARTI_CODI AS CODIGO',
  392. "FAMI_COFA AS ID_FAMILIA",
  393. "FAMI_NOFA AS FAMILIA",
  394. "SUBF_COSU AS ID_SUBFAMILIA",
  395. "SUBF_NOSU AS SUBFAMILIA",
  396. 'ARTI_NOMB AS ARTICULO',
  397. ]);
  398. } catch (\Throwable $th) {
  399. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  400. }
  401. try {
  402. $arrDescription = DB::table('S002V01TDEAR')
  403. ->where('DEAR_IDAR', '=', $idArtitle)
  404. ->where('DEAR_ESTA', '=', 'Activo')
  405. ->where('DEAR_NULI', '=', $line)
  406. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  407. ->get([
  408. 'DEAR_IDDE AS ID_DESCRIPCION',
  409. 'DEAR_DESC AS DESCRIPCION',
  410. 'DEAR_CARA AS CARACTERISTICAS',
  411. 'DEAR_COWE AS COMPRA_WEB',
  412. 'DEAR_IDUN AS TIPO_UNIDAD',
  413. 'DEAR_IMAG AS IMAGEN',
  414. 'DEAR_NUPR AS PROVEEDOR',
  415. 'DEAR_ESTA AS ESTADO',
  416. ]);
  417. } catch (\Throwable $th) {
  418. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  419. }
  420. if ( empty($arrDescription) ) {
  421. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: No se encontró ninguna descripción.", [], 500);
  422. }
  423. // Se obtienen las URL de las imagenes de los artículos
  424. foreach ($arrDescription as $description) {
  425. $arrImagen = json_decode($description->IMAGEN);
  426. $arrUrlImage = array();
  427. foreach ($arrImagen as $key => $imagen) {
  428. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  429. $arrResponseDocument = json_decode($responseDocument->original, true);
  430. if ($arrResponseDocument['error']) {
  431. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  432. }
  433. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  434. }
  435. $description->IMAGEN = $arrUrlImage;
  436. }
  437. foreach ($arrDescription as $description) {
  438. try {
  439. $arrDetails = DB::table('S002V01TINAR')
  440. ->where('INAR_IDDE', '=', $description->ID_DESCRIPCION)
  441. ->where('INAR_ESTA', '=', 'Activo')
  442. ->where('INAR_NULI', '=', $line)
  443. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  444. ->get([
  445. 'INAR_IDIN AS NUMERO_DETALLE',
  446. 'INAR_CODI AS CODIGO',
  447. 'INAR_MODE AS MODELO',
  448. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS MONEDA'),
  449. 'INAR_PREC AS PRECIO',
  450. 'INAR_MOMI AS MONTO_MINIMO',
  451. // 'INAR_CANT AS CANTIDAD',
  452. 'INAR_CARA AS CARACTERISTICAS',
  453. 'INAR_ESTA AS ESTADO',
  454. ]);
  455. } catch (\Throwable $th) {
  456. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET004: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  457. }
  458. $description->DETALLES = $arrDetails;
  459. try {
  460. $objProdiver = DB::table('S002V01TPROV')
  461. ->where('PROV_NUPR', '=', $description->PROVEEDOR)
  462. ->where('PROV_ESTA', '=', 'Activo')
  463. ->where('PROV_NULI', '=', $line)
  464. ->first([
  465. 'PROV_NUPR',
  466. 'PROV_NOCO',
  467. 'PROV_NOMB',
  468. 'PROV_APPA',
  469. 'PROV_APMA',
  470. 'PROV_CORR',
  471. 'PROV_LAD1',
  472. 'PROV_TEL1',
  473. 'PROV_LAD2',
  474. 'PROV_TEL2',
  475. 'PROV_XRFC',
  476. 'PROV_XTAX',
  477. 'PROV_CRFI',
  478. 'PROV_TIPO',
  479. 'PROV_SIWE',
  480. 'PROV_MEPA',
  481. 'PROV_USRE',
  482. 'PROV_FERE',
  483. 'PROV_USMO',
  484. 'PROV_FEMO',
  485. ]);
  486. $description->PROVEEDOR = $objProdiver;
  487. } catch (\Throwable $th) {
  488. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET005: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  489. }
  490. }
  491. $arrArtitle->INFORMACION = $arrDescription;
  492. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArtitle);
  493. }
  494. public function getAllArtitles($user, $line) {
  495. try {
  496. $resp = DB::table('S002V01TARTI')
  497. ->where("ARTI_NULI", "=", $line)
  498. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_COFA")
  499. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_COSU")
  500. ->get([
  501. "ARTI_IDAR AS ID_ARTICULO",
  502. "ARTI_NOMB AS MODELO",
  503. "FAMI_COFA AS ID_FAMILIA",
  504. "FAMI_NOFA AS FAMILIA",
  505. "SUBF_COSU AS ID_SUBFAMILIA",
  506. "SUBF_NOSU AS SUBFAMILIA",
  507. "ARTI_ESTA AS ESTADO",
  508. "ARTI_USRE AS USUARIO_REGISTRA",
  509. "ARTI_FERE AS FECHA_REGISTRA",
  510. "ARTI_USMO AS USUARIO_MODIFICA",
  511. "ARTI_FEMO AS FECHA_MODIFICA",
  512. ]);
  513. } catch (\Throwable $th) {
  514. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETALL000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  515. }
  516. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $resp);
  517. }
  518. public function registerArtitles(Request $request) {
  519. $validator = Validator::make($request->all(), [
  520. 'CODIGO' => 'required|string',
  521. 'ARTICULO' => 'required|string',
  522. 'FAMILIA' => 'required|integer',
  523. 'SUBFAMILIA' => 'required|integer',
  524. 'INFORMATION' => 'required|array',
  525. 'USUARIO' => 'required|string',
  526. 'NUMERO_LINEA' => 'required|string',
  527. ]);
  528. if ($validator->fails()) {
  529. return $this->responseController->makeResponse(
  530. true,
  531. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  532. $this->responseController->makeErrors($validator->errors()->messages()),
  533. 401
  534. );
  535. }
  536. DB::beginTransaction();
  537. $requestData = $request->all();
  538. foreach ($requestData['INFORMATION'] as $information) {
  539. $validator = Validator::make($information, [
  540. 'NO' => 'required|string',
  541. 'IMAGEN' => 'required|array',
  542. 'DESCRIPCION' => 'required|string',
  543. // 'CARACTERISTICAS' => '|string',
  544. 'TIPO_UNIDAD' => 'required|integer',
  545. 'PROVEEDOR' => 'required|string',
  546. 'COMPRA_WEB' => 'required|boolean',
  547. 'ESTADO' => 'required|string',
  548. 'DETAILS' => 'required|array',
  549. ]);
  550. if ($validator->fails()) {
  551. return $this->responseController->makeResponse(
  552. true,
  553. "ERR_ARTITLE_REG001: Se encontraron uno o más errores.",
  554. $this->responseController->makeErrors($validator->errors()->messages()),
  555. 401
  556. );
  557. }
  558. foreach ($information['DETAILS'] as $details) {
  559. $validator = Validator::make($details, [
  560. 'NO' => 'required|string',
  561. 'CODIGO' => 'required|string',
  562. 'MODELO' => 'required|string',
  563. 'MONEDA' => 'required|string',
  564. 'PRECIO' => 'required|string',
  565. 'MONTO_MINIMO' => 'required|string',
  566. 'ESTADO' => 'required|string',
  567. 'CARACTERISTICAS' => 'required|string',
  568. ]);
  569. if ($validator->fails()) {
  570. return $this->responseController->makeResponse(
  571. true,
  572. "ERR_ARTITLE_REG002: Se encontraron uno o más errores.",
  573. $this->responseController->makeErrors($validator->errors()->messages()),
  574. 401
  575. );
  576. }
  577. }
  578. foreach ($information['IMAGEN'] as $key => $imagen) {
  579. if (gettype($imagen) != 'string') {
  580. return $this->responseController->makeResponse(
  581. true,
  582. "ERR_ARTITLE_REG003: Se encontraron uno o más errores.",
  583. "Se se obtuvieron los ID de los archivos.",
  584. 401
  585. );
  586. }
  587. }
  588. }
  589. try {
  590. $usuario = $this->encController->decrypt($requestData['USUARIO']);
  591. } catch (\Throwable $th) {
  592. DB::rollBack();
  593. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG004: No se pudo obtener los datos del usuario", $th->getMessage(), 500);
  594. }
  595. $now = $this->functionsController->now();
  596. $currentDate = $now->toDateTimeString();
  597. try {
  598. $idArtitle = DB::table('S002V01TARTI')->insertGetId([
  599. 'ARTI_CODI' => $requestData['CODIGO'],
  600. 'ARTI_IDFA' => $requestData['FAMILIA'],
  601. 'ARTI_IDSU' => $requestData['SUBFAMILIA'],
  602. 'ARTI_NOMB' => $requestData['ARTICULO'],
  603. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  604. 'ARTI_USRE' => $usuario,
  605. 'ARTI_FERE' => $currentDate,
  606. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  607. ]);
  608. } catch (\Throwable $th) {
  609. DB::rollBack();
  610. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG005: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  611. }
  612. foreach ($requestData['INFORMATION'] as $keyInformation => $information) {
  613. $arrCodeImages = array();
  614. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  615. $idFile = $this->encController->decrypt($encIdFile);
  616. $tempFile = DB::table('S002V01TARTE')->where([
  617. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  618. ['ARTE_IDAR', '=', $idFile],
  619. ])->first();
  620. if(is_null($tempFile)){
  621. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado no está registrado', [], 404);
  622. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  623. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: El archivo consultado está eliminado', [], 404);
  624. }
  625. $fileResponse = $this->documentManagementController->moveFinalFile(
  626. intval($requestData['NUMERO_LINEA']),
  627. 'GEAD',
  628. 'FO',
  629. $tempFile,
  630. $usuario,
  631. );
  632. if(!$fileResponse[0]){
  633. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG008: '.$fileResponse[1], [], 400);
  634. }
  635. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  636. }
  637. $jsonImages = json_encode($arrCodeImages);
  638. try {
  639. $idDescription = DB::table('S002V01TDEAR')->insertGetId([
  640. 'DEAR_DESC' => $information['DESCRIPCION'],
  641. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  642. 'DEAR_COWE' => $information['COMPRA_WEB'],
  643. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  644. 'DEAR_IMAG' => $jsonImages,
  645. 'DEAR_NUPR' => $information['PROVEEDOR'],
  646. 'DEAR_IDAR' => $idArtitle,
  647. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  648. 'DEAR_USRE' => $usuario,
  649. 'DEAR_FERE' => $currentDate,
  650. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  651. ]);
  652. } catch (\Throwable $th) {
  653. DB::rollBack();
  654. 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);
  655. }
  656. $arrDetails = $information['DETAILS'];
  657. foreach ($arrDetails as $keyDetails => $details) {
  658. $insertDetails = [
  659. 'INAR_IDDE' => $idDescription,
  660. 'INAR_CODI' => $details['CODIGO'],
  661. 'INAR_MODE' => $details['MODELO'],
  662. 'INAR_COMO' => $details['MONEDA'],
  663. 'INAR_PREC' => $details['PRECIO'],
  664. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  665. // 'INAR_CANT' => $details['CANTIDAD'],
  666. 'INAR_CARA' => $details['CARACTERISTICAS'],
  667. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  668. 'INAR_USRE' => $usuario,
  669. 'INAR_FERE' => $currentDate,
  670. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  671. ];
  672. try {
  673. $validateDetails = DB::table('S002V01TINAR')->insert($insertDetails);
  674. } catch (\Throwable $th) {
  675. DB::rollBack();
  676. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG010: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  677. }
  678. if (!$validateDetails) {
  679. DB::rollBack();
  680. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG011: No se pudo insertar los datos de los detalles.", [], 500);
  681. }
  682. }
  683. }
  684. DB::commit();
  685. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  686. }
  687. public function updateArtitles(Request $request) {
  688. $validator = Validator::make($request->all(), [
  689. 'NO' => 'required|string',
  690. 'CODIGO' => 'required|string',
  691. 'ARTICULO' => 'required|string',
  692. 'FAMILIA' => 'required|integer',
  693. 'SUBFAMILIA' => 'required|integer',
  694. 'USUARIO' => 'required|string',
  695. 'NUMERO_LINEA' => 'required|string',
  696. 'INFORMATION' => 'required',
  697. ]);
  698. if ($validator->fails()) {
  699. return $this->responseController->makeResponse(
  700. true,
  701. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  702. $this->responseController->makeErrors($validator->errors()->messages()),
  703. 401
  704. );
  705. }
  706. DB::beginTransaction(); # Para impedir que las actualizaciones queden a incompletas
  707. $requestData = $request->all();
  708. foreach ($requestData['INFORMATION'] as $information) {
  709. $validator = Validator::make($information, [
  710. 'NO' => 'required|integer',
  711. 'IMAGEN' => 'required|array',
  712. 'DESCRIPCION' => 'required|string',
  713. // 'CARACTERISTICAS' => '|string',
  714. 'TIPO_UNIDAD' => 'required|integer',
  715. 'PROVEEDOR' => 'required|string',
  716. 'COMPRA_WEB' => 'required|boolean',
  717. 'ESTADO' => 'required|string',
  718. 'DETAILS' => 'required|array',
  719. ]);
  720. if ($validator->fails()) {
  721. return $this->responseController->makeResponse(
  722. true,
  723. "ERR_ARTITLE_MOD001: Se encontraron uno o más errores.",
  724. $this->responseController->makeErrors($validator->errors()->messages()),
  725. 401
  726. );
  727. }
  728. foreach ($information['DETAILS'] as $details) {
  729. $validator = Validator::make($details, [
  730. 'NO' => 'required|string',
  731. 'CODIGO' => 'required|string',
  732. 'MODELO' => 'required|string',
  733. 'MONEDA' => 'required|string',
  734. 'PRECIO' => 'required|string',
  735. 'MONTO_MINIMO' => 'required|string',
  736. 'ESTADO' => 'required|string',
  737. 'CARACTERISTICAS' => 'required|string',
  738. ]);
  739. if ($validator->fails()) {
  740. return $this->responseController->makeResponse(
  741. true,
  742. "ERR_ARTITLE_MOD002: Se encontraron uno o más errores.",
  743. $this->responseController->makeErrors($validator->errors()->messages()),
  744. 401
  745. );
  746. }
  747. }
  748. foreach ($information['IMAGEN'] as $key => $imagen) {
  749. if (gettype($imagen) != 'string') {
  750. return $this->responseController->makeResponse(
  751. true,
  752. "ERR_ARTITLE_MOD003: Se encontraron uno o más errores.",
  753. "Se se obtuvieron los ID de los archivos.",
  754. 401
  755. );
  756. }
  757. }
  758. }
  759. try {
  760. $usuario = $this->encController->decrypt($requestData['USUARIO']);
  761. } catch (\Throwable $th) {
  762. DB::rollBack();
  763. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD004: Ocurrió un error al desencriptar el usuario.", $th->getMessage(), 500);
  764. }
  765. $now = $this->functionsController->now();
  766. $currentDate = $now->toDateTimeString();
  767. $numeroArticulo = $requestData['NO'];
  768. try {
  769. $validateUpdate = DB::table('S002V01TARTI')
  770. ->where('ARTI_IDAR', '=', $numeroArticulo)
  771. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  772. ->update([
  773. 'ARTI_CODI' => $requestData['CODIGO'],
  774. 'ARTI_IDFA' => $requestData['FAMILIA'],
  775. 'ARTI_IDSU' => $requestData['SUBFAMILIA'],
  776. 'ARTI_NOMB' => $requestData['ARTICULO'],
  777. 'ARTI_USMO' => $usuario,
  778. 'ARTI_FEMO' => $currentDate,
  779. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  780. ]);
  781. } catch (\Throwable $th) {
  782. DB::rollBack();
  783. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD005: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  784. }
  785. if (!$validateUpdate) {
  786. DB::rollBack();
  787. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD0006: Ocurrió un error al modificar en la tabla.", [], 500);
  788. }
  789. $arrInformation = $requestData['INFORMATION'];
  790. foreach ($arrInformation as $keyInformation => $information) {
  791. // Número de ID de información
  792. $numeroInformation = $information['NO'];
  793. // Se verifica si la información ya está registrado o no
  794. if ($information['ESTADO'] === 'Modificado' || $information['ESTADO'] === 'Activo') {
  795. $arrCodeImages = array();
  796. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  797. $idFile = $this->encController->decrypt($encIdFile);
  798. // var_dump($idFile);
  799. $arrCode = explode('=', $idFile);
  800. if ( count($arrCode) == 3 ) {
  801. $arrStrucuteCode = explode("-", $arrCode[0]);
  802. $nameCode = explode(".", $arrCode[2]);
  803. $validateImage = DB::table('S002V01TAFAL')->where([
  804. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  805. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  806. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  807. ['AFAL_NOAR', '=', $nameCode[0]],
  808. ['AFAL_EXTE', '=', $nameCode[1]],
  809. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  810. if (!$validateImage) {
  811. DB::rollBack();
  812. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD007ERR_ARTITLE_MOD007: : La imagen con el código $idFile no existe.", [], 500);
  813. }
  814. $arrCodeImages[] = $this->encController->encrypt($idFile);
  815. } else {
  816. $tempFile = DB::table('S002V01TARTE')->where([
  817. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  818. ['ARTE_IDAR', '=', $idFile],
  819. ])->first();
  820. if(is_null($tempFile)){
  821. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD008: El archivo consultado no está registrado', [], 404);
  822. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  823. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD009: El archivo consultado está eliminado', [], 404);
  824. }
  825. $fileResponse = $this->documentManagementController->moveFinalFile(
  826. intval($requestData['NUMERO_LINEA']),
  827. 'GEAD',
  828. 'FO',
  829. $tempFile,
  830. $usuario,
  831. );
  832. if(!$fileResponse[0]){
  833. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD010: ".$fileResponse[1], [], 400);
  834. }
  835. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  836. // $arrCodeImages[] = $fileResponse[1];
  837. }
  838. }
  839. $jsonImages = json_encode($arrCodeImages);
  840. try {
  841. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  842. 'DEAR_DESC' => $information['DESCRIPCION'],
  843. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  844. 'DEAR_COWE' => $information['COMPRA_WEB'],
  845. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  846. 'DEAR_IMAG' => $jsonImages,
  847. 'DEAR_NUPR' => $information['PROVEEDOR'],
  848. 'DEAR_USMO' => $usuario,
  849. 'DEAR_FEMO' => $currentDate,
  850. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  851. ]);
  852. } catch (\Throwable $th) {
  853. DB::rollBack();
  854. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD011: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  855. }
  856. if (!$validate) {
  857. DB::rollBack();
  858. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD012: Ocurrió un error al modificar en la tabla.", [], 500);
  859. }
  860. $arrDetails = $information['DETAILS'];
  861. foreach ($arrDetails as $keyDetails => $details) {
  862. $numeroDetails = $details['NO'];
  863. if ( $details['ESTADO'] === 'Modificado' || $details['ESTADO'] === 'Activo') {
  864. try {
  865. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  866. 'INAR_CODI' => $details['CODIGO'],
  867. 'INAR_MODE' => $details['MODELO'],
  868. 'INAR_COMO' => $details['MONEDA'],
  869. 'INAR_PREC' => $details['PRECIO'],
  870. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  871. // 'INAR_CANT' => $details['CANTIDAD'],
  872. 'INAR_CARA' => $details['CARACTERISTICAS'],
  873. 'INAR_USMO' => $usuario,
  874. 'INAR_FEMO' => $currentDate,
  875. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  876. ]);
  877. } catch (\Throwable $th) {
  878. DB::rollBack();
  879. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  880. }
  881. if (!$validate) {
  882. DB::rollBack();
  883. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD014: Ocurrió un error al modificar en la tabla.", [], 500);
  884. }
  885. } else if ($details['ESTADO'] === 'Nuevo') {
  886. try {
  887. $validate = DB::table('S002V01TINAR')->insertGetId([
  888. 'INAR_IDDE' => $numeroInformation,
  889. 'INAR_CODI' => $details['CODIGO'],
  890. 'INAR_MODE' => $details['MODELO'],
  891. 'INAR_COMO' => $details['MONEDA'],
  892. 'INAR_PREC' => $details['PRECIO'],
  893. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  894. // 'INAR_CANT' => $details['CANTIDAD'],
  895. 'INAR_CARA' => $details['CARACTERISTICAS'],
  896. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  897. 'INAR_USRE' => $usuario,
  898. 'INAR_FERE' => $currentDate,
  899. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  900. ]);
  901. } catch (\Throwable $th) {
  902. DB::rollBack();
  903. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD015: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  904. }
  905. if (!$validate) {
  906. DB::rollBack();
  907. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD016: Ocurrió un error al modificar en la tabla.", [], 500);
  908. }
  909. } else if ($details['ESTADO'] === 'Eliminado') {
  910. try {
  911. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  912. 'INAR_ESTA' => 'Eliminado',
  913. 'INAR_USMO' => $usuario,
  914. 'INAR_FEMO' => $currentDate,
  915. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  916. ]);
  917. } catch (\Throwable $th) {
  918. DB::rollBack();
  919. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD017: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  920. }
  921. if (!$validate) {
  922. DB::rollBack();
  923. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD018: Ocurrió un error al modificar en la tabla.", [], 500);
  924. }
  925. }
  926. }
  927. } else if ($information['ESTADO'] === 'Nuevo') {
  928. $arrCodeImages = array();
  929. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  930. $idFile = $this->encController->decrypt($encIdFile);
  931. $arrCode = explode('=', $idFile);
  932. if ( count($arrCode) == 3 ) {
  933. $arrStrucuteCode = explode("-", $arrCode[0]);
  934. $nameCode = explode(".", $arrCode[2]);
  935. $validateImage = DB::table('S002V01TAFAL')->where([
  936. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  937. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  938. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  939. ['AFAL_NOAR', '=', $nameCode[0]],
  940. ['AFAL_EXTE', '=', $nameCode[1]],
  941. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  942. if (!$validateImage) {
  943. DB::rollBack();
  944. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD019: La imagen con el código $idFile no existe.", [], 500);
  945. }
  946. $arrCodeImages[] = $this->encController->encrypt($idFile);
  947. // $arrCodeImages[] = $idFile;
  948. } else {
  949. $tempFile = DB::table('S002V01TARTE')->where([
  950. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  951. ['ARTE_IDAR', '=', $idFile],
  952. ])->first();
  953. if(is_null($tempFile)){
  954. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD020: El archivo consultado no está registrado', [], 404);
  955. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  956. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD021: El archivo consultado está eliminado', [], 404);
  957. }
  958. $fileResponse = $this->documentManagementController->moveFinalFile(
  959. intval($requestData['NUMERO_LINEA']),
  960. 'GEAD',
  961. 'FO',
  962. $tempFile,
  963. $usuario,
  964. );
  965. if(!$fileResponse[0]){
  966. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD022: '.$fileResponse[1], [], 400);
  967. }
  968. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  969. // $arrCodeImages[] = $fileResponse[1];
  970. }
  971. }
  972. $jsonImages = json_encode($arrCodeImages);
  973. try {
  974. $numeroInformation = DB::table('S002V01TDEAR')->insertGetId([
  975. 'DEAR_DESC' => $information['DESCRIPCION'],
  976. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  977. 'DEAR_COWE' => $information['COMPRA_WEB'],
  978. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  979. 'DEAR_IMAG' => $jsonImages,
  980. 'DEAR_NUPR' => $information['PROVEEDOR'],
  981. 'DEAR_IDAR' => $numeroArticulo,
  982. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  983. 'DEAR_USRE' => $usuario,
  984. 'DEAR_FERE' => $currentDate,
  985. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  986. ]);
  987. } catch (\Throwable $th) {
  988. DB::rollBack();
  989. 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);
  990. }
  991. $arrDetails = $information['DETAILS'];
  992. foreach ($arrDetails as $keyDetails => $details) {
  993. try {
  994. DB::table('S002V01TINAR')->insertGetId([
  995. 'INAR_IDDE' => $numeroInformation,
  996. 'INAR_CODI' => $details['CODIGO'],
  997. 'INAR_MODE' => $details['MODELO'],
  998. 'INAR_COMO' => $details['MONEDA'],
  999. 'INAR_PREC' => $details['PRECIO'],
  1000. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1001. // 'INAR_CANT' => $details['CANTIDAD'],
  1002. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1003. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1004. 'INAR_USRE' => $usuario,
  1005. 'INAR_FERE' => $currentDate,
  1006. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1007. ]);
  1008. } catch (\Throwable $th) {
  1009. DB::rollBack();
  1010. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD024: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  1011. }
  1012. }
  1013. } else if ($information['ESTADO'] === 'Eliminado') {
  1014. try {
  1015. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1016. 'DEAR_ESTA' => 'Eliminado',
  1017. 'DEAR_USMO' => $usuario,
  1018. 'DEAR_FEMO' => $currentDate,
  1019. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1020. ]);
  1021. } catch (\Throwable $th) {
  1022. DB::rollBack();
  1023. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD025: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  1024. }
  1025. if (!$validate) {
  1026. DB::rollBack();
  1027. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD026: Ocurrió un error al modificar en la tabla.", [], 500);
  1028. }
  1029. }
  1030. }
  1031. DB::commit(); # Para guardar los cambios en la base de datos
  1032. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1033. }
  1034. public function deleteArtitle(Request $request) {
  1035. $validator = Validator::make($request->all(), [
  1036. 'NUMERO_ARTITULO' => 'required|string',
  1037. 'NUMERO_LINEA' => 'required|string',
  1038. 'USUARIO' => 'required|string',
  1039. ]);
  1040. if ($validator->fails()) {
  1041. return $this->responseController->makeResponse(
  1042. true,
  1043. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1044. $this->responseController->makeErrors($validator->errors()->messages()),
  1045. 401
  1046. );
  1047. }
  1048. $response = $request->all();
  1049. $numeroLinea = $response['NUMERO_LINEA'];
  1050. $numeroArticulo = $this->encController->decrypt($response['NUMERO_ARTITULO']);
  1051. $usuario = $this->encController->decrypt($response['USUARIO']);
  1052. DB::beginTransaction();
  1053. $now = $this->functionsController->now();
  1054. $currentDate = $now->toDateTimeString();
  1055. try {
  1056. $resp = DB::table('S002V01TARTI')
  1057. ->where('ARTI_IDAR', '=', $numeroArticulo)
  1058. ->where('ARTI_NULI', '=', $numeroLinea)
  1059. ->update([
  1060. 'ARTI_ESTA' => 'Eliminado',
  1061. 'ARTI_USMO' => $usuario,
  1062. 'ARTI_FEMO' => $currentDate,
  1063. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1064. ]);
  1065. if (!$resp) {
  1066. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL001: Ocurrió un error al modificar en la tabla.", [], 500);
  1067. }
  1068. } catch (\Throwable $th) {
  1069. DB::rollBack();
  1070. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1071. }
  1072. try {
  1073. $arrDescription = DB::table('S002V01TDEAR')->where('DEAR_IDAR', '=', $numeroArticulo)->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1074. } catch (\Throwable $th) {
  1075. DB::rollBack();
  1076. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al obtener los datos de la descripción del artículo", $th->getMessage(), 500);
  1077. }
  1078. foreach ($arrDescription as $keyDescription => $description) {
  1079. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1080. try {
  1081. $resp = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroDescripcion)->where('DEAR_NULI', '=', $numeroLinea)->update([
  1082. 'DEAR_ESTA' => 'Eliminado',
  1083. 'DEAR_USMO' => $usuario,
  1084. 'DEAR_FEMO' => $currentDate,
  1085. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1086. ]);
  1087. if (!$resp) {
  1088. DB::rollBack();
  1089. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1090. }
  1091. } catch (\Throwable $th) {
  1092. DB::rollBack();
  1093. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL005: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1094. }
  1095. try {
  1096. $resp = DB::table('S002V01TINAR')->where('INAR_IDDE', '=', $numeroDescripcion)->where('INAR_NULI', '=', $numeroLinea)->update([
  1097. 'INAR_ESTA' => 'Eliminado',
  1098. 'INAR_USMO' => $usuario,
  1099. 'INAR_FEMO' => $currentDate,
  1100. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1101. ]);
  1102. if (!$resp) {
  1103. DB::rollBack();
  1104. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1105. }
  1106. } catch (\Throwable $th) {
  1107. DB::rollBack();
  1108. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", $th->getMessage(), 500);
  1109. }
  1110. }
  1111. DB::commit(); # Para guardar los cambios en la base de datos
  1112. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1113. }
  1114. public function generateArtitles(Request $request) {
  1115. $validator = Validator::make($request->all(), [
  1116. 'FILE_ZIP' => 'required',
  1117. 'NUMERO_LINEA' => 'required',
  1118. 'USUARIO' => 'required',
  1119. ]);
  1120. if ($validator->fails()) {
  1121. return $this->responseController->makeResponse(
  1122. true,
  1123. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1124. $this->responseController->makeErrors($validator->errors()->messages()),
  1125. 401
  1126. );
  1127. }
  1128. }
  1129. public function getArtitleByInformation($information, $user, $line) {
  1130. try {
  1131. $objInformation = (array) DB::table('S002V01TINAR')
  1132. ->where('INAR_IDIN', '=', $information)
  1133. ->where('INAR_ESTA', '=', 'Activo')
  1134. ->where('DEAR_ESTA', '=', 'Activo')
  1135. ->where('ARTI_ESTA', '=', 'Activo')
  1136. ->where('FAMI_ESTA', '=', 'Activo')
  1137. ->where('SUBF_ESTA', '=', 'Activo')
  1138. ->where('UNID_ESTA', '=', 'Activo')
  1139. ->where('PROV_ESTA', '=', 'Activo')
  1140. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1141. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1142. ->join('S002V01TFAMI', 'FAMI_COFA', '=', 'ARTI_IDFA')
  1143. ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'ARTI_IDSU')
  1144. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1145. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1146. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1147. ->first([
  1148. 'INAR_IDIN', // Identificador de Información del artículo
  1149. 'INAR_CODI', // Código del artículo
  1150. 'INAR_MODE', // Modelo del artículo
  1151. // 'INAR_MONE', // Moneda
  1152. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1153. 'INAR_PREC', // Precio
  1154. // 'INAR_CANT', // Cantidad
  1155. 'INAR_CARA', // Características
  1156. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1157. 'DEAR_DESC', // Descripción del artículo
  1158. 'DEAR_CARA', // Características del artículo
  1159. 'DEAR_COWE', // Compra web
  1160. 'DEAR_IMAG', // Imagen
  1161. 'DEAR_IDUN', // Identificador de la unidad
  1162. 'UNID_NOMB', // Nombre de la unidad
  1163. 'UNID_ACRO', // Acrónimo de la familia
  1164. 'DEAR_NUPR', // Número del proveedor
  1165. 'ARTI_IDAR', // Identificador del artículo
  1166. 'ARTI_IDFA', // Identificador de la familia
  1167. 'FAMI_NOFA', // Nombre de la familia
  1168. 'ARTI_IDSU', // Identificador de la subfamilia
  1169. 'SUBF_NOSU', // Nombre de la subfamilia
  1170. 'ARTI_CODI', // Código del artículo
  1171. 'ARTI_NOMB', // Nombre del artículo
  1172. 'PROV_NOCO', // Nombre comercial
  1173. 'PROV_NOMB', // Nombre del proveedor
  1174. 'PROV_APPA', // Apellido paterno del proveedor
  1175. 'PROV_APMA', // Apellido materno del proveedor
  1176. 'PROV_CORR', // Correo electrónico
  1177. 'PROV_LAD1', // Lada 1
  1178. 'PROV_TEL1', // Teléfono 1
  1179. 'PROV_LAD2', // Lada 2
  1180. 'PROV_TEL2', // Teléfono 2
  1181. 'PROV_XRFC', // R.F.C
  1182. 'PROV_XTAX', // TAX ID
  1183. // 'PROV_GIRO', // Giro empresarial
  1184. 'PROV_TIPO', // Tipo
  1185. 'PROV_SIWE', // Sitio Web
  1186. 'PROV_MEPA', // Metodos de pago
  1187. ]);
  1188. } catch (\Throwable $th) {
  1189. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1190. }
  1191. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1192. $arrUrlImage = array();
  1193. foreach ($objInformation['DEAR_IMAG'] as $key => $imagen) {
  1194. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  1195. $arrResponseDocument = json_decode($responseDocument->original, true);
  1196. if ($arrResponseDocument['error']) {
  1197. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1198. }
  1199. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  1200. }
  1201. $objInformation['DEAR_IMAG'] = $arrUrlImage;
  1202. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1203. }
  1204. }