responseController = new ResponseController(); $this->encController = new EncryptionController(); } // 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') ->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($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){ 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') ->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', 'INAR_MONE AS MONEDA', '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"); } }