| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716 |
- <?php
- /*
- Desarrollador: Ing. Jean Jairo Benitez Meza
- Ultima Modificación: 27/04/2023
- Módulo: Gestión de Adquisiciones
- */
- namespace App\Http\Controllers;
- use App\Http\Controllers\ResponseController;
- use App\Http\Controllers\EncryptionController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- class RequestLineController extends Controller
- {
- private $responseController;
- private $encController;
- private $documentManagementController;
- public function __construct(){
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->documentManagementController = new DocumentManagementController();
- }
- // Se registran las líneas de solicitud
- public function createRequestLine(Request $request){
- $validator = Validator::make($request->all(), [
- 'line' => 'required|string',
- 'user' => 'required|string',
- // 'description' => 'required|string',
- 'products' => 'required|string'
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_REQUESTLINE_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['user']);
- } catch (\Throwable $th) {
- DB::rollBack();
- 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_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_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_REQUESTLINE_REG004: Ocurrió un error al obtener los productos del artículo.", [], 500);
- }
- if (empty($strArtitles)) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_REQUESTLINE_REG005: No se encontró ningún registro de productos.", [], 500);
- }
- $arrRequestLine = json_decode($strArtitles, true);
- 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 ($requestLine['ARTITLES'] as $key => $artitle) {
- try {
- $validate = DB::table('S002V01TARSE')->insert([
- 'ARSE_IDAS' => $secuence,
- 'ARSE_IDLI' => $idRegisterLine,
- '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(),
- 'ARSE_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- 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_REQUESTLINE_REG009: Ocurrió un error al hacer la inserción en la base.", [], 500);
- }
- $secuence++;
- }
- }
-
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro correcto");
- }
- // Se obtienen todas las líneas de solicitud
- 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_ESTA AS ESTADO',
- 'LINE_FERE AS FECHA_REGISTRA',
- 'LINE_FEMO AS FECHA_MODIFICA',
- 'LINE_USRE AS USUARIO_MODIFICA',
- 'LINE_USRE AS USUARIO_MODIFICA'
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET000: No se pudo realizar la consulta a la base.", [], 500);
- }
- foreach ($arrRequestLines as $keyRequest => $requestLines) {
- $idRequestLine = $requestLines->ID_LINEA_SOLICITUD;
- try {
- $countData = DB::table('S002V01TARSE')->where('ARSE_IDLI', '=', $idRequestLine)->count();
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET001: No se pudo realizar la consulta a la base", [], 500);
- }
- $requestLines->CANTIDAD = $countData;
- }
- 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')
- ->join('S002V01TCAMO','CAMO_COMO','=','INAR_COMO')
- ->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',
- 'CAMO_COMO',
- 'CAMO_DESC',
- '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) {
- $arrImagen = json_decode($selected['DEAR_IMAG']);
- $user = 'SFJKU29aaUtYbWwweFFzcmV4RVd6UEtNbWtlbU9VdkE3Vjg9fEU4N3pWWGFuWm5EbXBJaG1nZVl4RWJQcWtPTGZmT25H';
- $arrUrlImage = array();
- foreach ($arrImagen as $key => $imagen) {
- $responseDocument = $this->documentManagementController->getPublicDocumentURL($imagen, $user, $line);
-
- $arrResponseDocument = json_decode($responseDocument->original, true);
- if ($arrResponseDocument['error']) {
- return $this->responseController->makeResponse(true, "ERR_ARTITLE_GET003: Ocurrió un error al obtener la URL de la imágen.", [], 500);
- }
- $arrUrlImage[] = $arrResponseDocument['response']['public_uri'];
- }
- $arrSelected[$keySelected]['DEAR_IMAG'] = $arrUrlImage;
- }
- $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){
- try {
- $idRequestLine = $this->encController->decrypt($encIdRequestLine);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET000: Ocurrió un error al obtener el contenido.", [], 500);
- }
- try {
- $arrRequestLines = DB::table('S002V01TLINE')
- ->where("LINE_NULI", "=", $line)
- ->where("LINE_IDLI", "=", $idRequestLine)
- ->first([
- 'LINE_IDLI AS ID_LINEA_SOLICITUD',
- // 'LINE_DESC AS DESCRIPCION',
- 'LINE_ESTA AS ESTADO',
- 'LINE_IDME AS METODO_PAGO',
- 'LINE_FERE AS FECHA_REGISTRA',
- 'LINE_FEMO AS FECHA_MODIFICA',
- 'LINE_USRE AS USUARIO_MODIFICA',
- 'LINE_USRE AS USUARIO_MODIFICA'
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET001: No se pudo realizar la consulta a la base.", [], 500);
- }
- try {
- $arrProducts = DB::table('S002V01TARSE')
- ->where("ARSE_NULI", "=", $line)
- ->where('ARSE_IDLI', '=', $idRequestLine)
- ->where('PROV_ESTA', '=', 'Activo')
- ->join('S002V01TPROV', 'ARSE_NUPR', '=', 'PROV_NUPR')
- ->join('S002V01TINAR', 'ARSE_IDIN', '=', 'INAR_IDIN')
- ->join('S002V01TCAMO', 'CAMO_COMO', '=', 'INAR_COMO')
- ->get([
- 'ARSE_IDAS AS NUMERO_ARTI_SELE',
- 'ARSE_IDAR AS NUMERO_ARTICULO',
- 'ARSE_NUPR AS NUMERO_PRODUCTO',
- 'INAR_MODE AS MODELO',
- 'INAR_CODI AS CODIGO',
- 'INAR_CARA AS CARACTERISTICAS',
- 'ARSE_CANT AS CANTIDAD',
- 'INAR_PREC AS PRECIO_UNITARIO',
- 'CAMO_COMO AS MONEDA',
- 'CAMO_DESC AS MONEDA_DESCRIPCION',
- 'ARSE_PRTO AS PRECIO_TOTAL',
- 'ARSE_ESTA AS ESTADO',
- 'ARSE_USRE AS USUARIO_REGISTRA',
- 'ARSE_FERE AS FECHA_REGISTRA',
- 'ARSE_USMO AS USUARIO_MODIFICA',
- 'ARSE_FEMO AS FECHA_MODIFICA',
- 'PROV_NUPR AS NUMERO_PROVEEDOR',
- 'PROV_NOCO AS PROVEEDOR',
- 'PROV_ESTA AS ESTADO_PROVEEDOR'
- ]);
- foreach ($arrProducts as $productos) {
- if ($productos == 'Eliminado') {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET002: Existe un usuario en la solicitud que se encuentra eliminado", [], 500);
- }
- }
- $arrRequestLines->PRODUCTOS = $arrProducts;
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_ORDER_GET003: No se pudo realizar la consulta a la base.", [], 500);
- }
- return $this->responseController->makeResponse(false, "ÉXITO", $arrRequestLines);
- }
- // Se cancalan la linea de solicitud de compra
- public function cancelRequestLine(Request $request){
- $validator = Validator::make($request->all(), [
- 'line' => 'required|string',
- 'user' => 'required|string',
- 'idRequestLine' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_REQUESTLINE_CAN000: 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_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_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_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);
- }
- try {
- $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_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 - intval($countDeletArtitle + 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_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: Eliminación Correcta");
- }
- public function updateStatusRequestLine(Request $request) {
- $validator = Validator::make($request->all(), [
- 'NUMERO_SOLICITUD' => 'required|string',
- 'ESTADO' => 'required|string',
- 'USUARIO' => 'required|string',
- 'METODO_PAGO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- // 'COMENTARIOS' => 'string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_ORDER_UPST000: 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_ORDER_UPST001: Ocurrió un error al obtener el usuario.", [], 500);
- }
- $arrUpdate = [
- 'LINE_ESTA' => $requestData['ESTADO'],
- 'LINE_IDME' => $requestData['METODO_PAGO'],
- 'LINE_COME' => $requestData['COMENTARIOS'] === '' ? null : $requestData['COMENTARIOS'],
- 'LINE_USMO' => $user,
- 'LINE_FEMO' => Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(),
- 'LINE_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
- ];
- try {
- $validateUpdate = DB::table('S002V01TLINE')
- ->where('LINE_IDLI', '=', $requestData['NUMERO_SOLICITUD'])
- ->where('LINE_NULI', '=', $requestData['NUMERO_LINEA'])
- ->update($arrUpdate);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_ORDER_UPST002: Ocurrió un error al modificar el estado.", $th->getMessage(), 500);
- }
- if ( !$validateUpdate ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_ORDER_UPST003: No se pudo modificar el estado de la línea de solicitud.", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación de Estado Exitoso");
- }
-
- }
|