ArtitleController.php 54 KB

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