ArtitleController.php 63 KB

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