ArtitleController.php 63 KB

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