ArtitleController.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 02/05/2023
  5. Módulo: Gestión de Adquisiciones
  6. */
  7. namespace App\Http\Controllers;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Carbon;
  10. use Illuminate\Support\Facades\DB;
  11. use App\Http\Controllers\Controller;
  12. use Illuminate\Support\Facades\Validator;
  13. use App\Http\Controllers\ResponseController;
  14. use App\Http\Controllers\ResourcesController;
  15. use App\Http\Controllers\EncryptionController;
  16. use App\Http\Controllers\DocumentManagementController;
  17. use App\Http\Controllers\FunctionsController;
  18. class ArtitleController extends Controller {
  19. private $responseController;
  20. private $encController;
  21. private $resourcesController;
  22. private $documentManagementController;
  23. private $functionsController;
  24. public function __construct() {
  25. $this->responseController = new ResponseController();
  26. $this->encController = new EncryptionController();
  27. $this->resourcesController = new ResourcesController();
  28. $this->documentManagementController = new DocumentManagementController();
  29. $this->functionsController = new FunctionsController();
  30. }
  31. // Función para obtener todas las familias
  32. public function getFamilies() {
  33. try {
  34. $arrFamilias = DB::table('S002V01TFAMI')
  35. ->get([
  36. 'FAMI_IDFA AS ID_FAMILIA',
  37. 'FAMI_NOMB AS FAMILIA',
  38. ]);
  39. } catch (\Throwable $th) {
  40. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETFAMILY000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  41. }
  42. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  43. }
  44. // Función para obtener todas las familias activas
  45. public function getFamiliesActives() {
  46. try {
  47. $arrFamiliasActives = DB::table('S002V01TFAMI')
  48. ->where('FAMI_ESTA', '=', 'Activo')
  49. ->get([
  50. 'FAMI_IDFA',
  51. 'FAMI_NOMB',
  52. ]);
  53. } catch (\Throwable $th) {
  54. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETFAMILIACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  55. }
  56. return $this->responseController->makeResponse(false, "ÉXITO", $arrFamiliasActives);
  57. }
  58. // Función para obtener las familias y las subfamilias activas
  59. public function getFamiliesAndSubfamilies ($line) {
  60. try {
  61. $arrFamilias = DB::table('S002V01TFAMI')
  62. ->where('FAMI_ESTA', '=', 'Activo')
  63. ->where('FAMI_NULI', '=', $line)
  64. ->get([
  65. 'FAMI_IDFA AS ID_FAMILIA',
  66. 'FAMI_NOMB AS FAMILIA',
  67. ]);
  68. } catch (\Throwable $th) {
  69. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETFAMILYS000: No se pudo realizar la consulta de las familias en la base.", $th->getMessage(), 500);
  70. }
  71. try {
  72. $arrSubfamilias = DB::table('S002V01TSUBF')
  73. ->where('SUBF_ESTA', '=', 'Activo')
  74. ->where('SUBF_NULI', '=', $line)
  75. ->get([
  76. 'SUBF_IDSU AS ID_SUBFAMILIA',
  77. 'SUBF_NOMB AS SUBFAMILIA',
  78. 'SUBF_IDFA AS ID_FAMILIA',
  79. ]);
  80. } catch (\Throwable $th) {
  81. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETFAMILYS001: No se pudo realizar la consulta de las subfamilias en la base.", $th->getMessage(), 500);
  82. }
  83. $arrFamilasAndSubfamilias = array();
  84. foreach ($arrFamilias as $keyFamilias => $familias) {
  85. $familias->SUBFAMILIAS = array();
  86. foreach ($arrSubfamilias as $keySubfamilias => $subfamilias) {
  87. if ($familias->ID_FAMILIA == $subfamilias->ID_FAMILIA) {
  88. $familias->SUBFAMILIAS[] = array(
  89. "ID_SUBFAMILIA" => $subfamilias->ID_SUBFAMILIA,
  90. "SUBFAMILIA" => $subfamilias->SUBFAMILIA,
  91. );
  92. }
  93. }
  94. }
  95. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  96. }
  97. public function registerFamily(Request $request){
  98. $valitador = Validator::make($request->all(), [
  99. 'FAMILIA' => 'required|string|max:50',
  100. 'LINE' => 'required|integer',
  101. 'USER' => 'required|string'
  102. ]);
  103. if ($valitador->fails()) {
  104. return $this->responseController->makeResponse(
  105. true,
  106. "ERR_FAMILY_REG000: Se encontraron uno o más errores.",
  107. $this->responseController->makeErrors($valitador->errors()->messages()),
  108. 401
  109. );
  110. }
  111. DB::beginTransaction();
  112. $response = $request->all();
  113. try {
  114. $usuario = $this->encController->decrypt($response['USER']);
  115. } catch (\Throwable $th) {
  116. DB::rollBack();
  117. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG001: Ocurrió un error al desencriptar los datos.", [], 401);
  118. }
  119. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  120. $now = $this->functionsController->now();
  121. $currentDate = $now->toDateTimeString();
  122. $arrInsert = [
  123. "FAMI_NOMB" => trim($response['FAMILIA']),
  124. "FAMI_USRE" => $usuario,
  125. "FAMI_NULI" => $response['LINE'],
  126. "FAMI_FERE" => $currentDate,
  127. "FAMI_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  128. ];
  129. try {
  130. $valid = DB::table('S002V01TFAMI')->insert($arrInsert);
  131. } catch (\Throwable $th) {
  132. DB::rollBack();
  133. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG002: Ocurrió un error al ingresar los registros.", [], 401);
  134. }
  135. if (!$valid) {
  136. DB::rollBack();
  137. return $this->responseController->makeResponse(true, "ERR_FAMILY_REG003: No se pudo ingresar los datos a la base de datos.", [], 401);
  138. }
  139. DB::commit();
  140. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  141. }
  142. public function getUnits($line) {
  143. try {
  144. $arrFamilias = DB::table('S002V01TUNID')
  145. ->where('UNID_NULI', '=', $line)
  146. ->get([
  147. 'UNID_IDUN AS ID_UNIDAD',
  148. 'UNID_NOMB AS UNIDAD',
  149. 'UNID_ESTA AS ESTADO',
  150. 'UNID_USRE AS USUARIO_REGISTRA',
  151. 'UNID_FERE AS FECHA_REGISTRA',
  152. 'UNID_USMO AS USUARIO_MODIFICA',
  153. 'UNID_FEMO AS FECHA_MODIFICA',
  154. ]);
  155. } catch (\Throwable $th) {
  156. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETUNITS000: No se pudo realizar la consulta a la base.", [], 500);
  157. }
  158. return $this->responseController->makeResponse(false, "ÉXITO", $arrFamilias);
  159. }
  160. public function getUnitsActives($line) {
  161. try {
  162. $arrFamilias = DB::table('S002V01TUNID')
  163. ->where('UNID_NULI', '=', $line)
  164. ->where('UNID_ESTA', '=', 'Activo')
  165. ->get([
  166. 'UNID_IDUN AS ID_UNIDAD',
  167. 'UNID_NOMB AS UNIDAD',
  168. 'UNID_USRE AS USUARIO_REGISTRA',
  169. 'UNID_FERE AS FECHA_REGISTRA',
  170. 'UNID_USMO AS USUARIO_MODIFICA',
  171. 'UNID_FEMO AS FECHA_MODIFICA',
  172. ]);
  173. } catch (\Throwable $th) {
  174. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETUNITACTIVE000: No se pudo realizar la consulta a la base.", [], 500);
  175. }
  176. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFamilias);
  177. }
  178. public function registerUnit(Request $request){
  179. $valitador = Validator::make($request->all(), [
  180. 'UNIDAD' => 'required|string|max:50',
  181. 'LINE' => 'required|integer',
  182. 'USER' => 'required|string'
  183. ]);
  184. if ($valitador->fails()) {
  185. return $this->responseController->makeResponse(
  186. true,
  187. "ERR_ARTITLE_REGUNIT000: Se encontraron uno o más errores.",
  188. $this->responseController->makeErrors($valitador->errors()->messages()),
  189. 401
  190. );
  191. }
  192. DB::beginTransaction();
  193. $response = $request->all();
  194. try {
  195. $usuario = $this->encController->decrypt($response['USER']);
  196. } catch (\Throwable $th) {
  197. DB::rollBack();
  198. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT001: Ocurrió un error al desencriptar los datos.", [], 401);
  199. }
  200. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  201. $now = $this->functionsController->now();
  202. $currentDate = $now->toDateTimeString();
  203. $arrInsert = [
  204. "UNID_NOMB" => trim($response['UNIDAD']),
  205. "UNID_USRE" => $usuario,
  206. "UNID_NULI" => $response['LINE'],
  207. "UNID_FERE" => $currentDate,
  208. "UNID_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  209. ];
  210. try {
  211. $valid = DB::table('S002V01TUNID')->insert($arrInsert);
  212. } catch (\Throwable $th) {
  213. DB::rollBack();
  214. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT002: Ocurrió un error al ingresar los registros.", [], 401);
  215. }
  216. if (!$valid) {
  217. DB::rollBack();
  218. return $this->responseController->makeResponse(true, "ERR_ARTITLE_REGUNIT003: No se pudo ingresar los datos a la base de datos.", [], 401);
  219. }
  220. DB::commit();
  221. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  222. }
  223. public function registerSubfamily(Request $request){
  224. $valitador = Validator::make($request->all(), [
  225. 'ID_FAMILIA' => 'required|integer',
  226. 'SUBFAMILIA' => 'required|string|max:50',
  227. 'LINE' => 'required|integer',
  228. 'USER' => 'required|string'
  229. ]);
  230. if ($valitador->fails()) {
  231. return $this->responseController->makeResponse(
  232. true,
  233. "ERR_SUBFAMILY_REG000: Se encontraron uno o más errores.",
  234. $this->responseController->makeErrors($valitador->errors()->messages()),
  235. 401
  236. );
  237. }
  238. DB::beginTransaction();
  239. $response = $request->all();
  240. try {
  241. $exist = DB::table('S002V01TFAMI')
  242. ->where('FAMI_IDFA', '=', trim($response['ID_FAMILIA']))
  243. ->where('FAMI_ESTA', '=', 'Activo')
  244. ->where('FAMI_NULI', '=', $response['LINE'])
  245. ->exists();
  246. } catch (\Throwable $th) {
  247. DB::rollBack();
  248. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG002: Ocurrió al verificar la Familia.", [], 401);
  249. }
  250. if (!$exist) {
  251. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG003: La Familia seleccionada no existe.", [], 401);
  252. }
  253. try {
  254. $user = $this->encController->decrypt($response['USER']);
  255. } catch (\Throwable $th) {
  256. DB::rollBack();
  257. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG001: Ocurrió un error al desencriptar los datos.", [], 401);
  258. }
  259. $now = $this->functionsController->now();
  260. $currentDate = $now->toDateTimeString();
  261. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  262. $arrInsert = [
  263. "SUBF_IDFA" => $response['ID_FAMILIA'],
  264. "SUBF_NOMB" => $response['SUBFAMILIA'],
  265. "SUBF_USRE" => $user,
  266. "SUBF_NULI" => $response['LINE'],
  267. "SUBF_FERE" => $currentDate,
  268. "SUBF_FEAR" => DB::raw('CURRENT_TIMESTAMP')
  269. ];
  270. try {
  271. $valid = DB::table('S002V01TSUBF')->insert($arrInsert);
  272. } catch (\Throwable $th) {
  273. DB::rollBack();
  274. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG004: Ocurrió un error al ingresar los registros.", [], 401);
  275. }
  276. if (!$valid) {
  277. DB::rollBack();
  278. return $this->responseController->makeResponse(true, "ERR_SUBFAMILY_REG005: No se pudo ingresar los datos a la base de datos.", [], 401);
  279. }
  280. DB::commit();
  281. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  282. }
  283. public function getArtitles($line) {
  284. try {
  285. $getArtitle = DB::table('S002V01TARTI')
  286. ->where("ARTI_NULI", "=", $line)
  287. ->where("FAMI_NULI", "=", $line)
  288. ->where("SUBF_NULI", "=", $line)
  289. ->where("DEAR_NULI", "=", $line)
  290. ->where("PROV_NULI", "=", $line)
  291. ->where("UNID_NULI", "=", $line)
  292. ->where("ARTI_ESTA", "=", "Activo")
  293. ->where("FAMI_ESTA", "=", "Activo")
  294. ->where("SUBF_ESTA", "=", "Activo")
  295. ->where("DEAR_ESTA", "=", "Activo")
  296. ->where("PROV_ESTA", "=", "Activo")
  297. ->where("UNID_ESTA", "=", "Activo")
  298. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_IDFA")
  299. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  300. ->join("S002V01TDEAR", "ARTI_IDAR", "=", "DEAR_IDAR")
  301. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  302. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  303. ->get([
  304. "DEAR_IDDE AS ID_DESC_ARTI",
  305. "ARTI_IDAR AS ID_ARTICULO",
  306. "ARTI_NOMB AS MODELO",
  307. "FAMI_IDFA AS ID_FAMILIA",
  308. "FAMI_NOMB AS FAMILIA",
  309. "SUBF_IDSU AS ID_SUBFAMILIA",
  310. "SUBF_NOMB AS SUBFAMILIA",
  311. "DEAR_DESC AS DESCRIPCION",
  312. "DEAR_CARA AS CARACTERISTICAS",
  313. "DEAR_COWE AS COMPRA_WEB",
  314. "DEAR_IDUN AS TIPO_UNIDAD",
  315. "DEAR_IMAG AS URL_IMAGEN",
  316. "PROV_NUPR AS ID_PROVEEDOR",
  317. "PROV_NOCO AS PROVEEDOR",
  318. ]);
  319. } catch (\Throwable $th) {
  320. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  321. }
  322. foreach ($getArtitle as $artitle) {
  323. $arrImagen = json_decode($artitle->URL_IMAGEN);
  324. $user = 'SFJKU29aaUtYbWwweFFzcmV4RVd6UEtNbWtlbU9VdkE3Vjg9fEU4N3pWWGFuWm5EbXBJaG1nZVl4RWJQcWtPTGZmT25H';
  325. $arrUrlImage = array();
  326. foreach ($arrImagen as $key => $imagen) {
  327. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  328. $arrResponseDocument = json_decode($responseDocument->original, true);
  329. if ($arrResponseDocument['error']) {
  330. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  331. }
  332. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  333. }
  334. $artitle->URL_IMAGEN = $arrUrlImage;
  335. }
  336. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getArtitle);
  337. }
  338. public function getArtitlesByProvider(Request $request) {
  339. $validator = Validator::make($request->all(), [
  340. 'lineNumber' => 'required|integer',
  341. 'idArtitle' => 'required|string',
  342. 'idProvider' => 'required|string'
  343. ]);
  344. if ($validator->fails()) {
  345. return $this->responseController->makeResponse(
  346. true,
  347. "ERR_ARTITLE_GETBYPROVIDER000: Se encontraron uno o más errores.",
  348. $this->responseController->makeErrors($validator->errors()->messages()),
  349. 401
  350. );
  351. }
  352. $dataRequest = $request->all();
  353. $idArtitle = $this->encController->decrypt( $dataRequest['idArtitle'] );
  354. $idProvider = $this->encController->decrypt( $dataRequest['idProvider'] );
  355. try {
  356. $objArtitle = (array) DB::table('S002V01TDEAR')
  357. ->where("ARTI_NULI", "=", $dataRequest['lineNumber'])
  358. ->where("DEAR_IDDE", "=", $idArtitle)
  359. ->where("DEAR_NUPR", "=", $idProvider)
  360. ->join("S002V01TARTI", "ARTI_IDAR", "=", "DEAR_IDAR")
  361. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_IDFA")
  362. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  363. ->join("S002V01TPROV", "DEAR_NUPR", "=", "PROV_NUPR")
  364. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  365. ->first([
  366. "DEAR_IDDE AS ID_DESC_ARTI",
  367. "ARTI_IDAR AS ID_ARTICULO",
  368. // "ARTI_CODI AS CODIGO",
  369. "ARTI_NOMB AS MODELO",
  370. "FAMI_IDFA AS ID_FAMILIA",
  371. "FAMI_NOMB AS FAMILIA",
  372. "SUBF_IDSU AS ID_SUBFAMILIA",
  373. "SUBF_NOMB AS SUBFAMILIA",
  374. "DEAR_DESC AS DESCRIPCION",
  375. "DEAR_CARA AS CARACTERISTICAS",
  376. "DEAR_COWE AS COMPRA_WEB",
  377. "UNID_IDUN AS ID_UNIDAD",
  378. "UNID_NOMB AS UNIDAD",
  379. // "DEAR_INPR AS INFO_PRODUCTO",
  380. "DEAR_IMAG AS URL_IMAGEN",
  381. "PROV_NUPR AS ID_PROVEEDOR",
  382. "PROV_NOCO AS PROVEEDOR",
  383. ]);
  384. } catch (\Throwable $th) {
  385. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  386. }
  387. if ( empty($objArtitle) ) {
  388. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER002: No se encontró el resultado deseado.", [], 500);
  389. }
  390. $objArtitle['URL_IMAGEN'] = json_decode($objArtitle['URL_IMAGEN']);
  391. try {
  392. $arrInformation = DB::table('S002V01TINAR')
  393. ->where('INAR_ESTA', '=', 'Activo')
  394. ->where('INAR_NULI', '=', $dataRequest['lineNumber'])
  395. ->where('INAR_IDDE', '=', $objArtitle['ID_DESC_ARTI'])
  396. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  397. ->get([
  398. 'INAR_IDIN AS NUMERO_INFORMACION',
  399. 'INAR_CODI AS CODIGO',
  400. 'INAR_MODE AS MODELO',
  401. // DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS MONEDA'),
  402. 'CAMO_COMO AS MONEDA',
  403. 'CAMO_DESC AS MONEDA_DESCRIPCION',
  404. 'INAR_PREC AS PRECIO',
  405. 'INAR_MOMI AS MONTO_MINIMO',
  406. 'INAR_CARA AS CARACTERISTICAS',
  407. ]);
  408. } catch (\Throwable $th) {
  409. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYPROVIDER003: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  410. }
  411. $objArtitle['INFO_PRODUCTO'] = json_encode($arrInformation);
  412. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objArtitle);
  413. }
  414. public function getArtitleById($encIdArtitle, $line) {
  415. $idArtitle = $this->encController->decrypt($encIdArtitle);
  416. try {
  417. $arrArtitle = DB::table('S002V01TARTI')
  418. ->where('ARTI_IDAR', '=', $idArtitle)
  419. ->where('ARTI_ESTA', '=', 'Activo')
  420. ->where('ARTI_NULI', '=', $line)
  421. ->join("S002V01TFAMI", "ARTI_IDFA", "=", "FAMI_IDFA")
  422. ->join("S002V01TSUBF", "ARTI_IDSU", "=", "SUBF_IDSU")
  423. ->first([
  424. 'ARTI_IDAR AS NUMERO_ARTICULO',
  425. 'ARTI_CODI AS CODIGO',
  426. "FAMI_IDFA AS ID_FAMILIA",
  427. "FAMI_NOMB AS FAMILIA",
  428. "SUBF_IDSU AS ID_SUBFAMILIA",
  429. "SUBF_NOMB AS SUBFAMILIA",
  430. 'ARTI_NOMB AS ARTICULO',
  431. ]);
  432. } catch (\Throwable $th) {
  433. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  434. }
  435. try {
  436. $arrDescription = DB::table('S002V01TDEAR')
  437. ->where('DEAR_IDAR', '=', $idArtitle)
  438. ->where('DEAR_ESTA', '=', 'Activo')
  439. ->where('DEAR_NULI', '=', $line)
  440. ->join("S002V01TUNID", "DEAR_IDUN", "=", "UNID_IDUN")
  441. ->get([
  442. 'DEAR_IDDE AS ID_DESCRIPCION',
  443. 'DEAR_DESC AS DESCRIPCION',
  444. 'DEAR_CARA AS CARACTERISTICAS',
  445. 'DEAR_COWE AS COMPRA_WEB',
  446. 'DEAR_IDUN AS TIPO_UNIDAD',
  447. 'DEAR_IMAG AS IMAGEN',
  448. 'DEAR_NUPR AS PROVEEDOR',
  449. 'DEAR_ESTA AS ESTADO',
  450. ]);
  451. } catch (\Throwable $th) {
  452. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  453. }
  454. if ( empty($arrDescription) ) {
  455. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: No se encontró ninguna descripción.", [], 500);
  456. }
  457. // Se obtienen las URL de las imagenes de los artículos
  458. foreach ($arrDescription as $description) {
  459. $arrImagen = json_decode($description->IMAGEN);
  460. $user = 'SFJKU29aaUtYbWwweFFzcmV4RVd6UEtNbWtlbU9VdkE3Vjg9fEU4N3pWWGFuWm5EbXBJaG1nZVl4RWJQcWtPTGZmT25H';
  461. $arrUrlImage = array();
  462. foreach ($arrImagen as $key => $imagen) {
  463. $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
  464. $arrResponseDocument = json_decode($responseDocument->original, true);
  465. if ($arrResponseDocument['error']) {
  466. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
  467. }
  468. $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
  469. }
  470. $description->IMAGEN = $arrUrlImage;
  471. }
  472. foreach ($arrDescription as $description) {
  473. try {
  474. $arrDetails = DB::table('S002V01TINAR')
  475. ->where('INAR_IDDE', '=', $description->ID_DESCRIPCION)
  476. ->where('INAR_ESTA', '=', 'Activo')
  477. ->where('INAR_NULI', '=', $line)
  478. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  479. ->get([
  480. 'INAR_IDIN AS NUMERO_DETALLE',
  481. 'INAR_CODI AS CODIGO',
  482. 'INAR_MODE AS MODELO',
  483. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) 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', '=', $line)
  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_CRFI 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_GETALL000: 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_REG001: 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_REG002: 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_REG003: 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_REG004: 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_REG005: 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, 'ERR_ARTITLE_REG006: El archivo consultado no está registrado', [], 404);
  658. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  659. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: 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, 'ERR_ARTITLE_REG008: '.$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_REG009: 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_COMO' => $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_REG010: 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_REG011: 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_MOD004: 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. $validateUpdate = 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. } catch (\Throwable $th) {
  818. DB::rollBack();
  819. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD005: Ocurrió un error al modificar el registro.", [], 500);
  820. }
  821. if (!$validateUpdate) {
  822. DB::rollBack();
  823. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD0006: Ocurrió un error al modificar en la tabla.", [], 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. // var_dump($idFile);
  835. $arrCode = explode('=', $idFile);
  836. if ( count($arrCode) == 3 ) {
  837. $arrStrucuteCode = explode("-", $arrCode[0]);
  838. $nameCode = explode(".", $arrCode[2]);
  839. $validateImage = DB::table('S002V01TAFAL')->where([
  840. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  841. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  842. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  843. ['AFAL_NOAR', '=', $nameCode[0]],
  844. ['AFAL_EXTE', '=', $nameCode[1]],
  845. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  846. if (!$validateImage) {
  847. DB::rollBack();
  848. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD007ERR_ARTITLE_MOD007: : La imagen con el código $idFile no existe.", [], 500);
  849. }
  850. $arrCodeImages[] = $this->encController->encrypt($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, 'ERR_ARTITLE_MOD008: El archivo consultado no está registrado', [], 404);
  858. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  859. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD009: 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, "ERR_ARTITLE_MOD010: ".$fileResponse[1], [], 400);
  870. }
  871. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  872. // $arrCodeImages[] = $fileResponse[1];
  873. }
  874. }
  875. $jsonImages = json_encode($arrCodeImages);
  876. // exit;
  877. try {
  878. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  879. 'DEAR_DESC' => $information['DESCRIPCION'],
  880. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  881. 'DEAR_COWE' => $information['COMPRA_WEB'],
  882. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  883. 'DEAR_IMAG' => $jsonImages,
  884. 'DEAR_NUPR' => $information['PROVEEDOR'],
  885. 'DEAR_USMO' => $usuario,
  886. 'DEAR_FEMO' => $currentDate,
  887. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  888. ]);
  889. } catch (\Throwable $th) {
  890. DB::rollBack();
  891. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD011: Ocurrió un error al obtener el contenido.", [], 500);
  892. }
  893. if (!$validate) {
  894. DB::rollBack();
  895. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD012: Ocurrió un error al modificar en la tabla.", [], 500);
  896. }
  897. $arrDetails = $information['DETAILS'];
  898. foreach ($arrDetails as $keyDetails => $details) {
  899. $numeroDetails = $details['NO'];
  900. if ( $details['ESTADO'] === 'Modificado' || $details['ESTADO'] === 'Activo') {
  901. try {
  902. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  903. 'INAR_CODI' => $details['CODIGO'],
  904. 'INAR_MODE' => $details['MODELO'],
  905. 'INAR_COMO' => $details['MONEDA'],
  906. 'INAR_PREC' => $details['PRECIO'],
  907. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  908. // 'INAR_CANT' => $details['CANTIDAD'],
  909. 'INAR_CARA' => $details['CARACTERISTICAS'],
  910. 'INAR_USMO' => $usuario,
  911. 'INAR_FEMO' => $currentDate,
  912. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  913. ]);
  914. } catch (\Throwable $th) {
  915. DB::rollBack();
  916. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD013: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
  917. }
  918. if (!$validate) {
  919. DB::rollBack();
  920. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD014: Ocurrió un error al modificar en la tabla.", [], 500);
  921. }
  922. } else if ($details['ESTADO'] === 'Nuevo') {
  923. try {
  924. $validate = DB::table('S002V01TINAR')->insertGetId([
  925. 'INAR_IDDE' => $numeroInformation,
  926. 'INAR_CODI' => $details['CODIGO'],
  927. 'INAR_MODE' => $details['MODELO'],
  928. 'INAR_COMO' => $details['MONEDA'],
  929. 'INAR_PREC' => $details['PRECIO'],
  930. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  931. // 'INAR_CANT' => $details['CANTIDAD'],
  932. 'INAR_CARA' => $details['CARACTERISTICAS'],
  933. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  934. 'INAR_USRE' => $usuario,
  935. 'INAR_FERE' => $currentDate,
  936. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  937. ]);
  938. } catch (\Throwable $th) {
  939. DB::rollBack();
  940. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD015: Ocurrió un error al obtener el contenido.", [], 500);
  941. }
  942. if (!$validate) {
  943. DB::rollBack();
  944. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD016: Ocurrió un error al modificar en la tabla.", [], 500);
  945. }
  946. } else if ($details['ESTADO'] === 'Eliminado') {
  947. try {
  948. $validate = DB::table('S002V01TINAR')->where('INAR_IDIN', '=', $numeroDetails)->update([
  949. 'INAR_ESTA' => 'Eliminado',
  950. 'INAR_USMO' => $usuario,
  951. 'INAR_FEMO' => $currentDate,
  952. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  953. ]);
  954. } catch (\Throwable $th) {
  955. DB::rollBack();
  956. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD017: Ocurrió un error al obtener el contenido.", [], 500);
  957. }
  958. if (!$validate) {
  959. DB::rollBack();
  960. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD018: Ocurrió un error al modificar en la tabla.", [], 500);
  961. }
  962. }
  963. }
  964. } else if ($information['ESTADO'] === 'Nuevo') {
  965. $arrCodeImages = array();
  966. foreach ($information['IMAGEN'] as $key => $encIdFile) {
  967. $idFile = $this->encController->decrypt($encIdFile);
  968. $arrCode = explode('=', $idFile);
  969. if ( count($arrCode) == 3 ) {
  970. $arrStrucuteCode = explode("-", $arrCode[0]);
  971. $nameCode = explode(".", $arrCode[2]);
  972. $validateImage = DB::table('S002V01TAFAL')->where([
  973. ['AFAL_NULI', '=', $requestData['NUMERO_LINEA']],
  974. ['AFAL_COMO', '=', $arrStrucuteCode['1']],
  975. ['AFAL_CLDO', '=', $arrStrucuteCode['2']],
  976. ['AFAL_NOAR', '=', $nameCode[0]],
  977. ['AFAL_EXTE', '=', $nameCode[1]],
  978. ])->orderBy('AFAL_NUVE', 'desc')->exists();
  979. if (!$validateImage) {
  980. DB::rollBack();
  981. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD019: La imagen con el código $idFile no existe.", [], 500);
  982. }
  983. $arrCodeImages[] = $this->encController->encrypt($idFile);
  984. // $arrCodeImages[] = $idFile;
  985. } else {
  986. $tempFile = DB::table('S002V01TARTE')->where([
  987. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  988. ['ARTE_IDAR', '=', $idFile],
  989. ])->first();
  990. if(is_null($tempFile)){
  991. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD020: El archivo consultado no está registrado', [], 404);
  992. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  993. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD021: El archivo consultado está eliminado', [], 404);
  994. }
  995. $fileResponse = $this->documentManagementController->moveFinalFile(
  996. intval($requestData['NUMERO_LINEA']),
  997. 'GEAD',
  998. 'FO',
  999. $tempFile,
  1000. $usuario,
  1001. );
  1002. if(!$fileResponse[0]){
  1003. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_MOD022: '.$fileResponse[1], [], 400);
  1004. }
  1005. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  1006. // $arrCodeImages[] = $fileResponse[1];
  1007. }
  1008. }
  1009. $jsonImages = json_encode($arrCodeImages);
  1010. try {
  1011. $numeroInformation = DB::table('S002V01TDEAR')->insertGetId([
  1012. 'DEAR_DESC' => $information['DESCRIPCION'],
  1013. 'DEAR_CARA' => $information['CARACTERISTICAS'],
  1014. 'DEAR_COWE' => $information['COMPRA_WEB'],
  1015. 'DEAR_IDUN' => $information['TIPO_UNIDAD'],
  1016. 'DEAR_IMAG' => $jsonImages,
  1017. 'DEAR_NUPR' => $information['PROVEEDOR'],
  1018. 'DEAR_IDAR' => $numeroArticulo,
  1019. 'DEAR_NULI' => $requestData['NUMERO_LINEA'],
  1020. 'DEAR_USRE' => $usuario,
  1021. 'DEAR_FERE' => $currentDate,
  1022. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1023. ]);
  1024. } catch (\Throwable $th) {
  1025. DB::rollBack();
  1026. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD023: Ocurrió un error al insertar los datos de la información del artículo.", [], 500);
  1027. }
  1028. $arrDetails = $information['DETAILS'];
  1029. foreach ($arrDetails as $keyDetails => $details) {
  1030. try {
  1031. DB::table('S002V01TINAR')->insertGetId([
  1032. 'INAR_IDDE' => $numeroInformation,
  1033. 'INAR_CODI' => $details['CODIGO'],
  1034. 'INAR_MODE' => $details['MODELO'],
  1035. 'INAR_COMO' => $details['MONEDA'],
  1036. 'INAR_PREC' => $details['PRECIO'],
  1037. 'INAR_MOMI' => $details['MONTO_MINIMO'],
  1038. // 'INAR_CANT' => $details['CANTIDAD'],
  1039. 'INAR_CARA' => $details['CARACTERISTICAS'],
  1040. 'INAR_NULI' => $requestData['NUMERO_LINEA'],
  1041. 'INAR_USRE' => $usuario,
  1042. 'INAR_FERE' => $currentDate,
  1043. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1044. ]);
  1045. } catch (\Throwable $th) {
  1046. DB::rollBack();
  1047. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD024: Ocurrió un error al insertar los datos de los detalles del artículo.", [], 500);
  1048. }
  1049. }
  1050. } else if ($information['ESTADO'] === 'Eliminado') {
  1051. try {
  1052. $validate = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroInformation)->update([
  1053. 'DEAR_ESTA' => 'Eliminado',
  1054. 'DEAR_USMO' => $usuario,
  1055. 'DEAR_FEMO' => $currentDate,
  1056. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1057. ]);
  1058. } catch (\Throwable $th) {
  1059. DB::rollBack();
  1060. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD025: Ocurrió un error al obtener el contenido.", [], 500);
  1061. }
  1062. if (!$validate) {
  1063. DB::rollBack();
  1064. return $this->responseController->makeResponse(true, "ERR_ARTITLE_MOD026: Ocurrió un error al modificar en la tabla.", [], 500);
  1065. }
  1066. }
  1067. }
  1068. DB::commit(); # Para guardar los cambios en la base de datos
  1069. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1070. }
  1071. public function deleteArtitle(Request $request) {
  1072. $validator = Validator::make($request->all(), [
  1073. 'NUMERO_ARTITULO' => 'required|string',
  1074. 'NUMERO_LINEA' => 'required|string',
  1075. 'USUARIO' => 'required|string',
  1076. ]);
  1077. if ($validator->fails()) {
  1078. return $this->responseController->makeResponse(
  1079. true,
  1080. "ERR_ARTITLE_DEL000: Se encontraron uno o más errores.",
  1081. $this->responseController->makeErrors($validator->errors()->messages()),
  1082. 401
  1083. );
  1084. }
  1085. $response = $request->all();
  1086. $numeroLinea = $response['NUMERO_LINEA'];
  1087. $numeroArticulo = $this->encController->decrypt($response['NUMERO_ARTITULO']);
  1088. $usuario = $this->encController->decrypt($response['USUARIO']);
  1089. DB::beginTransaction();
  1090. // $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
  1091. $now = $this->functionsController->now();
  1092. $currentDate = $now->toDateTimeString();
  1093. try {
  1094. $resp = DB::table('S002V01TARTI')
  1095. ->where('ARTI_IDAR', '=', $numeroArticulo)
  1096. ->where('ARTI_NULI', '=', $numeroLinea)
  1097. ->update([
  1098. 'ARTI_ESTA' => 'Eliminado',
  1099. 'ARTI_USMO' => $usuario,
  1100. 'ARTI_FEMO' => $currentDate,
  1101. 'ARTI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1102. ]);
  1103. if (!$resp) {
  1104. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL001: Ocurrió un error al modificar en la tabla.", [], 500);
  1105. }
  1106. } catch (\Throwable $th) {
  1107. DB::rollBack();
  1108. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL002: Ocurrió un error al modificar el registro.", [], 500);
  1109. }
  1110. try {
  1111. $arrDescription = DB::table('S002V01TDEAR')->where('DEAR_IDAR', '=', $numeroArticulo)->get([ 'DEAR_IDDE AS NUMERO_DESCRIPCION' ]);
  1112. } catch (\Throwable $th) {
  1113. DB::rollBack();
  1114. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL003: Ocurrió un error al obtener los datos de la descripción del artículo", [], 500);
  1115. }
  1116. foreach ($arrDescription as $keyDescription => $description) {
  1117. $numeroDescripcion = $description->NUMERO_DESCRIPCION;
  1118. try {
  1119. $resp = DB::table('S002V01TDEAR')->where('DEAR_IDDE', '=', $numeroDescripcion)->where('DEAR_NULI', '=', $numeroLinea)->update([
  1120. 'DEAR_ESTA' => 'Eliminado',
  1121. 'DEAR_USMO' => $usuario,
  1122. 'DEAR_FEMO' => $currentDate,
  1123. 'DEAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1124. ]);
  1125. if (!$resp) {
  1126. DB::rollBack();
  1127. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL004: Ocurrió un error al modificar en la tabla.", [], 500);
  1128. }
  1129. } catch (\Throwable $th) {
  1130. DB::rollBack();
  1131. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL005: Ocurrió un error al modificar el registro.", [], 500);
  1132. }
  1133. try {
  1134. $resp = DB::table('S002V01TINAR')->where('INAR_IDDE', '=', $numeroDescripcion)->where('INAR_NULI', '=', $numeroLinea)->update([
  1135. 'INAR_ESTA' => 'Eliminado',
  1136. 'INAR_USMO' => $usuario,
  1137. 'INAR_FEMO' => $currentDate,
  1138. 'INAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1139. ]);
  1140. if (!$resp) {
  1141. DB::rollBack();
  1142. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL006: Ocurrió un error al modificar en la tabla.", [], 500);
  1143. }
  1144. } catch (\Throwable $th) {
  1145. DB::rollBack();
  1146. return $this->responseController->makeResponse(true, "ERR_ARTITLE_DEL007: Ocurrió un error al modificar el registro.", [], 500);
  1147. }
  1148. }
  1149. DB::commit(); # Para guardar los cambios en la base de datos
  1150. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1151. }
  1152. public function generateArtitles(Request $request) {
  1153. $validator = Validator::make($request->all(), [
  1154. 'FILE_ZIP' => 'required',
  1155. 'NUMERO_LINEA' => 'required',
  1156. 'USUARIO' => 'required',
  1157. ]);
  1158. if ($validator->fails()) {
  1159. return $this->responseController->makeResponse(
  1160. true,
  1161. "ERR_ARTITLE_MOD000: Se encontraron uno o más errores.",
  1162. $this->responseController->makeErrors($validator->errors()->messages()),
  1163. 401
  1164. );
  1165. }
  1166. }
  1167. public function getArtitleByInformation($information, $line) {
  1168. try {
  1169. $objInformation = (array) DB::table('S002V01TINAR')
  1170. ->where('INAR_IDIN', '=', $information)
  1171. ->where('INAR_ESTA', '=', 'Activo')
  1172. ->where('DEAR_ESTA', '=', 'Activo')
  1173. ->where('ARTI_ESTA', '=', 'Activo')
  1174. ->where('FAMI_ESTA', '=', 'Activo')
  1175. ->where('SUBF_ESTA', '=', 'Activo')
  1176. ->where('UNID_ESTA', '=', 'Activo')
  1177. ->where('PROV_ESTA', '=', 'Activo')
  1178. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  1179. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'DEAR_IDAR')
  1180. ->join('S002V01TFAMI', 'FAMI_IDFA', '=', 'ARTI_IDFA')
  1181. ->join('S002V01TSUBF', 'SUBF_IDSU', '=', 'ARTI_IDSU')
  1182. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  1183. ->join('S002V01TPROV', 'PROV_NUPR', '=', 'DEAR_NUPR')
  1184. ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
  1185. ->first([
  1186. 'INAR_IDIN', // Identificador de Información del artículo
  1187. 'INAR_CODI', // Código del artículo
  1188. 'INAR_MODE', // Modelo del artículo
  1189. // 'INAR_MONE', // Moneda
  1190. DB::raw('CONCAT("(", CAMO_COMO, ") ", CAMO_DESC) AS CAMO_COMO'),
  1191. 'INAR_PREC', // Precio
  1192. // 'INAR_CANT', // Cantidad
  1193. 'INAR_CARA', // Características
  1194. 'DEAR_IDDE', // Identificador de la descripción del artículo
  1195. 'DEAR_DESC', // Descripción del artículo
  1196. 'DEAR_CARA', // Características del artículo
  1197. 'DEAR_COWE', // Compra web
  1198. 'DEAR_IMAG', // Imagen
  1199. 'DEAR_IDUN', // Identificador de la unidad
  1200. 'UNID_NOMB', // Nombre de la unidad
  1201. 'UNID_ACRO', // Acrónimo de la familia
  1202. 'DEAR_NUPR', // Número del proveedor
  1203. 'ARTI_IDAR', // Identificador del artículo
  1204. 'ARTI_IDFA', // Identificador de la familia
  1205. 'FAMI_NOMB', // Nombre de la familia
  1206. 'ARTI_IDSU', // Identificador de la subfamilia
  1207. 'SUBF_NOMB', // Nombre de la subfamilia
  1208. 'ARTI_CODI', // Código del artículo
  1209. 'ARTI_NOMB', // Nombre del artículo
  1210. 'PROV_NOCO', // Nombre comercial
  1211. 'PROV_NOMB', // Nombre del proveedor
  1212. 'PROV_APPA', // Apellido paterno del proveedor
  1213. 'PROV_APMA', // Apellido materno del proveedor
  1214. 'PROV_CORR', // Correo electrónico
  1215. 'PROV_LAD1', // Lada 1
  1216. 'PROV_TEL1', // Teléfono 1
  1217. 'PROV_LAD2', // Lada 2
  1218. 'PROV_TEL2', // Teléfono 2
  1219. 'PROV_XRFC', // R.F.C
  1220. 'PROV_XTAX', // TAX ID
  1221. 'PROV_GIRO', // Giro empresarial
  1222. 'PROV_TIPO', // Tipo
  1223. 'PROV_SIWE', // Sitio Web
  1224. 'PROV_MEPA', // Metodos de pago
  1225. ]);
  1226. } catch (\Throwable $th) {
  1227. return $this->responseController->makeResponse(true, "ERR_ARTITLE_GETBYINFORMATION000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  1228. }
  1229. $objInformation['DEAR_IMAG'] = json_decode($objInformation['DEAR_IMAG']);
  1230. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $objInformation);
  1231. }
  1232. }