|
|
@@ -2231,10 +2231,18 @@ class StockController extends Controller
|
|
|
'AREA' => 'required|string',
|
|
|
'LEVEL' => 'required|string',
|
|
|
'ZONE' => 'required|string',
|
|
|
- 'CODIGO_EQUIPAMIENTO' => 'required|string',
|
|
|
'ORDER' => 'required|string',
|
|
|
+ 'PRE_CODIFICATE' => 'required|array',
|
|
|
'ID_INFORMATION' => 'required|integer',
|
|
|
+ 'FAMILIA' => 'required|string',
|
|
|
+ 'SUBFAMILIA' => 'required|string',
|
|
|
+ 'MODELO' => 'required|string',
|
|
|
+ 'CODIGO_MODELO' => 'required|string',
|
|
|
'NUMBER_ITEMS' => 'required|integer',
|
|
|
+ 'CODIGO_BARRAS' => 'required|string',
|
|
|
+ 'FECHA_VENCIMIENTO' => 'nullable|string',
|
|
|
+ 'IMAGES' => 'required|json',
|
|
|
+ 'PRE_GENERATED_CODE' => 'required|string',
|
|
|
'USUARIO' => 'required|string',
|
|
|
'NUMERO_LINEA' => 'required|string',
|
|
|
]);
|
|
|
@@ -2249,12 +2257,19 @@ class StockController extends Controller
|
|
|
401
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
+ DB::beginTransaction();
|
|
|
$requestData = $request->all();
|
|
|
|
|
|
+ // Se verifica la precodificación
|
|
|
+ if ( count($requestData['PRE_CODIFICATE']) !== $requestData['NUMBER_ITEMS']) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La cantidad registrada de la precodificación no es igual la cantidad de artículos seleccionados.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
// Se desencripta y se verifica si el usuario existe
|
|
|
$arrResponseCheckUser = $this->resourcesController->checkUserEnc($requestData['USUARIO'], $requestData['NUMERO_LINEA']);
|
|
|
if ($arrResponseCheckUser['error']) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
|
|
|
}
|
|
|
$user = $arrResponseCheckUser['response'];
|
|
|
@@ -2264,36 +2279,64 @@ class StockController extends Controller
|
|
|
try {
|
|
|
$idWarehouse = $this->encController->decrypt($requestData['WAREHOUSE']);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el almacen.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($idWarehouse === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'La encriptación del almacen no es correcta.', [], 500);
|
|
|
}
|
|
|
try {
|
|
|
$idArea = $this->encController->decrypt($requestData['AREA']);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el área.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($idArea === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'La encriptacipon del área no es correcta.', [], 500);
|
|
|
}
|
|
|
try {
|
|
|
$idLevel = $this->encController->decrypt($requestData['LEVEL']);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener el nivel.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($idLevel === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'La encriptación del nivel no es correcta.', [], 500);
|
|
|
}
|
|
|
try {
|
|
|
$idZone = $this->encController->decrypt($requestData['ZONE']);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la zona.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($idZone === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'La encriptación de la zona no es correcta.', [], 500);
|
|
|
}
|
|
|
|
|
|
+ try {
|
|
|
+ $idFamily = $this->encController->decrypt($requestData['FAMILIA']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la familia.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($idFamily === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La encriptación de la familia no es correcta.', [], 500);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ $idSubfamily = $this->encController->decrypt($requestData['SUBFAMILIA']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la subfamilia.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($idSubfamily === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La encriptación de la subfamilia no es correcta.', [], 500);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// Se verifica que la información exista
|
|
|
@@ -2303,9 +2346,11 @@ class StockController extends Controller
|
|
|
->where('ALMA_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
->exists();
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el almacen existe.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($validateWarehouse === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'El almacen no existe.', [], 500);
|
|
|
}
|
|
|
|
|
|
@@ -2316,9 +2361,11 @@ class StockController extends Controller
|
|
|
->where('AREA_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
->exists();
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el área existe.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($validateArea === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'El área no existe.', [], 500);
|
|
|
}
|
|
|
|
|
|
@@ -2330,9 +2377,11 @@ class StockController extends Controller
|
|
|
->where('NIVE_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
->exists();
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si el nivel existe.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($validateLevel === false) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'El nivel no existe.', [], 500);
|
|
|
}
|
|
|
|
|
|
@@ -2345,12 +2394,42 @@ class StockController extends Controller
|
|
|
->where('ZONA_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
->exists();
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si la zona existe.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ($validateZone === false) {
|
|
|
return $this->responseController->makeResponse(true, 'La zona no existe.', [], 500);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateFamily = DB::table('S002V01TFAMI')
|
|
|
+ ->where('FAMI_COFA', '=', $idFamily)
|
|
|
+ ->where('FAMI_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
+ ->exists();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si la familia existe.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($validateFamily === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La familia no existe.', [], 500);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ $validateSubfamily = DB::table('S002V01TSUBF')
|
|
|
+ ->where('SUBF_COFA', '=', $idFamily)
|
|
|
+ ->where('SUBF_COSU', '=', $idSubfamily)
|
|
|
+ ->where('SUBF_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
+ ->exists();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar si la subfamilia existe.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($validateSubfamily === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La subfamilia no existe.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
$orden = (array) DB::table('S002V01TORCO')
|
|
|
->where('ORCO_NUOR', '=', $requestData['ORDER'])
|
|
|
@@ -2361,16 +2440,21 @@ class StockController extends Controller
|
|
|
'ORCO_IDDE AS ID_DESCRIPCION',
|
|
|
]);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de la orden de compra.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if (is_null($orden)) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'La orden de compra no exite.', [], 500);
|
|
|
}
|
|
|
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $currentDate = $now->toDateTimeString();
|
|
|
|
|
|
try {
|
|
|
$info = DB::table('S002V01TARSE')
|
|
|
->where('ARSE_IDIN', '=', $requestData['ID_INFORMATION'])
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
->where('ARSE_IDLI', '=', $orden['ID_LINEA_SOLICITUD'])
|
|
|
->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
->where('ARTI_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
@@ -2382,11 +2466,16 @@ class StockController extends Controller
|
|
|
->where('DEAR_ESTA', '=', 'Activo')
|
|
|
->where('UNID_ESTA', '=', 'Activo')
|
|
|
->where('INAR_ESTA', '=', 'Activo')
|
|
|
+ ->where('INAR_CODI', '=', $requestData['CODIGO_MODELO'])
|
|
|
+ ->where('INAR_MODE', '=', $requestData['MODELO'])
|
|
|
->join('S002V01TARTI', 'ARTI_IDAR', '=', 'ARSE_IDAR')
|
|
|
->join('S002V01TINAR', 'INAR_IDIN', '=', 'ARSE_IDIN')
|
|
|
->join('S002V01TDEAR', 'DEAR_IDDE', '=', 'INAR_IDDE')
|
|
|
->join('S002V01TUNID', 'UNID_IDUN', '=', 'DEAR_IDUN')
|
|
|
+ ->limit($requestData['NUMBER_ITEMS'])
|
|
|
->get([
|
|
|
+ 'ARSE_IDAS AS NUMERO_SELECCIONADO',
|
|
|
+
|
|
|
'ARTI_IDAR AS ID_ARTICULO',
|
|
|
'ARTI_COFA AS CODIGO_FAMILIA',
|
|
|
'ARTI_COSU AS CODIGO_SUBFAMILIA',
|
|
|
@@ -2414,19 +2503,283 @@ class StockController extends Controller
|
|
|
]);
|
|
|
$info = json_decode(json_encode($info ), true);
|
|
|
} catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'Ocurrió un error al obtener la información de los productos.', $th->getMessage(), 500);
|
|
|
}
|
|
|
if ( is_null($info) || empty($info) ) {
|
|
|
+ DB::rollBack();
|
|
|
return $this->responseController->makeResponse(true, 'No existen artículos asociados a la orden de compra.', [], 500);
|
|
|
}
|
|
|
|
|
|
// Se verifica que existan los datos suficientes para hacer el traslado.
|
|
|
- if ( count($info) < $requestData['NUMBER_ITEMS']) {
|
|
|
- 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);
|
|
|
+ if ( count($info) !== $requestData['NUMBER_ITEMS']) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'La cantidad de artículos en la orden de compra no corresponde a la cantidad de artículos seleccionados a Stock.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Se verifica los códigos de barras
|
|
|
+ $uniqueBarcode = false;
|
|
|
+ $arrBarcode = explode(',', $requestData['CODIGO_BARRAS']);
|
|
|
+ if ( count($arrBarcode) === 0) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No hay códigos de barras registrados.', [], 500);
|
|
|
+ } else if (count($arrBarcode) === $requestData['NUMBER_ITEMS']) {
|
|
|
+ $uniqueBarcode = false;
|
|
|
+ } else if (array_key_exists(0, $arrBarcode) && count($arrBarcode) === 1 && $arrBarcode[0] !== '' ) {
|
|
|
+ $uniqueBarcode = true;
|
|
|
+ } else {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error con los códigos de barras registrados.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Se verifica que los códigos de barras del formulario no sean repetidos
|
|
|
+ $temp_array = array_unique($arrBarcode);
|
|
|
+ $duplicates = sizeof($temp_array) != sizeof($arrBarcode);
|
|
|
+ if ($duplicates) {
|
|
|
+ return $this->responseController->makeResponse(true, 'Los códigos de barras no se pueden repetir.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Se verifican que los códigos de barras no se repitan
|
|
|
+ foreach ($arrBarcode as $key => $barcode) {
|
|
|
+ try {
|
|
|
+ $validateBarcode = DB::table('S002V01TSTAR')
|
|
|
+ ->where('STAR_COBA', '=', $barcode)
|
|
|
+ ->where('STAR_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
+ ->exists();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar los códigos de barras.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($validateBarcode === true) {
|
|
|
+ return $this->responseController->makeResponse(true, 'El código '.$barcode.' ya se encuentra registrado', [], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Se verifica la fecha de vencimientos
|
|
|
+ $arrDueDate = array();
|
|
|
+ $uniqueDueDate = false;
|
|
|
+ if ($requestData['FECHA_VENCIMIENTO'] !== '' && !is_null($requestData['FECHA_VENCIMIENTO'])) {
|
|
|
+ $arrDueDate = explode(',', $requestData['FECHA_VENCIMIENTO']);
|
|
|
+ if ( count($arrDueDate) === 0) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No hay fechas de vencimientos registradas.', [], 500);
|
|
|
+ } else if (count($arrDueDate) === $requestData['NUMBER_ITEMS']) {
|
|
|
+ $uniqueDueDate = false;
|
|
|
+ } else if (array_key_exists(0, $arrDueDate) && count($arrDueDate) === 1 && $arrDueDate[0] !== '' ) {
|
|
|
+ $uniqueDueDate = true;
|
|
|
+ } else {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error con las fechas de vencimientos registrados.', [], 500);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // Se obtiene la fecha actual
|
|
|
+ $now = $this->functionsController->now();
|
|
|
+ $currentDate = $now->toDateTimeString();
|
|
|
+
|
|
|
+ $idInfoStock = null;
|
|
|
+ try {
|
|
|
+ $infoStock = (array) DB::table('S002V01TINST')
|
|
|
+ ->where('INST_COFA', '=', $idFamily)
|
|
|
+ ->where('INST_COSU', '=', $idSubfamily)
|
|
|
+ ->where('INST_ARTI', '=', $info[0]['ID_ARTICULO'])
|
|
|
+ ->where('INST_MODE', '=', $requestData['MODELO'])
|
|
|
+ ->where('INST_COMO', '=', $requestData['CODIGO_MODELO'])
|
|
|
+ ->where('INST_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
+ ->where('INST_ESTA', '=', 'Activo')
|
|
|
+ ->first([
|
|
|
+ 'INST_IDIS AS ID_INFO_STOCK'
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al verificar la información del stock.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if (empty($infoStock) || is_null($infoStock)) {
|
|
|
+ // Se obtiene el arreglo de las imagenes
|
|
|
+ $imagesArr = json_decode($requestData['IMAGES'], true);
|
|
|
+ // Se verifica que el arreglo contenga imagenes
|
|
|
+ if(count($imagesArr) < 1){
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes está vacío.', [], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $imagesGallery = [];
|
|
|
+ // Se iteran las imagenes
|
|
|
+ foreach($imagesArr as $imageFile){
|
|
|
+ // Se verifica que tenga un formato correcto
|
|
|
+ if(!array_key_exists('type', $imageFile)){
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'El arreglo de la galería de imágenes tiene un formato inválido.', [], 400);
|
|
|
+ // Si la imagen es nueva, entonces...
|
|
|
+ }else if($imageFile['type'] == 'Nuevo'){
|
|
|
+ // Se obtiene el ID de la imagen
|
|
|
+ $tempFileID = $this->encController->decrypt($imageFile['id']);
|
|
|
+ // Se obtiene la información registrada en la tabla de archivos temporales
|
|
|
+ $tempFile = DB::table('S002V01TARTE')->where([
|
|
|
+ ['ARTE_IDAR', '=', $tempFileID],
|
|
|
+ ['ARTE_NULI', '=', $requestData['NUMERO_LINEA']]
|
|
|
+ ])->first();
|
|
|
+ // La imagen es colocada en su posición final
|
|
|
+ $finalFile = $this->documentManagementController->moveFinalFile($requestData['NUMERO_LINEA'], 'GEEQ', 'FO', $tempFile, $user);
|
|
|
+ // Si ocurrió un error, entonces se manda el error
|
|
|
+ if(!$finalFile[0]){
|
|
|
+ return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
|
|
|
+ }
|
|
|
+ // La información es guardada en un arreglo
|
|
|
+ $imagesGallery[] = $finalFile[1];
|
|
|
+ }else{
|
|
|
+ // Se desencripta el id de la imagen
|
|
|
+ $fileID = $this->encController->decrypt($imageFile['id']);
|
|
|
+ // Es guardada en un arreglo
|
|
|
+ $imagesGallery[] = $fileID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // El arreglo de las imagenes es pasada en formato string
|
|
|
+ $imagesGalleryStr = json_encode($imagesGallery);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $idInsert = DB::table('S002V01TINST')->insertGetId([
|
|
|
+ 'INST_NULI' => $requestData['NUMERO_LINEA'],
|
|
|
+ 'INST_COFA' => $idFamily,
|
|
|
+ 'INST_COSU' => $idSubfamily,
|
|
|
+ 'INST_ARTI' => $info[0]['ID_ARTICULO'],
|
|
|
+ 'INST_MODE' => $requestData['MODELO'],
|
|
|
+ 'INST_COMO' => $requestData['CODIGO_MODELO'],
|
|
|
+ 'INST_IMAG' => $imagesGalleryStr,
|
|
|
+ 'INST_USRE' => $user,
|
|
|
+ 'INST_FERE' => $currentDate,
|
|
|
+ 'INST_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al insertar la información del stock.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($idInsert === false || is_null($idInsert)) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo insertar la información del stock.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ $idInfoStock = $idInsert;
|
|
|
+ } else {
|
|
|
+ $idInfoStock = $infoStock['ID_INFO_STOCK'];
|
|
|
+ }
|
|
|
+ if (is_null($idInfoStock)) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo obtener el ID de la información del Stock.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ for ($i=0; $i < $requestData['NUMBER_ITEMS']; $i++) {
|
|
|
+
|
|
|
+ $dueDate = null;
|
|
|
+ if (count($arrDueDate) > 0 && $uniqueDueDate === true) {
|
|
|
+ $dueDate = $arrDueDate[0];
|
|
|
+ } else if (count($arrDueDate) > 0 && $uniqueDueDate === false) {
|
|
|
+ $dueDate = $arrDueDate[$i];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!is_null($dueDate) && str_contains($dueDate, 'T')) {
|
|
|
+ $dueDate = explode('T', $dueDate)[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $preCodificate = $this->encController->decrypt($requestData['PRE_CODIFICATE'][$i]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el identificador de la pre-codificación.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($preCodificate === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo desencriptar el identificador de la pre-codificación.', [], 500);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ try {
|
|
|
+ $idInsertStAr = DB::table('S002V01TSTAR')->insertGetId([
|
|
|
+ 'STAR_NULI' => $requestData['NUMERO_LINEA'],
|
|
|
+ 'STAR_IDIS' => $idInfoStock,
|
|
|
+ 'STAR_COBA' => $uniqueBarcode === true ? $arrBarcode[0] : $arrBarcode[$i],
|
|
|
+ 'STAR_FEVE' => $dueDate,
|
|
|
+ 'STAR_IDUN' => $info[$i]['ID_UNIDAD'],
|
|
|
+ 'STAR_NUPR' => $info[$i]['NUMERO_PROVEEDOR'],
|
|
|
+ 'STAR_TIAD' => 'Por pedido',
|
|
|
+ 'STAR_IDPC' => $preCodificate,
|
|
|
+ 'STAR_ESTA' => 'Pendiente',
|
|
|
+ 'STAR_USRE' => $user,
|
|
|
+ 'STAR_FERE' => $currentDate,
|
|
|
+ 'STAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar el equipamiento.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($idInsertStAr === false || is_null($idInsertStAr)) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo registrar el equipamiento.', [], 500);
|
|
|
+ }
|
|
|
|
|
|
- return $info;
|
|
|
+ try {
|
|
|
+ $preCodeCodificate = $this->encController->decrypt($requestData['PRE_GENERATED_CODE']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al desencriptar el pre-código generado', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ( $preCodeCodificate === false ) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo desencriptar el pre-código del equipamientos.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateInsertUbAr = DB::table('S002V01TUBAR')->insert([
|
|
|
+ 'UBAR_NULI' => $requestData['NUMERO_LINEA'],
|
|
|
+ 'UBAR_COAL' => $idWarehouse,
|
|
|
+ 'UBAR_COAR' => $idArea,
|
|
|
+ 'UBAR_CONI' => $idLevel,
|
|
|
+ 'UBAR_COZO' => $idZone,
|
|
|
+ 'UBAR_IDST' => $idInsertStAr,
|
|
|
+ 'UBAR_COUB' => $preCodeCodificate,
|
|
|
+ 'UBAR_ESTA' => 'Pendiente',
|
|
|
+ 'UBAR_USRE' => $user,
|
|
|
+ 'UBAR_FERE' => $currentDate,
|
|
|
+ 'UBAR_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al registrar la ubicación del artículo.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ( $validateInsertUbAr === false ) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo registrar la ubicación del artículo.', [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateUpdateArSe = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDAS', '=', $info[$i]['NUMERO_SELECCIONADO'])
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['NUMERO_LINEA'])
|
|
|
+ ->where('ARSE_IDLI', '=', $orden['ID_LINEA_SOLICITUD'])
|
|
|
+ ->where('ARSE_IDAR', '=', $info[$i]['ID_ARTICULO'])
|
|
|
+ ->where('ARSE_NUPR', '=', $info[$i]['NUMERO_PROVEEDOR'])
|
|
|
+ ->where('ARSE_IDIN', '=', $requestData['ID_INFORMATION'])
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->update([
|
|
|
+ 'ARSE_ESTA' => 'Guardado',
|
|
|
+ 'ARSE_USMO' => $user,
|
|
|
+ 'ARSE_FEMO' => $currentDate,
|
|
|
+ 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'Ocurrió un error al modificar el artículo seleccionado.', $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if ($validateUpdateArSe === false) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, 'No se pudo modificar el artículo seleccionado.', [], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
|
|
|
}
|
|
|
}
|