ArtitleController.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  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_IDFA AS ID_FAMILIA',
  39. 'FAMI_NOMB 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_IDSU AS ID_SUBFAMILIA',
  50. 'SUBF_NOMB AS SUBFAMILIA',
  51. 'SUBF_IDFA 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.", [], 401);
  91. }
  92. $now = $this->functionsController->now();
  93. $currentDate = $now->toDateTimeString();
  94. $arrInsert = [
  95. "FAMI_NOMB" => 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.", [], 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.", [], 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.", [], 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.", [], 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.", [], 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_IDFA', '=', 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.", [], 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.", [], 401);
  229. }
  230. $now = $this->functionsController->now();
  231. $currentDate = $now->toDateTimeString();
  232. $arrInsert = [
  233. "SUBF_IDFA" => $response['ID_FAMILIA'],
  234. "SUBF_NOMB" => $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_IDFA")
  269. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  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_IDFA AS ID_FAMILIA",
  278. "FAMI_NOMB AS FAMILIA",
  279. "SUBF_IDSU AS ID_SUBFAMILIA",
  280. "SUBF_NOMB 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_IDFA")
  318. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  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_IDFA AS ID_FAMILIA",
  327. "FAMI_NOMB AS FAMILIA",
  328. "SUBF_IDSU AS ID_SUBFAMILIA",
  329. "SUBF_NOMB 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_IDFA")
  388. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  389. ->first([
  390. 'ARTI_IDAR AS NUMERO_ARTICULO',
  391. 'ARTI_CODI AS CODIGO',
  392. "FAMI_IDFA AS ID_FAMILIA",
  393. "FAMI_NOMB AS FAMILIA",
  394. "SUBF_IDSU AS ID_SUBFAMILIA",
  395. "SUBF_NOMB 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_IDFA")
  499. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  500. ->get([
  501. "ARTI_IDAR AS ID_ARTICULO",
  502. "ARTI_NOMB AS MODELO",
  503. "FAMI_IDFA AS ID_FAMILIA",
  504. "FAMI_NOMB AS FAMILIA",
  505. "SUBF_IDSU AS ID_SUBFAMILIA",
  506. "SUBF_NOMB 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.", [], 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.", [], 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.", [], 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. // exit;
  841. try {
  842. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  843. 'DEAR_DESC' => $information['DESCRIPCION'],
  844. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  845. 'DEAR_COWE' => $information['COMPRA_WEB'],
  846. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  847. 'DEAR_IMAG' => $jsonImages,
  848. 'DEAR_NUPR' => $information['PROVEEDOR'],
  849. 'DEAR_USMO' => $usuario,
  850. 'DEAR_FEMO' => $currentDate,
  851. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  852. ]);
  853. } catch (\Throwable $th) {
  854. DB::rollBack();
  855. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD011: Ocurrió un error al obtener el contenido.", [], 500);
  856. }
  857. if (!$validate) {
  858. DB::rollBack();
  859. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD012: Ocurrió un error al modificar en la tabla.", [], 500);
  860. }
  861. $arrDetails = $information['DETAILS'];
  862. foreach ($arrDetails as $keyDetails => $details) {
  863. $numeroDetails = $details['NO'];
  864. if ( $details['ESTADO'] === 'Modificado' || $details['ESTADO'] === 'Activo') {
  865. try {
  866. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  867. 'INAR_CODI' => $details['CODIGO'],
  868. 'INAR_MODE' => $details['MODELO'],
  869. 'INAR_COMO' => $details['MONEDA'],
  870. 'INAR_PREC' => $details['PRECIO'],
  871. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  872. // 'INAR_CANT' => $details['CANTIDAD'],
  873. 'INAR_CARA' => $details['CARACTERISTICAS'],
  874. 'INAR_USMO' => $usuario,
  875. 'INAR_FEMO' => $currentDate,
  876. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  877. ]);
  878. } catch (\Throwable $th) {
  879. DB::rollBack();
  880. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  881. }
  882. if (!$validate) {
  883. DB::rollBack();
  884. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD014: Ocurrió un error al modificar en la tabla.", [], 500);
  885. }
  886. } else if ($details['ESTADO'] === 'Nuevo') {
  887. try {
  888. $validate = DB::table('S002V01TINAR')->insertGetId([
  889. 'INAR_IDDE' => $numeroInformation,
  890. 'INAR_CODI' => $details['CODIGO'],
  891. 'INAR_MODE' => $details['MODELO'],
  892. 'INAR_COMO' => $details['MONEDA'],
  893. 'INAR_PREC' => $details['PRECIO'],
  894. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  895. // 'INAR_CANT' => $details['CANTIDAD'],
  896. 'INAR_CARA' => $details['CARACTERISTICAS'],
  897. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  898. 'INAR_USRE' => $usuario,
  899. 'INAR_FERE' => $currentDate,
  900. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  901. ]);
  902. } catch (\Throwable $th) {
  903. DB::rollBack();
  904. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD015: Ocurrió un error al obtener el contenido.", [], 500);
  905. }
  906. if (!$validate) {
  907. DB::rollBack();
  908. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD016: Ocurrió un error al modificar en la tabla.", [], 500);
  909. }
  910. } else if ($details['ESTADO'] === 'Eliminado') {
  911. try {
  912. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  913. 'INAR_ESTA' => 'Eliminado',
  914. 'INAR_USMO' => $usuario,
  915. 'INAR_FEMO' => $currentDate,
  916. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  917. ]);
  918. } catch (\Throwable $th) {
  919. DB::rollBack();
  920. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD017: Ocurrió un error al obtener el contenido.", [], 500);
  921. }
  922. if (!$validate) {
  923. DB::rollBack();
  924. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD018: Ocurrió un error al modificar en la tabla.", [], 500);
  925. }
  926. }
  927. }
  928. } else if ($information['ESTADO'] === 'Nuevo') {
  929. $arrCodeImages = array();
  930. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  931. $idFile = $this->encController->decrypt($encIdFile);
  932. $arrCode = explode('=', $idFile);
  933. if ( count($arrCode) == 3 ) {
  934. $arrStrucuteCode = explode("-", $arrCode[0]);
  935. $nameCode = explode(".", $arrCode[2]);
  936. $validateImage = DB::table('S002V01TAFAL')->where([
  937. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  938. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  939. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  940. ['AFAL_NOAR', '=', $nameCode[0]],
  941. ['AFAL_EXTE', '=', $nameCode[1]],
  942. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  943. if (!$validateImage) {
  944. DB::rollBack();
  945. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD019: La imagen con el código $idFile no existe.", [], 500);
  946. }
  947. $arrCodeImages[] = $this->encController->encrypt($idFile);
  948. // $arrCodeImages[] = $idFile;
  949. } else {
  950. $tempFile = DB::table('S002V01TARTE')->where([
  951. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  952. ['ARTE_IDAR', '=', $idFile],
  953. ])->first();
  954. if(is_null($tempFile)){
  955. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD020: El archivo consultado no está registrado', [], 404);
  956. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  957. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD021: El archivo consultado está eliminado', [], 404);
  958. }
  959. $fileResponse = $this->documentManagementController->moveFinalFile(
  960. intval($requestData['NUMERO_LINEA']),
  961. 'GEAD',
  962. 'FO',
  963. $tempFile,
  964. $usuario,
  965. );
  966. if(!$fileResponse[0]){
  967. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD022: '.$fileResponse[1], [], 400);
  968. }
  969. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  970. // $arrCodeImages[] = $fileResponse[1];
  971. }
  972. }
  973. $jsonImages = json_encode($arrCodeImages);
  974. try {
  975. $numeroInformation = DB::table('S002V01TDEAR')->insertGetId([
  976. 'DEAR_DESC' => $information['DESCRIPCION'],
  977. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  978. 'DEAR_COWE' => $information['COMPRA_WEB'],
  979. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  980. 'DEAR_IMAG' => $jsonImages,
  981. 'DEAR_NUPR' => $information['PROVEEDOR'],
  982. 'DEAR_IDAR' => $numeroArticulo,
  983. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  984. 'DEAR_USRE' => $usuario,
  985. 'DEAR_FERE' => $currentDate,
  986. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  987. ]);
  988. } catch (\Throwable $th) {
  989. DB::rollBack();
  990. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD023: Ocurrió un error al insertar los datos de la información del artículo.", [], 500);
  991. }
  992. $arrDetails = $information['DETAILS'];
  993. foreach ($arrDetails as $keyDetails => $details) {
  994. try {
  995. DB::table('S002V01TINAR')->insertGetId([
  996. 'INAR_IDDE' => $numeroInformation,
  997. 'INAR_CODI' => $details['CODIGO'],
  998. 'INAR_MODE' => $details['MODELO'],
  999. 'INAR_COMO' => $details['MONEDA'],
  1000. 'INAR_PREC' => $details['PRECIO'],
  1001. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1002. // 'INAR_CANT' => $details['CANTIDAD'],
  1003. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1004. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1005. 'INAR_USRE' => $usuario,
  1006. 'INAR_FERE' => $currentDate,
  1007. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1008. ]);
  1009. } catch (\Throwable $th) {
  1010. DB::rollBack();
  1011. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD024: Ocurrió un error al insertar los datos de los detalles del artículo.", [], 500);
  1012. }
  1013. }
  1014. } else if ($information['ESTADO'] === 'Eliminado') {
  1015. try {
  1016. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1017. 'DEAR_ESTA' => 'Eliminado',
  1018. 'DEAR_USMO' => $usuario,
  1019. 'DEAR_FEMO' => $currentDate,
  1020. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1021. ]);
  1022. } catch (\Throwable $th) {
  1023. DB::rollBack();
  1024. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD025: Ocurrió un error al obtener el contenido.", [], 500);
  1025. }
  1026. if (!$validate) {
  1027. DB::rollBack();
  1028. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD026: Ocurrió un error al modificar en la tabla.", [], 500);
  1029. }
  1030. }
  1031. }
  1032. DB::commit(); # Para guardar los cambios en la base de datos
  1033. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1034. }
  1035. public function deleteArtitle(Request $request) {
  1036. $validator = Validator::make($request->all(), [
  1037. 'NUMERO_ARTITULO' => 'required|string',
  1038. 'NUMERO_LINEA' => 'required|string',
  1039. 'USUARIO' => 'required|string',
  1040. ]);
  1041. if ($validator->fails()) {
  1042. return $this->responseController->makeResponse(
  1043. true,
  1044. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1045. $this->responseController->makeErrors($validator->errors()->messages()),
  1046. 401
  1047. );
  1048. }
  1049. $response = $request->all();
  1050. $numeroLinea = $response['NUMERO_LINEA'];
  1051. $numeroArticulo = $this->encController->decrypt($response['NUMERO_ARTITULO']);
  1052. $usuario = $this->encController->decrypt($response['USUARIO']);
  1053. DB::beginTransaction();
  1054. $now = $this->functionsController->now();
  1055. $currentDate = $now->toDateTimeString();
  1056. try {
  1057. $resp = DB::table('S002V01TARTI')
  1058. ->where('ARTI_IDAR', '=', $numeroArticulo)
  1059. ->where('ARTI_NULI', '=', $numeroLinea)
  1060. ->update([
  1061. 'ARTI_ESTA' => 'Eliminado',
  1062. 'ARTI_USMO' => $usuario,
  1063. 'ARTI_FEMO' => $currentDate,
  1064. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1065. ]);
  1066. if (!$resp) {
  1067. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL001: Ocurrió un error al modificar en la tabla.", [], 500);
  1068. }
  1069. } catch (\Throwable $th) {
  1070. DB::rollBack();
  1071. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.", [], 500);
  1072. }
  1073. try {
  1074. $arrDescription = DB::table('S002V01TDEAR')->where('DEAR_IDAR', '=', $numeroArticulo)->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1075. } catch (\Throwable $th) {
  1076. DB::rollBack();
  1077. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al obtener los datos de la descripción del artículo", [], 500);
  1078. }
  1079. foreach ($arrDescription as $keyDescription => $description) {
  1080. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1081. try {
  1082. $resp = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroDescripcion)->where('DEAR_NULI', '=', $numeroLinea)->update([
  1083. 'DEAR_ESTA' => 'Eliminado',
  1084. 'DEAR_USMO' => $usuario,
  1085. 'DEAR_FEMO' => $currentDate,
  1086. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1087. ]);
  1088. if (!$resp) {
  1089. DB::rollBack();
  1090. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1091. }
  1092. } catch (\Throwable $th) {
  1093. DB::rollBack();
  1094. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL005: Ocurrió un error al modificar el registro.", [], 500);
  1095. }
  1096. try {
  1097. $resp = DB::table('S002V01TINAR')->where('INAR_IDDE', '=', $numeroDescripcion)->where('INAR_NULI', '=', $numeroLinea)->update([
  1098. 'INAR_ESTA' => 'Eliminado',
  1099. 'INAR_USMO' => $usuario,
  1100. 'INAR_FEMO' => $currentDate,
  1101. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1102. ]);
  1103. if (!$resp) {
  1104. DB::rollBack();
  1105. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1106. }
  1107. } catch (\Throwable $th) {
  1108. DB::rollBack();
  1109. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", [], 500);
  1110. }
  1111. }
  1112. DB::commit(); # Para guardar los cambios en la base de datos
  1113. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1114. }
  1115. public function generateArtitles(Request $request) {
  1116. $validator = Validator::make($request->all(), [
  1117. 'FILE_ZIP' => 'required',
  1118. 'NUMERO_LINEA' => 'required',
  1119. 'USUARIO' => 'required',
  1120. ]);
  1121. if ($validator->fails()) {
  1122. return $this->responseController->makeResponse(
  1123. true,
  1124. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1125. $this->responseController->makeErrors($validator->errors()->messages()),
  1126. 401
  1127. );
  1128. }
  1129. }
  1130. public function getArtitleByInformation($information, $user, $line) {
  1131. try {
  1132. $objInformation = (array) DB::table('S002V01TINAR')
  1133. ->where('INAR_IDIN', '=', $information)
  1134. ->where('INAR_ESTA', '=', 'Activo')
  1135. ->where('DEAR_ESTA', '=', 'Activo')
  1136. ->where('ARTI_ESTA', '=', 'Activo')
  1137. ->where('FAMI_ESTA', '=', 'Activo')
  1138. ->where('SUBF_ESTA', '=', 'Activo')
  1139. ->where('UNID_ESTA', '=', 'Activo')
  1140. ->where('PROV_ESTA', '=', 'Activo')
  1141. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1142. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1143. ->join('S002V01TFAMI', 'FAMI_IDFA', '=', 'ARTI_IDFA')
  1144. ->join('S002V01TSUBF', 'SUBF_IDSU', '=', 'ARTI_IDSU')
  1145. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1146. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1147. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1148. ->first([
  1149. 'INAR_IDIN', // Identificador de Información del artículo
  1150. 'INAR_CODI', // Código del artículo
  1151. 'INAR_MODE', // Modelo del artículo
  1152. // 'INAR_MONE', // Moneda
  1153. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1154. 'INAR_PREC', // Precio
  1155. // 'INAR_CANT', // Cantidad
  1156. 'INAR_CARA', // Características
  1157. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1158. 'DEAR_DESC', // Descripción del artículo
  1159. 'DEAR_CARA', // Características del artículo
  1160. 'DEAR_COWE', // Compra web
  1161. 'DEAR_IMAG', // Imagen
  1162. 'DEAR_IDUN', // Identificador de la unidad
  1163. 'UNID_NOMB', // Nombre de la unidad
  1164. 'UNID_ACRO', // Acrónimo de la familia
  1165. 'DEAR_NUPR', // Número del proveedor
  1166. 'ARTI_IDAR', // Identificador del artículo
  1167. 'ARTI_IDFA', // Identificador de la familia
  1168. 'FAMI_NOMB', // Nombre de la familia
  1169. 'ARTI_IDSU', // Identificador de la subfamilia
  1170. 'SUBF_NOMB', // Nombre de la subfamilia
  1171. 'ARTI_CODI', // Código del artículo
  1172. 'ARTI_NOMB', // Nombre del artículo
  1173. 'PROV_NOCO', // Nombre comercial
  1174. 'PROV_NOMB', // Nombre del proveedor
  1175. 'PROV_APPA', // Apellido paterno del proveedor
  1176. 'PROV_APMA', // Apellido materno del proveedor
  1177. 'PROV_CORR', // Correo electrónico
  1178. 'PROV_LAD1', // Lada 1
  1179. 'PROV_TEL1', // Teléfono 1
  1180. 'PROV_LAD2', // Lada 2
  1181. 'PROV_TEL2', // Teléfono 2
  1182. 'PROV_XRFC', // R.F.C
  1183. 'PROV_XTAX', // TAX ID
  1184. // 'PROV_GIRO', // Giro empresarial
  1185. 'PROV_TIPO', // Tipo
  1186. 'PROV_SIWE', // Sitio Web
  1187. 'PROV_MEPA', // Metodos de pago
  1188. ]);
  1189. } catch (\Throwable $th) {
  1190. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1191. }
  1192. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1193. $arrUrlImage = array();
  1194. foreach ($objInformation['DEAR_IMAG'] as $key => $imagen) {
  1195. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  1196. $arrResponseDocument = json_decode($responseDocument->original, true);
  1197. if ($arrResponseDocument['error']) {
  1198. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  1199. }
  1200. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  1201. }
  1202. $objInformation['DEAR_IMAG'] = $arrUrlImage;
  1203. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1204. }
  1205. }