|
|
@@ -37,7 +37,7 @@ class RequestLineController extends Controller
|
|
|
if ($validator->fails()) {
|
|
|
return $this->responseController->makeResponse(
|
|
|
true,
|
|
|
- "ERR_ORDER_REG000: Se encontraron uno o más errores.",
|
|
|
+ "ERR_REQUESTLINE_REG000: Se encontraron uno o más errores.",
|
|
|
$this->responseController->makeErrors($validator->errors()->messages()),
|
|
|
401
|
|
|
);
|
|
|
@@ -50,74 +50,68 @@ class RequestLineController extends Controller
|
|
|
$user = $this->encController->decrypt($requestData['user']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG001: Ocurrió un error al obtener el usuario.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG001: Ocurrió un error al obtener el usuario.", [], 500);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
$line = $this->encController->decrypt($requestData['line']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG002: Ocurrió un error al obtener la línea.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG002: Ocurrió un error al obtener la línea.", [], 500);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
$description = $this->encController->decrypt($requestData['description']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG003: Ocurrió un error al obtener el contenido de la descripción.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG003: Ocurrió un error al obtener el contenido de la descripción.", [], 500);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
$strArtitles = $this->encController->decrypt($requestData['products']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG004: Ocurrió un error al obtener los productos del artículo.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG004: Ocurrió un error al obtener los productos del artículo.", [], 500);
|
|
|
}
|
|
|
|
|
|
if (empty($strArtitles)) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG005: No se encontró ningún registro de productos.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG005: No se encontró ningún registro de productos.", [], 500);
|
|
|
}
|
|
|
|
|
|
- $arrResponseArti = [
|
|
|
- 'LINE_DESC' => $description,
|
|
|
- 'LINE_NULI' => $line,
|
|
|
- 'LINE_USRE' => $user,
|
|
|
- 'LINE_FERE' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
- 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
|
|
|
- ];
|
|
|
-
|
|
|
- try {
|
|
|
- $idRegisterLine = DB::table('S002V01TLINE')->insertGetId($arrResponseArti);
|
|
|
- } catch (\Throwable $th) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG006: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
|
|
|
- }
|
|
|
-
|
|
|
- if ($idRegisterLine == null || $idRegisterLine <= 0) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG007: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $arrArtitles = json_decode($strArtitles);
|
|
|
- $lineOrder = 1;
|
|
|
- foreach ($arrArtitles as $keyArtitles => $artitles) {
|
|
|
+ $arrRequestLine = json_decode($strArtitles, true);
|
|
|
|
|
|
- $idArtitle = $artitles->idArtitle;
|
|
|
- $arrProducts = $artitles->content;
|
|
|
- $idProvider = $artitles->idProvider;
|
|
|
+ foreach ($arrRequestLine as $keyRequest => $requestLine) {
|
|
|
+ try {
|
|
|
+ $idRegisterLine = DB::table('S002V01TLINE')->insertGetId([
|
|
|
+ 'LINE_NUPR' => $requestLine['PROVIDER'],
|
|
|
+ 'LINE_DESC' => $description,
|
|
|
+ 'LINE_NULI' => $line,
|
|
|
+ 'LINE_USRE' => $user,
|
|
|
+ 'LINE_FERE' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG006: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($idRegisterLine == null || $idRegisterLine <= 0) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG007: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
+ }
|
|
|
+ $secuence = 1;
|
|
|
|
|
|
- foreach ($arrProducts as $keyProducts => $products) {
|
|
|
+ foreach ($requestLine['ARTITLES'] as $key => $artitle) {
|
|
|
try {
|
|
|
$validate = DB::table('S002V01TARSE')->insert([
|
|
|
- 'ARSE_IDAS' => $lineOrder,
|
|
|
+ 'ARSE_IDAS' => $secuence,
|
|
|
'ARSE_IDLI' => $idRegisterLine,
|
|
|
- 'ARSE_IDAR' => $idArtitle,
|
|
|
- 'ARSE_NUPR' => $idProvider,
|
|
|
- 'ARSE_IDIN' => $products->NUMERO_INFORMACION,
|
|
|
- 'ARSE_CANT' => $products->CANTIDAD,
|
|
|
- 'ARSE_PRTO' => $products->CANTIDAD * $products->PRECIO,
|
|
|
+ 'ARSE_IDAR' => $artitle['NUMERO_ARTICULO'],
|
|
|
+ 'ARSE_NUPR' => $requestLine['PROVIDER'],
|
|
|
+ 'ARSE_IDIN' => $artitle['NUMERO_INFORMACION'],
|
|
|
+ 'ARSE_CANT' => $artitle['CANTIDAD'],
|
|
|
+ 'ARSE_PRTO' => $artitle['CANTIDAD'] * $artitle['PRECIO'],
|
|
|
'ARSE_NULI' => $line,
|
|
|
'ARSE_USRE' => $user,
|
|
|
'ARSE_FERE' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
@@ -125,29 +119,30 @@ class RequestLineController extends Controller
|
|
|
]);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG008: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG008: Ocurrió un error al hacer la inserción en la base.", $th->getMessage(), 500);
|
|
|
}
|
|
|
|
|
|
if (!$validate) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_REG009: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG009: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
}
|
|
|
|
|
|
- $lineOrder++;
|
|
|
+ $secuence++;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
DB::commit();
|
|
|
return $this->responseController->makeResponse(false, "ÉXITO: Registro correcto");
|
|
|
}
|
|
|
|
|
|
// Se obtienen todas las líneas de solicitud
|
|
|
- public function getAllRequestLines($line){
|
|
|
+ public function getAllRequestLinesOld($line){
|
|
|
try {
|
|
|
$arrRequestLines = DB::table('S002V01TLINE')
|
|
|
->where("LINE_NULI", "=", $line)
|
|
|
->get([
|
|
|
'LINE_IDLI AS ID_LINEA_SOLICITUD',
|
|
|
- 'LINE_DESC AS DESCRIPCION',
|
|
|
+ // 'LINE_DESC AS DESCRIPCION',
|
|
|
'LINE_ESTA AS ESTADO',
|
|
|
'LINE_FERE AS FECHA_REGISTRA',
|
|
|
'LINE_FEMO AS FECHA_MODIFICA',
|
|
|
@@ -171,6 +166,108 @@ class RequestLineController extends Controller
|
|
|
return $this->responseController->makeResponse(false, "ÉXITO", $arrRequestLines);
|
|
|
}
|
|
|
|
|
|
+ public function getAllRequestLines($line) {
|
|
|
+ try {
|
|
|
+ $getRequestLines = DB::table('S002V01TLINE')
|
|
|
+ ->where("LINE_NULI", "=", $line)
|
|
|
+ ->join('S002V01TPROV', 'PROV_NUPR', '=', 'LINE_NUPR')
|
|
|
+ ->get([
|
|
|
+ 'LINE_IDLI',
|
|
|
+ 'LINE_NUPR',
|
|
|
+ 'PROV_NOCO',
|
|
|
+ 'LINE_NUOR',
|
|
|
+ 'LINE_OTPR',
|
|
|
+ 'LINE_OTCO',
|
|
|
+ 'LINE_ESTA',
|
|
|
+ 'LINE_USRE',
|
|
|
+ 'LINE_FERE',
|
|
|
+ 'LINE_USMO',
|
|
|
+ 'LINE_FEMO',
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ $arrRequestLines = json_decode(json_encode($getRequestLines), true);
|
|
|
+
|
|
|
+ foreach ($arrRequestLines as $keyRequest => $requestLine) {
|
|
|
+ try {
|
|
|
+ $getSelected = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDLI', '=', $requestLine['LINE_IDLI'])
|
|
|
+ // ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ // ->where('INAR_ESTA', '=', 'Activo')
|
|
|
+ // ->where('DEAR_ESTA', '=', 'Activo')
|
|
|
+ // ->where('ARTI_ESTA', '=', 'Activo')
|
|
|
+ // ->where('FAMI_ESTA', '=', 'Activo')
|
|
|
+ // ->where('SUBF_ESTA', '=', 'Activo')
|
|
|
+ // ->where('UNID_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $line)
|
|
|
+ ->where('INAR_NULI', '=', $line)
|
|
|
+ ->where('DEAR_NULI', '=', $line)
|
|
|
+ ->where('ARTI_NULI', '=', $line)
|
|
|
+ ->where('FAMI_NULI', '=', $line)
|
|
|
+ ->where('SUBF_NULI', '=', $line)
|
|
|
+ ->where('UNID_NULI', '=', $line)
|
|
|
+ ->join('S002V01TINAR','INAR_IDIN','=','ARSE_IDIN')
|
|
|
+ ->join('S002V01TDEAR','DEAR_IDDE','=','INAR_IDDE')
|
|
|
+ ->join('S002V01TARTI','ARTI_IDAR','=','DEAR_IDAR')
|
|
|
+ ->join('S002V01TFAMI','FAMI_IDFA','=','ARTI_IDFA')
|
|
|
+ ->join('S002V01TSUBF','SUBF_IDSU','=','ARTI_IDSU')
|
|
|
+ ->join('S002V01TUNID','UNID_IDUN','=','DEAR_IDUN')
|
|
|
+ ->get([
|
|
|
+ 'ARSE_IDAS',
|
|
|
+ 'ARSE_IDAR',
|
|
|
+ 'ARSE_NUPR',
|
|
|
+ 'ARSE_IDIN',
|
|
|
+ 'ARSE_CANT',
|
|
|
+ 'ARSE_PRTO',
|
|
|
+ 'ARSE_ESTA',
|
|
|
+ 'ARSE_USRE',
|
|
|
+ 'ARSE_FERE',
|
|
|
+ 'ARSE_USMO',
|
|
|
+ 'ARSE_FEMO',
|
|
|
+ 'INAR_IDIN',
|
|
|
+ 'INAR_CODI',
|
|
|
+ 'INAR_MODE',
|
|
|
+ 'INAR_MONE',
|
|
|
+ 'INAR_PREC',
|
|
|
+ 'INAR_MOMI',
|
|
|
+ 'INAR_CARA',
|
|
|
+ 'DEAR_IDDE',
|
|
|
+ 'DEAR_IMAG',
|
|
|
+ 'DEAR_DESC',
|
|
|
+ 'DEAR_CARA',
|
|
|
+ 'DEAR_COWE',
|
|
|
+ 'ARTI_IDAR',
|
|
|
+ 'ARTI_CODI',
|
|
|
+ 'ARTI_NOMB',
|
|
|
+ 'FAMI_IDFA',
|
|
|
+ 'FAMI_NOMB',
|
|
|
+ 'SUBF_IDSU',
|
|
|
+ 'SUBF_NOMB',
|
|
|
+ 'UNID_IDUN',
|
|
|
+ 'UNID_NOMB',
|
|
|
+ 'UNID_ACRO',
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_GET002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ $arrSelected = json_decode(json_encode($getSelected), true);
|
|
|
+
|
|
|
+ foreach ($arrSelected as $keySelected => $selected) {
|
|
|
+ $arrSelected[$keySelected]['DEAR_IMAG'] = json_decode(json_decode($selected['DEAR_IMAG']));
|
|
|
+
|
|
|
+ /* foreach ($arrSelected[$keySelected]['DEAR_IMAG'] as $keyimagen => $imagen) {
|
|
|
+ $arrSelected[$keySelected]['DEAR_IMAG'][$keyimagen] = array( 'image' => $imagen);
|
|
|
+ } */
|
|
|
+ }
|
|
|
+
|
|
|
+ $arrRequestLines[$keyRequest]['SELECTED'] = $arrSelected;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->responseController->makeResponse(false, "ÉXITO", $arrRequestLines);
|
|
|
+ }
|
|
|
+
|
|
|
// Se obtiene una línea de solicitud en específico
|
|
|
public function getRequestLine($encIdRequestLine, $line){
|
|
|
|
|
|
@@ -185,7 +282,7 @@ class RequestLineController extends Controller
|
|
|
->where("LINE_IDLI", "=", $idRequestLine)
|
|
|
->first([
|
|
|
'LINE_IDLI AS ID_LINEA_SOLICITUD',
|
|
|
- 'LINE_DESC AS DESCRIPCION',
|
|
|
+ // 'LINE_DESC AS DESCRIPCION',
|
|
|
'LINE_ESTA AS ESTADO',
|
|
|
'LINE_IDME AS METODO_PAGO',
|
|
|
'LINE_FERE AS FECHA_REGISTRA',
|
|
|
@@ -250,7 +347,7 @@ class RequestLineController extends Controller
|
|
|
if ($validator->fails()) {
|
|
|
return $this->responseController->makeResponse(
|
|
|
true,
|
|
|
- "ERR_ORDER_CAN000: Se encontraron uno o más errores.",
|
|
|
+ "ERR_REQUESTLINE_CAN000: Se encontraron uno o más errores.",
|
|
|
$this->responseController->makeErrors($validator->errors()->messages()),
|
|
|
401
|
|
|
);
|
|
|
@@ -263,41 +360,282 @@ class RequestLineController extends Controller
|
|
|
$user = $this->encController->decrypt($requestData['user']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_CAN001: Ocurrió un error al obtener el contenido.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN001: Ocurrió un error al obtener el contenido.", $th->getMessage(), 500);
|
|
|
}
|
|
|
try {
|
|
|
$line = $this->encController->decrypt($requestData['line']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_CAN002: Ocurrió un error al obtener la línea.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN002: Ocurrió un error al obtener la línea.", $th->getMessage(), 500);
|
|
|
}
|
|
|
try {
|
|
|
$idRequestLine = $this->encController->decrypt($requestData['idRequestLine']);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_CAN003: Ocurrió un error al obtener el identificador de la línea de solicitud de compra.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN003: Ocurrió un error al obtener el identificador de la línea de solicitud de compra.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $getRequestLine = (array) DB::table('S002V01TLINE')->where('LINE_IDLI', '=', $idRequestLine)->where('LINE_NULI', '=', $line)->first();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN004: Ocurrió un error al verificar que exista la línea de solicitud de compra.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if (empty($getRequestLine)) {
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN005: La línea de solicitud de compra no existe.", [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $response = DB::table('S002V01TLINE')
|
|
|
+ ->where('LINE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('LINE_NULI', '=', $line)
|
|
|
+ ->update([
|
|
|
+ 'LINE_ESTA' => 'Cancelado',
|
|
|
+ 'LINE_USMO' => $user,
|
|
|
+ 'LINE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN006: No se pudo realizar la modificación a la base.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if (!$response) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN007: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ $countDeleteArtitles = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_ESTA', '=', 'Eliminado')
|
|
|
+ ->where('ARSE_NULI', '=', $line)
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->count();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN008: Ocurrió un error al obtener los artículos seleccionados.", $th->getMessage(), 500);
|
|
|
}
|
|
|
|
|
|
- $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString();
|
|
|
- $objRequest = [
|
|
|
- 'LINE_ESTA' => 'Cancelado',
|
|
|
- 'LINE_USMO' => $user,
|
|
|
- 'LINE_FEMO' => $currentDate,
|
|
|
- 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
- ];
|
|
|
|
|
|
try {
|
|
|
- $response = DB::table('S002V01TLINE')->where('LINE_IDLI', '=', $idRequestLine)->update($objRequest);
|
|
|
- if ($response == null || $response <= 0) {
|
|
|
+ $getArtitleSelected = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $line)
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->get([
|
|
|
+ 'ARSE_IDAS',
|
|
|
+ 'ARSE_IDLI',
|
|
|
+ 'ARSE_IDAR',
|
|
|
+ 'ARSE_NUPR',
|
|
|
+ 'ARSE_IDIN',
|
|
|
+ 'ARSE_CANT',
|
|
|
+ 'ARSE_PRTO',
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN008: Ocurrió un error al obtener los artículos seleccionados.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ $arrArtitleSelected = json_decode(json_encode($getArtitleSelected), true);
|
|
|
+
|
|
|
+ foreach ($arrArtitleSelected as $keyArtitle => $artitleSelected) {
|
|
|
+ try {
|
|
|
+ $validateUpdate = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDAS', '=', $artitleSelected['ARSE_IDAS'])
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->update([
|
|
|
+ 'ARSE_IDAS' => 999 - $countDeleteArtitles - ($keyArtitle + 1),
|
|
|
+ 'ARSE_ESTA' => 'Eliminado',
|
|
|
+ 'ARSE_USMO' => $user,
|
|
|
+ 'ARSE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_CAN004: Ocurrió un error al hacer la inserción en la base.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN009: Ocurrió un error al eliminar los artículos seleccionados.", $th->getMessage(), 500);
|
|
|
}
|
|
|
+
|
|
|
+ if (!$validateUpdate) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_CAN010: No se pudo modificar el estado de los artículos seleccionados", [], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* DB::rollBack();
|
|
|
+ return $arrArtitleSelected; */
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return $this->responseController->makeResponse(false, "ÉXITO: Cancelación Exitosa");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteArtitleByRequestLine(Request $request) {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'LINE_NUMBER' => 'required|string',
|
|
|
+ 'USER' => 'required|string',
|
|
|
+ 'ID_SELECTED' => 'required|string',
|
|
|
+ 'REQUEST_LINE' => 'required|string',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->responseController->makeResponse(
|
|
|
+ true,
|
|
|
+ "ERR_REQUESTLINE_DEL000: 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['USER']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $idSelected = $this->encController->decrypt($requestData['ID_SELECTED']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL002: Ocurrió un error al obtener el artículo seleccionado.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ $idRequestLine = $this->encController->decrypt($requestData['REQUEST_LINE']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL003: Ocurrió un error al obtener la línea de solicitud de compra.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateRequestLine = DB::table('S002V01TLINE')
|
|
|
+ ->where('LINE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('LINE_ESTA', '=', 'En espera')
|
|
|
+ ->where('LINE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->exists();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL004: Ocurrió un error al verificar que exista la línea de solicitud de compra.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if (!$validateRequestLine) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL005: La línea de solicitud no existe o tiene un estado más avanzado.", [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateArtitleSelected = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDAS', '=', $idSelected)
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->exists();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL005: Ocurrió un error al verificar que exista el artículo seleccionado.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+ if (!$validateArtitleSelected) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL006: El artículo seleccionado no existe en la línea de solicitud de compra.", [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ $countDeletArtitle = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDAS', '=', $idSelected)
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('ARSE_ESTA', '=', 'Eliminado')
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->count();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL007: Ocurrió un error al verificar que exista el artículo seleccionado.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $validateUpdate = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDAS', '=', $idSelected)
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->update([
|
|
|
+ 'ARSE_IDAS' => 999 - $countDeletArtitle,
|
|
|
+ 'ARSE_ESTA' => 'Eliminado',
|
|
|
+ 'ARSE_USMO' => $user,
|
|
|
+ 'ARSE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
} catch (\Throwable $th) {
|
|
|
DB::rollBack();
|
|
|
- return $this->responseController->makeResponse(true, "ERR_ORDER_CAN005: No se pudo realizar la modificación a la base.", [], 500);
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL008: Ocurrió un error al eliminar el artículo.", $th->getMessage(), 500);
|
|
|
}
|
|
|
+
|
|
|
+ if (!$validateUpdate) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL009: No se pudo eliminar el archivo seleccionado.", [], 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $getArtitleSelectedActives = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->get();
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL010: Ocurrió un error al verificar que exista el artículo seleccionado.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ $arrArtitleSelectedActives = json_decode(json_encode($getArtitleSelectedActives), true);
|
|
|
+
|
|
|
+ if (count($arrArtitleSelectedActives) > 0) {
|
|
|
+ foreach ($arrArtitleSelectedActives as $keyArtitles => $artitleSelected) {
|
|
|
+ try {
|
|
|
+ $validateUpdateActives = DB::table('S002V01TARSE')
|
|
|
+ ->where('ARSE_IDLI', '=', $idRequestLine)
|
|
|
+ ->where('ARSE_ESTA', '=', 'Activo')
|
|
|
+ ->where('ARSE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->update([
|
|
|
+ 'ARSE_IDAS' => $keyArtitles + 1,
|
|
|
+ 'ARSE_USMO' => $user,
|
|
|
+ 'ARSE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL011: Ocurrió un error al reeligir el número de línea de los artículos", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$validateUpdateActives) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL012: No se pudo reeligir el número de línea de los artículos.", [], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ $validateUpdate = DB::table('S002V01TLINE')
|
|
|
+ ->where('LINE_IDLI', '=', $idRequestLine)
|
|
|
+ // ->where('LINE_ESTA', '=', 'En espera')
|
|
|
+ ->where('LINE_NULI', '=', $requestData['LINE_NUMBER'])
|
|
|
+ ->update([
|
|
|
+ 'LINE_ESTA' => 'Cancelado',
|
|
|
+ 'LINE_USMO' => $user,
|
|
|
+ 'LINE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
|
|
|
+ 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL013: Ocurrió un error al eliminar el artículo.", $th->getMessage(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$validateUpdate) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_DEL014: No se pudo eliminar el archivo seleccionado.", [], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
DB::commit();
|
|
|
- return $this->responseController->makeResponse(false, "ÉXITO: Cancelación Exitosa");
|
|
|
+ return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Correcta");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function updateStatusRequestLine(Request $request) {
|
|
|
@@ -357,4 +695,6 @@ class RequestLineController extends Controller
|
|
|
return $this->responseController->makeResponse(false, "ÉXITO: Modificación de Estado Exitoso");
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|