StockController.php 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 11/04/2023
  5. Módulo: Gestión de Inventario y/o Stock
  6. */
  7. namespace App\Http\Controllers;
  8. use App\Http\Controllers\Controller;
  9. use App\Http\Controllers\ResourcesController;
  10. use App\Http\Controllers\ResponseController;
  11. use App\Http\Controllers\EncryptionController;
  12. use App\Http\Controllers\DocumentManagementController;
  13. use Illuminate\Database\Query\JoinClause;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Validator;
  17. use App\Http\Controllers\FunctionsController;
  18. class StockController extends Controller
  19. {
  20. private $responseController;
  21. private $encController;
  22. private $resourcesController;
  23. private $documentManagementController;
  24. private $functionsController;
  25. public function __construct(){
  26. $this->responseController = new ResponseController();
  27. $this->encController = new EncryptionController();
  28. $this->resourcesController = new ResourcesController();
  29. $this->documentManagementController = new DocumentManagementController();
  30. $this->functionsController = new FunctionsController();
  31. }
  32. public function getWarehouse( $user, $line ) {
  33. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  34. if ($arrResponseCheckUser['error']) {
  35. DB::rollBack();
  36. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  37. }
  38. try {
  39. $arrWarehouse = DB::table('S002V01TALMA')
  40. ->where('ALMA_NULI', '=', $line)
  41. ->get([
  42. 'ALMA_COAL AS CODIGO_ALMACEN',
  43. 'ALMA_NOAL AS NOMBRE_ALMACEN',
  44. 'ALMA_NORE AS NOMBRE_RESPONSABLE',
  45. 'ALMA_APRE AS APELLIDO_PATERNO_RESPONSABLE',
  46. 'ALMA_AMRE AS APELLIDO_MATERNO_RESPONSABLE',
  47. 'ALMA_COR1 AS CORREO1',
  48. 'ALMA_COR2 AS CORREO2',
  49. 'ALMA_LAD1 AS LADA1',
  50. 'ALMA_TEL1 AS TELEFONO1',
  51. 'ALMA_LAD2 AS LADA2',
  52. 'ALMA_TEL2 AS TELEFONO2',
  53. 'ALMA_CALL AS CALLE',
  54. 'ALMA_NUEX AS NUMERO_EXTERIOR',
  55. 'ALMA_NUIN AS NUMERO_INTERIOR',
  56. 'ALMA_COPO AS CODIGO_POSTAL',
  57. 'ALMA_COLO AS COLONIA',
  58. 'ALMA_LOCA AS LOCALIDAD',
  59. 'ALMA_MUNI AS MUNICIPIO',
  60. 'ALMA_ENTI AS ENTIDAD_FEDERATIVA',
  61. 'ALMA_PAIS AS PAIS',
  62. 'ALMA_ESTA AS ESTADO',
  63. 'ALMA_USRE AS USUARIO_REGISTRA',
  64. 'ALMA_FERE AS FECHA_REGISTRA',
  65. 'ALMA_USMO AS USUARIO_MODIFICA',
  66. 'ALMA_FEMO AS FECHA_MODIFICA',
  67. ]);
  68. $arrWarehouse = json_decode( json_encode($arrWarehouse), true );
  69. } catch (\Throwable $th) {
  70. DB::rollBack();
  71. return $this->responseController->makeResponse(
  72. true,
  73. "ERR_WAREHOUSE_GET001: Ocurrió un error al obtener los almacenes.",
  74. $th->getMessage(),
  75. 500
  76. );
  77. }
  78. foreach ($arrWarehouse as $keyWarehouse => $warehouse) {
  79. $arrResponseGetAddress = $this->resourcesController->getAddress(
  80. $warehouse['CODIGO_POSTAL'],
  81. $warehouse['COLONIA'],
  82. $warehouse['MUNICIPIO'],
  83. $warehouse['LOCALIDAD'],
  84. $warehouse['ENTIDAD_FEDERATIVA'],
  85. $warehouse['PAIS'],
  86. $line
  87. );
  88. if ($arrResponseGetAddress['error']) {
  89. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GET002: '.$arrResponseGetAddress['msg'], $arrResponseGetAddress['response'], 401);
  90. }
  91. $warehouse['CODIGO_POSTAL'] = $arrResponseGetAddress['response']['CODIGO_POSTAL'];
  92. $warehouse['COLONIA'] = $arrResponseGetAddress['response']['COLONIA'];
  93. $warehouse['MUNICIPIO'] = $arrResponseGetAddress['response']['MUNICIPIO'];
  94. $warehouse['LOCALIDAD'] = $arrResponseGetAddress['response']['LOCALIDAD'];
  95. $warehouse['ENTIDAD_FEDERATIVA'] = $arrResponseGetAddress['response']['ENTIDAD_FEDERATIVA'];
  96. $warehouse['PAIS'] = $arrResponseGetAddress['response']['PAIS'];
  97. $arrWarehouse[$keyWarehouse] = $warehouse;
  98. }
  99. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWarehouse);
  100. }
  101. public function getWarehouseById( $idWarehouse, $user, $line ) {
  102. try {
  103. $idWarehouse = $this->encController->decrypt($idWarehouse);
  104. } catch (\Throwable $th) {
  105. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  106. }
  107. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  108. if ($arrResponseCheckUser['error']) {
  109. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  110. }
  111. try {
  112. $arrWarehouse = (array) DB::table('S002V01TALMA')
  113. ->where('ALMA_COAL', '=', $idWarehouse)
  114. ->where('ALMA_NULI', '=', $line)
  115. ->first([
  116. 'ALMA_COAL AS CODIGO_ALMACEN',
  117. 'ALMA_NOAL AS NOMBRE_ALMACEN',
  118. 'ALMA_NORE AS NOMBRE_RESPONSABLE',
  119. 'ALMA_APRE AS APELLIDO_PATERNO_RESPONSABLE',
  120. 'ALMA_AMRE AS APELLIDO_MATERNO_RESPONSABLE',
  121. 'ALMA_COR1 AS CORREO1',
  122. 'ALMA_COR2 AS CORREO2',
  123. 'ALMA_LAD1 AS LADA1',
  124. 'ALMA_TEL1 AS TELEFONO1',
  125. 'ALMA_LAD2 AS LADA2',
  126. 'ALMA_TEL2 AS TELEFONO2',
  127. 'ALMA_CALL AS CALLE',
  128. 'ALMA_NUEX AS NUMERO_EXTERIOR',
  129. 'ALMA_NUIN AS NUMERO_INTERIOR',
  130. 'ALMA_COPO AS CODIGO_POSTAL',
  131. 'ALMA_COLO AS COLONIA',
  132. 'ALMA_LOCA AS LOCALIDAD',
  133. 'ALMA_MUNI AS MUNICIPIO',
  134. 'ALMA_ENTI AS ENTIDAD_FEDERATIVA',
  135. 'ALMA_PAIS AS PAIS',
  136. 'ALMA_ESTA AS ESTADO',
  137. 'ALMA_USRE AS USUARIO_REGISTRA',
  138. 'ALMA_FERE AS FECHA_REGISTRA',
  139. 'ALMA_USMO AS USUARIO_MODIFICA',
  140. 'ALMA_FEMO AS FECHA_MODIFICA',
  141. ]);
  142. $arrWarehouse = json_decode( json_encode($arrWarehouse), true );
  143. } catch (\Throwable $th) {
  144. DB::rollBack();
  145. return $this->responseController->makeResponse(
  146. true,
  147. "ERR_WAREHOUSE_GETBY001: Ocurrió un error al obtener los almacenes.",
  148. $th->getMessage(),
  149. 500
  150. );
  151. }
  152. if (!empty($arrWarehouse)) {
  153. $arrResponseGetAddress = $this->resourcesController->getAddress(
  154. $arrWarehouse['CODIGO_POSTAL'],
  155. $arrWarehouse['COLONIA'],
  156. $arrWarehouse['MUNICIPIO'],
  157. $arrWarehouse['LOCALIDAD'],
  158. $arrWarehouse['ENTIDAD_FEDERATIVA'],
  159. $arrWarehouse['PAIS'],
  160. $line
  161. );
  162. if ($arrResponseGetAddress['error']) {
  163. return $this->responseController->makeResponse(true, 'ERR_arrWarehouse_GETBY002: '.$arrResponseGetAddress['msg'], $arrResponseGetAddress['response'], 406);
  164. }
  165. $arrWarehouse['CODIGO_POSTAL'] = $arrResponseGetAddress['response']['CODIGO_POSTAL'];
  166. $arrWarehouse['COLONIA'] = $arrResponseGetAddress['response']['COLONIA'];
  167. $arrWarehouse['MUNICIPIO'] = $arrResponseGetAddress['response']['MUNICIPIO'];
  168. $arrWarehouse['LOCALIDAD'] = $arrResponseGetAddress['response']['LOCALIDAD'];
  169. $arrWarehouse['ENTIDAD_FEDERATIVA'] = $arrResponseGetAddress['response']['ENTIDAD_FEDERATIVA'];
  170. $arrWarehouse['PAIS'] = $arrResponseGetAddress['response']['PAIS'];
  171. }
  172. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWarehouse);
  173. }
  174. public function getWarehouseActives($user, $line) {
  175. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  176. if ($arrResponseCheckUser['error']) {
  177. DB::rollBack();
  178. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
  179. }
  180. try {
  181. $arrWarehouse = DB::table('S002V01TALMA')
  182. ->where('ALMA_NULI', '=', $line)
  183. ->where('ALMA_ESTA', '=', 'Activo')
  184. ->get([
  185. 'ALMA_COAL AS CODIGO_ALMACEN',
  186. 'ALMA_NOAL AS NOMBRE_ALMACEN',
  187. 'ALMA_NORE AS NOMBRE_RESPONSABLE',
  188. 'ALMA_APRE AS APELLIDO_PATERNO_RESPONSABLE',
  189. 'ALMA_AMRE AS APELLIDO_MATERNO_RESPONSABLE',
  190. 'ALMA_COR1 AS CORREO1',
  191. 'ALMA_LAD1 AS LADA1',
  192. 'ALMA_TEL1 AS TELEFONO1',
  193. ]);
  194. $arrWarehouse = json_decode( json_encode($arrWarehouse), true );
  195. } catch (\Throwable $th) {
  196. DB::rollBack();
  197. return $this->responseController->makeResponse(
  198. true,
  199. "ERR_WAREHOUSE_GET001: Ocurrió un error al obtener los almacenes.",
  200. $th->getMessage(),
  201. 500
  202. );
  203. }
  204. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWarehouse);
  205. }
  206. public function createWarehouse( Request $request ) {
  207. $validator = Validator::make($request->all(), [
  208. 'CODIGO_ALMACEN' => 'required|string',
  209. 'NOMBRE_ALMACEN' => 'required|string',
  210. 'NOMBRE_RESPONSABLE' => 'required|string',
  211. 'APELLIDO_PATERNO_RESPONSABLE' => 'required|string',
  212. 'APELLIDO_MATERNO_RESPONSABLE' => 'nullable|string',
  213. 'CORREO1' => 'required|string',
  214. 'CORREO2' => 'nullable|string',
  215. 'LADA1' => 'required|string',
  216. 'TELEFONO1' => 'required|string',
  217. 'LADA2' => 'nullable|string',
  218. 'TELEFONO2' => 'nullable|string',
  219. 'CALLE' => 'required|string',
  220. 'NUMERO_EXTERIOR' => 'required|string',
  221. 'NUMERO_INTERIOR' => 'nullable|string',
  222. 'CODIGO_POSTAL' => 'required|string',
  223. 'COLONIA' => 'required|string',
  224. 'LOCALIDAD' => 'nullable|string',
  225. 'MUNICIPIO' => 'required|string',
  226. 'ENTIDAD_FEDERATIVA' => 'required|string',
  227. 'PAIS' => 'required|string',
  228. 'USUARIO' => 'required|string',
  229. 'NUMERO_LINEA' => 'required|string',
  230. ]);
  231. if ($validator->fails()) {
  232. return $this->responseController->makeResponse(
  233. true,
  234. "ERR_WAREHOUSE_REG000: Se encontraron uno o más errores.",
  235. $this->responseController->makeErrors($validator->errors()->messages()),
  236. 401
  237. );
  238. }
  239. DB::beginTransaction();
  240. $requestData = $request->all();
  241. // Se valida y se obtiene el usuario
  242. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  243. if ($arrResponseCheckUser['error']) {
  244. DB::rollBack();
  245. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  246. }
  247. $user = $arrResponseCheckUser['response'];
  248. // Se vallidan los campos de dirección
  249. $arrResponseCheckAddress = $this->resourcesController->validateAddress(
  250. $requestData['CODIGO_POSTAL'],
  251. $requestData['COLONIA'],
  252. $requestData['MUNICIPIO'],
  253. $requestData['LOCALIDAD'],
  254. $requestData['ENTIDAD_FEDERATIVA'],
  255. $requestData['PAIS'],
  256. $requestData['NUMERO_LINEA'],
  257. );
  258. if ($arrResponseCheckAddress['error']) {
  259. DB::rollBack();
  260. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_REG002: '.$arrResponseCheckAddress['msg'], $arrResponseCheckAddress['response'], 401);
  261. }
  262. $now = $this->functionsController->now();
  263. $currentDate = $now->toDateTimeString();
  264. try {
  265. $validateInsert = DB::table('S002V01TALMA')->insert([
  266. 'ALMA_NULI' => $requestData['NUMERO_LINEA'],
  267. 'ALMA_COAL' => $requestData['CODIGO_ALMACEN'],
  268. 'ALMA_NOAL' => $requestData['NOMBRE_ALMACEN'],
  269. 'ALMA_NORE' => $requestData['NOMBRE_RESPONSABLE'],
  270. 'ALMA_APRE' => $requestData['APELLIDO_PATERNO_RESPONSABLE'],
  271. 'ALMA_AMRE' => $requestData['APELLIDO_MATERNO_RESPONSABLE'],
  272. 'ALMA_COR1' => $requestData['CORREO1'],
  273. 'ALMA_COR2' => $requestData['CORREO2'],
  274. 'ALMA_LAD1' => $requestData['LADA1'],
  275. 'ALMA_TEL1' => $requestData['TELEFONO1'],
  276. 'ALMA_LAD2' => $requestData['LADA2'],
  277. 'ALMA_TEL2' => $requestData['TELEFONO2'],
  278. 'ALMA_CALL' => $requestData['CALLE'],
  279. 'ALMA_NUEX' => $requestData['NUMERO_EXTERIOR'],
  280. 'ALMA_NUIN' => $requestData['NUMERO_INTERIOR'],
  281. 'ALMA_COPO' => $requestData['CODIGO_POSTAL'],
  282. 'ALMA_COLO' => $requestData['COLONIA'],
  283. 'ALMA_LOCA' => $requestData['LOCALIDAD'],
  284. 'ALMA_MUNI' => $requestData['MUNICIPIO'],
  285. 'ALMA_ENTI' => $requestData['ENTIDAD_FEDERATIVA'],
  286. 'ALMA_PAIS' => $requestData['PAIS'],
  287. 'ALMA_USRE' => $user,
  288. 'ALMA_FERE' => $currentDate,
  289. 'ALMA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  290. ]);
  291. } catch (\Throwable $th) {
  292. DB::rollBack();
  293. return $this->responseController->makeResponse(
  294. true,
  295. "ERR_WAREHOUSE_REG003: Ocurrió un error al insertar el registro del almacen.",
  296. $th->getMessage(),
  297. 500
  298. );
  299. }
  300. if (!$validateInsert) {
  301. DB::rollBack();
  302. return $this->responseController->makeResponse(
  303. true,
  304. "ERR_WAREHOUSE_REG004: No se pudo insertar el registro del almacen.",
  305. [],
  306. 500
  307. );
  308. }
  309. DB::commit();
  310. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  311. }
  312. public function updateWarehouse( Request $request, $idWarehouse ) {
  313. $validator = Validator::make($request->all(), [
  314. 'CODIGO_ALMACEN' => 'required|string',
  315. 'NOMBRE_ALMACEN' => 'required|string',
  316. 'NOMBRE_RESPONSABLE' => 'required|string',
  317. 'APELLIDO_PATERNO_RESPONSABLE' => 'required|string',
  318. 'APELLIDO_MATERNO_RESPONSABLE' => 'nullable|string',
  319. 'CORREO1' => 'required|string',
  320. 'CORREO2' => 'nullable|string',
  321. 'LADA1' => 'required|string',
  322. 'TELEFONO1' => 'required|string',
  323. 'LADA2' => 'nullable|string',
  324. 'TELEFONO2' => 'nullable|string',
  325. 'CALLE' => 'required|string',
  326. 'NUMERO_EXTERIOR' => 'required|string',
  327. 'NUMERO_INTERIOR' => 'nullable|string',
  328. 'CODIGO_POSTAL' => 'required|string',
  329. 'COLONIA' => 'required|string',
  330. 'LOCALIDAD' => 'nullable|string',
  331. 'MUNICIPIO' => 'required|string',
  332. 'ENTIDAD_FEDERATIVA' => 'required|string',
  333. 'PAIS' => 'required|string',
  334. 'USUARIO' => 'required|string',
  335. 'NUMERO_LINEA' => 'required|string',
  336. ]);
  337. if ($validator->fails()) {
  338. return $this->responseController->makeResponse(
  339. true,
  340. "ERR_WAREHOUSE_UPD000: Se encontraron uno o más errores.",
  341. $this->responseController->makeErrors($validator->errors()->messages()),
  342. 401
  343. );
  344. }
  345. DB::beginTransaction();
  346. $requestData = $request->all();
  347. try {
  348. $idWarehouse = $this->encController->decrypt($idWarehouse);
  349. } catch (\Throwable $th) {
  350. return $this->responseController->makeResponse(true, "ERR_WAREHOUSE_UPD001: Ocurrió un error al desencriptar el ID del almacen.". $th->getMessage(), 406);
  351. }
  352. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  353. if ($arrResponseCheckUser['error']) {
  354. DB::rollBack();
  355. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_UPD002:'.$arrResponseCheckUser['msg'], [], 401);
  356. }
  357. $user = $arrResponseCheckUser['response'];
  358. $arrResponseCheckAddress = $this->resourcesController->validateAddress(
  359. $requestData['CODIGO_POSTAL'],
  360. $requestData['COLONIA'],
  361. $requestData['MUNICIPIO'],
  362. $requestData['LOCALIDAD'],
  363. $requestData['ENTIDAD_FEDERATIVA'],
  364. $requestData['PAIS'],
  365. $requestData['NUMERO_LINEA'],
  366. );
  367. if ($arrResponseCheckAddress['error']) {
  368. DB::rollBack();
  369. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_UPD003: '.$arrResponseCheckAddress['msg'], $arrResponseCheckAddress['response'], 401);
  370. }
  371. $now = $this->functionsController->now();
  372. $currentDate = $now->toDateTimeString();
  373. try {
  374. $validateUpdate = DB::table('S002V01TALMA')
  375. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  376. ->where('ALMA_COAL', '=', $idWarehouse)
  377. ->update([
  378. 'ALMA_COAL' => $requestData['CODIGO_ALMACEN'],
  379. 'ALMA_NOAL' => $requestData['NOMBRE_ALMACEN'],
  380. 'ALMA_NORE' => $requestData['NOMBRE_RESPONSABLE'],
  381. 'ALMA_APRE' => $requestData['APELLIDO_PATERNO_RESPONSABLE'],
  382. 'ALMA_AMRE' => $requestData['APELLIDO_MATERNO_RESPONSABLE'],
  383. 'ALMA_COR1' => $requestData['CORREO1'],
  384. 'ALMA_COR2' => $requestData['CORREO2'],
  385. 'ALMA_LAD1' => $requestData['LADA1'],
  386. 'ALMA_TEL1' => $requestData['TELEFONO1'],
  387. 'ALMA_LAD2' => $requestData['LADA2'],
  388. 'ALMA_TEL2' => $requestData['TELEFONO2'],
  389. 'ALMA_CALL' => $requestData['CALLE'],
  390. 'ALMA_NUEX' => $requestData['NUMERO_EXTERIOR'],
  391. 'ALMA_NUIN' => $requestData['NUMERO_INTERIOR'],
  392. 'ALMA_COPO' => $requestData['CODIGO_POSTAL'],
  393. 'ALMA_COLO' => $requestData['COLONIA'],
  394. 'ALMA_LOCA' => $requestData['LOCALIDAD'],
  395. 'ALMA_MUNI' => $requestData['MUNICIPIO'],
  396. 'ALMA_ENTI' => $requestData['ENTIDAD_FEDERATIVA'],
  397. 'ALMA_PAIS' => $requestData['PAIS'],
  398. 'ALMA_USMO' => $user,
  399. 'ALMA_FEMO' => $currentDate,
  400. 'ALMA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  401. ]);
  402. } catch (\Throwable $th) {
  403. DB::rollBack();
  404. return $this->responseController->makeResponse(
  405. true,
  406. "ERR_WAREHOUSE_UPD004: Ocurrió un error al insertar el registro del almacen.",
  407. $th->getMessage(),
  408. 500
  409. );
  410. }
  411. if (!$validateUpdate) {
  412. DB::rollBack();
  413. return $this->responseController->makeResponse(
  414. true,
  415. "ERR_WAREHOUSE_UPD005: No se pudo insertar el registro del almacen.",
  416. [],
  417. 500
  418. );
  419. }
  420. DB::commit();
  421. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  422. }
  423. public function deleteWarehouse( Request $request, $idWarehouse ) {
  424. $validator = Validator::make($request->all(), [
  425. 'USUARIO' => 'required|string',
  426. 'NUMERO_LINEA' => 'required|string',
  427. ]);
  428. if ($validator->fails()) {
  429. return $this->responseController->makeResponse(
  430. true,
  431. "ERR_WAREHOUSE_DEL000: Se encontraron uno o más errores.",
  432. $this->responseController->makeErrors($validator->errors()->messages()),
  433. 401
  434. );
  435. }
  436. DB::beginTransaction();
  437. $requestData = $request->all();
  438. try {
  439. $idWarehouse = $this->encController->decrypt($idWarehouse);
  440. } catch (\Throwable $th) {
  441. DB::rollBack();
  442. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL001: Ocurrió un error al desencriptar el nivel.', $th->getMessage(), 500);
  443. }
  444. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  445. if ($arrResponseCheckUser['error']) {
  446. DB::rollBack();
  447. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL002:'.$arrResponseCheckUser['msg'], [], 401);
  448. }
  449. $user = $arrResponseCheckUser['response'];
  450. try {
  451. $validateExists = DB::table('S002V01TALMA')
  452. ->where('ALMA_COAL', '=', $idWarehouse)
  453. ->where('ALMA_ESTA', '=', 'Activo')
  454. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  455. ->exists();
  456. } catch (\Throwable $th) {
  457. DB::rollBack();
  458. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL003: Ocurrió un error al obtener la información del área.', $th->getMessage(), 500);
  459. }
  460. if (!$validateExists) {
  461. DB::rollBack();
  462. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL004: El almacen no existe.', [], 406);
  463. }
  464. try {
  465. $validateExists = DB::table('S002V01TUBAR')
  466. ->where('UBAR_COAL', '=', $idWarehouse)
  467. ->where('UBAR_NULI', '=', $requestData['NUMERO_LINEA'])
  468. ->where('UBAR_ESTA', '=', 'Activo')
  469. ->exists();
  470. } catch (\Throwable $th) {
  471. DB::rollBack();
  472. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL005: Ocurrió un error al obtener las ubicaciones de los artículos.', $th->getMessage(), 500);
  473. }
  474. if($validateExists) {
  475. DB::rollBack();
  476. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL006: No se puede eliminar debido a que existen artículos ubicados en el almacen.', [], 406);
  477. }
  478. try {
  479. $countArea = DB::table('S002V01TAREA')
  480. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  481. ->where('AREA_COAL', '=', $idWarehouse)
  482. ->where('AREA_ESTA', '=', 'Activo')
  483. ->count();
  484. } catch (\Throwable $th) {
  485. DB::rollBack();
  486. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL007: Ocurrió un error al obtener la información del área.', $th->getMessage(), 500);
  487. }
  488. if ($countArea > 0) {
  489. DB::rollBack();
  490. $quantity = $countArea === 1 ? 'existe 1 área activa' : 'existen'.$countArea.' áreas activas';
  491. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL008: No se puede elminar debido a que '.$quantity.'.', [], 406);
  492. }
  493. try {
  494. $countLevel = DB::table('S002V01TNIVE')
  495. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  496. ->where('NIVE_COAL', '=', $idWarehouse)
  497. ->where('NIVE_ESTA', '=', 'Activo')
  498. ->count();
  499. } catch (\Throwable $th) {
  500. DB::rollBack();
  501. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL009: Ocurrió un error al obtener las zonas.', $th->getMessage(), 500);
  502. }
  503. if ($countLevel > 0) {
  504. DB::rollBack();
  505. $quantity = $countLevel === 1 ? 'existe 1 nivel activo' : 'existen '.$countLevel.' niveles activos';
  506. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL010: No se puede eliminar debido a que '.$quantity.'.', [], 406);
  507. }
  508. try {
  509. $countZones = DB::table('S002V01TZONA')
  510. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  511. ->where('ZONA_COAL', '=', $idWarehouse)
  512. ->where('ZONA_ESTA', '=', 'Activo')
  513. ->count();
  514. } catch (\Throwable $th) {
  515. DB::rollBack();
  516. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL011: Ocurrió un error al obtener las zonas.', $th->getMessage(), 500);
  517. }
  518. if ($countZones > 0) {
  519. DB::rollBack();
  520. $quantity = $countZones === 1 ? 'existe 1 zona activa' : 'existen '.$countZones.' zonas activas';
  521. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL012: No se puede eliminar debido a que '.$quantity.'.', [], 406);
  522. }
  523. $now = $this->functionsController->now();
  524. $currentDate = $now->toDateTimeString();
  525. try {
  526. $validateUpdate = DB::table('S002V01TALMA')
  527. ->where('ALMA_COAL', '=', $idWarehouse)
  528. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  529. ->update([
  530. 'ALMA_ESTA' => 'Eliminado',
  531. 'ALMA_USMO' => $user,
  532. 'ALMA_FEMO' => $currentDate,
  533. 'ALMA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  534. ]);
  535. } catch (\Throwable $th) {
  536. DB::rollBack();
  537. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL013: Ocurrió un error al eliminar el área.', $th->getMessage(), 500);
  538. }
  539. if (!$validateUpdate) {
  540. DB::rollBack();
  541. return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_DEL014: No se pudo eliminar el área.', [], 406);
  542. }
  543. DB::commit();
  544. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  545. }
  546. // Crear Artículo en Stock
  547. public function createArtitleWithoutOrder(Request $request) {
  548. $validator = Validator::make($request->all(), [
  549. 'ARTICULO' => 'required',
  550. 'MODELO' => 'required',
  551. 'CODIGO_MODELO' => 'required',
  552. 'FAMILIA' => 'required',
  553. 'SUBFAMILIA' => 'required',
  554. 'UNIDAD' => 'required',
  555. 'CODIGO_BARRAS' => 'required',
  556. 'CANTIDAD' => 'required',
  557. 'STOCK_MINIMO' => 'required',
  558. 'STOCK_MAXIMO' => 'required',
  559. 'REPARACION' => 'required|boolean',
  560. 'CONSUMIBLE' => 'required|boolean',
  561. 'PELIGROSO' => 'required|boolean',
  562. // 'FECHA_VENCIMIENTO' => '',
  563. // 'PROVEEDOR' => 'required',
  564. 'IMAGEN' => 'required',
  565. 'NUMERO_LINEA' => 'required',
  566. 'USUARIO' => 'required',
  567. ]);
  568. if ($validator->fails()) {
  569. return $this->responseController->makeResponse(
  570. true,
  571. "ERR_STOCK_REG000: Se encontraron uno o más errores.",
  572. $this->responseController->makeErrors($validator->errors()->messages()),
  573. 401
  574. );
  575. }
  576. DB::beginTransaction();
  577. $requestData = $request->all();
  578. try {
  579. $user = $this->encController->decrypt($requestData['USUARIO']);
  580. } catch (\Throwable $th) {
  581. DB::rollBack();
  582. return $this->responseController->makeResponse(true, "ERR_STOCK_REG001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  583. }
  584. try {
  585. $validateFamily = DB::table('S002V01TFAMI')
  586. ->where('FAMI_COFA','=', $requestData['FAMILIA'])
  587. ->where('FAMI_NULI','=', $requestData['NUMERO_LINEA'])
  588. ->where('FAMI_ESTA','=','Activo')
  589. ->exists();
  590. } catch (\Throwable $th) {
  591. DB::rollBack();
  592. return $this->responseController->makeResponse(true, "ERR_STOCK_REG002: Ocurrió un error al validar la familia.", $th->getMessage(), 500);
  593. }
  594. if (!$validateFamily) {
  595. DB::rollBack();
  596. return $this->responseController->makeResponse(true, "ERR_STOCK_REG003: La familia no existe.", [], 500);
  597. }
  598. try {
  599. $validateSubfamily = DB::table('S002V01TSUBF')
  600. ->where('SUBF_COSU','=', $requestData['SUBFAMILIA'])
  601. ->where('SUBF_NULI','=', $requestData['NUMERO_LINEA'])
  602. ->where('SUBF_ESTA','=','Activo')
  603. ->exists();
  604. } catch (\Throwable $th) {
  605. DB::rollBack();
  606. return $this->responseController->makeResponse(true, "ERR_STOCK_REG004: Ocurrió un error al validar la subfamilia.", $th->getMessage(), 500);
  607. }
  608. if (!$validateSubfamily) {
  609. DB::rollBack();
  610. return $this->responseController->makeResponse(true, "ERR_STOCK_REG005: La subfamilia no existe.", [], 500);
  611. }
  612. try {
  613. $validateUnit = DB::table('S002V01TUNID')
  614. ->where('UNID_IDUN','=', $requestData['UNIDAD'])
  615. ->where('UNID_NULI','=', $requestData['NUMERO_LINEA'])
  616. ->where('UNID_ESTA','=','Activo')
  617. ->exists();
  618. } catch (\Throwable $th) {
  619. DB::rollBack();
  620. return $this->responseController->makeResponse(true, "ERR_STOCK_REG006: Ocurrió un error al validar la unidad.", $th->getMessage(), 500);
  621. }
  622. if (!$validateUnit) {
  623. DB::rollBack();
  624. return $this->responseController->makeResponse(true, "ERR_STOCK_REG007: La unidad no existe.", [], 500);
  625. }
  626. $requestData['PROVEEDOR'] = $requestData['PROVEEDOR'] === '' ? null : $requestData['PROVEEDOR'];
  627. if (!is_null($requestData['PROVEEDOR'])) {
  628. try {
  629. $validateUnit = DB::table('S002V01TPROV')
  630. ->where('PROV_NUPR','=', $requestData['PROVEEDOR'])
  631. ->where('PROV_NULI','=', $requestData['NUMERO_LINEA'])
  632. ->where('PROV_ESTA','=','Activo')
  633. ->exists();
  634. } catch (\Throwable $th) {
  635. DB::rollBack();
  636. return $this->responseController->makeResponse(true, "ERR_STOCK_REG008: Ocurrió un error al validar el proveedor.", $th->getMessage(), 500);
  637. }
  638. if (!$validateUnit) {
  639. DB::rollBack();
  640. return $this->responseController->makeResponse(true, "ERR_STOCK_REG009: El proveedor no existe.", [], 500);
  641. }
  642. }
  643. $arrCodeImages = array();
  644. foreach ($requestData['IMAGEN'] as $key => $encIdFile) {
  645. $idFile = $this->encController->decrypt($encIdFile);
  646. $tempFile = DB::table('S002V01TARTE')->where([
  647. ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
  648. ['ARTE_IDAR', '=', $idFile],
  649. ])->first();
  650. if(is_null($tempFile)){
  651. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado no está registrado', [], 404);
  652. }else if($tempFile->ARTE_ESTA == 'Eliminado'){
  653. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: El archivo consultado está eliminado', [], 404);
  654. }
  655. $fileResponse = $this->documentManagementController->moveFinalFile(
  656. intval($requestData['NUMERO_LINEA']),
  657. 'GIST',
  658. 'FO',
  659. $tempFile,
  660. $user,
  661. );
  662. if(!$fileResponse[0]){
  663. return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG008: '.$fileResponse[1], [], 400);
  664. }
  665. $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
  666. }
  667. $jsonImages = json_encode($arrCodeImages);
  668. $now = $this->functionsController->now();
  669. $currentDate = $now->toDateTimeString();
  670. try {
  671. $validateRegister = DB::table('S002V01TSTAR')->insert([
  672. // 'STAR_CODI' => $requestData['CODIGO_STOCK'],
  673. 'STAR_ARTI' => $requestData['ARTICULO'],
  674. 'STAR_MODE' => $requestData['MODELO'],
  675. 'STAR_COMO' => $requestData['CODIGO_MODELO'],
  676. 'STAR_IDFA' => $requestData['FAMILIA'],
  677. 'STAR_IDSU' => $requestData['SUBFAMILIA'],
  678. 'STAR_NUPR' => $requestData['PROVEEDOR'],
  679. 'STAR_IDUN' => $requestData['UNIDAD'],
  680. 'STAR_COBA' => $requestData['CODIGO_BARRAS'],
  681. 'STAR_CANT' => $requestData['CANTIDAD'],
  682. 'STAR_STMI' => $requestData['STOCK_MINIMO'],
  683. 'STAR_STMA' => $requestData['STOCK_MAXIMO'],
  684. 'STAR_REPA' => $requestData['REPARACION'],
  685. 'STAR_CONS' => $requestData['CONSUMIBLE'],
  686. 'STAR_PELI' => $requestData['PELIGROSO'],
  687. 'STAR_FEVE' => $requestData['FECHA_VENCIMIENTO'],
  688. 'STAR_IMAG' => $jsonImages,
  689. 'STAR_TIAD' => 'Sin Pedido',
  690. 'STAR_NULI' => $requestData['NUMERO_LINEA'],
  691. 'STAR_USRE' => $user,
  692. 'STAR_FERE' => $currentDate,
  693. 'STAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  694. ]);
  695. } catch (\Throwable $th) {
  696. DB::rollBack();
  697. return $this->responseController->makeResponse(true, "ERR_STOCK_REG011: Ocurrió un error al registrar el artículo.", $th->getMessage(), 500);
  698. }
  699. if (!$validateRegister) {
  700. DB::rollBack();
  701. return $this->responseController->makeResponse(true, "ERR_STOCK_REG012: No se pudo registrar el artículo.", [], 500);
  702. }
  703. DB::commit();
  704. return $this->responseController->makeResponse(false, "EXITO: Registro Exitoso");
  705. }
  706. public function getAreaByWarehouse($idWarehouse, $user, $line) {
  707. try {
  708. $idWarehouse = $this->encController->decrypt($idWarehouse);
  709. } catch (\Throwable $th) {
  710. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  711. }
  712. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  713. if ($arrResponseCheckUser['error']) {
  714. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY001:'.$arrResponseCheckUser['msg'], [], 401);
  715. }
  716. try {
  717. $getArea = DB::table('S002V01TAREA')
  718. ->where('AREA_COAL', '=', $idWarehouse)
  719. ->where('AREA_NULI', '=', $line)
  720. ->get([
  721. 'AREA_COAR AS CODIGO_AREA',
  722. 'AREA_NOAR AS NOMBRE_AREA',
  723. 'AREA_COME AS COMENTARIOS',
  724. 'AREA_ESTA AS ESTADO',
  725. 'AREA_USRE AS USUARIO_REGISTRA',
  726. 'AREA_FERE AS FECHA_REGISTRA',
  727. 'AREA_USMO AS USUARIO_MODIFICA',
  728. 'AREA_FEMO AS FECHA_MODIFICA',
  729. ]);
  730. $arrArea = json_decode(json_encode($getArea), true);
  731. } catch (\Throwable $th) {
  732. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY002: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  733. }
  734. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArea);
  735. }
  736. public function getAreaById($idArea, $user, $line) {
  737. try {
  738. $idArea = $this->encController->decrypt($idArea);
  739. } catch (\Throwable $th) {
  740. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  741. }
  742. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  743. if ($arrResponseCheckUser['error']) {
  744. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY001:'.$arrResponseCheckUser['msg'], [], 401);
  745. }
  746. try {
  747. $getArea = (array) DB::table('S002V01TAREA')
  748. ->where('AREA_COAR', '=', $idArea)
  749. ->where('AREA_NULI', '=', $line)
  750. ->first([
  751. 'AREA_NOAR AS NOMBRE_AREA',
  752. 'AREA_COME AS COMENTARIOS',
  753. 'AREA_ESTA AS ESTADO',
  754. 'AREA_USRE AS USUARIO_REGISTRA',
  755. 'AREA_FERE AS FECHA_REGISTRA',
  756. 'AREA_USMO AS USUARIO_MODIFICA',
  757. 'AREA_FEMO AS FECHA_MODIFICA',
  758. ]);
  759. $arrArea = json_decode(json_encode($getArea), true);
  760. } catch (\Throwable $th) {
  761. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBY002: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  762. }
  763. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArea);
  764. }
  765. public function getAreaByWarehouseActives($idWarehouse, $user, $line) {
  766. try {
  767. $idWarehouse = $this->encController->decrypt($idWarehouse);
  768. } catch (\Throwable $th) {
  769. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBYACTIVE000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  770. }
  771. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  772. if ($arrResponseCheckUser['error']) {
  773. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBYACTIVE001:'.$arrResponseCheckUser['msg'], [], 401);
  774. }
  775. try {
  776. $validateExists = DB::table('S002V01TALMA')
  777. ->where('ALMA_NULI', '=', $line)
  778. ->where('ALMA_COAL', '=', $idWarehouse)
  779. ->exists();
  780. } catch (\Throwable $th) {
  781. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBYACTIVE002: Ocurrió un error al obtener el almacen.', $th->getMessage(), 406);
  782. }
  783. if (!$validateExists) {
  784. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBYACTIVE003: El almacen no existe.', [], 401);
  785. }
  786. try {
  787. $getArea = DB::table('S002V01TAREA')
  788. ->where('AREA_COAL', '=', $idWarehouse)
  789. ->where('AREA_NULI', '=', $line)
  790. ->where('AREA_ESTA', '=', 'Activo')
  791. ->get([
  792. 'AREA_COAR AS CODIGO_AREA',
  793. 'AREA_NOAR AS NOMBRE_AREA',
  794. 'AREA_COME AS COMENTARIOS',
  795. ]);
  796. $arrArea = json_decode(json_encode($getArea), true);
  797. } catch (\Throwable $th) {
  798. return $this->responseController->makeResponse(true, 'ERR_AREA_GETBYACTIVE004: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  799. }
  800. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrArea);
  801. }
  802. public function registerArea(Request $request) {
  803. $validator = Validator::make($request->all(), [
  804. 'CODIGO_ALMACEN' => 'required|string',
  805. 'CODIGO_AREA' => 'required|string',
  806. 'NOMBRE_AREA' => 'required|string',
  807. 'COMENTARIOS' => 'nullable|string',
  808. 'USUARIO' => 'required|string',
  809. 'NUMERO_LINEA' => 'required|string',
  810. ]);
  811. if ($validator->fails()) {
  812. return $this->responseController->makeResponse(
  813. true,
  814. "ERR_AREA_REG000: Se encontraron uno o más errores.",
  815. $this->responseController->makeErrors($validator->errors()->messages()),
  816. 401
  817. );
  818. }
  819. DB::beginTransaction();
  820. $requestData = $request->all();
  821. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  822. if ($arrResponseCheckUser['error']) {
  823. return $this->responseController->makeResponse(true, 'ERR_AREA_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  824. }
  825. $user = $arrResponseCheckUser['response'];
  826. try {
  827. $validateExistWarehouse = DB::table('S002V01TALMA')
  828. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  829. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  830. ->where('ALMA_ESTA', '=', 'Activo')
  831. ->exists();
  832. } catch (\Throwable $th) {
  833. DB::rollBack();
  834. return $this->responseController->makeResponse(true, 'ERR_AREA_REG002: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  835. }
  836. if (!$validateExistWarehouse) {
  837. DB::rollBack();
  838. return $this->responseController->makeResponse(true, 'ERR_AREA_REG003: El almacen no existe.', [], 406);
  839. }
  840. try {
  841. $validateExistCode = DB::table('S002V01TAREA')
  842. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  843. ->where('AREA_COAR', '=', $requestData['CODIGO_AREA'])
  844. ->where('AREA_ESTA', '=', 'Activo')
  845. ->exists();
  846. } catch (\Throwable $th) {
  847. DB::rollBack();
  848. return $this->responseController->makeResponse(true, 'ERR_AREA_REG004: Ocurrió un error al verificar el código del área.', $th->getMessage(), 500);
  849. }
  850. if ($validateExistCode) {
  851. DB::rollBack();
  852. return $this->responseController->makeResponse(true, 'ERR_AREA_REG005: El código del área ya se encuentra registrado.', [], 406);
  853. }
  854. $now = $this->functionsController->now();
  855. $currentDate = $now->toDateTimeString();
  856. try {
  857. $validateInsert = DB::table('S002V01TAREA')->insert([
  858. 'AREA_COAL' => $requestData['CODIGO_ALMACEN'],
  859. 'AREA_COAR' => $requestData['CODIGO_AREA'],
  860. 'AREA_NOAR' => $requestData['NOMBRE_AREA'],
  861. 'AREA_COME' => $requestData['COMENTARIOS'],
  862. 'AREA_NULI' => $requestData['NUMERO_LINEA'],
  863. 'AREA_USRE' => $user,
  864. 'AREA_FERE' => $currentDate,
  865. 'AREA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  866. ]);
  867. } catch (\Throwable $th) {
  868. DB::rollBack();
  869. return $this->responseController->makeResponse(true, 'ERR_AREA_REG006: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  870. }
  871. if (!$validateInsert) {
  872. DB::rollBack();
  873. return $this->responseController->makeResponse(true, 'ERR_AREA_REG007: No se pudo guardar la información en la base de datos.', [], 406);
  874. }
  875. DB::commit();
  876. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  877. }
  878. public function updateArea(Request $request, $idArea) {
  879. $validator = Validator::make($request->all(), [
  880. 'CODIGO_ALMACEN' => 'required|string',
  881. 'NOMBRE_AREA' => 'required|string',
  882. 'COMENTARIOS' => 'nullable|string',
  883. 'USUARIO' => 'required|string',
  884. 'NUMERO_LINEA' => 'required|string',
  885. ]);
  886. if ($validator->fails()) {
  887. return $this->responseController->makeResponse(
  888. true,
  889. "ERR_AREA_UPD000: Se encontraron uno o más errores.",
  890. $this->responseController->makeErrors($validator->errors()->messages()),
  891. 401
  892. );
  893. }
  894. DB::beginTransaction();
  895. $requestData = $request->all();
  896. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  897. if ($arrResponseCheckUser['error']) {
  898. DB::rollBack();
  899. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD001:'.$arrResponseCheckUser['msg'], $arrResponseCheckUser['response'], 401);
  900. }
  901. $user = $arrResponseCheckUser['response'];
  902. try {
  903. $idArea = $this->encController->decrypt($idArea);
  904. } catch (\Throwable $th) {
  905. DB::rollBack();
  906. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD002: Ocurrió un error al desencriptar el área.', $th->getMessage(), 500);
  907. }
  908. try {
  909. $validateExistArea = DB::table('S002V01TAREA')
  910. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  911. ->where('AREA_COAR', '=', $idArea)
  912. ->where('AREA_ESTA', '=', 'Activo')
  913. ->exists();
  914. } catch (\Throwable $th) {
  915. DB::rollBack();
  916. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD003: Ocurrió un error al verificar el código del área.', $th->getMessage(), 500);
  917. }
  918. if (!$validateExistArea) {
  919. DB::rollBack();
  920. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD004: El área no existe.', [], 406);
  921. }
  922. try {
  923. $validateExistWarehouse = DB::table('S002V01TALMA')
  924. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  925. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  926. ->where('ALMA_ESTA', '=', 'Activo')
  927. ->exists();
  928. } catch (\Throwable $th) {
  929. DB::rollBack();
  930. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD005: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  931. }
  932. if (!$validateExistWarehouse) {
  933. DB::rollBack();
  934. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD006: El almacen no existe.', [], 406);
  935. }
  936. try {
  937. $validateExistCode = DB::table('S002V01TAREA')
  938. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  939. ->where('AREA_COAR', '!=', $idArea)
  940. ->where('AREA_ESTA', '=', 'Activo')
  941. ->exists();
  942. } catch (\Throwable $th) {
  943. DB::rollBack();
  944. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD007: Ocurrió un error al verificar el código del área.', $th->getMessage(), 500);
  945. }
  946. if ($validateExistCode) {
  947. DB::rollBack();
  948. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD008: El código del área ya se encuentra registrado.', [], 406);
  949. }
  950. $now = $this->functionsController->now();
  951. $currentDate = $now->toDateTimeString();
  952. try {
  953. $validateUpdate = DB::table('S002V01TAREA')
  954. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  955. ->where('AREA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  956. ->where('AREA_COAR', '=', $idArea)
  957. ->update([
  958. 'AREA_NOAR' => $requestData['NOMBRE_AREA'],
  959. 'AREA_COME' => $requestData['COMENTARIOS'],
  960. 'AREA_USMO' => $user,
  961. 'AREA_FEMO' => $currentDate,
  962. 'AREA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  963. ]);
  964. } catch (\Throwable $th) {
  965. DB::rollBack();
  966. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD009: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  967. }
  968. if (!$validateUpdate) {
  969. DB::rollBack();
  970. return $this->responseController->makeResponse(true, 'ERR_AREA_UPD010: No se pudo guardar la información en la base de datos.', [], 406);
  971. }
  972. DB::commit();
  973. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  974. }
  975. public function deleteArea(Request $request, $idArea) {
  976. $validator = Validator::make($request->all(), [
  977. 'USUARIO' => 'required|string',
  978. 'NUMERO_LINEA' => 'required|string',
  979. ]);
  980. if ($validator->fails()) {
  981. return $this->responseController->makeResponse(
  982. true,
  983. "ERR_AREA_DEL000: Se encontraron uno o más errores.",
  984. $this->responseController->makeErrors($validator->errors()->messages()),
  985. 401
  986. );
  987. }
  988. DB::beginTransaction();
  989. $requestData = $request->all();
  990. try {
  991. $idArea = $this->encController->decrypt($idArea);
  992. } catch (\Throwable $th) {
  993. DB::rollBack();
  994. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL001: Ocurrió un error al desencriptar el nivel.', $th->getMessage(), 500);
  995. }
  996. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  997. if ($arrResponseCheckUser['error']) {
  998. DB::rollBack();
  999. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL002:'.$arrResponseCheckUser['msg'], [], 401);
  1000. }
  1001. $user = $arrResponseCheckUser['response'];
  1002. try {
  1003. $arrArea = (array) DB::table('S002V01TAREA')
  1004. ->where('AREA_COAR', '=', $idArea)
  1005. ->where('AREA_ESTA', '=', 'Activo')
  1006. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1007. ->first([
  1008. 'AREA_COAL',
  1009. ]);
  1010. } catch (\Throwable $th) {
  1011. DB::rollBack();
  1012. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL003: Ocurrió un error al obtener la información del área.', $th->getMessage(), 500);
  1013. }
  1014. if (empty($arrArea)) {
  1015. DB::rollBack();
  1016. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL004: El área no existe.', [], 406);
  1017. }
  1018. try {
  1019. $validateExists = DB::table('S002V01TUBAR')
  1020. ->where('UBAR_COAL', '=', $arrArea['AREA_COAL'])
  1021. ->where('UBAR_COZO', '=', $idArea)
  1022. ->where('UBAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1023. ->where('UBAR_ESTA', '=', 'Activo')
  1024. ->exists();
  1025. } catch (\Throwable $th) {
  1026. DB::rollBack();
  1027. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL005: Ocurrió un error al obtener las ubicaciones de los artículos.', $th->getMessage(), 500);
  1028. }
  1029. if($validateExists) {
  1030. DB::rollBack();
  1031. return $this->responseController->makeResponse(true, 'ERR_AREA_DEL006: No se puede eliminar debido a que existen artículos ubicados en el área.', [], 406);
  1032. }
  1033. try {
  1034. $countLevel = DB::table('S002V01TNIVE')
  1035. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1036. ->where('NIVE_COAL', '=', $arrArea['AREA_COAL'])
  1037. ->where('NIVE_COAR', '=', $idArea)
  1038. ->where('NIVE_ESTA', '=', 'Activo')
  1039. ->count();
  1040. } catch (\Throwable $th) {
  1041. DB::rollBack();
  1042. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL007: Ocurrió un error al obtener las zonas.', $th->getMessage(), 500);
  1043. }
  1044. if ($countLevel > 0) {
  1045. DB::rollBack();
  1046. $quantity = $countLevel === 1 ? 'existe 1 nivel activo' : 'existen '.$countLevel.' niveles activos';
  1047. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL008: No se puede eliminar debido a que '.$quantity.'.', [], 406);
  1048. }
  1049. try {
  1050. $countZones = DB::table('S002V01TZONA')
  1051. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1052. ->where('ZONA_COAL', '=', $arrArea['AREA_COAL'])
  1053. ->where('ZONA_COAR', '=', $idArea)
  1054. ->where('ZONA_ESTA', '=', 'Activo')
  1055. ->count();
  1056. } catch (\Throwable $th) {
  1057. DB::rollBack();
  1058. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL009: Ocurrió un error al obtener las zonas.', $th->getMessage(), 500);
  1059. }
  1060. if ($countZones > 0) {
  1061. DB::rollBack();
  1062. $quantity = $countZones === 1 ? 'existe 1 zona activa' : 'existen '.$countZones.' zonas activas';
  1063. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL010: No se puede eliminar debido a que '.$quantity.'.', [], 406);
  1064. }
  1065. $now = $this->functionsController->now();
  1066. $currentDate = $now->toDateTimeString();
  1067. try {
  1068. $validateUpdate = DB::table('S002V01TAREA')
  1069. ->where('AREA_COAR', '=', $idArea)
  1070. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1071. ->update([
  1072. 'AREA_ESTA' => 'Eliminado',
  1073. 'AREA_USMO' => $user,
  1074. 'AREA_FEMO' => $currentDate,
  1075. 'AREA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1076. ]);
  1077. } catch (\Throwable $th) {
  1078. DB::rollBack();
  1079. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL011: Ocurrió un error al eliminar el área.', $th->getMessage(), 500);
  1080. }
  1081. if (!$validateUpdate) {
  1082. DB::rollBack();
  1083. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL012: No se pudo eliminar el área.', [], 406);
  1084. }
  1085. DB::commit();
  1086. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1087. }
  1088. public function getLevelByAreaWarehouse($idWarehouse, $idArea, $user, $line) {
  1089. try {
  1090. $idWarehouse = $this->encController->decrypt($idWarehouse);
  1091. } catch (\Throwable $th) {
  1092. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1093. }
  1094. try {
  1095. $idArea = $this->encController->decrypt($idArea);
  1096. } catch (\Throwable $th) {
  1097. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY001: Ocurrió un error al desencriptar el ID del área', $th->getMessage(), 406);
  1098. }
  1099. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1100. if ($arrResponseCheckUser['error']) {
  1101. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY002:'.$arrResponseCheckUser['msg'], [], 401);
  1102. }
  1103. try {
  1104. $getLevel = DB::table('S002V01TNIVE')
  1105. ->where('NIVE_COAL', '=', $idWarehouse)
  1106. ->where('NIVE_COAR', '=', $idArea)
  1107. ->where('NIVE_NULI', '=', $line)
  1108. ->get([
  1109. 'NIVE_CONI AS CODIGO_NIVEL',
  1110. 'NIVE_NONI AS NOMBRE_NIVEL',
  1111. 'NIVE_COME AS COMENTARIOS',
  1112. 'NIVE_ESTA AS ESTADO',
  1113. 'NIVE_USRE AS USUARIO_REGISTRA',
  1114. 'NIVE_FERE AS FECHA_REGISTRA',
  1115. 'NIVE_USMO AS USUARIO_MODIFICA',
  1116. 'NIVE_FEMO AS FECHA_MODIFICA',
  1117. ]);
  1118. $arrLevel = json_decode(json_encode($getLevel), true);
  1119. } catch (\Throwable $th) {
  1120. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY003: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1121. }
  1122. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrLevel);
  1123. }
  1124. public function getLevelById( $idLevel, $user, $line ) {
  1125. try {
  1126. $idLevel = $this->encController->decrypt($idLevel);
  1127. } catch (\Throwable $th) {
  1128. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1129. }
  1130. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1131. if ($arrResponseCheckUser['error']) {
  1132. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY001:'.$arrResponseCheckUser['msg'], [], 401);
  1133. }
  1134. try {
  1135. $getLevel = (array) DB::table('S002V01TNIVE')
  1136. ->where('NIVE_CONI', '=', $idLevel)
  1137. ->where('NIVE_NULI', '=', $line)
  1138. ->first([
  1139. 'NIVE_NONI AS NOMBRE_NIVEL',
  1140. 'NIVE_COME AS COMENTARIOS',
  1141. 'NIVE_ESTA AS ESTADO',
  1142. 'NIVE_USRE AS USUARIO_REGISTRA',
  1143. 'NIVE_FERE AS FECHA_REGISTRA',
  1144. 'NIVE_USMO AS USUARIO_MODIFICA',
  1145. 'NIVE_FEMO AS FECHA_MODIFICA',
  1146. ]);
  1147. $arrLevel = json_decode(json_encode($getLevel), true);
  1148. } catch (\Throwable $th) {
  1149. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBY002: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1150. }
  1151. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrLevel);
  1152. }
  1153. public function getLevelByAreaWarehouseActives($idWarehouse, $idArea, $user, $line) {
  1154. try {
  1155. $idWarehouse = $this->encController->decrypt($idWarehouse);
  1156. } catch (\Throwable $th) {
  1157. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1158. }
  1159. try {
  1160. $idArea = $this->encController->decrypt($idArea);
  1161. } catch (\Throwable $th) {
  1162. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE001: Ocurrió un error al desencriptar el ID del área', $th->getMessage(), 406);
  1163. }
  1164. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1165. if ($arrResponseCheckUser['error']) {
  1166. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE002:'.$arrResponseCheckUser['msg'], [], 401);
  1167. }
  1168. try {
  1169. $validateExists = DB::table('S002V01TALMA')
  1170. ->where('ALMA_NULI', '=', $line)
  1171. ->where('ALMA_COAL', '=', $idWarehouse)
  1172. ->exists();
  1173. } catch (\Throwable $th) {
  1174. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE003: Ocurrió un error al obtener el almacen.', $th->getMessage(), 406);
  1175. }
  1176. if (!$validateExists) {
  1177. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE004: El almacen no existe.', [], 401);
  1178. }
  1179. try {
  1180. $validateExists = DB::table('S002V01TAREA')
  1181. ->where('AREA_NULI', '=', $line)
  1182. ->where('AREA_COAL', '=', $idWarehouse)
  1183. ->where('AREA_COAR', '=', $idArea)
  1184. ->exists();
  1185. } catch (\Throwable $th) {
  1186. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE005: Ocurrió un error al obtener el área.', $th->getMessage(), 406);
  1187. }
  1188. if (!$validateExists) {
  1189. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE006: El área no existe.', [], 401);
  1190. }
  1191. try {
  1192. $getLevel = DB::table('S002V01TNIVE')
  1193. ->where('NIVE_COAL', '=', $idWarehouse)
  1194. ->where('NIVE_COAR', '=', $idArea)
  1195. ->where('NIVE_NULI', '=', $line)
  1196. ->where('NIVE_ESTA', '=', 'Activo')
  1197. ->get([
  1198. 'NIVE_CONI AS CODIGO_NIVEL',
  1199. 'NIVE_NONI AS NOMBRE_NIVEL',
  1200. 'NIVE_COME AS COMENTARIOS',
  1201. ]);
  1202. $arrLevel = json_decode(json_encode($getLevel), true);
  1203. } catch (\Throwable $th) {
  1204. return $this->responseController->makeResponse(true, 'ERR_LEVEL_GETBYACTIVE007: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1205. }
  1206. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrLevel);
  1207. }
  1208. public function registerLevel(Request $request) {
  1209. $validator = Validator::make($request->all(), [
  1210. 'CODIGO_ALMACEN' => 'required|string',
  1211. 'CODIGO_AREA' => 'required|string',
  1212. 'CODIGO_NIVEL' => 'required|string',
  1213. 'NOMBRE_NIVEL' => 'required|string',
  1214. 'COMENTARIOS' => 'nullable|string',
  1215. 'USUARIO' => 'required|string',
  1216. 'NUMERO_LINEA' => 'required|string',
  1217. ]);
  1218. if ($validator->fails()) {
  1219. return $this->responseController->makeResponse(
  1220. true,
  1221. "ERR_LEVEL_REG000: Se encontraron uno o más errores.",
  1222. $this->responseController->makeErrors($validator->errors()->messages()),
  1223. 401
  1224. );
  1225. }
  1226. DB::beginTransaction();
  1227. $requestData = $request->all();
  1228. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1229. if ($arrResponseCheckUser['error']) {
  1230. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  1231. }
  1232. $user = $arrResponseCheckUser['response'];
  1233. try {
  1234. $validateExistWarehouse = DB::table('S002V01TALMA')
  1235. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  1236. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1237. ->where('ALMA_ESTA', '=', 'Activo')
  1238. ->exists();
  1239. } catch (\Throwable $th) {
  1240. DB::rollBack();
  1241. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG002: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  1242. }
  1243. if (!$validateExistWarehouse) {
  1244. DB::rollBack();
  1245. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG003: El almacen no existe.', [], 406);
  1246. }
  1247. try {
  1248. $validateExistArea = DB::table('S002V01TAREA')
  1249. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1250. ->where('AREA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1251. ->where('AREA_COAR', '=', $requestData['CODIGO_AREA'])
  1252. ->where('AREA_ESTA', '=', 'Activo')
  1253. ->exists();
  1254. } catch (\Throwable $th) {
  1255. DB::rollBack();
  1256. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG004: Ocurrió un error al verificar el área.', $th->getMessage(), 500);
  1257. }
  1258. if (!$validateExistArea) {
  1259. DB::rollBack();
  1260. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG005: El área no existe.', [], 406);
  1261. }
  1262. try {
  1263. $validateExistLevel = DB::table('S002V01TNIVE')
  1264. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1265. ->where('NIVE_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1266. ->where('NIVE_COAR', '=', $requestData['CODIGO_AREA'])
  1267. ->where('NIVE_CONI', '=', $requestData['CODIGO_NIVEL'])
  1268. ->exists();
  1269. } catch (\Throwable $th) {
  1270. DB::rollBack();
  1271. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG006: Ocurrió un error al verificar el código del nivel.', $th->getMessage(), 406);
  1272. }
  1273. if ($validateExistLevel) {
  1274. DB::rollBack();
  1275. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG007: El código del nivel ya existe.', [], 406);
  1276. }
  1277. $now = $this->functionsController->now();
  1278. $currentDate = $now->toDateTimeString();
  1279. try {
  1280. $validateInsert = DB::table('S002V01TNIVE')->insert([
  1281. 'NIVE_NULI' => $requestData['NUMERO_LINEA'],
  1282. 'NIVE_COAL' => $requestData['CODIGO_ALMACEN'],
  1283. 'NIVE_COAR' => $requestData['CODIGO_AREA'],
  1284. 'NIVE_CONI' => $requestData['CODIGO_NIVEL'],
  1285. 'NIVE_NONI' => $requestData['NOMBRE_NIVEL'],
  1286. 'NIVE_COME' => $requestData['COMENTARIOS'],
  1287. 'NIVE_USRE' => $user,
  1288. 'NIVE_FERE' => $currentDate,
  1289. 'NIVE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1290. ]);
  1291. } catch (\Throwable $th) {
  1292. DB::rollBack();
  1293. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG008: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  1294. }
  1295. if (!$validateInsert) {
  1296. DB::rollBack();
  1297. return $this->responseController->makeResponse(true, 'ERR_LEVEL_REG009: No se pudo guardar la información en la base de datos.', [], 406);
  1298. }
  1299. DB::commit();
  1300. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1301. }
  1302. public function updateLevel(Request $request, $idLevel) {
  1303. $validator = Validator::make($request->all(), [
  1304. 'CODIGO_ALMACEN' => 'required|string',
  1305. 'NOMBRE_NIVEL' => 'required|string',
  1306. 'COMENTARIOS' => 'nullable|string',
  1307. 'USUARIO' => 'required|string',
  1308. 'NUMERO_LINEA' => 'required|string',
  1309. ]);
  1310. if ($validator->fails()) {
  1311. return $this->responseController->makeResponse(
  1312. true,
  1313. "ERR_LEVEL_UPD000: Se encontraron uno o más errores.",
  1314. $this->responseController->makeErrors($validator->errors()->messages()),
  1315. 401
  1316. );
  1317. }
  1318. DB::beginTransaction();
  1319. $requestData = $request->all();
  1320. try {
  1321. $idLevel = $this->encController->decrypt($idLevel);
  1322. } catch (\Throwable $th) {
  1323. DB::rollBack();
  1324. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD001: Ocurrió un error al desencriptar el área.', $th->getMessage(), 500);
  1325. }
  1326. try {
  1327. $validateExistLevel = DB::table('S002V01TNIVE')
  1328. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1329. ->where('NIVE_CONI', '=', $idLevel)
  1330. ->where('NIVE_ESTA', '=', 'Activo')
  1331. ->exists();
  1332. } catch (\Throwable $th) {
  1333. DB::rollBack();
  1334. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD002: Ocurrió un error al verificar el código del área.', $th->getMessage(), 500);
  1335. }
  1336. if (!$validateExistLevel) {
  1337. DB::rollBack();
  1338. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD003: El área no existe.', [], 406);
  1339. }
  1340. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1341. if ($arrResponseCheckUser['error']) {
  1342. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD004:'.$arrResponseCheckUser['msg'], [], 401);
  1343. }
  1344. $user = $arrResponseCheckUser['response'];
  1345. try {
  1346. $validateExistWarehouse = DB::table('S002V01TALMA')
  1347. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  1348. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1349. ->where('ALMA_ESTA', '=', 'Activo')
  1350. ->exists();
  1351. } catch (\Throwable $th) {
  1352. DB::rollBack();
  1353. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD005: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  1354. }
  1355. if (!$validateExistWarehouse) {
  1356. DB::rollBack();
  1357. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD006: El almacen no existe.', [], 406);
  1358. }
  1359. try {
  1360. $validateExistArea = DB::table('S002V01TAREA')
  1361. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1362. ->where('AREA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1363. ->where('AREA_COAR', '=', $requestData['CODIGO_AREA'])
  1364. ->where('AREA_ESTA', '=', 'Activo')
  1365. ->exists();
  1366. } catch (\Throwable $th) {
  1367. DB::rollBack();
  1368. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD007: Ocurrió un error al verificar el área.', $th->getMessage(), 500);
  1369. }
  1370. if (!$validateExistArea) {
  1371. DB::rollBack();
  1372. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD008: El área no existe.', [], 406);
  1373. }
  1374. try {
  1375. $validateExistLevel = DB::table('S002V01TNIVE')
  1376. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1377. ->where('NIVE_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1378. ->where('NIVE_COAR', '=', $requestData['CODIGO_AREA'])
  1379. ->where('NIVE_CONI', '=', $requestData['CODIGO_NIVEL'])
  1380. ->exists();
  1381. } catch (\Throwable $th) {
  1382. DB::rollBack();
  1383. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD009: Ocurrió un error al verificar el código del nivel.', $th->getMessage(), 406);
  1384. }
  1385. if ($validateExistLevel) {
  1386. DB::rollBack();
  1387. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD010: El código del nivel ya existe.', [], 406);
  1388. }
  1389. $now = $this->functionsController->now();
  1390. $currentDate = $now->toDateTimeString();
  1391. try {
  1392. $validateUpdate = DB::table('S002V01TNIVE')
  1393. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1394. ->where('NIVE_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1395. ->where('NIVE_COAR', '=', $requestData['CODIGO_AREA'])
  1396. ->where('NIVE_CONI', '=', $idLevel)
  1397. ->update([
  1398. 'NIVE_NONI' => $requestData['NOMBRE_NIVEL'],
  1399. 'NIVE_COME' => $requestData['COMENTARIOS'],
  1400. 'NIVE_USMO' => $user,
  1401. 'NIVE_FEMO' => $currentDate,
  1402. 'NIVE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1403. ]);
  1404. } catch (\Throwable $th) {
  1405. DB::rollBack();
  1406. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD011: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  1407. }
  1408. if (!$validateUpdate) {
  1409. DB::rollBack();
  1410. return $this->responseController->makeResponse(true, 'ERR_LEVEL_UPD012: No se pudo guardar la información en la base de datos.', [], 406);
  1411. }
  1412. DB::commit();
  1413. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1414. }
  1415. public function deleteLevel(Request $request, $idLevel) {
  1416. $validator = Validator::make($request->all(), [
  1417. 'USUARIO' => 'required|string',
  1418. 'NUMERO_LINEA' => 'required|string',
  1419. ]);
  1420. if ($validator->fails()) {
  1421. return $this->responseController->makeResponse(
  1422. true,
  1423. "ERR_LEVEL_DEL000: Se encontraron uno o más errores.",
  1424. $this->responseController->makeErrors($validator->errors()->messages()),
  1425. 401
  1426. );
  1427. }
  1428. DB::beginTransaction();
  1429. $requestData = $request->all();
  1430. try {
  1431. $idLevel = $this->encController->decrypt($idLevel);
  1432. } catch (\Throwable $th) {
  1433. DB::rollBack();
  1434. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL001: Ocurrió un error al desencriptar el nivel.', $th->getMessage(), 500);
  1435. }
  1436. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1437. if ($arrResponseCheckUser['error']) {
  1438. DB::rollBack();
  1439. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL002:'.$arrResponseCheckUser['msg'], [], 401);
  1440. }
  1441. $user = $arrResponseCheckUser['response'];
  1442. try {
  1443. $arrLevel = (array) DB::table('S002V01TNIVE')
  1444. ->where('NIVE_CONI', '=', $idLevel)
  1445. ->where('NIVE_ESTA', '=', 'Activo')
  1446. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1447. ->first([
  1448. 'NIVE_COAL',
  1449. 'NIVE_COAR'
  1450. ]);
  1451. } catch (\Throwable $th) {
  1452. DB::rollBack();
  1453. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL003: Ocurrió un error al obtener la información del nivel.', $th->getMessage(), 500);
  1454. }
  1455. if (empty($arrLevel)) {
  1456. DB::rollBack();
  1457. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL004: El nivel no existe.', [], 406);
  1458. }
  1459. try {
  1460. $validateExists = DB::table('S002V01TUBAR')
  1461. ->where('UBAR_COAL', '=', $arrLevel['NIVE_COAL'])
  1462. ->where('UBAR_COAR', '=', $arrLevel['NIVE_COAR'])
  1463. ->where('UBAR_COZO', '=', $idLevel)
  1464. ->where('UBAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1465. ->where('UBAR_ESTA', '=', 'Activo')
  1466. ->exists();
  1467. } catch (\Throwable $th) {
  1468. DB::rollBack();
  1469. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL005: Ocurrió un error al obtener las ubicaciones de los artículos.', $th->getMessage(), 500);
  1470. }
  1471. if($validateExists) {
  1472. DB::rollBack();
  1473. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL006: No se puede eliminar debido a que existen artículos ubicados en el nivel.', [], 406);
  1474. }
  1475. try {
  1476. $countZones = DB::table('S002V01TZONA')
  1477. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1478. ->where('ZONA_COAL', '=', $arrLevel['NIVE_COAL'])
  1479. ->where('ZONA_COAR', '=', $arrLevel['NIVE_COAR'])
  1480. ->where('ZONA_CONI', '=', $idLevel)
  1481. ->where('ZONA_ESTA', '=', 'Activo')
  1482. ->count();
  1483. } catch (\Throwable $th) {
  1484. DB::rollBack();
  1485. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL007: Ocurrió un error al obtener las zonas.', $th->getMessage(), 500);
  1486. }
  1487. if ($countZones > 0) {
  1488. DB::rollBack();
  1489. $quantity = $countZones === 1 ? 'existe 1 zona activa' : 'existen '.$countZones.' zonas activas';
  1490. return $this->responseController->makeResponse(true, 'ERR_LEVEL_DEL008: No se puede eliminar debido a que '.$quantity.'.', [], 406);
  1491. }
  1492. $now = $this->functionsController->now();
  1493. $currentDate = $now->toDateTimeString();
  1494. try {
  1495. $validateUpdate = DB::table('S002V01TNIVE')
  1496. ->where('NIVE_CONI', '=', $idLevel)
  1497. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1498. ->update([
  1499. 'NIVE_ESTA' => 'Eliminado',
  1500. 'NIVE_USMO' => $user,
  1501. 'NIVE_FEMO' => $currentDate,
  1502. 'NIVE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1503. ]);
  1504. } catch (\Throwable $th) {
  1505. DB::rollBack();
  1506. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL009: Ocurrió un error al eliminar el nivel.', $th->getMessage(), 500);
  1507. }
  1508. if (!$validateUpdate) {
  1509. DB::rollBack();
  1510. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL010: No se pudo eliminar el nivel.', [], 406);
  1511. }
  1512. DB::commit();
  1513. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1514. }
  1515. public function getZoneByLevelAreaWarehouse($idWarehouse, $idArea, $idLevel, $user, $line) {
  1516. try {
  1517. $idWarehouse = $this->encController->decrypt($idWarehouse);
  1518. } catch (\Throwable $th) {
  1519. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1520. }
  1521. try {
  1522. $idArea = $this->encController->decrypt($idArea);
  1523. } catch (\Throwable $th) {
  1524. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY001: Ocurrió un error al desencriptar el ID del área', $th->getMessage(), 406);
  1525. }
  1526. try {
  1527. $idLevel = $this->encController->decrypt($idLevel);
  1528. } catch (\Throwable $th) {
  1529. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY002: Ocurrió un error al desencriptar el ID del nivel', $th->getMessage(), 406);
  1530. }
  1531. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1532. if ($arrResponseCheckUser['error']) {
  1533. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY003:'.$arrResponseCheckUser['msg'], [], 401);
  1534. }
  1535. try {
  1536. $getZone = DB::table('S002V01TZONA')
  1537. ->where('ZONA_COAL', '=', $idWarehouse)
  1538. ->where('ZONA_COAR', '=', $idArea)
  1539. ->where('ZONA_CONI', '=', $idLevel)
  1540. ->where('ZONA_NULI', '=', $line)
  1541. ->get([
  1542. 'ZONA_COZO AS CODIGO_ZONA',
  1543. 'ZONA_NOZO AS NOMBRE_ZONA',
  1544. 'ZONA_COME AS COMENTARIOS',
  1545. 'ZONA_ESTA AS ESTADO',
  1546. 'ZONA_USRE AS USUARIO_REGISTRA',
  1547. 'ZONA_FERE AS FECHA_REGISTRA',
  1548. 'ZONA_USMO AS USUARIO_MODIFICA',
  1549. 'ZONA_FEMO AS FECHA_MODIFICA',
  1550. ]);
  1551. $arrZone = json_decode(json_encode($getZone), true);
  1552. } catch (\Throwable $th) {
  1553. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY004: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1554. }
  1555. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrZone);
  1556. }
  1557. public function getZoneById($idZone, $user, $line) {
  1558. try {
  1559. $idZone = $this->encController->decrypt($idZone);
  1560. } catch (\Throwable $th) {
  1561. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1562. }
  1563. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1564. if ($arrResponseCheckUser['error']) {
  1565. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY001:'.$arrResponseCheckUser['msg'], [], 401);
  1566. }
  1567. try {
  1568. $getZone = (array) DB::table('S002V01TZONA')
  1569. ->where('ZONA_COZO', '=', $idZone)
  1570. ->where('ZONA_NULI', '=', $line)
  1571. ->first([
  1572. 'ZONA_NOZO AS NOMBRE_ZONA',
  1573. 'ZONA_COME AS COMENTARIOS',
  1574. 'ZONA_ESTA AS ESTADO',
  1575. 'ZONA_USRE AS USUARIO_REGISTRA',
  1576. 'ZONA_FERE AS FECHA_REGISTRA',
  1577. 'ZONA_USMO AS USUARIO_MODIFICA',
  1578. 'ZONA_FEMO AS FECHA_MODIFICA',
  1579. ]);
  1580. $arrZone = json_decode(json_encode($getZone), true);
  1581. } catch (\Throwable $th) {
  1582. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBY002: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1583. }
  1584. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrZone);
  1585. }
  1586. public function getZoneByLevelAreaWarehouseActive($idWarehouse, $idArea, $idLevel, $user, $line) {
  1587. try {
  1588. $idWarehouse = $this->encController->decrypt($idWarehouse);
  1589. } catch (\Throwable $th) {
  1590. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
  1591. }
  1592. try {
  1593. $idArea = $this->encController->decrypt($idArea);
  1594. } catch (\Throwable $th) {
  1595. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE001: Ocurrió un error al desencriptar el ID del área', $th->getMessage(), 406);
  1596. }
  1597. try {
  1598. $idLevel = $this->encController->decrypt($idLevel);
  1599. } catch (\Throwable $th) {
  1600. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE002: Ocurrió un error al desencriptar el ID del nivel', $th->getMessage(), 406);
  1601. }
  1602. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  1603. if ($arrResponseCheckUser['error']) {
  1604. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE003:'.$arrResponseCheckUser['msg'], [], 401);
  1605. }
  1606. try {
  1607. $validateExists = DB::table('S002V01TALMA')
  1608. ->where('ALMA_NULI', '=', $line)
  1609. ->where('ALMA_COAL', '=', $idWarehouse)
  1610. ->exists();
  1611. } catch (\Throwable $th) {
  1612. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE004: Ocurrió un error al obtener el almacen.', $th->getMessage(), 406);
  1613. }
  1614. if (!$validateExists) {
  1615. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE005: El almacen no existe.', [], 401);
  1616. }
  1617. try {
  1618. $validateExists = DB::table('S002V01TAREA')
  1619. ->where('AREA_NULI', '=', $line)
  1620. ->where('AREA_COAL', '=', $idWarehouse)
  1621. ->where('AREA_COAR', '=', $idArea)
  1622. ->exists();
  1623. } catch (\Throwable $th) {
  1624. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE006: Ocurrió un error al obtener el área.', $th->getMessage(), 406);
  1625. }
  1626. if (!$validateExists) {
  1627. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE007: El área no existe.', [], 401);
  1628. }
  1629. try {
  1630. $validateExists = DB::table('S002V01TNIVE')
  1631. ->where('NIVE_NULI', '=', $line)
  1632. ->where('NIVE_COAL', '=', $idWarehouse)
  1633. ->where('NIVE_COAR', '=', $idArea)
  1634. ->where('NIVE_CONI', '=', $idLevel)
  1635. ->exists();
  1636. } catch (\Throwable $th) {
  1637. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE008: Ocurrió un error al obtener el nivel.', $th->getMessage(), 406);
  1638. }
  1639. if (!$validateExists) {
  1640. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE009: El nivel no existe.', [], 401);
  1641. }
  1642. try {
  1643. $getZone = DB::table('S002V01TZONA')
  1644. ->where('ZONA_COAL', '=', $idWarehouse)
  1645. ->where('ZONA_COAR', '=', $idArea)
  1646. ->where('ZONA_CONI', '=', $idLevel)
  1647. ->where('ZONA_NULI', '=', $line)
  1648. ->where('ZONA_ESTA', '=', 'Activo')
  1649. ->get([
  1650. 'ZONA_COZO AS CODIGO_ZONA',
  1651. 'ZONA_NOZO AS NOMBRE_ZONA',
  1652. 'ZONA_COME AS COMENTARIOS',
  1653. ]);
  1654. $arrZone = json_decode(json_encode($getZone), true);
  1655. } catch (\Throwable $th) {
  1656. return $this->responseController->makeResponse(true, 'ERR_ZONE_GETBYACTIVE010: Ocurrió un error al obtener los registros del área.', $th->getMessage(), 406);
  1657. }
  1658. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrZone);
  1659. }
  1660. public function registerZone(Request $request) {
  1661. $validator = Validator::make($request->all(), [
  1662. 'CODIGO_ALMACEN' => 'required|string',
  1663. 'CODIGO_AREA' => 'required|string',
  1664. 'CODIGO_NIVEL' => 'required|string',
  1665. 'CODIGO_ZONA' => 'required|string',
  1666. 'NOMBRE_ZONA' => 'required|string',
  1667. 'COMENTARIOS' => 'nullable|string',
  1668. 'USUARIO' => 'required|string',
  1669. 'NUMERO_LINEA' => 'required|string',
  1670. ]);
  1671. if ($validator->fails()) {
  1672. return $this->responseController->makeResponse(
  1673. true,
  1674. "ERR_ZONE_REG000: Se encontraron uno o más errores.",
  1675. $this->responseController->makeErrors($validator->errors()->messages()),
  1676. 401
  1677. );
  1678. }
  1679. DB::beginTransaction();
  1680. $requestData = $request->all();
  1681. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1682. if ($arrResponseCheckUser['error']) {
  1683. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG001:'.$arrResponseCheckUser['msg'], [], 401);
  1684. }
  1685. $user = $arrResponseCheckUser['response'];
  1686. try {
  1687. $validateExistWarehouse = DB::table('S002V01TALMA')
  1688. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  1689. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1690. ->where('ALMA_ESTA', '=', 'Activo')
  1691. ->exists();
  1692. } catch (\Throwable $th) {
  1693. DB::rollBack();
  1694. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG002: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  1695. }
  1696. if (!$validateExistWarehouse) {
  1697. DB::rollBack();
  1698. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG003: El almacen no existe.', [], 406);
  1699. }
  1700. try {
  1701. $validateExistArea = DB::table('S002V01TAREA')
  1702. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1703. ->where('AREA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1704. ->where('AREA_COAR', '=', $requestData['CODIGO_AREA'])
  1705. ->where('AREA_ESTA', '=', 'Activo')
  1706. ->exists();
  1707. } catch (\Throwable $th) {
  1708. DB::rollBack();
  1709. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG004: Ocurrió un error al verificar el área.', $th->getMessage(), 500);
  1710. }
  1711. if (!$validateExistArea) {
  1712. DB::rollBack();
  1713. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG005: El área no existe.', [], 406);
  1714. }
  1715. try {
  1716. $validateExistNivel = DB::table('S002V01TNIVE')
  1717. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1718. ->where('NIVE_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1719. ->where('NIVE_COAR', '=', $requestData['CODIGO_AREA'])
  1720. ->where('NIVE_CONI', '=', $requestData['CODIGO_NIVEL'])
  1721. ->where('NIVE_ESTA', '=', 'Activo')
  1722. ->exists();
  1723. } catch (\Throwable $th) {
  1724. DB::rollBack();
  1725. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG006: Ocurrió un error al verificar el nivel.', $th->getMessage(), 500);
  1726. }
  1727. if (!$validateExistNivel) {
  1728. DB::rollBack();
  1729. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG007: El nivel no existe.', [], 406);
  1730. }
  1731. try {
  1732. $validateExistZone = DB::table('S002V01TZONA')
  1733. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1734. ->where('ZONA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1735. ->where('ZONA_COAR', '=', $requestData['CODIGO_AREA'])
  1736. ->where('ZONA_CONI', '=', $requestData['CODIGO_NIVEL'])
  1737. ->where('ZONA_COZO', '=', $requestData['CODIGO_ZONA'])
  1738. ->exists();
  1739. } catch (\Throwable $th) {
  1740. DB::rollBack();
  1741. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG008: Ocurrió un error al verificar el código de la zona.', $th->getMessage(), 406);
  1742. }
  1743. if ($validateExistZone) {
  1744. DB::rollBack();
  1745. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG009: El código de la zona ya existe.', [], 406);
  1746. }
  1747. $now = $this->functionsController->now();
  1748. $currentDate = $now->toDateTimeString();
  1749. try {
  1750. $validateInsert = DB::table('S002V01TZONA')->insert([
  1751. 'ZONA_NULI' => $requestData['NUMERO_LINEA'],
  1752. 'ZONA_COAL' => $requestData['CODIGO_ALMACEN'],
  1753. 'ZONA_COAR' => $requestData['CODIGO_AREA'],
  1754. 'ZONA_CONI' => $requestData['CODIGO_NIVEL'],
  1755. 'ZONA_COZO' => $requestData['CODIGO_ZONA'],
  1756. 'ZONA_NOZO' => $requestData['NOMBRE_ZONA'],
  1757. 'ZONA_COME' => $requestData['COMENTARIOS'],
  1758. 'ZONA_USRE' => $user,
  1759. 'ZONA_FERE' => $currentDate,
  1760. 'ZONA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1761. ]);
  1762. } catch (\Throwable $th) {
  1763. DB::rollBack();
  1764. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG010: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  1765. }
  1766. if (!$validateInsert) {
  1767. DB::rollBack();
  1768. return $this->responseController->makeResponse(true, 'ERR_ZONE_REG011: No se pudo guardar la información en la base de datos.', [], 406);
  1769. }
  1770. DB::commit();
  1771. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1772. }
  1773. public function updateZone(Request $request, $idZone) {
  1774. $validator = Validator::make($request->all(), [
  1775. 'CODIGO_ALMACEN' => 'required|string',
  1776. 'CODIGO_AREA' => 'required|string',
  1777. 'CODIGO_NIVEL' => 'required|string',
  1778. 'NOMBRE_ZONA' => 'required|string',
  1779. 'COMENTARIOS' => 'nullable|string',
  1780. 'USUARIO' => 'required|string',
  1781. 'NUMERO_LINEA' => 'required|string',
  1782. ]);
  1783. if ($validator->fails()) {
  1784. return $this->responseController->makeResponse(
  1785. true,
  1786. "ERR_ZONE_UPD000: Se encontraron uno o más errores.",
  1787. $this->responseController->makeErrors($validator->errors()->messages()),
  1788. 401
  1789. );
  1790. }
  1791. DB::beginTransaction();
  1792. $requestData = $request->all();
  1793. try {
  1794. $idZone = $this->encController->decrypt($idZone);
  1795. } catch (\Throwable $th) {
  1796. DB::rollBack();
  1797. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD001: Ocurrió un error al desencriptar la zona.', $th->getMessage(), 500);
  1798. }
  1799. try {
  1800. $validateExistLevel = DB::table('S002V01TZONA')
  1801. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1802. ->where('ZONA_COZO', '=', $idZone)
  1803. ->where('ZONA_ESTA', '=', 'Activo')
  1804. ->exists();
  1805. } catch (\Throwable $th) {
  1806. DB::rollBack();
  1807. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD002: Ocurrió un error al verificar el código de la zona.', $th->getMessage(), 500);
  1808. }
  1809. if (!$validateExistLevel) {
  1810. DB::rollBack();
  1811. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD003: El área no existe.', [], 406);
  1812. }
  1813. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1814. if ($arrResponseCheckUser['error']) {
  1815. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD004:'.$arrResponseCheckUser['msg'], [], 401);
  1816. }
  1817. $user = $arrResponseCheckUser['response'];
  1818. try {
  1819. $validateExistWarehouse = DB::table('S002V01TALMA')
  1820. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  1821. ->where('ALMA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1822. ->where('ALMA_ESTA', '=', 'Activo')
  1823. ->exists();
  1824. } catch (\Throwable $th) {
  1825. DB::rollBack();
  1826. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD005: Ocurrió un error al verificar el almacen.', $th->getMessage(), 500);
  1827. }
  1828. if (!$validateExistWarehouse) {
  1829. DB::rollBack();
  1830. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD006: El almacen no existe.', [], 406);
  1831. }
  1832. try {
  1833. $validateExistArea = DB::table('S002V01TAREA')
  1834. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  1835. ->where('AREA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1836. ->where('AREA_COAR', '=', $requestData['CODIGO_AREA'])
  1837. ->where('AREA_ESTA', '=', 'Activo')
  1838. ->exists();
  1839. } catch (\Throwable $th) {
  1840. DB::rollBack();
  1841. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD007: Ocurrió un error al verificar el área.', $th->getMessage(), 500);
  1842. }
  1843. if (!$validateExistArea) {
  1844. DB::rollBack();
  1845. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD008: El área no existe.', [], 406);
  1846. }
  1847. try {
  1848. $validateExistNivel = DB::table('S002V01TNIVE')
  1849. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  1850. ->where('NIVE_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1851. ->where('NIVE_COAR', '=', $requestData['CODIGO_AREA'])
  1852. ->where('NIVE_CONI', '=', $requestData['CODIGO_NIVEL'])
  1853. ->where('NIVE_ESTA', '=', 'Activo')
  1854. ->exists();
  1855. } catch (\Throwable $th) {
  1856. DB::rollBack();
  1857. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD009: Ocurrió un error al verificar el nivel.', $th->getMessage(), 500);
  1858. }
  1859. if (!$validateExistNivel) {
  1860. DB::rollBack();
  1861. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD010: El nivel no existe.', [], 406);
  1862. }
  1863. try {
  1864. $validateExistZone = DB::table('S002V01TZONA')
  1865. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1866. ->where('ZONA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1867. ->where('ZONA_COAR', '=', $requestData['CODIGO_AREA'])
  1868. ->where('ZONA_CONI', '=', $requestData['CODIGO_NIVEL'])
  1869. ->where('ZONA_COZO', '=', $requestData['CODIGO_ZONA'])
  1870. ->exists();
  1871. } catch (\Throwable $th) {
  1872. DB::rollBack();
  1873. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD011: Ocurrió un error al verificar el código de la zona.', $th->getMessage(), 406);
  1874. }
  1875. if ($validateExistZone) {
  1876. DB::rollBack();
  1877. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD012: El código de la zona ya existe.', [], 406);
  1878. }
  1879. $now = $this->functionsController->now();
  1880. $currentDate = $now->toDateTimeString();
  1881. try {
  1882. $validateUpdate = DB::table('S002V01TZONA')
  1883. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1884. ->where('ZONA_COAL', '=', $requestData['CODIGO_ALMACEN'])
  1885. ->where('ZONA_COAR', '=', $requestData['CODIGO_AREA'])
  1886. ->where('ZONA_CONI', '=', $requestData['CODIGO_NIVEL'])
  1887. ->where('ZONA_COZO', '=', $idZone)
  1888. ->update([
  1889. 'ZONA_NOZO' => $requestData['NOMBRE_ZONA'],
  1890. 'ZONA_COME' => $requestData['COMENTARIOS'],
  1891. 'ZONA_USMO' => $user,
  1892. 'ZONA_FEMO' => $currentDate,
  1893. 'ZONA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1894. ]);
  1895. } catch (\Throwable $th) {
  1896. DB::rollBack();
  1897. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD013: Ocurrió un error al ingresar la información a la base de datos.', $th->getMessage(), 500);
  1898. }
  1899. if (!$validateUpdate) {
  1900. DB::rollBack();
  1901. return $this->responseController->makeResponse(true, 'ERR_ZONE_UPD014: No se pudo guardar la información en la base de datos.', [], 406);
  1902. }
  1903. DB::commit();
  1904. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1905. }
  1906. public function deleteZone(Request $request, $idZone) {
  1907. $validator = Validator::make($request->all(), [
  1908. 'USUARIO' => 'required|string',
  1909. 'NUMERO_LINEA' => 'required|string',
  1910. ]);
  1911. if ($validator->fails()) {
  1912. return $this->responseController->makeResponse(
  1913. true,
  1914. "ERR_ZONE_DEL000: Se encontraron uno o más errores.",
  1915. $this->responseController->makeErrors($validator->errors()->messages()),
  1916. 401
  1917. );
  1918. }
  1919. DB::beginTransaction();
  1920. $requestData = $request->all();
  1921. try {
  1922. $idZone = $this->encController->decrypt($idZone);
  1923. } catch (\Throwable $th) {
  1924. DB::rollBack();
  1925. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL001: Ocurrió un error al desencriptar la zona.', $th->getMessage(), 500);
  1926. }
  1927. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  1928. if ($arrResponseCheckUser['error']) {
  1929. DB::rollBack();
  1930. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL002:'.$arrResponseCheckUser['msg'], [], 401);
  1931. }
  1932. $user = $arrResponseCheckUser['response'];
  1933. try {
  1934. $arrZone = (array) DB::table('S002V01TZONA')
  1935. ->where('ZONA_COZO', '=', $idZone)
  1936. ->where('ZONA_ESTA', '=', 'Activo')
  1937. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1938. ->first([
  1939. 'ZONA_COAL',
  1940. 'ZONA_COAR',
  1941. 'ZONA_CONI',
  1942. ]);
  1943. } catch (\Throwable $th) {
  1944. DB::rollBack();
  1945. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL003: Ocurrió un error al obtener la información de la zona.', $th->getMessage(), 500);
  1946. }
  1947. if (empty($arrZone)) {
  1948. DB::rollBack();
  1949. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL004: La zona no existe.', [], 406);
  1950. }
  1951. try {
  1952. $validateExists = DB::table('S002V01TUBAR')
  1953. ->where('UBAR_COAL', '=', $arrZone['ZONA_COAL'])
  1954. ->where('UBAR_COAR', '=', $arrZone['ZONA_COAR'])
  1955. ->where('UBAR_CONI', '=', $arrZone['ZONA_CONI'])
  1956. ->where('UBAR_COZO', '=', $idZone)
  1957. ->where('UBAR_NULI', '=', $requestData['NUMERO_LINEA'])
  1958. ->where('UBAR_ESTA', '=', 'Activo')
  1959. ->exists();
  1960. } catch (\Throwable $th) {
  1961. DB::rollBack();
  1962. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL005: Ocurrió un error al obtener las ubicaciones de los artículos.', $th->getMessage(), 500);
  1963. }
  1964. if($validateExists) {
  1965. DB::rollBack();
  1966. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL006: No se puede eliminar debido a que existen artículos ubicados en la zona.', [], 406);
  1967. }
  1968. $now = $this->functionsController->now();
  1969. $currentDate = $now->toDateTimeString();
  1970. try {
  1971. $validateUpdate = DB::table('S002V01TZONA')
  1972. ->where('ZONA_COZO', '=', $idZone)
  1973. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  1974. ->update([
  1975. 'ZONA_ESTA' => 'Eliminado',
  1976. 'ZONA_USMO' => $user,
  1977. 'ZONA_FEMO' => $currentDate,
  1978. 'ZONA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1979. ]);
  1980. } catch (\Throwable $th) {
  1981. DB::rollBack();
  1982. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL007: Ocurrió un error al eliminar la zona.', $th->getMessage(), 500);
  1983. }
  1984. if (!$validateUpdate) {
  1985. DB::rollBack();
  1986. return $this->responseController->makeResponse(true, 'ERR_ZONE_DEL008: No se pudo eliminar la zona.', [], 406);
  1987. }
  1988. DB::commit();
  1989. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  1990. }
  1991. public function registerToStock(Request $request) {
  1992. $validator = Validator::make($request->all(), [
  1993. 'WAREHOUSE' => 'required|string',
  1994. 'AREA' => 'required|string',
  1995. 'LEVEL' => 'required|string',
  1996. 'ZONE' => 'required|string',
  1997. 'CODIGO_EQUIPAMIENTO' => 'required|string',
  1998. 'ORDER' => 'required|string',
  1999. 'ID_INFORMATION' => 'required|integer',
  2000. 'NUMBER_ITEMS' => 'required|integer',
  2001. 'USUARIO' => 'required|string',
  2002. 'NUMERO_LINEA' => 'required|string',
  2003. ]);
  2004. if($validator->fails()){
  2005. return $this->responseController->makeResponse(
  2006. true,
  2007. "Se encontraron uno o más errores.",
  2008. $this->responseController->makeErrors(
  2009. $validator->errors()->messages()
  2010. ),
  2011. 401
  2012. );
  2013. }
  2014. $requestData = $request->all();
  2015. // Se desencripta y se verifica si el usuario existe
  2016. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
  2017. if ($arrResponseCheckUser['error']) {
  2018. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  2019. }
  2020. $user = $arrResponseCheckUser['response'];
  2021. // Se obtiene la información encriptada
  2022. try {
  2023. $idWarehouse = $this->encController->decrypt($requestData['WAREHOUSE']);
  2024. } catch (\Throwable $th) {
  2025. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el almacen.', $th->getMessage(), 500);
  2026. }
  2027. if ($idWarehouse === false) {
  2028. return $this->responseController->makeResponse(true, 'La encriptación del almacen no es correcta.', [], 500);
  2029. }
  2030. try {
  2031. $idArea = $this->encController->decrypt($requestData['AREA']);
  2032. } catch (\Throwable $th) {
  2033. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el área.', $th->getMessage(), 500);
  2034. }
  2035. if ($idArea === false) {
  2036. return $this->responseController->makeResponse(true, 'La encriptacipon del área no es correcta.', [], 500);
  2037. }
  2038. try {
  2039. $idLevel = $this->encController->decrypt($requestData['LEVEL']);
  2040. } catch (\Throwable $th) {
  2041. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el nivel.', $th->getMessage(), 500);
  2042. }
  2043. if ($idLevel === false) {
  2044. return $this->responseController->makeResponse(true, 'La encriptación del nivel no es correcta.', [], 500);
  2045. }
  2046. try {
  2047. $idZone = $this->encController->decrypt($requestData['ZONE']);
  2048. } catch (\Throwable $th) {
  2049. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la zona.', $th->getMessage(), 500);
  2050. }
  2051. if ($idZone === false) {
  2052. return $this->responseController->makeResponse(true, 'La encriptación de la zona no es correcta.', [], 500);
  2053. }
  2054. // Se verifica que la información exista
  2055. try {
  2056. $validateWarehouse = DB::table('S002V01TALMA')
  2057. ->where('ALMA_COAL', '=', $idWarehouse)
  2058. ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
  2059. ->exists();
  2060. } catch (\Throwable $th) {
  2061. return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el almacen existe.', $th->getMessage(), 500);
  2062. }
  2063. if ($validateWarehouse === false) {
  2064. return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
  2065. }
  2066. try {
  2067. $validateArea = DB::table('S002V01TAREA')
  2068. ->where('AREA_COAL', '=', $idWarehouse)
  2069. ->where('AREA_COAR', '=', $idArea)
  2070. ->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
  2071. ->exists();
  2072. } catch (\Throwable $th) {
  2073. return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el área existe.', $th->getMessage(), 500);
  2074. }
  2075. if ($validateArea === false) {
  2076. return $this->responseController->makeResponse(true, 'El área no existe.', [], 500);
  2077. }
  2078. try {
  2079. $validateLevel = DB::table('S002V01TNIVE')
  2080. ->where('NIVE_COAL', '=', $idWarehouse)
  2081. ->where('NIVE_COAR', '=', $idArea)
  2082. ->where('NIVE_CONI', '=', $idLevel)
  2083. ->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
  2084. ->exists();
  2085. } catch (\Throwable $th) {
  2086. return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el nivel existe.', $th->getMessage(), 500);
  2087. }
  2088. if ($validateLevel === false) {
  2089. return $this->responseController->makeResponse(true, 'El nivel no existe.', [], 500);
  2090. }
  2091. try {
  2092. $validateZone = DB::table('S002V01TZONA')
  2093. ->where('ZONA_COAL', '=', $idWarehouse)
  2094. ->where('ZONA_COAR', '=', $idArea)
  2095. ->where('ZONA_CONI', '=', $idLevel)
  2096. ->where('ZONA_COZO', '=', $idZone)
  2097. ->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
  2098. ->exists();
  2099. } catch (\Throwable $th) {
  2100. return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si la zona existe.', $th->getMessage(), 500);
  2101. }
  2102. if ($validateZone === false) {
  2103. return $this->responseController->makeResponse(true, 'La zona no existe.', [], 500);
  2104. }
  2105. try {
  2106. $orden = (array) DB::table('S002V01TORCO')
  2107. ->where('ORCO_NUOR', '=', $requestData['ORDER'])
  2108. ->where('ORCO_NULI', '=', $requestData['NUMERO_LINEA'])
  2109. ->where('ORCO_ESTA', '=', 'Recibido')
  2110. ->first([
  2111. 'ORCO_IDLI AS ID_LINEA_SOLICITUD',
  2112. 'ORCO_IDDE AS ID_DESCRIPCION',
  2113. ]);
  2114. } catch (\Throwable $th) {
  2115. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de la orden de compra.', $th->getMessage(), 500);
  2116. }
  2117. if (is_null($orden)) {
  2118. return $this->responseController->makeResponse(true, 'La orden de compra no exite.', [], 500);
  2119. }
  2120. try {
  2121. $info = DB::table('S002V01TARSE')
  2122. ->where('ARSE_IDIN', '=', $requestData['ID_INFORMATION'])
  2123. ->where('ARSE_IDLI', '=', $orden['ID_LINEA_SOLICITUD'])
  2124. ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
  2125. ->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
  2126. ->where('DEAR_NULI', '=', $requestData['NUMERO_LINEA'])
  2127. ->where('UNID_NULI', '=', $requestData['NUMERO_LINEA'])
  2128. ->where('INAR_NULI', '=', $requestData['NUMERO_LINEA'])
  2129. ->where('ARSE_ESTA', '=', 'Activo')
  2130. ->where('ARTI_ESTA', '=', 'Activo')
  2131. ->where('DEAR_ESTA', '=', 'Activo')
  2132. ->where('UNID_ESTA', '=', 'Activo')
  2133. ->where('INAR_ESTA', '=', 'Activo')
  2134. ->join('S002V01TARTI', 'ARTI_IDAR', '=', 'ARSE_IDAR')
  2135. ->join('S002V01TINAR', 'INAR_IDIN', '=', 'ARSE_IDIN')
  2136. ->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
  2137. ->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
  2138. ->get([
  2139. 'ARTI_IDAR AS ID_ARTICULO',
  2140. 'ARTI_COFA AS CODIGO_FAMILIA',
  2141. 'ARTI_COSU AS CODIGO_SUBFAMILIA',
  2142. 'ARTI_CODI AS CODIGO_ARTICULO',
  2143. 'ARTI_NOMB AS NOMBRE_ARTICULO',
  2144. 'DEAR_IDDE AS ID_DESCRIPCION',
  2145. 'DEAR_IMAG AS IMAGENES',
  2146. 'DEAR_DESC AS DESCRIPCION',
  2147. 'DEAR_CARA AS CARACTERISTICAS',
  2148. 'DEAR_COWE AS COMPRA_WEB',
  2149. 'DEAR_NUPR AS NUMERO_PROVEEDOR',
  2150. 'UNID_IDUN AS ID_UNIDAD',
  2151. 'UNID_NOMB AS NOMBRE_UNIDAD',
  2152. 'UNID_ACRO AS ACRONIMO_UNIDAD',
  2153. 'INAR_IDIN AS ID_INFORMACION',
  2154. 'INAR_CODI AS CODIGO_INFORMACION',
  2155. 'INAR_MODE AS MODELO_INFORMACION',
  2156. 'INAR_COMO AS CODIGO_MONEDA',
  2157. 'INAR_PREC AS PRECIO',
  2158. 'INAR_MOMI AS MONTO_MINIMO',
  2159. 'INAR_CARA AS CARACTERISTICAS',
  2160. ]);
  2161. $info = json_decode(json_encode($info ), true);
  2162. } catch (\Throwable $th) {
  2163. return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de los productos.', $th->getMessage(), 500);
  2164. }
  2165. if ( is_null($info) || empty($info) ) {
  2166. return $this->responseController->makeResponse(true, 'No existen artículos asociados a la orden de compra.', [], 500);
  2167. }
  2168. // Se verifica que existan los datos suficientes para hacer el traslado.
  2169. if ( count($info) < $requestData['NUMBER_ITEMS']) {
  2170. return $this->responseController->makeResponse(true, 'La cantidad de artículos en la orden de compra es menor a la cantidad de artículos seleccionados a Stock.', [], 500);
  2171. }
  2172. return $info;
  2173. }
  2174. }