RequestLineController.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 27/04/2023
  5. Módulo: Gestión de Adquisiciones
  6. */
  7. namespace App\Http\Controllers;
  8. use App\Http\Controllers\ResponseController;
  9. use App\Http\Controllers\EncryptionController;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Carbon;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Validator;
  14. use App\Http\Controllers\FunctionsController;
  15. class RequestLineController extends Controller
  16. {
  17. private $responseController;
  18. private $encController;
  19. private $documentManagementController;
  20. private $functionsController;
  21. private $resourcesController;
  22. private $processManagementController;
  23. public function __construct(){
  24. $this->responseController = new ResponseController();
  25. $this->encController = new EncryptionController();
  26. $this->documentManagementController = new DocumentManagementController();
  27. $this->functionsController = new FunctionsController();
  28. $this->resourcesController = new ResourcesController();
  29. $this->processManagementController = new ProcessManagementController();
  30. }
  31. // Se registran las líneas de solicitud
  32. public function createRequestLine(Request $request){
  33. $validator = Validator::make($request->all(), [
  34. 'LINE' => 'required|integer',
  35. 'USER' => 'required|string',
  36. 'PRODUCTS' => 'required|array',
  37. 'PURPOSE' => 'required',
  38. ]);
  39. if ($validator->fails()) {
  40. return $this->responseController->makeResponse(
  41. true,
  42. "ERR_REQUESTLINE_REG000: Se encontraron uno o más errores.",
  43. $this->responseController->makeErrors($validator->errors()->messages()),
  44. 401
  45. );
  46. }
  47. DB::beginTransaction();
  48. $requestData = $request->all();
  49. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USER'], $requestData['LINE']);
  50. if ($arrResponseCheckUser['error']) {
  51. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  52. }
  53. $user = $arrResponseCheckUser['response'];
  54. $idOrderPreventive = null;
  55. if ($requestData['PURPOSE']['PROPOSITO'] == 'MANT-PREV') {
  56. $idOrderPreventive = $requestData['PURPOSE']['ID'];
  57. try {
  58. $validateExistsPreventive = DB::table('S002V01TOTPR')
  59. ->where('OTPR_NULI', '=', $requestData['LINE'])
  60. ->where('OTPR_IDOT', '=', $idOrderPreventive )
  61. ->exists();
  62. } catch (\Throwable $th) {
  63. DB::rollBack();
  64. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG002: Ocurrió un error al validar la orden de mantenimiento preventivo.", $th->getMessage(), 500);
  65. }
  66. if (!$validateExistsPreventive) {
  67. DB::rollBack();
  68. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG003: La orden de mantenimiento preventivo no existe", [], 500);
  69. }
  70. }
  71. $idOrderCorrective = null;
  72. if ($requestData['PURPOSE']['PROPOSITO'] == 'MANT-CORR') {
  73. $idOrderCorrective = $requestData['PURPOSE']['ID'];
  74. try {
  75. $validateExistsCorrective = DB::table('S002V01TOTCO')
  76. ->where('OTCO_NULI', '=', $requestData['LINE'])
  77. ->where('OTCO_IDOT', '=', $idOrderCorrective )
  78. ->exists();
  79. } catch (\Throwable $th) {
  80. DB::rollBack();
  81. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG004: Ocurrió un error al validar la orden de mantenimiento correctivo.", $th->getMessage(), 500);
  82. }
  83. if (!$validateExistsCorrective) {
  84. DB::rollBack();
  85. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG005: La orden de mantenimiento correctivo no existe", [], 500);
  86. }
  87. }
  88. $arrArtitles = array();
  89. $count = 0;
  90. foreach ($requestData['PRODUCTS'] as $keyProducts => $products) {
  91. if ($keyProducts === 0) {
  92. $arrArtitles[$count] = [
  93. "NUMERO_ARTICULO" => $products['NUMERO_ARTICULO'],
  94. "NUMERO_PROVEEDOR" => $products['NUMERO_PROVEEDOR'],
  95. "NUMERO_INFORMACION" => $products['NUMERO_INFORMACION'],
  96. "CANTIDAD" => 1,
  97. ];
  98. $count++;
  99. } else {
  100. $find = false;
  101. foreach ($arrArtitles as $key => $value) {
  102. if (
  103. $value['NUMERO_ARTICULO'] === $products['NUMERO_ARTICULO'] &&
  104. $value['NUMERO_PROVEEDOR'] === $products['NUMERO_PROVEEDOR'] &&
  105. $value['NUMERO_INFORMACION'] === $products['NUMERO_INFORMACION']
  106. ) {
  107. $arrArtitles[$key]['CANTIDAD']++;
  108. $find = true;
  109. }
  110. }
  111. if ($find === false) {
  112. $arrArtitles[$count] = [
  113. "NUMERO_ARTICULO" => $products['NUMERO_ARTICULO'],
  114. "NUMERO_PROVEEDOR" => $products['NUMERO_PROVEEDOR'],
  115. "NUMERO_INFORMACION" => $products['NUMERO_INFORMACION'],
  116. "CANTIDAD" => 1,
  117. ];
  118. $count++;
  119. }
  120. }
  121. }
  122. $arrToWorkflow = array();
  123. foreach ($arrArtitles as $articles) {
  124. try {
  125. $arrArticle = (array) DB::table('S002V01TARTI')
  126. ->where('ARTI_IDAR', '=', $articles['NUMERO_ARTICULO'])
  127. ->where('INAR_IDIN', '=', $articles['NUMERO_INFORMACION'])
  128. ->where('ARTI_NULI', '=', $requestData['LINE'])
  129. ->where('DEAR_NULI', '=', $requestData['LINE'])
  130. ->where('INAR_NULI', '=', $requestData['LINE'])
  131. ->where('ARTI_ESTA', '=', 'Activo')
  132. ->where('DEAR_ESTA', '=', 'Activo')
  133. ->where('INAR_ESTA', '=', 'Activo')
  134. ->join('S002V01TDEAR', 'DEAR_IDAR', '=', 'ARTI_IDAR')
  135. ->join('S002V01TINAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  136. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  137. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  138. ->first([
  139. DB::raw('CONCAT(FAMI_NOFA, " (", FAMI_COFA, ")") AS FAMILIA'),
  140. DB::raw('CONCAT(SUBF_NOSU, " (", SUBF_COSU, ")") AS SUBFAMILIA'),
  141. 'INAR_MODE AS MODELO',
  142. 'INAR_CODI AS CODIGO_MODELO',
  143. DB::raw('CONCAT("$ ", INAR_PREC, " ", INAR_COMO) AS PRECIO'),
  144. ]);
  145. } catch (\Throwable $th) {
  146. DB::rollBack();
  147. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG005: No se pudo obtener la información de los productos.", $th->getMessage(), 500);
  148. }
  149. $arrArticle['CANTIDAD'] = $articles['CANTIDAD'];
  150. $arrArticle['NUMERO_PROVEEDOR'] = $articles['NUMERO_PROVEEDOR'];
  151. $arrToWorkflow[] = $arrArticle;
  152. }
  153. $strToWorkflow = json_encode($arrToWorkflow);
  154. $encToWorkflow = $this->encController->encrypt($strToWorkflow);
  155. $now = $this->functionsController->now();
  156. $currentDate = $now->toDateTimeString();
  157. $arrProviders = array_unique(array_column($requestData['PRODUCTS'], 'NUMERO_PROVEEDOR'));
  158. $arrInfoRegistro = array();
  159. foreach ($arrProviders as $provider) {
  160. try {
  161. $idRegisterLine = DB::table('S002V01TLINE')->insertGetId([
  162. 'LINE_NUPR' => $provider,
  163. 'LINE_OTPR' => $idOrderPreventive,
  164. 'LINE_OTCO' => $idOrderCorrective,
  165. 'LINE_NULI' => $requestData['LINE'],
  166. 'LINE_ESTA' => 'Workflow',
  167. 'LINE_USRE' => $user,
  168. 'LINE_FERE' => $currentDate,
  169. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  170. ]);
  171. } catch (\Throwable $th) {
  172. DB::rollBack();
  173. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG006: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
  174. }
  175. if ($idRegisterLine == null || $idRegisterLine <= 0) {
  176. DB::rollBack();
  177. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG007: Ocurrió un error al hacer la inserción en la base.", [], 500);
  178. }
  179. $arrInfoRegistro['S002V01TLINE'][] = [
  180. 'LINE_IDLI' => $idRegisterLine,
  181. ];
  182. $nuar = 0;
  183. foreach ($requestData['PRODUCTS'] as $products) {
  184. if ($products['NUMERO_PROVEEDOR'] === $provider) {
  185. try {
  186. $validateInsert = DB::table('S002V01TARSE')->insert([
  187. 'ARSE_IDAS' => $nuar,
  188. 'ARSE_NULI' => $requestData['LINE'],
  189. 'ARSE_IDLI' => $idRegisterLine,
  190. 'ARSE_IDAR' => $products['NUMERO_ARTICULO'],
  191. 'ARSE_NUPR' => $products['NUMERO_PROVEEDOR'],
  192. 'ARSE_IDIN' => $products['NUMERO_INFORMACION'],
  193. 'ARSE_USRE' => $user,
  194. 'ARSE_FERE' => $currentDate,
  195. 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  196. ]);
  197. } catch (\Throwable $th) {
  198. DB::rollBack();
  199. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG008: Ocurrió un error al insertar los artículos en la base de datos.", $th->getMessage(), 500);
  200. }
  201. if (!$validateInsert) {
  202. DB::rollBack();
  203. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG009: No se pudo insertar los datos en la base de datos.", [], 500);
  204. }
  205. $nuar = $nuar + 1;
  206. }
  207. }
  208. }
  209. $strInfoRegistro = json_encode($arrInfoRegistro);
  210. $encInfoRegistro = $this->encController->encrypt($strInfoRegistro);
  211. $arrResponseRequestWorkflow = $this->processManagementController->registerRequestWorkflow(1, $encToWorkflow, $encInfoRegistro, $user, $requestData['LINE']);
  212. if ($arrResponseRequestWorkflow['error']) {
  213. DB::rollBack();
  214. return $this->responseController->makeResponse(true, $arrResponseRequestWorkflow['msg'], $arrResponseRequestWorkflow['response'], 500);
  215. }
  216. DB::commit();
  217. return $this->responseController->makeResponse(false, "ÉXITO: Registro correcto");
  218. }
  219. public function getAllRequestLines($user, $line) {
  220. try {
  221. $arrRequestLines = DB::table('S002V01TLINE')
  222. ->where("LINE_NULI", "=", $line)
  223. ->where("LINE_ESTA", "!=", 'Workflow')
  224. ->where("LINE_ESTA", "!=", 'Workflow Rechazado')
  225. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
  226. ->get([
  227. 'LINE_IDLI AS ID_LINEA_SOLICITUD',
  228. 'LINE_NUPR AS NUMERO_PROVEEDOR',
  229. 'PROV_NOCO AS NOMBRE_COMERCIAL',
  230. 'LINE_OTPR AS ORDEN_TRABAJO_PREVENTIVO',
  231. 'LINE_OTCO AS ORDEN_TRABAJO_CORRECTIVO',
  232. 'LINE_ESTA AS ESTADO',
  233. 'LINE_USRE AS USUARIO_REGISTRA',
  234. 'LINE_FERE AS FECHA_REGISTRA',
  235. 'LINE_USMO AS USUARIO_MODIFICA',
  236. 'LINE_FEMO AS FECHA_MODIFICA',
  237. ]);
  238. } catch (\Throwable $th) {
  239. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  240. }
  241. $arrRequestLines = json_decode(json_encode($arrRequestLines), true);
  242. $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrRequestLines, $line);
  243. if ($responseCheckLatestUpdate['error']) {
  244. return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
  245. }
  246. $arrRequestLines = $responseCheckLatestUpdate['response'];
  247. try {
  248. $arrOrders= DB::table('S002V01TORCO')
  249. ->where("ORCO_NULI", "=", $line)
  250. ->get([
  251. 'ORCO_NUOR AS NUMERO_ORDEN',
  252. 'ORCO_IDLI AS ID_LINEA_SOLICITUD',
  253. 'ORCO_IDDE AS ID_DESPACHO',
  254. 'ORCO_ESTA AS ESTADO',
  255. ]);
  256. } catch (\Throwable $th) {
  257. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  258. }
  259. $arrOrders = json_decode(json_encode($arrOrders), true);
  260. foreach ($arrRequestLines as $keyRequest => $requestLine) {
  261. try {
  262. $getSelected = DB::table('S002V01TARSE')
  263. ->where('ARSE_IDLI', '=', $requestLine['ID_LINEA_SOLICITUD'])
  264. ->where('ARSE_NULI', '=', $line)
  265. ->where('INAR_NULI', '=', $line)
  266. ->where('DEAR_NULI', '=', $line)
  267. ->where('ARTI_NULI', '=', $line)
  268. ->where('FAMI_NULI', '=', $line)
  269. ->where('SUBF_NULI', '=', $line)
  270. ->where('UNID_NULI', '=', $line)
  271. ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
  272. ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
  273. ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
  274. ->join('S002V01TFAMI','FAMI_COFA','=','ARTI_COFA')
  275. ->join('S002V01TSUBF','SUBF_COSU','=','ARTI_COSU')
  276. ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
  277. ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
  278. ->get([
  279. 'ARSE_IDAS AS ID_ARTICULO_SELECCIONADO',
  280. 'ARSE_NUPR AS NUMERO_PROVEEDOR',
  281. 'ARSE_ESTA AS ESTADO',
  282. 'INAR_IDIN AS NUMERO_INFORMACION',
  283. 'INAR_CODI AS CODIGO_INFORMACION',
  284. 'INAR_MODE AS MODELO_INFORMACION',
  285. 'CAMO_COMO AS CODIGO_MONEDA',
  286. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  287. 'INAR_PREC AS PRECIO_UNITARIO',
  288. 'INAR_MOMI AS MONTO_MINIMO',
  289. 'INAR_CARA AS CARACTERISTICAS_INFORMACION',
  290. 'DEAR_IDDE AS NUMERO_DESCRIPCION',
  291. 'DEAR_IMAG AS IMAGENES',
  292. 'DEAR_DESC AS DESCRIPCION',
  293. 'DEAR_CARA AS CARACTERISTICAS',
  294. 'DEAR_COWE AS COMPRA_WEB',
  295. 'ARTI_IDAR AS NUMERO_ARTICULO',
  296. 'ARTI_CODI AS CODIGO',
  297. 'ARTI_NOMB AS ARTICULO',
  298. 'FAMI_COFA AS CODIGO_FAMILIA',
  299. 'FAMI_NOFA AS NOMBRE_FAMILIA',
  300. 'SUBF_COSU AS CODIGO_SUBFAMILIA',
  301. 'SUBF_NOSU AS NOMBRE_SUBFAMILIA',
  302. 'UNID_IDUN AS ID_UNIDAD',
  303. 'UNID_NOMB AS NOMBRE_UNIDAD',
  304. 'UNID_ACRO AS ACRONIMO_UNIDAD',
  305. ]);
  306. } catch (\Throwable $th) {
  307. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  308. }
  309. $arrSelected = json_decode(json_encode($getSelected), true);
  310. $index = 0;
  311. $arrArtitles = array();
  312. foreach ($arrSelected as $keyArtitle => $artitles) {
  313. if ($keyArtitle === 0) {
  314. $arrArtitles[$index] = $artitles;
  315. $arrArtitles[$index]['CANTIDAD'] = 1;
  316. } else {
  317. if (
  318. in_array($artitles['NUMERO_INFORMACION'], array_column($arrArtitles, 'NUMERO_INFORMACION'))
  319. ) {
  320. $indexArtitle = array_search($artitles['NUMERO_INFORMACION'], array_column($arrArtitles, 'NUMERO_INFORMACION'));
  321. $arrArtitles[$indexArtitle]['CANTIDAD'] = $arrArtitles[$indexArtitle]['CANTIDAD'] + 1;
  322. } else {
  323. $index = $index + 1;
  324. $arrArtitles[$index] = $artitles;
  325. $arrArtitles[$index]['CANTIDAD'] = 1;
  326. }
  327. }
  328. }
  329. foreach ($arrArtitles as $keySelected => $selected) {
  330. $arrImagen = json_decode($selected['IMAGENES']);
  331. $arrUrlImage = array();
  332. foreach ($arrImagen as $key => $imagen) {
  333. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($imagen, $user, $line);
  334. if ($responseDocument['error']) {
  335. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  336. }
  337. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  338. }
  339. $arrArtitles[$keySelected]['IMAGENES'] = $arrUrlImage;
  340. }
  341. foreach ($arrOrders as $order) {
  342. if ($requestLine['ID_LINEA_SOLICITUD'] == $order['ID_LINEA_SOLICITUD']) {
  343. $requestLine['NUMERO_ORDEN'] = $order['NUMERO_ORDEN'];
  344. }
  345. }
  346. if (!array_key_exists('LINE_NUOR', $requestLine)) {
  347. $requestLine['NUMERO_ORDEN'] = null;
  348. }
  349. $arrRequestLines[$keyRequest] = $requestLine;
  350. $arrRequestLines[$keyRequest]['SELECTED'] = $arrArtitles;
  351. }
  352. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrRequestLines);
  353. }
  354. // Se obtiene una línea de solicitud en específico
  355. public function getRequestLine($encIdRequestLine, $user, $line){
  356. try {
  357. $idRequestLine = $this->encController->decrypt($encIdRequestLine);
  358. } catch (\Throwable $th) {
  359. return $this->responseController->makeResponse(true, "ERR_ORDER_GET000: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  360. }
  361. try {
  362. $arrRequestLines = DB::table('S002V01TLINE')
  363. ->where("LINE_NULI", "=", $line)
  364. ->where("LINE_IDLI", "=", $idRequestLine)
  365. ->first([
  366. 'LINE_IDLI AS ID_LINEA_SOLICITUD',
  367. 'LINE_ESTA AS ESTADO',
  368. 'LINE_IDME AS METODO_PAGO',
  369. 'LINE_FERE AS FECHA_REGISTRA',
  370. 'LINE_FEMO AS FECHA_MODIFICA',
  371. 'LINE_USRE AS USUARIO_REGISTRA',
  372. 'LINE_USMO AS USUARIO_MODIFICA'
  373. ]);
  374. } catch (\Throwable $th) {
  375. return $this->responseController->makeResponse(true, "ERR_ORDER_GET001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  376. }
  377. try {
  378. $arrProducts = DB::table('S002V01TARSE')
  379. ->where("ARSE_NULI", "=", $line)
  380. ->where('ARSE_IDLI', '=', $idRequestLine)
  381. ->where('PROV_ESTA', '=', 'Activo')
  382. ->join('S002V01TPROV', 'ARSE_NUPR', '=', 'PROV_NUPR')
  383. ->join('S002V01TINAR', 'ARSE_IDIN', '=', 'INAR_IDIN')
  384. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  385. ->get([
  386. 'ARSE_IDAS AS NUMERO_ARTI_SELE',
  387. 'ARSE_IDAR AS NUMERO_ARTICULO',
  388. 'ARSE_NUPR AS NUMERO_PRODUCTO',
  389. 'INAR_MODE AS MODELO',
  390. 'INAR_CODI AS CODIGO',
  391. 'INAR_CARA AS CARACTERISTICAS',
  392. 'ARSE_CANT AS CANTIDAD',
  393. 'INAR_PREC AS PRECIO_UNITARIO',
  394. 'CAMO_COMO AS MONEDA',
  395. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  396. // 'ARSE_PRTO AS PRECIO_TOTAL',
  397. 'ARSE_ESTA AS ESTADO',
  398. 'ARSE_USRE AS USUARIO_REGISTRA',
  399. 'ARSE_FERE AS FECHA_REGISTRA',
  400. 'ARSE_USMO AS USUARIO_MODIFICA',
  401. 'ARSE_FEMO AS FECHA_MODIFICA',
  402. 'PROV_NUPR AS NUMERO_PROVEEDOR',
  403. 'PROV_NOCO AS PROVEEDOR',
  404. 'PROV_ESTA AS ESTADO_PROVEEDOR'
  405. ]);
  406. foreach ($arrProducts as $productos) {
  407. if ($productos == 'Eliminado') {
  408. return $this->responseController->makeResponse(true, "ERR_ORDER_GET002: Existe un usuario en la solicitud que se encuentra eliminado", [], 500);
  409. }
  410. }
  411. $arrRequestLines->PRODUCTOS = $arrProducts;
  412. } catch (\Throwable $th) {
  413. return $this->responseController->makeResponse(true, "ERR_ORDER_GET003: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  414. }
  415. return $this->responseController->makeResponse(false, "ÉXITO", $arrRequestLines);
  416. }
  417. // Se cancalan la linea de solicitud de compra
  418. public function cancelRequestLine(Request $request){
  419. $validator = Validator::make($request->all(), [
  420. 'ID_LINEA_SOLICITUD' => 'required|string',
  421. 'NUMERO_PROVEEDOR' => 'required|string',
  422. 'NUMERO_LINEA' => 'required|integer',
  423. 'USUARIO' => 'required|string',
  424. ]);
  425. if ($validator->fails()) {
  426. return $this->responseController->makeResponse(
  427. true,
  428. "ERR_REQUESTLINE_CAN000: Se encontraron uno o más errores.",
  429. $this->responseController->makeErrors($validator->errors()->messages()),
  430. 401
  431. );
  432. }
  433. DB::beginTransaction();
  434. $requestData = $request->all();
  435. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  436. if ($arrResponseCheckUser['error']) {
  437. DB::rollBack();
  438. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN001:'.$arrResponseCheckUser['msg'], [], 401);
  439. }
  440. $user = $arrResponseCheckUser['response'];
  441. try {
  442. $requestData['ID_LINEA_SOLICITUD'] = $this->encController->decrypt($requestData['ID_LINEA_SOLICITUD']);
  443. } catch (\Throwable $th) {
  444. DB::rollBack();
  445. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN002: Ocurrió un error al desencriptar la línea de solicitud de compra.', $th->getMessage(), 500);
  446. }
  447. try {
  448. $requestData['NUMERO_PROVEEDOR'] = $this->encController->decrypt($requestData['NUMERO_PROVEEDOR']);
  449. } catch (\Throwable $th) {
  450. DB::rollBack();
  451. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN003: Ocurrió un error al desencriptar el número de proveedor.', $th->getMessage(), 500);
  452. }
  453. $now = $this->functionsController->now();
  454. $currentDate = $now->toDateTimeString();
  455. try {
  456. $validateExists = DB::table('S002V01TPROV')
  457. ->where('PROV_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  458. ->where('PROV_NULI', '=', $requestData['NUMERO_LINEA'])
  459. ->where('PROV_ESTA', '=', 'Activo')
  460. ->exists();
  461. } catch (\Throwable $th) {
  462. DB::rollBack();
  463. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN004: Ocurrió un error al verificar el número del proveedor.', $th->getMessage(), 500);
  464. }
  465. if (!$validateExists) {
  466. DB::rollBack();
  467. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN005: El número del proveedor no existe.', [], 500);
  468. }
  469. try {
  470. $validateExists = DB::table('S002V01TLINE')
  471. ->where('LINE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  472. ->where('LINE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  473. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  474. ->exists();
  475. } catch (\Throwable $th) {
  476. DB::rollBack();
  477. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN006: Ocurrió un error al verificar la línea de solicitud de compra.', $th->getMessage(), 500);
  478. }
  479. if (!$validateExists) {
  480. DB::rollBack();
  481. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN007: La linea de solicitud de compra no existe.', [], 500);
  482. }
  483. try {
  484. $validateUpdate = DB::table('S002V01TLINE')
  485. ->where('LINE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  486. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  487. ->where('LINE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  488. ->update([
  489. 'LINE_ESTA' => 'Cancelado',
  490. 'LINE_USMO' => $user,
  491. 'LINE_FEMO' => $currentDate,
  492. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  493. ]);
  494. } catch (\Throwable $th) {
  495. DB::rollBack();
  496. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN008: Ocurrió un error al modificar la línea de solicitud de compra.', $th->getMessage(), 500);
  497. }
  498. if (!$validateUpdate) {
  499. DB::rollBack();
  500. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN009: No se pudo cancelar la solicitud de compra.', [], 500);
  501. }
  502. try {
  503. $validateUpdate = DB::table('S002V01TARSE')
  504. ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
  505. ->where('ARSE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  506. ->where('ARSE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  507. ->update([
  508. 'ARSE_ESTA' => 'Eliminado',
  509. 'ARSE_USMO' => $user,
  510. 'ARSE_FEMO' => $currentDate,
  511. 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  512. ]);
  513. } catch (\Throwable $th) {
  514. DB::rollBack();
  515. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN010: Ocurrió un error al modificar la línea de solicitud de compra.', $th->getMessage(), 500);
  516. }
  517. if (!$validateUpdate) {
  518. DB::rollBack();
  519. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_CAN011: No se pudo eliminar los artículos seleccionados.', [], 500);
  520. }
  521. DB::commit();
  522. return $this->responseController->makeResponse(false, "ÉXITO: Cancelación Exitosa");
  523. }
  524. public function deleteArtitleByRequestLine(Request $request) {
  525. $validator = Validator::make($request->all(), [
  526. 'USUARIO' => 'required|string',
  527. 'NUMERO_LINEA' => 'required|integer',
  528. 'NUMERO_INFORMACION' => 'required|string',
  529. 'NUMERO_PROVEEDOR' => 'required|string',
  530. 'NUMERO_ARTICULO' => 'required|string',
  531. 'ID_LINEA_SOLICITUD' => 'required|string',
  532. ]);
  533. if ($validator->fails()) {
  534. return $this->responseController->makeResponse(
  535. true,
  536. "ERR_REQUESTLINE_DEL000: Se encontraron uno o más errores.",
  537. $this->responseController->makeErrors($validator->errors()->messages()),
  538. 401
  539. );
  540. }
  541. DB::beginTransaction();
  542. $requestData = $request->all();
  543. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  544. if ($arrResponseCheckUser['error']) {
  545. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD004:'.$arrResponseCheckUser['msg'], [], 401);
  546. }
  547. $user = $arrResponseCheckUser['response'];
  548. try {
  549. $requestData['NUMERO_INFORMACION'] = $this->encController->decrypt($requestData['NUMERO_INFORMACION']);
  550. } catch (\Throwable $th) {
  551. DB::rollBack();
  552. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL002: Ocurrió un error al obtener el número de información.", $th->getMessage(), 500);
  553. }
  554. try {
  555. $requestData['ID_LINEA_SOLICITUD'] = $this->encController->decrypt($requestData['ID_LINEA_SOLICITUD']);
  556. } catch (\Throwable $th) {
  557. DB::rollBack();
  558. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL003: Ocurrió un error al obtener la línea de solicitud de compra.", $th->getMessage(), 500);
  559. }
  560. try {
  561. $requestData['NUMERO_PROVEEDOR'] = $this->encController->decrypt($requestData['NUMERO_PROVEEDOR']);
  562. } catch (\Throwable $th) {
  563. DB::rollBack();
  564. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL004: Ocurrió un error al obtener el número del proveedor.", $th->getMessage(), 500);
  565. }
  566. try {
  567. $requestData['NUMERO_ARTICULO'] = $this->encController->decrypt($requestData['NUMERO_ARTICULO']);
  568. } catch (\Throwable $th) {
  569. DB::rollBack();
  570. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL005: Ocurrió un error al obtener el número del artículo.", $th->getMessage(), 500);
  571. }
  572. $now = $this->functionsController->now();
  573. $currentDate = $now->toDateTimeString();
  574. try {
  575. $validateExists = DB::table('S002V01TLINE')
  576. ->where('LINE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  577. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  578. ->exists();
  579. } catch (\Throwable $th) {
  580. DB::rollBack();
  581. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL006: Ocurrió un error al verificar si existe la línea de solicitud de comrpa.", $th->getMessage(), 500);
  582. }
  583. if (!$validateExists) {
  584. DB::rollBack();
  585. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL007: El número de línea de solicitud de compra no existe.", [], 500);
  586. }
  587. try {
  588. $validateExists = DB::table('S002V01TARTI')
  589. ->where('ARTI_IDAR', '=', $requestData['NUMERO_ARTICULO'])
  590. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  591. ->where('ARTI_ESTA', '=', 'Activo')
  592. ->exists();
  593. } catch (\Throwable $th) {
  594. DB::rollBack();
  595. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL008: Ocurrió un error al verificar si existe el número del artículo.", $th->getMessage(), 500);
  596. }
  597. if (!$validateExists) {
  598. DB::rollBack();
  599. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL009: El número del artículo no existe.", [], 500);
  600. }
  601. try {
  602. $validateExists = DB::table('S002V01TPROV')
  603. ->where('PROV_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  604. ->where('PROV_NULI', '=', $requestData['NUMERO_LINEA'])
  605. ->where('PROV_ESTA', '=', 'Activo')
  606. ->exists();
  607. } catch (\Throwable $th) {
  608. DB::rollBack();
  609. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL010: Ocurrió un error al verificar si existe el número de proveedor.", $th->getMessage(), 500);
  610. }
  611. if (!$validateExists) {
  612. DB::rollBack();
  613. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL011: El número de proveedor no existe.", [], 500);
  614. }
  615. try {
  616. $validateExists = DB::table('S002V01TINAR')
  617. ->where('INAR_IDIN', '=', $requestData['NUMERO_INFORMACION'])
  618. ->where('INAR_NULI', '=', $requestData['NUMERO_LINEA'])
  619. ->where('INAR_ESTA', '=', 'Activo')
  620. ->exists();
  621. } catch (\Throwable $th) {
  622. DB::rollBack();
  623. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL012: Ocurrió un error al verificar si existe el numero de información del artículo.", $th->getMessage(), 500);
  624. }
  625. if (!$validateExists) {
  626. DB::rollBack();
  627. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL013: El número de información del artículo no existe.", [], 500);
  628. }
  629. try {
  630. $existsSelected = DB::table('S002V01TARSE')
  631. ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
  632. ->where('ARSE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  633. ->where('ARSE_IDAR', '=', $requestData['NUMERO_ARTICULO'])
  634. ->where('ARSE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  635. ->where('ARSE_IDIN', '=', $requestData['NUMERO_INFORMACION'])
  636. ->exists();
  637. } catch (\Throwable $th) {
  638. DB::rollBack();
  639. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL014: Ocurrió un error al modificar los artículos seleccionados.", $th->getMessage(), 500);
  640. }
  641. if (!$existsSelected) {
  642. DB::rollBack();
  643. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL015: No existen artículos asociados a la información obtenida.", [], 500);
  644. }
  645. try {
  646. $validateUpdate = DB::table('S002V01TARSE')
  647. ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
  648. ->where('ARSE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  649. ->where('ARSE_IDAR', '=', $requestData['NUMERO_ARTICULO'])
  650. ->where('ARSE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  651. ->where('ARSE_IDIN', '=', $requestData['NUMERO_INFORMACION'])
  652. ->update([
  653. 'ARSE_ESTA' => 'Eliminado',
  654. 'ARSE_USMO' => $user,
  655. 'ARSE_FEMO' => $currentDate,
  656. 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  657. ]);
  658. } catch (\Throwable $th) {
  659. DB::rollBack();
  660. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL016: Ocurrió un error al modificar los artículos seleccionados.", $th->getMessage(), 500);
  661. }
  662. if (!$validateUpdate) {
  663. DB::rollBack();
  664. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL017: Ocurrió un error al eliminar el artículo seleccionado.", [], 500);
  665. }
  666. try {
  667. $existsArtitles = DB::table('S002V01TARSE')
  668. ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
  669. ->where('ARSE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  670. ->where('ARSE_ESTA', '=', 'Activo')
  671. ->exists();
  672. } catch (\Throwable $th) {
  673. DB::rollBack();
  674. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL018: Ocurrió un error al verificar los artículos disponibles.", $th->getMessage(), 500);
  675. }
  676. if (!$existsArtitles) {
  677. try {
  678. $validateUpdate = DB::table('S002V01TLINE')
  679. ->where('LINE_IDLI', '=', $requestData['ID_LINEA_SOLICITUD'])
  680. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  681. ->where('LINE_NUPR', '=', $requestData['NUMERO_PROVEEDOR'])
  682. ->update([
  683. 'LINE_ESTA' => 'Cancelado',
  684. 'LINE_USMO' => $user,
  685. 'LINE_FEMO' => $currentDate,
  686. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  687. ]);
  688. } catch (\Throwable $th) {
  689. DB::rollBack();
  690. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL019: Ocurrió un error al cancelar la línea de solicitud de compra.", $th->getMessage(), 500);
  691. }
  692. if (!$validateUpdate) {
  693. DB::rollBack();
  694. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL020: No se pudo cancelar la línea de solicitud de compra.", [], 500);
  695. }
  696. }
  697. DB::commit();
  698. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Correcta");
  699. }
  700. public function updateStatusRequestLine(Request $request) {
  701. $validator = Validator::make($request->all(), [
  702. 'NUMERO_SOLICITUD' => 'required|string',
  703. 'ESTADO' => 'required|string',
  704. 'USUARIO' => 'required|string',
  705. 'METODO_PAGO' => 'required|string',
  706. 'NUMERO_LINEA' => 'required|integer',
  707. // 'COMENTARIOS' => 'string',
  708. ]);
  709. if ($validator->fails()) {
  710. return $this->responseController->makeResponse(
  711. true,
  712. "ERR_ORDER_UPST000: Se encontraron uno o más errores.",
  713. $this->responseController->makeErrors($validator->errors()->messages()),
  714. 401
  715. );
  716. }
  717. DB::beginTransaction();
  718. $requestData = $request->all();
  719. try {
  720. $user = $this->encController->decrypt($requestData['USUARIO']);
  721. } catch (\Throwable $th) {
  722. DB::rollBack();
  723. return $this->responseController->makeResponse(true, "ERR_ORDER_UPST001: Ocurrió un error al obtener el usuario.", [], 500);
  724. }
  725. $now = $this->functionsController->now();
  726. $currentDate = $now->toDateTimeString();
  727. try {
  728. $validateUpdate = DB::table('S002V01TLINE')
  729. ->where('LINE_IDLI', '=', $requestData['NUMERO_SOLICITUD'])
  730. ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
  731. ->update([
  732. 'LINE_ESTA' => $requestData['ESTADO'],
  733. 'LINE_IDME' => $requestData['METODO_PAGO'],
  734. 'LINE_COME' => $requestData['COMENTARIOS'] === '' ? null : $requestData['COMENTARIOS'],
  735. 'LINE_USMO' => $user,
  736. 'LINE_FEMO' => $currentDate,
  737. 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  738. ]);
  739. } catch (\Throwable $th) {
  740. DB::rollBack();
  741. return $this->responseController->makeResponse(true, "ERR_ORDER_UPST002: Ocurrió un error al modificar el estado.", $th->getMessage(), 500);
  742. }
  743. if ( !$validateUpdate ) {
  744. DB::rollBack();
  745. return $this->responseController->makeResponse(true, "ERR_ORDER_UPST003: No se pudo modificar el estado de la línea de solicitud.", [], 500);
  746. }
  747. DB::commit();
  748. return $this->responseController->makeResponse(false, "ÉXITO: Modificación de Estado Exitoso");
  749. }
  750. public function getArtitlesByRequestLine($requestLine, $user, $line) {
  751. try {
  752. $requestLine = $this->encController->decrypt($requestLine);
  753. } catch (\Throwable $th) {
  754. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GETBY000: Ocurrió un error al obtener la línea de solicitud.", $th->getMessage(), 500);
  755. }
  756. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  757. if ($arrResponseCheckUser['error']) {
  758. return $this->responseController->makeResponse(true, 'ERR_REQUESTLINE_GETBY001:'.$arrResponseCheckUser['msg'], [], 401);
  759. }
  760. try {
  761. $getArtitleSelected = DB::table('S002V01TARSE')
  762. ->where('ARSE_IDLI', '=', $requestLine)
  763. ->where('ARSE_NULI', '=', $line)
  764. ->where('INAR_NULI', '=', $line)
  765. ->where('DEAR_NULI', '=', $line)
  766. ->where('ARTI_NULI', '=', $line)
  767. ->where('FAMI_NULI', '=', $line)
  768. ->where('SUBF_NULI', '=', $line)
  769. ->where('UNID_NULI', '=', $line)
  770. ->where('ARSE_ESTA', '=', 'Activo')
  771. ->where('INAR_ESTA', '=', 'Activo')
  772. ->where('DEAR_ESTA', '=', 'Activo')
  773. ->where('ARTI_ESTA', '=', 'Activo')
  774. ->where('FAMI_ESTA', '=', 'Activo')
  775. ->where('SUBF_ESTA', '=', 'Activo')
  776. ->where('UNID_ESTA', '=', 'Activo')
  777. ->join('S002V01TINAR', 'INAR_IDIN', '=', 'ARSE_IDIN')
  778. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  779. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  780. ->join('S002V01TFAMI', 'FAMI_COFA', '=', 'ARTI_COFA')
  781. ->join('S002V01TSUBF', 'SUBF_COSU', '=', 'ARTI_COSU')
  782. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  783. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  784. ->get([
  785. 'ARTI_IDAR AS NUMERO_ARTICULO',
  786. 'DEAR_IDDE AS NUMERO_DESCRIPCION',
  787. 'DEAR_NUPR AS NUMERO_PROVEEDOR',
  788. 'DEAR_IMAG AS IMAGENES',
  789. 'ARTI_NOMB AS ARTICULO',
  790. 'INAR_CARA AS CARACTERISTICAS',
  791. 'INAR_CODI AS CODIGO',
  792. 'INAR_MODE AS MODELO',
  793. 'CAMO_COMO AS MONEDA',
  794. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  795. 'INAR_MOMI AS MONTO_MINIMO',
  796. 'INAR_IDIN AS NUMERO_INFORMACION',
  797. 'INAR_PREC AS PRECIO',
  798. ]);
  799. } catch (\Throwable $th) {
  800. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GETBY002: Ocurrió un error al obtener la información.", $th->getMessage(), 500);
  801. }
  802. $arrArtitleSelected = json_decode(json_encode($getArtitleSelected), true);
  803. $index = 0;
  804. $arrArtitles = array();
  805. foreach ($arrArtitleSelected as $keyArtitle => $artitles) {
  806. if ($keyArtitle === 0) {
  807. $arrArtitles[$index] = $artitles;
  808. $arrArtitles[$index]['CANTIDAD'] = 1;
  809. } else {
  810. if (
  811. in_array($artitles['NUMERO_INFORMACION'], array_column($arrArtitles, 'NUMERO_INFORMACION'))
  812. ) {
  813. $indexArtitle = array_search($artitles['NUMERO_INFORMACION'], array_column($arrArtitles, 'NUMERO_INFORMACION'));
  814. $arrArtitles[$indexArtitle]['CANTIDAD'] = $arrArtitles[$indexArtitle]['CANTIDAD'] + 1;
  815. } else {
  816. $index = $index + 1;
  817. $arrArtitles[$index] = $artitles;
  818. $arrArtitles[$index]['CANTIDAD'] = 1;
  819. }
  820. }
  821. }
  822. $arrArtitleSelected = $arrArtitles;
  823. foreach ($arrArtitleSelected as $keyArtitleSelected => $artitleSelected) {
  824. $arrImage = json_decode($artitleSelected['IMAGENES']);
  825. $arrUrlImage = array();
  826. foreach ($arrImage as $key => $encImage) {
  827. $responseDocument = $this->documentManagementController->privateGetPublicDocumentURL($encImage, $user, $line);
  828. if ($responseDocument['error']) {
  829. return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GETBY003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  830. }
  831. $arrUrlImage[] = $responseDocument['response']['public_uri'];
  832. }
  833. $artitleSelected['IMAGENES'] = $arrUrlImage;
  834. $arrArtitleSelected[$keyArtitleSelected] = $artitleSelected;
  835. }
  836. return $this->responseController->makeResponse(false, "ÉXITO", $arrArtitleSelected);
  837. }
  838. }