ArtitleController.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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($encIdArtitle, $line) {
  424. $idArtitle = $this->encController->decrypt($encIdArtitle);
  425. try {
  426. $arrArtitle = DB::table('S002V01TARTI')
  427. ->where('ARTI_IDAR', '=', $idArtitle)
  428. ->where('ARTI_ESTA', '=', 'Activo')
  429. ->where('ARTI_NULI', '=', $line)
  430. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_IDFA")
  431. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  432. ->first([
  433. 'ARTI_IDAR AS NUMERO_ARTICULO',
  434. 'ARTI_CODI AS CODIGO',
  435. "FAMI_IDFA AS ID_FAMILIA",
  436. "FAMI_NOMB AS FAMILIA",
  437. "SUBF_IDSU AS ID_SUBFAMILIA",
  438. "SUBF_NOMB AS SUBFAMILIA",
  439. 'ARTI_NOMB AS ARTICULO',
  440. ]);
  441. } catch (\Throwable $th) {
  442. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  443. }
  444. try {
  445. $arrDescription = DB::table('S002V01TDEAR')
  446. ->where('DEAR_IDAR', '=', $idArtitle)
  447. ->where('DEAR_ESTA', '=', 'Activo')
  448. ->where('DEAR_NULI', '=', $line)
  449. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  450. ->get([
  451. 'DEAR_IDDE AS ID_DESCRIPCION',
  452. 'DEAR_DESC AS DESCRIPCION',
  453. 'DEAR_CARA AS CARACTERISTICAS',
  454. 'DEAR_COWE AS COMPRA_WEB',
  455. 'DEAR_IDUN AS TIPO_UNIDAD',
  456. 'DEAR_IMAG AS IMAGEN',
  457. 'DEAR_NUPR AS PROVEEDOR',
  458. 'DEAR_ESTA AS ESTADO',
  459. ]);
  460. } catch (\Throwable $th) {
  461. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  462. }
  463. if ( empty($arrDescription) ) {
  464. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: No se encontró ninguna descripción.", [], 500);
  465. }
  466. foreach ($arrDescription as $description) {
  467. $description->IMAGEN = json_decode($description->IMAGEN);
  468. // $description->IMAGEN = json_decode($description->IMAGEN);
  469. // var_dump($description->IMAGEN);
  470. }
  471. foreach ($arrDescription as $description) {
  472. try {
  473. $arrDetails = DB::table('S002V01TINAR')
  474. ->where('INAR_IDDE', '=', $description->ID_DESCRIPCION)
  475. ->where('INAR_ESTA', '=', 'Activo')
  476. ->where('INAR_NULI', '=', $line)
  477. ->get([
  478. 'INAR_IDIN AS NUMERO_DETALLE',
  479. 'INAR_CODI AS CODIGO',
  480. 'INAR_MODE AS MODELO',
  481. 'INAR_MONE AS MONEDA',
  482. 'INAR_PREC AS PRECIO',
  483. 'INAR_MOMI AS MONTO_MINIMO',
  484. // 'INAR_CANT AS CANTIDAD',
  485. 'INAR_CARA AS CARACTERISTICAS',
  486. 'INAR_ESTA AS ESTADO',
  487. ]);
  488. } catch (\Throwable $th) {
  489. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET004: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  490. }
  491. $description->DETALLES = $arrDetails;
  492. try {
  493. $objProdiver = DB::table('S002V01TPROV')
  494. ->where('PROV_NUPR', '=', $description->PROVEEDOR)
  495. ->where('PROV_ESTA', '=', 'Activo')
  496. ->where('PROV_NULI', '=', $line)
  497. ->first([
  498. 'PROV_NUPR AS NUMERO_PROVEEDOR',
  499. 'PROV_NOCO AS RAZON_SOCIAL',
  500. 'PROV_NOMB AS NOMBRE',
  501. 'PROV_APPA AS PRIMER_APELLIDO',
  502. 'PROV_APMA AS SEGUNDO_APELLIDO',
  503. 'PROV_CORR AS CORREO',
  504. 'PROV_LAD1 AS LADA1',
  505. 'PROV_TEL1 AS TELEFONO1',
  506. 'PROV_LAD2 AS LADA2',
  507. 'PROV_TEL2 AS TELEFONO2',
  508. 'PROV_XRFC AS RFC',
  509. 'PROV_XTAX AS TAXID',
  510. 'PROV_CORF AS GIRO_EMPRESA',
  511. 'PROV_TIPO AS TIPO_EMPRESA',
  512. 'PROV_SIWE AS SITIO_WEB',
  513. 'PROV_MEPA AS METODO_PAGO',
  514. 'PROV_USRE AS USUARIO_REGISTRA',
  515. 'PROV_FERE AS FECHA_REGISTRA',
  516. 'PROV_USMO AS USUARIO_MODIFICA',
  517. 'PROV_FEMO AS FECHA_MODIFICA',
  518. ]);
  519. $description->PROVEEDOR = $objProdiver;
  520. } catch (\Throwable $th) {
  521. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET005: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  522. }
  523. }
  524. $arrArtitle->INFORMACION = $arrDescription;
  525. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArtitle);
  526. }
  527. public function getAllArtitles($line) {
  528. try {
  529. $resp = DB::table('S002V01TARTI')
  530. ->where("ARTI_NULI", "=", $line)
  531. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_IDFA")
  532. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  533. ->get([
  534. "ARTI_IDAR AS ID_ARTICULO",
  535. "ARTI_NOMB AS MODELO",
  536. "FAMI_IDFA AS ID_FAMILIA",
  537. "FAMI_NOMB AS FAMILIA",
  538. "SUBF_IDSU AS ID_SUBFAMILIA",
  539. "SUBF_NOMB AS SUBFAMILIA",
  540. "ARTI_ESTA AS ESTADO",
  541. "ARTI_USRE AS USUARIO_REGISTRA",
  542. "ARTI_FERE AS FECHA_REGISTRA",
  543. "ARTI_USMO AS USUARIO_MODIFICA",
  544. "ARTI_FEMO AS FECHA_MODIFICA",
  545. ]);
  546. } catch (\Throwable $th) {
  547. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET000: No se pudo realizar la consulta a la base.", [], 500);
  548. }
  549. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $resp);
  550. }
  551. public function registerArtitles(Request $request) {
  552. $validator = Validator::make($request->all(), [
  553. 'CODIGO' => 'required|string',
  554. 'ARTICULO' => 'required|string',
  555. 'FAMILIA' => 'required|integer',
  556. 'SUBFAMILIA' => 'required|integer',
  557. 'INFORMATION' => 'required|array',
  558. 'USUARIO' => 'required|string',
  559. 'NUMERO_LINEA' => 'required|string',
  560. ]);
  561. if ($validator->fails()) {
  562. return $this->responseController->makeResponse(
  563. true,
  564. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  565. $this->responseController->makeErrors($validator->errors()->messages()),
  566. 401
  567. );
  568. }
  569. DB::beginTransaction();
  570. $requestData = $request->all();
  571. foreach ($requestData['INFORMATION'] as $information) {
  572. $validator = Validator::make($information, [
  573. 'NO' => 'required|string',
  574. 'IMAGEN' => 'required|array',
  575. 'DESCRIPCION' => 'required|string',
  576. // 'CARACTERISTICAS' => '|string',
  577. 'TIPO_UNIDAD' => 'required|integer',
  578. 'PROVEEDOR' => 'required|string',
  579. 'COMPRA_WEB' => 'required|boolean',
  580. 'ESTADO' => 'required|string',
  581. 'DETAILS' => 'required|array',
  582. ]);
  583. if ($validator->fails()) {
  584. return $this->responseController->makeResponse(
  585. true,
  586. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  587. $this->responseController->makeErrors($validator->errors()->messages()),
  588. 401
  589. );
  590. }
  591. foreach ($information['DETAILS'] as $details) {
  592. $validator = Validator::make($details, [
  593. 'NO' => 'required|string',
  594. 'CODIGO' => 'required|string',
  595. 'MODELO' => 'required|string',
  596. 'MONEDA' => 'required|string',
  597. 'PRECIO' => 'required|string',
  598. 'MONTO_MINIMO' => 'required|string',
  599. 'ESTADO' => 'required|string',
  600. 'CARACTERISTICAS' => 'required|string',
  601. ]);
  602. if ($validator->fails()) {
  603. return $this->responseController->makeResponse(
  604. true,
  605. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  606. $this->responseController->makeErrors($validator->errors()->messages()),
  607. 401
  608. );
  609. }
  610. }
  611. foreach ($information['IMAGEN'] as $key => $imagen) {
  612. if (gettype($imagen) != 'string') {
  613. return $this->responseController->makeResponse(
  614. true,
  615. "ERR_ARTITLE_REG000: Se encontraron uno o más errores.",
  616. "Se se obtuvieron los ID de los archivos.",
  617. 401
  618. );
  619. }
  620. }
  621. }
  622. try {
  623. $usuario = $this->encController->decrypt($requestData['USUARIO']);
  624. } catch (\Throwable $th) {
  625. DB::rollBack();
  626. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG001: No se pudo obtener los datos del usuario", $th->getMessage(), 500);
  627. }
  628. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  629. $now = $this->functionsController->now();
  630. $currentDate = $now->toDateTimeString();
  631. try {
  632. $idArtitle = DB::table('S002V01TARTI')->insertGetId([
  633. 'ARTI_CODI' => $requestData['CODIGO'],
  634. 'ARTI_IDFA' => $requestData['FAMILIA'],
  635. 'ARTI_IDSU' => $requestData['SUBFAMILIA'],
  636. 'ARTI_NOMB' => $requestData['ARTICULO'],
  637. 'ARTI_NULI' => $requestData['NUMERO_LINEA'],
  638. 'ARTI_USRE' => $usuario,
  639. 'ARTI_FERE' => $currentDate,
  640. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  641. ]);
  642. } catch (\Throwable $th) {
  643. DB::rollBack();
  644. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  645. }
  646. foreach ($requestData['INFORMATION'] as $keyInformation => $information) {
  647. $arrCodeImages = array();
  648. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  649. $idFile = $this->encController->decrypt($encIdFile);
  650. $tempFile = DB::table('S002V01TARTE')->where([
  651. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  652. ['ARTE_IDAR', '=', $idFile],
  653. ])->first();
  654. if(is_null($tempFile)){
  655. return $this->responseController->makeResponse(true, 'El archivo consultado no está registrado', [], 404);
  656. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  657. return $this->responseController->makeResponse(true, 'El archivo consultado está eliminado', [], 404);
  658. }
  659. $fileResponse = $this->documentManagementController->moveFinalFile(
  660. intval($requestData['NUMERO_LINEA']),
  661. 'GEAD',
  662. 'FO',
  663. $tempFile,
  664. $usuario,
  665. );
  666. if(!$fileResponse[0]){
  667. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  668. }
  669. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  670. }
  671. $jsonImages = json_encode($arrCodeImages);
  672. try {
  673. $idDescription = DB::table('S002V01TDEAR')->insertGetId([
  674. 'DEAR_DESC' => $information['DESCRIPCION'],
  675. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  676. 'DEAR_COWE' => $information['COMPRA_WEB'],
  677. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  678. 'DEAR_IMAG' => $jsonImages,
  679. 'DEAR_NUPR' => $information['PROVEEDOR'],
  680. 'DEAR_IDAR' => $idArtitle,
  681. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  682. 'DEAR_USRE' => $usuario,
  683. 'DEAR_FERE' => $currentDate,
  684. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  685. ]);
  686. } catch (\Throwable $th) {
  687. DB::rollBack();
  688. 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);
  689. }
  690. $arrDetails = $information['DETAILS'];
  691. foreach ($arrDetails as $keyDetails => $details) {
  692. $insertDetails = [
  693. 'INAR_IDDE' => $idDescription,
  694. 'INAR_CODI' => $details['CODIGO'],
  695. 'INAR_MODE' => $details['MODELO'],
  696. 'INAR_MONE' => $details['MONEDA'],
  697. 'INAR_PREC' => $details['PRECIO'],
  698. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  699. // 'INAR_CANT' => $details['CANTIDAD'],
  700. 'INAR_CARA' => $details['CARACTERISTICAS'],
  701. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  702. 'INAR_USRE' => $usuario,
  703. 'INAR_FERE' => $currentDate,
  704. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  705. ];
  706. try {
  707. $validateDetails = DB::table('S002V01TINAR')->insert($insertDetails);
  708. } catch (\Throwable $th) {
  709. DB::rollBack();
  710. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG005: Ocurrió un error al insertar los datos de los detalles del artículo.", $th->getMessage(), 500);
  711. }
  712. if (!$validateDetails) {
  713. DB::rollBack();
  714. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REG006: No se pudo insertar los datos de los detalles.", [], 500);
  715. }
  716. }
  717. }
  718. DB::commit();
  719. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  720. }
  721. public function updateArtitles(Request $request) {
  722. $validator = Validator::make($request->all(), [
  723. 'NO' => 'required|string',
  724. 'CODIGO' => 'required|string',
  725. 'ARTICULO' => 'required|string',
  726. 'FAMILIA' => 'required|integer',
  727. 'SUBFAMILIA' => 'required|integer',
  728. 'USUARIO' => 'required|string',
  729. 'NUMERO_LINEA' => 'required|string',
  730. 'INFORMATION' => 'required',
  731. ]);
  732. if ($validator->fails()) {
  733. return $this->responseController->makeResponse(
  734. true,
  735. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  736. $this->responseController->makeErrors($validator->errors()->messages()),
  737. 401
  738. );
  739. }
  740. DB::beginTransaction(); # Para impedir que las actualizaciones queden a incompletas
  741. $requestData = $request->all();
  742. foreach ($requestData['INFORMATION'] as $information) {
  743. $validator = Validator::make($information, [
  744. 'NO' => 'required|integer',
  745. 'IMAGEN' => 'required|array',
  746. 'DESCRIPCION' => 'required|string',
  747. // 'CARACTERISTICAS' => '|string',
  748. 'TIPO_UNIDAD' => 'required|integer',
  749. 'PROVEEDOR' => 'required|string',
  750. 'COMPRA_WEB' => 'required|boolean',
  751. 'ESTADO' => 'required|string',
  752. 'DETAILS' => 'required|array',
  753. ]);
  754. if ($validator->fails()) {
  755. return $this->responseController->makeResponse(
  756. true,
  757. "ERR_ARTITLE_MOD001: Se encontraron uno o más errores.",
  758. $this->responseController->makeErrors($validator->errors()->messages()),
  759. 401
  760. );
  761. }
  762. foreach ($information['DETAILS'] as $details) {
  763. $validator = Validator::make($details, [
  764. 'NO' => 'required|string',
  765. 'CODIGO' => 'required|string',
  766. 'MODELO' => 'required|string',
  767. 'MONEDA' => 'required|string',
  768. 'PRECIO' => 'required|string',
  769. 'MONTO_MINIMO' => 'required|string',
  770. 'ESTADO' => 'required|string',
  771. 'CARACTERISTICAS' => 'required|string',
  772. ]);
  773. if ($validator->fails()) {
  774. return $this->responseController->makeResponse(
  775. true,
  776. "ERR_ARTITLE_MOD002: Se encontraron uno o más errores.",
  777. $this->responseController->makeErrors($validator->errors()->messages()),
  778. 401
  779. );
  780. }
  781. }
  782. foreach ($information['IMAGEN'] as $key => $imagen) {
  783. if (gettype($imagen) != 'string') {
  784. return $this->responseController->makeResponse(
  785. true,
  786. "ERR_ARTITLE_MOD003: Se encontraron uno o más errores.",
  787. "Se se obtuvieron los ID de los archivos.",
  788. 401
  789. );
  790. }
  791. }
  792. }
  793. try {
  794. $usuario = $this->encController->decrypt($requestData['USUARIO']);
  795. } catch (\Throwable $th) {
  796. DB::rollBack();
  797. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD001: Ocurrió un error al desencriptar el usuario.", [], 500);
  798. }
  799. $now = $this->functionsController->now();
  800. $currentDate = $now->toDateTimeString();
  801. $numeroArticulo = $requestData['NO'];
  802. try {
  803. $resp = DB::table('S002V01TARTI')
  804. ->where('ARTI_IDAR', '=', $numeroArticulo)
  805. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  806. ->update([
  807. 'ARTI_CODI' => $requestData['CODIGO'],
  808. 'ARTI_IDFA' => $requestData['FAMILIA'],
  809. 'ARTI_IDSU' => $requestData['SUBFAMILIA'],
  810. 'ARTI_NOMB' => $requestData['ARTICULO'],
  811. 'ARTI_USMO' => $usuario,
  812. 'ARTI_FEMO' => $currentDate,
  813. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  814. ]);
  815. if (!$resp) {
  816. DB::rollBack();
  817. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD002: Ocurrió un error al modificar en la tabla.", [], 500);
  818. }
  819. } catch (\Throwable $th) {
  820. DB::rollBack();
  821. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD003: Ocurrió un error al modificar el registro.", [], 500);
  822. }
  823. $arrInformation = $requestData['INFORMATION'];
  824. foreach ($arrInformation as $keyInformation => $information) {
  825. // Número de ID de información
  826. $numeroInformation = $information['NO'];
  827. // Se verifica si la información ya está registrado o no
  828. if ($information['ESTADO'] === 'Modificado' || $information['ESTADO'] === 'Activo') {
  829. $arrCodeImages = array();
  830. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  831. var_dump($encIdFile);
  832. $idFile = $this->encController->decrypt($encIdFile);
  833. $arrCode = explode('=', $idFile);
  834. if ( count($arrCode) == 3 ) {
  835. $arrStrucuteCode = explode("-", $arrCode[0]);
  836. $nameCode = explode(".", $arrCode[2]);
  837. $validateImage = DB::table('S002V01TAFAL')->where([
  838. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  839. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  840. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  841. ['AFAL_NOAR', '=', $nameCode[0]],
  842. ['AFAL_EXTE', '=', $nameCode[1]],
  843. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  844. if (!$validateImage) {
  845. DB::rollBack();
  846. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD003: La imagen con el código $idFile no existe.", [], 500);
  847. }
  848. $arrCodeImages[] = $this->encController->encrypt($idFile);
  849. // $arrCodeImages[] = $idFile;
  850. } else {
  851. $tempFile = DB::table('S002V01TARTE')->where([
  852. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  853. ['ARTE_IDAR', '=', $idFile],
  854. ])->first();
  855. if(is_null($tempFile)){
  856. return $this->responseController->makeResponse(true, 'El archivo consultado no está registrado', [], 404);
  857. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  858. return $this->responseController->makeResponse(true, 'El archivo consultado está eliminado', [], 404);
  859. }
  860. $fileResponse = $this->documentManagementController->moveFinalFile(
  861. intval($requestData['NUMERO_LINEA']),
  862. 'GEAD',
  863. 'FO',
  864. $tempFile,
  865. $usuario,
  866. );
  867. if(!$fileResponse[0]){
  868. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  869. }
  870. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  871. // $arrCodeImages[] = $fileResponse[1];
  872. }
  873. }
  874. $jsonImages = json_encode($arrCodeImages);
  875. try {
  876. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  877. 'DEAR_DESC' => $information['DESCRIPCION'],
  878. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  879. 'DEAR_COWE' => $information['COMPRA_WEB'],
  880. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  881. 'DEAR_IMAG' => $jsonImages,
  882. 'DEAR_NUPR' => $information['PROVEEDOR'],
  883. 'DEAR_USMO' => $usuario,
  884. 'DEAR_FEMO' => $currentDate,
  885. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  886. ]);
  887. } catch (\Throwable $th) {
  888. DB::rollBack();
  889. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD004: Ocurrió un error al obtener el contenido.", [], 500);
  890. }
  891. if (!$validate) {
  892. DB::rollBack();
  893. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD005: Ocurrió un error al modificar en la tabla.", [], 500);
  894. }
  895. $arrDetails = $information['DETAILS'];
  896. foreach ($arrDetails as $keyDetails => $details) {
  897. $numeroDetails = $details['NO'];
  898. if ( $details['ESTADO'] === 'Modificado' || $details['ESTADO'] === 'Activo') {
  899. try {
  900. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  901. 'INAR_CODI' => $details['CODIGO'],
  902. 'INAR_MODE' => $details['MODELO'],
  903. 'INAR_MONE' => $details['MONEDA'],
  904. 'INAR_PREC' => $details['PRECIO'],
  905. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  906. // 'INAR_CANT' => $details['CANTIDAD'],
  907. 'INAR_CARA' => $details['CARACTERISTICAS'],
  908. 'INAR_USMO' => $usuario,
  909. 'INAR_FEMO' => $currentDate,
  910. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  911. ]);
  912. } catch (\Throwable $th) {
  913. DB::rollBack();
  914. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD006: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  915. }
  916. if (!$validate) {
  917. DB::rollBack();
  918. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD007: Ocurrió un error al modificar en la tabla.", [], 500);
  919. }
  920. } else if ($details['ESTADO'] === 'Nuevo') {
  921. try {
  922. $validate = DB::table('S002V01TINAR')->insertGetId([
  923. 'INAR_IDDE' => $numeroInformation,
  924. 'INAR_CODI' => $details['CODIGO'],
  925. 'INAR_MODE' => $details['MODELO'],
  926. 'INAR_MONE' => $details['MONEDA'],
  927. 'INAR_PREC' => $details['PRECIO'],
  928. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  929. // 'INAR_CANT' => $details['CANTIDAD'],
  930. 'INAR_CARA' => $details['CARACTERISTICAS'],
  931. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  932. 'INAR_USRE' => $usuario,
  933. 'INAR_FERE' => $currentDate,
  934. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  935. ]);
  936. } catch (\Throwable $th) {
  937. DB::rollBack();
  938. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD008: Ocurrió un error al obtener el contenido.", [], 500);
  939. }
  940. if (!$validate) {
  941. DB::rollBack();
  942. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD009: Ocurrió un error al modificar en la tabla.", [], 500);
  943. }
  944. } else if ($details['ESTADO'] === 'Eliminado') {
  945. try {
  946. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  947. 'INAR_ESTA' => 'Eliminado',
  948. 'INAR_USMO' => $usuario,
  949. 'INAR_FEMO' => $currentDate,
  950. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  951. ]);
  952. } catch (\Throwable $th) {
  953. DB::rollBack();
  954. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD010: Ocurrió un error al obtener el contenido.", [], 500);
  955. }
  956. if (!$validate) {
  957. DB::rollBack();
  958. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD011: Ocurrió un error al modificar en la tabla.", [], 500);
  959. }
  960. }
  961. }
  962. } else if ($information['ESTADO'] === 'Nuevo') {
  963. $arrCodeImages = array();
  964. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  965. $idFile = $this->encController->decrypt($encIdFile);
  966. $arrCode = explode('=', $idFile);
  967. if ( count($arrCode) == 3 ) {
  968. $arrStrucuteCode = explode("-", $arrCode[0]);
  969. $nameCode = explode(".", $arrCode[2]);
  970. $validateImage = DB::table('S002V01TAFAL')->where([
  971. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  972. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  973. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  974. ['AFAL_NOAR', '=', $nameCode[0]],
  975. ['AFAL_EXTE', '=', $nameCode[1]],
  976. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  977. if (!$validateImage) {
  978. DB::rollBack();
  979. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD003: La imagen con el código $idFile no existe.", [], 500);
  980. }
  981. $arrCodeImages[] = $this->encController->encrypt($idFile);
  982. // $arrCodeImages[] = $idFile;
  983. } else {
  984. $tempFile = DB::table('S002V01TARTE')->where([
  985. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  986. ['ARTE_IDAR', '=', $idFile],
  987. ])->first();
  988. if(is_null($tempFile)){
  989. return $this->responseController->makeResponse(true, 'El archivo consultado no está registrado', [], 404);
  990. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  991. return $this->responseController->makeResponse(true, 'El archivo consultado está eliminado', [], 404);
  992. }
  993. $fileResponse = $this->documentManagementController->moveFinalFile(
  994. intval($requestData['NUMERO_LINEA']),
  995. 'GEAD',
  996. 'FO',
  997. $tempFile,
  998. $usuario,
  999. );
  1000. if(!$fileResponse[0]){
  1001. return $this->responseController->makeResponse(true, $fileResponse[1], [], 400);
  1002. }
  1003. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  1004. // $arrCodeImages[] = $fileResponse[1];
  1005. }
  1006. }
  1007. $jsonImages = json_encode($arrCodeImages);
  1008. try {
  1009. $numeroInformation = DB::table('S002V01TDEAR')->insertGetId([
  1010. 'DEAR_DESC' => $information['DESCRIPCION'],
  1011. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  1012. 'DEAR_COWE' => $information['COMPRA_WEB'],
  1013. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  1014. 'DEAR_IMAG' => $jsonImages,
  1015. 'DEAR_NUPR' => $information['PROVEEDOR'],
  1016. 'DEAR_IDAR' => $numeroArticulo,
  1017. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  1018. 'DEAR_USRE' => $usuario,
  1019. 'DEAR_FERE' => $currentDate,
  1020. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1021. ]);
  1022. } catch (\Throwable $th) {
  1023. DB::rollBack();
  1024. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD013: Ocurrió un error al insertar los datos de la información del artículo.", [], 500);
  1025. }
  1026. $arrDetails = $information['DETAILS'];
  1027. foreach ($arrDetails as $keyDetails => $details) {
  1028. try {
  1029. DB::table('S002V01TINAR')->insertGetId([
  1030. 'INAR_IDDE' => $numeroInformation,
  1031. 'INAR_CODI' => $details['CODIGO'],
  1032. 'INAR_MODE' => $details['MODELO'],
  1033. 'INAR_MONE' => $details['MONEDA'],
  1034. 'INAR_PREC' => $details['PRECIO'],
  1035. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1036. // 'INAR_CANT' => $details['CANTIDAD'],
  1037. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1038. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1039. 'INAR_USRE' => $usuario,
  1040. 'INAR_FERE' => $currentDate,
  1041. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1042. ]);
  1043. } catch (\Throwable $th) {
  1044. DB::rollBack();
  1045. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD014: Ocurrió un error al insertar los datos de los detalles del artículo.", [], 500);
  1046. }
  1047. }
  1048. } else if ($information['ESTADO'] === 'Eliminado') {
  1049. try {
  1050. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1051. 'DEAR_ESTA' => 'Eliminado',
  1052. 'DEAR_USMO' => $usuario,
  1053. 'DEAR_FEMO' => $currentDate,
  1054. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1055. ]);
  1056. } catch (\Throwable $th) {
  1057. DB::rollBack();
  1058. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD015: Ocurrió un error al obtener el contenido.", [], 500);
  1059. }
  1060. if (!$validate) {
  1061. DB::rollBack();
  1062. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD016: Ocurrió un error al modificar en la tabla.", [], 500);
  1063. }
  1064. }
  1065. }
  1066. DB::commit(); # Para guardar los cambios en la base de datos
  1067. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1068. }
  1069. public function deleteArtitle(Request $request) {
  1070. $validator = Validator::make($request->all(), [
  1071. 'NUMERO_ARTITULO' => 'required|string',
  1072. 'NUMERO_LINEA' => 'required|string',
  1073. 'USUARIO' => 'required|string',
  1074. ]);
  1075. if ($validator->fails()) {
  1076. return $this->responseController->makeResponse(
  1077. true,
  1078. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1079. $this->responseController->makeErrors($validator->errors()->messages()),
  1080. 401
  1081. );
  1082. }
  1083. $response = $request->all();
  1084. $numeroLinea = $response['NUMERO_LINEA'];
  1085. $numeroArticulo = $this->encController->decrypt($response['NUMERO_ARTITULO']);
  1086. $usuario = $this->encController->decrypt($response['USUARIO']);
  1087. DB::beginTransaction();
  1088. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  1089. $now = $this->functionsController->now();
  1090. $currentDate = $now->toDateTimeString();
  1091. try {
  1092. $resp = DB::table('S002V01TARTI')
  1093. ->where('ARTI_IDAR', '=', $numeroArticulo)
  1094. ->where('ARTI_NULI', '=', $numeroLinea)
  1095. ->update([
  1096. 'ARTI_ESTA' => 'Eliminado',
  1097. 'ARTI_USMO' => $usuario,
  1098. 'ARTI_FEMO' => $currentDate,
  1099. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1100. ]);
  1101. if (!$resp) {
  1102. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL001: Ocurrió un error al modificar en la tabla.", [], 500);
  1103. }
  1104. } catch (\Throwable $th) {
  1105. DB::rollBack();
  1106. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.", [], 500);
  1107. }
  1108. try {
  1109. $arrDescription = DB::table('S002V01TDEAR')->where('DEAR_IDAR', '=', $numeroArticulo)->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1110. } catch (\Throwable $th) {
  1111. DB::rollBack();
  1112. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al obtener los datos de la descripción del artículo", [], 500);
  1113. }
  1114. foreach ($arrDescription as $keyDescription => $description) {
  1115. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1116. try {
  1117. $resp = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroDescripcion)->where('DEAR_NULI', '=', $numeroLinea)->update([
  1118. 'DEAR_ESTA' => 'Eliminado',
  1119. 'DEAR_USMO' => $usuario,
  1120. 'DEAR_FEMO' => $currentDate,
  1121. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1122. ]);
  1123. if (!$resp) {
  1124. DB::rollBack();
  1125. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1126. }
  1127. } catch (\Throwable $th) {
  1128. DB::rollBack();
  1129. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL005: Ocurrió un error al modificar el registro.", [], 500);
  1130. }
  1131. try {
  1132. $resp = DB::table('S002V01TINAR')->where('INAR_IDDE', '=', $numeroDescripcion)->where('INAR_NULI', '=', $numeroLinea)->update([
  1133. 'INAR_ESTA' => 'Eliminado',
  1134. 'INAR_USMO' => $usuario,
  1135. 'INAR_FEMO' => $currentDate,
  1136. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1137. ]);
  1138. if (!$resp) {
  1139. DB::rollBack();
  1140. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1141. }
  1142. } catch (\Throwable $th) {
  1143. DB::rollBack();
  1144. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", [], 500);
  1145. }
  1146. }
  1147. DB::commit(); # Para guardar los cambios en la base de datos
  1148. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1149. }
  1150. public function generateArtitles(Request $request) {
  1151. $validator = Validator::make($request->all(), [
  1152. 'FILE_ZIP' => 'required',
  1153. 'NUMERO_LINEA' => 'required',
  1154. 'USUARIO' => 'required',
  1155. ]);
  1156. if ($validator->fails()) {
  1157. return $this->responseController->makeResponse(
  1158. true,
  1159. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1160. $this->responseController->makeErrors($validator->errors()->messages()),
  1161. 401
  1162. );
  1163. }
  1164. }
  1165. public function getArtitleByInformation($information, $line) {
  1166. try {
  1167. $objInformation = (array) DB::table('S002V01TINAR')
  1168. ->where('INAR_IDIN', '=', $information)
  1169. ->where('INAR_ESTA', '=', 'Activo')
  1170. ->where('DEAR_ESTA', '=', 'Activo')
  1171. ->where('ARTI_ESTA', '=', 'Activo')
  1172. ->where('FAMI_ESTA', '=', 'Activo')
  1173. ->where('SUBF_ESTA', '=', 'Activo')
  1174. ->where('UNID_ESTA', '=', 'Activo')
  1175. ->where('PROV_ESTA', '=', 'Activo')
  1176. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1177. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1178. ->join('S002V01TFAMI', 'FAMI_IDFA', '=', 'ARTI_IDFA')
  1179. ->join('S002V01TSUBF', 'SUBF_IDSU', '=', 'ARTI_IDSU')
  1180. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1181. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1182. ->first([
  1183. 'INAR_IDIN', // Identificador de Información del artículo
  1184. 'INAR_CODI', // Código del artículo
  1185. 'INAR_MODE', // Modelo del artículo
  1186. 'INAR_MONE', // Moneda
  1187. 'INAR_PREC', // Precio
  1188. // 'INAR_CANT', // Cantidad
  1189. 'INAR_CARA', // Características
  1190. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1191. 'DEAR_DESC', // Descripción del artículo
  1192. 'DEAR_CARA', // Características del artículo
  1193. 'DEAR_COWE', // Compra web
  1194. 'DEAR_IMAG', // Imagen
  1195. 'DEAR_IDUN', // Identificador de la unidad
  1196. 'UNID_NOMB', // Nombre de la unidad
  1197. 'UNID_ACRO', // Acrónimo de la familia
  1198. 'DEAR_NUPR', // Número del proveedor
  1199. 'ARTI_IDAR', // Identificador del artículo
  1200. 'ARTI_IDFA', // Identificador de la familia
  1201. 'FAMI_NOMB', // Nombre de la familia
  1202. 'ARTI_IDSU', // Identificador de la subfamilia
  1203. 'SUBF_NOMB', // Nombre de la subfamilia
  1204. 'ARTI_CODI', // Código del artículo
  1205. 'ARTI_NOMB', // Nombre del artículo
  1206. 'PROV_NOCO', // Nombre comercial
  1207. 'PROV_NOMB', // Nombre del proveedor
  1208. 'PROV_APPA', // Apellido paterno del proveedor
  1209. 'PROV_APMA', // Apellido materno del proveedor
  1210. 'PROV_CORR', // Correo electrónico
  1211. 'PROV_LAD1', // Lada 1
  1212. 'PROV_TEL1', // Teléfono 1
  1213. 'PROV_LAD2', // Lada 2
  1214. 'PROV_TEL2', // Teléfono 2
  1215. 'PROV_XRFC', // R.F.C
  1216. 'PROV_XTAX', // TAX ID
  1217. 'PROV_GIRO', // Giro empresarial
  1218. 'PROV_TIPO', // Tipo
  1219. 'PROV_SIWE', // Sitio Web
  1220. 'PROV_MEPA', // Metodos de pago
  1221. ]);
  1222. } catch (\Throwable $th) {
  1223. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1224. }
  1225. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1226. // $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1227. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1228. }
  1229. }