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