| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- <?php
- /*
- Desarrollador: Ing. Jean Jairo Benitez Meza
- Ultima Modificación: 11/04/2023
- Módulo: Gestión de Inventario y/o Stock
- */
- namespace App\Http\Controllers;
- use App\Http\Controllers\Controller;
- use App\Http\Controllers\ResourcesController;
- use App\Http\Controllers\ResponseController;
- use App\Http\Controllers\EncryptionController;
- use App\Http\Controllers\DocumentManagementController;
- use Illuminate\Database\Query\JoinClause;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use App\Http\Controllers\FunctionsController;
- class StockController extends Controller
- {
- private $responseController;
- private $encController;
- private $resourcesController;
- private $documentManagementController;
- private $functionsController;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->resourcesController = new ResourcesController();
- $this->documentManagementController = new DocumentManagementController();
- $this->functionsController = new FunctionsController();
- }
- public function getWarehouse( $user, $line ) {
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
- }
-
- try {
- $arrWarehouse = DB::table('S002V01TALMA')
- ->where('ALMA_NULI', '=', $line)
- ->get([
- 'ALMA_IDAL AS ID_ALMACEN',
- 'ALMA_COAL AS CODIGO_ALMACEN',
- 'ALMA_COAL AS NOMBRE_ALMACEN',
- 'ALMA_NORE AS NOMBRE_RESPONSABLE',
- 'ALMA_APRE AS APELLIDO_PATERNO_RESPONSABLE',
- 'ALMA_AMRE AS APELLIDO_MATERNO_RESPONSABLE',
- 'ALMA_COR1 AS CORREO1',
- 'ALMA_COR2 AS CORREO2',
- 'ALMA_LAD1 AS LADA1',
- 'ALMA_TEL1 AS TELEFONO1',
- 'ALMA_LAD2 AS LADA2',
- 'ALMA_TEL2 AS TELEFONO2',
- 'ALMA_CALL AS CALLE',
- 'ALMA_NUEX AS NUMERO_EXTERIOR',
- 'ALMA_NUIN AS NUMERO_INTERIOR',
- 'ALMA_COPO AS CODIGO_POSTAL',
- 'ALMA_COLO AS COLONIA',
- 'ALMA_LOCA AS LOCALIDAD',
- 'ALMA_MUNI AS MUNICIPIO',
- 'ALMA_ENTI AS ENTIDAD_FEDERATIVA',
- 'ALMA_PAIS AS PAIS',
- 'ALMA_ESTA AS ESTADO',
- 'ALMA_USRE AS USUARIO_REGISTRA',
- 'ALMA_FERE AS FECHA_REGISTRA',
- 'ALMA_USMO AS USUARIO_MODIFICA',
- 'ALMA_FEMO AS FECHA_MODIFICA',
- ]);
- $arrWarehouse = json_decode( json_encode($arrWarehouse), true );
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_GET001: Ocurrió un error al obtener los almacenes.",
- $th->getMessage(),
- 500
- );
- }
- foreach ($arrWarehouse as $keyWarehouse => $warehouse) {
- $arrResponseGetAddress = $this->resourcesController->getAddress(
- $warehouse['CODIGO_POSTAL'],
- $warehouse['COLONIA'],
- $warehouse['MUNICIPIO'],
- $warehouse['LOCALIDAD'],
- $warehouse['ENTIDAD_FEDERATIVA'],
- $warehouse['PAIS'],
- $line
- );
- if ($arrResponseGetAddress['error']) {
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GET002: '.$arrResponseGetAddress['msg'], $arrResponseGetAddress['response'], 401);
- }
- $warehouse['CODIGO_POSTAL'] = $arrResponseGetAddress['response']['CODIGO_POSTAL'];
- $warehouse['COLONIA'] = $arrResponseGetAddress['response']['COLONIA'];
- $warehouse['MUNICIPIO'] = $arrResponseGetAddress['response']['MUNICIPIO'];
- $warehouse['LOCALIDAD'] = $arrResponseGetAddress['response']['LOCALIDAD'];
- $warehouse['ENTIDAD_FEDERATIVA'] = $arrResponseGetAddress['response']['ENTIDAD_FEDERATIVA'];
- $warehouse['PAIS'] = $arrResponseGetAddress['response']['PAIS'];
- $arrWarehouse[$keyWarehouse] = $warehouse;
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWarehouse);
- }
- public function getWarehouseById( $idWarehouse, $user, $line ) {
- try {
- $idWarehouse = $this->encController->decrypt($idWarehouse);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000: Ocurrió un error al desencriptar el ID del almacen', $th->getMessage(), 406);
- }
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
- if ($arrResponseCheckUser['error']) {
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_GETBY000:'.$arrResponseCheckUser['msg'], [], 401);
- }
-
- try {
- $arrWarehouse = (array) DB::table('S002V01TALMA')
- ->where('ALMA_IDAL', '=', $idWarehouse)
- ->where('ALMA_NULI', '=', $line)
- ->first([
- 'ALMA_COAL AS CODIGO_ALMACEN',
- 'ALMA_COAL AS NOMBRE_ALMACEN',
- 'ALMA_NORE AS NOMBRE_RESPONSABLE',
- 'ALMA_APRE AS APELLIDO_PATERNO_RESPONSABLE',
- 'ALMA_AMRE AS APELLIDO_MATERNO_RESPONSABLE',
- 'ALMA_COR1 AS CORREO1',
- 'ALMA_COR2 AS CORREO2',
- 'ALMA_LAD1 AS LADA1',
- 'ALMA_TEL1 AS TELEFONO1',
- 'ALMA_LAD2 AS LADA2',
- 'ALMA_TEL2 AS TELEFONO2',
- 'ALMA_CALL AS CALLE',
- 'ALMA_NUEX AS NUMERO_EXTERIOR',
- 'ALMA_NUIN AS NUMERO_INTERIOR',
- 'ALMA_COPO AS CODIGO_POSTAL',
- 'ALMA_COLO AS COLONIA',
- 'ALMA_LOCA AS LOCALIDAD',
- 'ALMA_MUNI AS MUNICIPIO',
- 'ALMA_ENTI AS ENTIDAD_FEDERATIVA',
- 'ALMA_PAIS AS PAIS',
- 'ALMA_ESTA AS ESTADO',
- 'ALMA_USRE AS USUARIO_REGISTRA',
- 'ALMA_FERE AS FECHA_REGISTRA',
- 'ALMA_USMO AS USUARIO_MODIFICA',
- 'ALMA_FEMO AS FECHA_MODIFICA',
- ]);
- $arrWarehouse = json_decode( json_encode($arrWarehouse), true );
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_GETBY001: Ocurrió un error al obtener los almacenes.",
- $th->getMessage(),
- 500
- );
- }
- if (!empty($arrWarehouse)) {
- $arrResponseGetAddress = $this->resourcesController->getAddress(
- $arrWarehouse['CODIGO_POSTAL'],
- $arrWarehouse['COLONIA'],
- $arrWarehouse['MUNICIPIO'],
- $arrWarehouse['LOCALIDAD'],
- $arrWarehouse['ENTIDAD_FEDERATIVA'],
- $arrWarehouse['PAIS'],
- $line
- );
- if ($arrResponseGetAddress['error']) {
- return $this->responseController->makeResponse(true, 'ERR_arrWarehouse_GETBY002: '.$arrResponseGetAddress['msg'], $arrResponseGetAddress['response'], 406);
- }
-
- $arrWarehouse['CODIGO_POSTAL'] = $arrResponseGetAddress['response']['CODIGO_POSTAL'];
- $arrWarehouse['COLONIA'] = $arrResponseGetAddress['response']['COLONIA'];
- $arrWarehouse['MUNICIPIO'] = $arrResponseGetAddress['response']['MUNICIPIO'];
- $arrWarehouse['LOCALIDAD'] = $arrResponseGetAddress['response']['LOCALIDAD'];
- $arrWarehouse['ENTIDAD_FEDERATIVA'] = $arrResponseGetAddress['response']['ENTIDAD_FEDERATIVA'];
- $arrWarehouse['PAIS'] = $arrResponseGetAddress['response']['PAIS'];
-
- }
-
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrWarehouse);
- }
- public function createWarehouse( Request $request ) {
- $validator = Validator::make($request->all(), [
- 'CODIGO_ALMACEN' => 'required|string',
- 'NOMBRE_ALMACEN' => 'required|string',
- 'NOMBRE_RESPONSABLE' => 'required|string',
- 'APELLIDO_PATERNO_RESPONSABLE' => 'required|string',
- 'APELLIDO_MATERNO_RESPONSABLE' => 'nullable|string',
- 'CORREO1' => 'required|string',
- 'CORREO2' => 'nullable|string',
- 'LADA1' => 'required|string',
- 'TELEFONO1' => 'required|string',
- 'LADA2' => 'nullable|string',
- 'TELEFONO2' => 'nullable|string',
- 'CALLE' => 'required|string',
- 'NUMERO_EXTERIOR' => 'required|string',
- 'NUMERO_INTERIOR' => 'nullable|string',
- 'CODIGO_POSTAL' => 'required|string',
- 'COLONIA' => 'required|string',
- 'LOCALIDAD' => 'nullable|string',
- 'MUNICIPIO' => 'required|string',
- 'ENTIDAD_FEDERATIVA' => 'required|string',
- 'PAIS' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_REG000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
-
- // Se valida y se obtiene el usuario
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_REG001:'.$arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- // Se vallidan los campos de dirección
- $arrResponseCheckAddress = $this->resourcesController->validateAddress(
- $requestData['CODIGO_POSTAL'],
- $requestData['COLONIA'],
- $requestData['MUNICIPIO'],
- $requestData['LOCALIDAD'],
- $requestData['ENTIDAD_FEDERATIVA'],
- $requestData['PAIS'],
- $requestData['NUMERO_LINEA'],
- );
- if ($arrResponseCheckAddress['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_REG002: '.$arrResponseCheckAddress['msg'], $arrResponseCheckAddress['response'], 401);
- }
-
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TALMA')->insert([
- 'ALMA_NULI' => $requestData['NUMERO_LINEA'],
- 'ALMA_COAL' => $requestData['CODIGO_ALMACEN'],
- 'ALMA_NOAL' => $requestData['NOMBRE_ALMACEN'],
- 'ALMA_NORE' => $requestData['NOMBRE_RESPONSABLE'],
- 'ALMA_APRE' => $requestData['APELLIDO_PATERNO_RESPONSABLE'],
- 'ALMA_AMRE' => $requestData['APELLIDO_MATERNO_RESPONSABLE'],
- 'ALMA_COR1' => $requestData['CORREO1'],
- 'ALMA_COR2' => $requestData['CORREO2'],
- 'ALMA_LAD1' => $requestData['LADA1'],
- 'ALMA_TEL1' => $requestData['TELEFONO1'],
- 'ALMA_LAD2' => $requestData['LADA2'],
- 'ALMA_TEL2' => $requestData['TELEFONO2'],
- 'ALMA_CALL' => $requestData['CALLE'],
- 'ALMA_NUEX' => $requestData['NUMERO_EXTERIOR'],
- 'ALMA_NUIN' => $requestData['NUMERO_INTERIOR'],
- 'ALMA_COPO' => $requestData['CODIGO_POSTAL'],
- 'ALMA_COLO' => $requestData['COLONIA'],
- 'ALMA_LOCA' => $requestData['LOCALIDAD'],
- 'ALMA_MUNI' => $requestData['MUNICIPIO'],
- 'ALMA_ENTI' => $requestData['ENTIDAD_FEDERATIVA'],
- 'ALMA_PAIS' => $requestData['PAIS'],
- 'ALMA_USRE' => $user,
- 'ALMA_FERE' => $currentDate,
- 'ALMA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_REG003: Ocurrió un error al insertar el registro del almacen.",
- $th->getMessage(),
- 500
- );
- }
- if (!$validateInsert) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_REG004: No se pudo insertar el registro del almacen.",
- [],
- 500
- );
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
- }
- public function updateWarehouse( Request $request, $idWarehouse ) {
- $validator = Validator::make($request->all(), [
- 'CODIGO_ALMACEN' => 'required|string',
- 'NOMBRE_ALMACEN' => 'required|string',
- 'NOMBRE_RESPONSABLE' => 'required|string',
- 'APELLIDO_PATERNO_RESPONSABLE' => 'required|string',
- 'APELLIDO_MATERNO_RESPONSABLE' => 'nullable|string',
- 'CORREO1' => 'required|string',
- 'CORREO2' => 'nullable|string',
- 'LADA1' => 'required|string',
- 'TELEFONO1' => 'required|string',
- 'LADA2' => 'nullable|string',
- 'TELEFONO2' => 'nullable|string',
- 'CALLE' => 'required|string',
- 'NUMERO_EXTERIOR' => 'required|string',
- 'NUMERO_INTERIOR' => 'nullable|string',
- 'CODIGO_POSTAL' => 'required|string',
- 'COLONIA' => 'required|string',
- 'LOCALIDAD' => 'nullable|string',
- 'MUNICIPIO' => 'required|string',
- 'ENTIDAD_FEDERATIVA' => 'required|string',
- 'PAIS' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_UPD000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $idWarehouse = $this->encController->decrypt($idWarehouse);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_WAREHOUSE_UPD001: Ocurrió un error al desencriptar el ID del almacen.". $th->getMessage(), 406);
- }
- $arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
- if ($arrResponseCheckUser['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_UPD002:'.$arrResponseCheckUser['msg'], [], 401);
- }
- $user = $arrResponseCheckUser['response'];
- $arrResponseCheckAddress = $this->resourcesController->validateAddress(
- $requestData['CODIGO_POSTAL'],
- $requestData['COLONIA'],
- $requestData['MUNICIPIO'],
- $requestData['LOCALIDAD'],
- $requestData['ENTIDAD_FEDERATIVA'],
- $requestData['PAIS'],
- $requestData['NUMERO_LINEA'],
- );
- if ($arrResponseCheckAddress['error']) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, 'ERR_WAREHOUSE_UPD003: '.$arrResponseCheckAddress['msg'], $arrResponseCheckAddress['response'], 401);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateUpdate = DB::table('S002V01TALMA')
- ->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('ALMA_IDAL', '=', $idWarehouse)
- ->update([
- 'ALMA_COAL' => $requestData['CODIGO_ALMACEN'],
- 'ALMA_NOAL' => $requestData['NOMBRE_ALMACEN'],
- 'ALMA_NORE' => $requestData['NOMBRE_RESPONSABLE'],
- 'ALMA_APRE' => $requestData['APELLIDO_PATERNO_RESPONSABLE'],
- 'ALMA_AMRE' => $requestData['APELLIDO_MATERNO_RESPONSABLE'],
- 'ALMA_COR1' => $requestData['CORREO1'],
- 'ALMA_COR2' => $requestData['CORREO2'],
- 'ALMA_LAD1' => $requestData['LADA1'],
- 'ALMA_TEL1' => $requestData['TELEFONO1'],
- 'ALMA_LAD2' => $requestData['LADA2'],
- 'ALMA_TEL2' => $requestData['TELEFONO2'],
- 'ALMA_CALL' => $requestData['CALLE'],
- 'ALMA_NUEX' => $requestData['NUMERO_EXTERIOR'],
- 'ALMA_NUIN' => $requestData['NUMERO_INTERIOR'],
- 'ALMA_COPO' => $requestData['CODIGO_POSTAL'],
- 'ALMA_COLO' => $requestData['COLONIA'],
- 'ALMA_LOCA' => $requestData['LOCALIDAD'],
- 'ALMA_MUNI' => $requestData['MUNICIPIO'],
- 'ALMA_ENTI' => $requestData['ENTIDAD_FEDERATIVA'],
- 'ALMA_PAIS' => $requestData['PAIS'],
- 'ALMA_USMO' => $user,
- 'ALMA_FEMO' => $currentDate,
- 'ALMA_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_UPD004: Ocurrió un error al insertar el registro del almacen.",
- $th->getMessage(),
- 500
- );
- }
- if (!$validateUpdate) {
- DB::rollBack();
- return $this->responseController->makeResponse(
- true,
- "ERR_WAREHOUSE_UPD005: No se pudo insertar el registro del almacen.",
- [],
- 500
- );
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- // Crear Artículo en Stock
- public function createArtitleWithoutOrder(Request $request) {
- $validator = Validator::make($request->all(), [
- 'ARTICULO' => 'required',
- 'MODELO' => 'required',
- 'CODIGO_MODELO' => 'required',
- 'FAMILIA' => 'required',
- 'SUBFAMILIA' => 'required',
- 'UNIDAD' => 'required',
- 'CODIGO_BARRAS' => 'required',
- 'CANTIDAD' => 'required',
- 'STOCK_MINIMO' => 'required',
- 'STOCK_MAXIMO' => 'required',
- 'REPARACION' => 'required|boolean',
- 'CONSUMIBLE' => 'required|boolean',
- 'PELIGROSO' => 'required|boolean',
- // 'FECHA_VENCIMIENTO' => '',
- // 'PROVEEDOR' => 'required',
- 'IMAGEN' => 'required',
- 'NUMERO_LINEA' => 'required',
- 'USUARIO' => 'required',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_STOCK_REG000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $user = $this->encController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $validateFamily = DB::table('S002V01TFAMI')
- ->where('FAMI_COFA','=', $requestData['FAMILIA'])
- ->where('FAMI_NULI','=', $requestData['NUMERO_LINEA'])
- ->where('FAMI_ESTA','=','Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG002: Ocurrió un error al validar la familia.", $th->getMessage(), 500);
- }
- if (!$validateFamily) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG003: La familia no existe.", [], 500);
- }
- try {
- $validateSubfamily = DB::table('S002V01TSUBF')
- ->where('SUBF_COSU','=', $requestData['SUBFAMILIA'])
- ->where('SUBF_NULI','=', $requestData['NUMERO_LINEA'])
- ->where('SUBF_ESTA','=','Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG004: Ocurrió un error al validar la subfamilia.", $th->getMessage(), 500);
- }
- if (!$validateSubfamily) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG005: La subfamilia no existe.", [], 500);
- }
-
- try {
- $validateUnit = DB::table('S002V01TUNID')
- ->where('UNID_IDUN','=', $requestData['UNIDAD'])
- ->where('UNID_NULI','=', $requestData['NUMERO_LINEA'])
- ->where('UNID_ESTA','=','Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG006: Ocurrió un error al validar la unidad.", $th->getMessage(), 500);
- }
- if (!$validateUnit) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG007: La unidad no existe.", [], 500);
- }
- $requestData['PROVEEDOR'] = $requestData['PROVEEDOR'] === '' ? null : $requestData['PROVEEDOR'];
- if (!is_null($requestData['PROVEEDOR'])) {
- try {
- $validateUnit = DB::table('S002V01TPROV')
- ->where('PROV_NUPR','=', $requestData['PROVEEDOR'])
- ->where('PROV_NULI','=', $requestData['NUMERO_LINEA'])
- ->where('PROV_ESTA','=','Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG008: Ocurrió un error al validar el proveedor.", $th->getMessage(), 500);
- }
- if (!$validateUnit) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG009: El proveedor no existe.", [], 500);
- }
- }
-
- $arrCodeImages = array();
- foreach ($requestData['IMAGEN'] as $key => $encIdFile) {
- $idFile = $this->encController->decrypt($encIdFile);
- $tempFile = DB::table('S002V01TARTE')->where([
- ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']],
- ['ARTE_IDAR', '=', $idFile],
- ])->first();
- if(is_null($tempFile)){
- return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG006: El archivo consultado no está registrado', [], 404);
- }else if($tempFile->ARTE_ESTA == 'Eliminado'){
- return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG007: El archivo consultado está eliminado', [], 404);
- }
- $fileResponse = $this->documentManagementController->moveFinalFile(
- intval($requestData['NUMERO_LINEA']),
- 'GIST',
- 'FO',
- $tempFile,
- $user,
- );
- if(!$fileResponse[0]){
- return $this->responseController->makeResponse(true, 'ERR_ARTITLE_REG008: '.$fileResponse[1], [], 400);
- }
- $arrCodeImages[] = $this->encController->encrypt($fileResponse[1]);
- }
- $jsonImages = json_encode($arrCodeImages);
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateRegister = DB::table('S002V01TSTAR')->insert([
- // 'STAR_CODI' => $requestData['CODIGO_STOCK'],
- 'STAR_ARTI' => $requestData['ARTICULO'],
- 'STAR_MODE' => $requestData['MODELO'],
- 'STAR_COMO' => $requestData['CODIGO_MODELO'],
- 'STAR_IDFA' => $requestData['FAMILIA'],
- 'STAR_IDSU' => $requestData['SUBFAMILIA'],
- 'STAR_NUPR' => $requestData['PROVEEDOR'],
- 'STAR_IDUN' => $requestData['UNIDAD'],
- 'STAR_COBA' => $requestData['CODIGO_BARRAS'],
- 'STAR_CANT' => $requestData['CANTIDAD'],
- 'STAR_STMI' => $requestData['STOCK_MINIMO'],
- 'STAR_STMA' => $requestData['STOCK_MAXIMO'],
- 'STAR_REPA' => $requestData['REPARACION'],
- 'STAR_CONS' => $requestData['CONSUMIBLE'],
- 'STAR_PELI' => $requestData['PELIGROSO'],
- 'STAR_FEVE' => $requestData['FECHA_VENCIMIENTO'],
- 'STAR_IMAG' => $jsonImages,
- 'STAR_TIAD' => 'Sin Pedido',
- 'STAR_NULI' => $requestData['NUMERO_LINEA'],
- 'STAR_USRE' => $user,
- 'STAR_FERE' => $currentDate,
- 'STAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG011: Ocurrió un error al registrar el artículo.", $th->getMessage(), 500);
- }
- if (!$validateRegister) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_STOCK_REG012: No se pudo registrar el artículo.", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "EXITO: Registro Exitoso");
- }
- }
|