Backend:
Diseño de un AuditoriaController con un patrón para añadir endpoints de historial para diferentes entidades. Implementación de la lógica de servicio y repositorio para obtener datos de las tablas _H para: Usuarios (gral_Usuarios_H) Pagos de Distribuidores (cue_PagosDistribuidor_H) Notas de Crédito/Débito (cue_CreditosDebitos_H) Entradas/Salidas de Distribuidores (dist_EntradasSalidas_H) Entradas/Salidas de Canillitas (dist_EntradasSalidasCanillas_H) Novedades de Canillitas (dist_dtNovedadesCanillas_H) Ajustes Manuales de Saldo (cue_SaldoAjustesHistorial) Tipos de Pago (cue_dtTipopago_H) Canillitas (Maestro) (dist_dtCanillas_H) Distribuidores (Maestro) (dist_dtDistribuidores_H) Empresas (Maestro) (dist_dtEmpresas_H) DTOs específicos para cada tipo de historial, incluyendo NombreUsuarioModifico. Frontend: Servicio auditoriaService.ts con métodos para llamar a cada endpoint de historial. Página AuditoriaGeneralPage.tsx con: Selector de "Tipo de Entidad a Auditar". Filtros comunes (Fechas, Usuario Modificador, Tipo de Modificación, ID Entidad). Un DataGrid que muestra las columnas dinámicamente según el tipo de entidad seleccionada. Lógica para cargar los datos correspondientes. DTOs de historial en TypeScript. Actualizaciones en AppRoutes.tsx y MainLayout.tsx para la nueva sección de Auditoría (restringida a SuperAdmin).
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,10 +11,13 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
Task<IEnumerable<NotaCreditoDebitoDto>> ObtenerTodosAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
string? destino, int? idDestino, int? idEmpresa, string? tipoNota);
|
||||
|
||||
Task<NotaCreditoDebitoDto?> ObtenerPorIdAsync(int idNota);
|
||||
Task<(NotaCreditoDebitoDto? Nota, string? Error)> CrearAsync(CreateNotaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idNota, UpdateNotaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idNota, int idUsuario);
|
||||
Task<IEnumerable<NotaCreditoDebitoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idNotaAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,5 +16,9 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
Task<(PagoDistribuidorDto? Pago, string? Error)> CrearAsync(CreatePagoDistribuidorDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idPago, UpdatePagoDistribuidorDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idPago, int idUsuario);
|
||||
Task<IEnumerable<PagoDistribuidorHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPagoAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,5 +9,9 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
{
|
||||
Task<IEnumerable<SaldoGestionDto>> ObtenerSaldosParaGestionAsync(string? destinoFilter, int? idDestinoFilter, int? idEmpresaFilter);
|
||||
Task<(bool Exito, string? Error, SaldoGestionDto? SaldoActualizado)> RealizarAjusteManualSaldoAsync(AjusteSaldoRequestDto ajusteDto, int idUsuarioAjuste);
|
||||
Task<IEnumerable<SaldoAjusteHistorialDto>> ObtenerHistorialAjustesAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico,
|
||||
string? destino, int? idDestino, int? idEmpresa);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
Task<(TipoPagoDto? TipoPago, string? Error)> CrearAsync(CreateTipoPagoDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdateTipoPagoDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario);
|
||||
Task<IEnumerable<TipoPagoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTipoPagoAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Contables;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using GestionIntegral.Api.Models.Contables;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -55,7 +56,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
var canData = await _canillaRepo.GetByIdAsync(nota.IdDestino);
|
||||
nombreDestinatario = canData.Canilla?.NomApe ?? "Canillita Desconocido";
|
||||
}
|
||||
|
||||
|
||||
var empresa = await _empresaRepo.GetByIdAsync(nota.IdEmpresa);
|
||||
|
||||
return new NotaCreditoDebitoDto
|
||||
@@ -102,7 +103,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
else if (createDto.Destino == "Canillas")
|
||||
{
|
||||
if (await _canillaRepo.GetByIdSimpleAsync(createDto.IdDestino) == null)
|
||||
if (await _canillaRepo.GetByIdSimpleAsync(createDto.IdDestino) == null)
|
||||
return (null, "El canillita especificado no existe.");
|
||||
}
|
||||
else { return (null, "Tipo de destino inválido."); }
|
||||
@@ -131,16 +132,16 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
|
||||
var notaCreada = await _notaRepo.CreateAsync(nuevaNota, idUsuario, transaction);
|
||||
if (notaCreada == null) throw new DataException("Error al registrar la nota.");
|
||||
|
||||
decimal montoParaSaldo;
|
||||
if (createDto.Tipo == "Credito")
|
||||
if (createDto.Tipo == "Credito")
|
||||
{
|
||||
montoParaSaldo = -createDto.Monto;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
montoParaSaldo = createDto.Monto;
|
||||
}
|
||||
@@ -178,14 +179,14 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var notaExistente = await _notaRepo.GetByIdAsync(idNota);
|
||||
if (notaExistente == null)
|
||||
|
||||
var notaExistente = await _notaRepo.GetByIdAsync(idNota);
|
||||
if (notaExistente == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "Nota no encontrada.");
|
||||
}
|
||||
|
||||
|
||||
decimal impactoOriginalSaldo = notaExistente.Tipo == "Credito" ? -notaExistente.Monto : notaExistente.Monto;
|
||||
decimal impactoNuevoSaldo = notaExistente.Tipo == "Credito" ? -updateDto.Monto : updateDto.Monto;
|
||||
decimal diferenciaAjusteSaldo = impactoNuevoSaldo - impactoOriginalSaldo;
|
||||
@@ -193,14 +194,14 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
var notaParaActualizarEnRepo = new NotaCreditoDebito
|
||||
{
|
||||
IdNota = notaExistente.IdNota,
|
||||
Destino = notaExistente.Destino,
|
||||
IdDestino = notaExistente.IdDestino,
|
||||
Referencia = notaExistente.Referencia,
|
||||
Tipo = notaExistente.Tipo,
|
||||
Fecha = notaExistente.Fecha,
|
||||
Monto = updateDto.Monto,
|
||||
Observaciones = updateDto.Observaciones,
|
||||
IdEmpresa = notaExistente.IdEmpresa
|
||||
Destino = notaExistente.Destino,
|
||||
IdDestino = notaExistente.IdDestino,
|
||||
Referencia = notaExistente.Referencia,
|
||||
Tipo = notaExistente.Tipo,
|
||||
Fecha = notaExistente.Fecha,
|
||||
Monto = updateDto.Monto,
|
||||
Observaciones = updateDto.Observaciones,
|
||||
IdEmpresa = notaExistente.IdEmpresa
|
||||
};
|
||||
|
||||
var actualizado = await _notaRepo.UpdateAsync(notaParaActualizarEnRepo, idUsuario, transaction);
|
||||
@@ -227,7 +228,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
{
|
||||
if (connection.State == ConnectionState.Open)
|
||||
{
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.CloseAsync(); else connection.Close();
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.CloseAsync(); else connection.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,17 +241,17 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
{
|
||||
if (connection.State != ConnectionState.Open)
|
||||
{
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var notaExistente = await _notaRepo.GetByIdAsync(idNota);
|
||||
if (notaExistente == null)
|
||||
if (notaExistente == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "Nota no encontrada.");
|
||||
}
|
||||
|
||||
|
||||
decimal montoReversion = notaExistente.Tipo == "Credito" ? notaExistente.Monto : -notaExistente.Monto;
|
||||
|
||||
var eliminado = await _notaRepo.DeleteAsync(idNota, idUsuario, transaction);
|
||||
@@ -278,5 +279,30 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<NotaCreditoDebitoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idNotaAfectada)
|
||||
{
|
||||
var historialData = await _notaRepo.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idNotaAfectada);
|
||||
|
||||
return historialData.Select(h => new NotaCreditoDebitoHistorialDto
|
||||
{
|
||||
Id_Nota = h.Historial.Id_Nota,
|
||||
Destino = h.Historial.Destino,
|
||||
Id_Destino = h.Historial.Id_Destino,
|
||||
Referencia = h.Historial.Referencia,
|
||||
Tipo = h.Historial.Tipo,
|
||||
Fecha = h.Historial.Fecha, // Fecha original de la nota
|
||||
Monto = h.Historial.Monto,
|
||||
Observaciones = h.Historial.Observaciones,
|
||||
Id_Empresa = h.Historial.Id_Empresa,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod, // Fecha de la auditoría
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Contables;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using GestionIntegral.Api.Models.Contables;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -93,7 +94,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
if (await _empresaRepo.GetByIdAsync(createDto.IdEmpresa) == null)
|
||||
return (null, "Empresa no válida.");
|
||||
if (await _pagoRepo.ExistsByReciboAndTipoMovimientoAsync(createDto.Recibo, createDto.TipoMovimiento))
|
||||
return (null, $"Ya existe un pago '{createDto.TipoMovimiento}' con el número de recibo '{createDto.Recibo}'.");
|
||||
return (null, $"Ya existe un pago '{createDto.TipoMovimiento}' con el número de recibo '{createDto.Recibo}'.");
|
||||
|
||||
var nuevoPago = new PagoDistribuidor
|
||||
{
|
||||
@@ -116,18 +117,18 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
|
||||
var pagoCreado = await _pagoRepo.CreateAsync(nuevoPago, idUsuario, transaction);
|
||||
if (pagoCreado == null) throw new DataException("Error al registrar el pago.");
|
||||
|
||||
decimal montoParaSaldo;
|
||||
if (createDto.TipoMovimiento == "Recibido")
|
||||
{
|
||||
montoParaSaldo = -createDto.Monto;
|
||||
montoParaSaldo = -createDto.Monto;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
montoParaSaldo = createDto.Monto;
|
||||
montoParaSaldo = createDto.Monto;
|
||||
}
|
||||
|
||||
bool saldoActualizado = await _saldoRepo.ModificarSaldoAsync("Distribuidores", pagoCreado.IdDistribuidor, pagoCreado.IdEmpresa, montoParaSaldo, transaction);
|
||||
@@ -143,7 +144,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
_logger.LogError(ex, "Error CrearAsync PagoDistribuidor.");
|
||||
return (null, $"Error interno: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
finally
|
||||
{
|
||||
if (connection.State == ConnectionState.Open)
|
||||
{
|
||||
@@ -164,8 +165,8 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var pagoExistente = await _pagoRepo.GetByIdAsync(idPago);
|
||||
if (pagoExistente == null)
|
||||
var pagoExistente = await _pagoRepo.GetByIdAsync(idPago);
|
||||
if (pagoExistente == null)
|
||||
{
|
||||
transaction.Rollback(); // Rollback si no se encuentra
|
||||
return (false, "Pago no encontrado.");
|
||||
@@ -176,7 +177,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
transaction.Rollback();
|
||||
return (false, "Tipo de pago no válido.");
|
||||
}
|
||||
|
||||
|
||||
decimal impactoOriginalSaldo = pagoExistente.TipoMovimiento == "Recibido" ? -pagoExistente.Monto : pagoExistente.Monto;
|
||||
decimal impactoNuevoSaldo = pagoExistente.TipoMovimiento == "Recibido" ? -updateDto.Monto : updateDto.Monto;
|
||||
decimal diferenciaAjusteSaldo = impactoNuevoSaldo - impactoOriginalSaldo;
|
||||
@@ -184,14 +185,14 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
var pagoParaActualizarEnRepo = new PagoDistribuidor
|
||||
{
|
||||
IdPago = pagoExistente.IdPago,
|
||||
IdDistribuidor = pagoExistente.IdDistribuidor,
|
||||
Fecha = pagoExistente.Fecha,
|
||||
TipoMovimiento = pagoExistente.TipoMovimiento,
|
||||
Recibo = pagoExistente.Recibo,
|
||||
Monto = updateDto.Monto,
|
||||
IdTipoPago = updateDto.IdTipoPago,
|
||||
Detalle = updateDto.Detalle,
|
||||
IdEmpresa = pagoExistente.IdEmpresa
|
||||
IdDistribuidor = pagoExistente.IdDistribuidor,
|
||||
Fecha = pagoExistente.Fecha,
|
||||
TipoMovimiento = pagoExistente.TipoMovimiento,
|
||||
Recibo = pagoExistente.Recibo,
|
||||
Monto = updateDto.Monto,
|
||||
IdTipoPago = updateDto.IdTipoPago,
|
||||
Detalle = updateDto.Detalle,
|
||||
IdEmpresa = pagoExistente.IdEmpresa
|
||||
};
|
||||
|
||||
var actualizado = await _pagoRepo.UpdateAsync(pagoParaActualizarEnRepo, idUsuario, transaction);
|
||||
@@ -214,7 +215,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
_logger.LogError(ex, "Error ActualizarAsync PagoDistribuidor ID: {Id}", idPago);
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
finally
|
||||
{
|
||||
if (connection.State == ConnectionState.Open)
|
||||
{
|
||||
@@ -231,17 +232,17 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
{
|
||||
if (connection.State != ConnectionState.Open)
|
||||
{
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
if (connection is System.Data.Common.DbConnection dbConn) await dbConn.OpenAsync(); else connection.Open();
|
||||
}
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
|
||||
var pagoExistente = await _pagoRepo.GetByIdAsync(idPago);
|
||||
if (pagoExistente == null)
|
||||
if (pagoExistente == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "Pago no encontrado.");
|
||||
}
|
||||
|
||||
|
||||
decimal montoReversion = pagoExistente.TipoMovimiento == "Recibido" ? pagoExistente.Monto : -pagoExistente.Monto;
|
||||
|
||||
var eliminado = await _pagoRepo.DeleteAsync(idPago, idUsuario, transaction);
|
||||
@@ -269,5 +270,30 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PagoDistribuidorHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPagoAfectado)
|
||||
{
|
||||
var historialData = await _pagoRepo.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPagoAfectado);
|
||||
|
||||
return historialData.Select(h => new PagoDistribuidorHistorialDto
|
||||
{
|
||||
Id_Pago = h.Historial.Id_Pago,
|
||||
Id_Distribuidor = h.Historial.Id_Distribuidor,
|
||||
Fecha = h.Historial.Fecha,
|
||||
TipoMovimiento = h.Historial.TipoMovimiento,
|
||||
Recibo = h.Historial.Recibo,
|
||||
Monto = h.Historial.Monto,
|
||||
Id_TipoPago = h.Historial.Id_TipoPago,
|
||||
Detalle = h.Historial.Detalle,
|
||||
Id_Empresa = h.Historial.Id_Empresa,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Contables;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion; // Para IDistribuidorRepository, ICanillaRepository
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using GestionIntegral.Api.Models.Contables;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -52,7 +53,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
var canData = await _canillaRepo.GetByIdAsync(saldo.IdDestino);
|
||||
nombreDestinatario = canData.Canilla?.NomApe ?? $"Can. ID {saldo.IdDestino}";
|
||||
}
|
||||
|
||||
|
||||
var empresa = await _empresaRepo.GetByIdAsync(saldo.IdEmpresa);
|
||||
|
||||
return new SaldoGestionDto
|
||||
@@ -94,11 +95,13 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
{
|
||||
if (await _canillaRepo.GetByIdSimpleAsync(ajusteDto.IdDestino) == null)
|
||||
return (false, "El canillita especificado no existe.", null);
|
||||
} else {
|
||||
return (false, "Tipo de destino inválido.", null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (false, "Tipo de destino inválido.", null);
|
||||
}
|
||||
if (await _empresaRepo.GetByIdAsync(ajusteDto.IdEmpresa) == null)
|
||||
return (false, "La empresa especificada no existe.", null);
|
||||
return (false, "La empresa especificada no existe.", null);
|
||||
|
||||
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
@@ -116,7 +119,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
|
||||
decimal saldoAnterior = saldoActual.Monto;
|
||||
|
||||
|
||||
bool modificado = await _saldoRepo.ModificarSaldoAsync(ajusteDto.Destino, ajusteDto.IdDestino, ajusteDto.IdEmpresa, ajusteDto.MontoAjuste, transaction);
|
||||
if (!modificado)
|
||||
{
|
||||
@@ -125,7 +128,7 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
|
||||
// Obtener el saldo después de la modificación para el historial
|
||||
var saldoDespuesDeModificacion = await _saldoRepo.GetSaldoAsync(ajusteDto.Destino, ajusteDto.IdDestino, ajusteDto.IdEmpresa, transaction);
|
||||
if(saldoDespuesDeModificacion == null) throw new DataException("No se pudo obtener el saldo después de la modificación.");
|
||||
if (saldoDespuesDeModificacion == null) throw new DataException("No se pudo obtener el saldo después de la modificación.");
|
||||
|
||||
|
||||
var historial = new SaldoAjusteHistorial
|
||||
@@ -145,20 +148,44 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
transaction.Commit();
|
||||
_logger.LogInformation("Ajuste manual de saldo realizado para {Destino} ID {IdDestino}, Empresa ID {IdEmpresa} por Usuario ID {IdUsuarioAjuste}. Monto: {MontoAjuste}",
|
||||
ajusteDto.Destino, ajusteDto.IdDestino, ajusteDto.IdEmpresa, idUsuarioAjuste, ajusteDto.MontoAjuste);
|
||||
|
||||
|
||||
var saldoDtoActualizado = await MapToGestionDto(saldoDespuesDeModificacion);
|
||||
return (true, null, saldoDtoActualizado);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { transaction.Rollback(); } catch (Exception rbEx){ _logger.LogError(rbEx, "Error en Rollback de RealizarAjusteManualSaldoAsync."); }
|
||||
try { transaction.Rollback(); } catch (Exception rbEx) { _logger.LogError(rbEx, "Error en Rollback de RealizarAjusteManualSaldoAsync."); }
|
||||
_logger.LogError(ex, "Error en RealizarAjusteManualSaldoAsync.");
|
||||
return (false, $"Error interno al realizar el ajuste: {ex.Message}", null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (connection.State == ConnectionState.Open) { if (connection is System.Data.Common.DbConnection dbConn) await dbConn.CloseAsync(); else connection.Close(); }
|
||||
if (connection.State == ConnectionState.Open) { if (connection is System.Data.Common.DbConnection dbConn) await dbConn.CloseAsync(); else connection.Close(); }
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SaldoAjusteHistorialDto>> ObtenerHistorialAjustesAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico,
|
||||
string? destino, int? idDestino, int? idEmpresa)
|
||||
{
|
||||
var historialData = await _saldoRepo.GetHistorialAjustesAsync(fechaDesde, fechaHasta, idUsuarioModifico, destino, idDestino, idEmpresa);
|
||||
|
||||
return historialData.Select(h => new SaldoAjusteHistorialDto
|
||||
{
|
||||
IdSaldoAjusteHist = h.Historial.IdSaldoAjusteHist,
|
||||
Destino = h.Historial.Destino,
|
||||
Id_Destino = h.Historial.IdDestino,
|
||||
Id_Empresa = h.Historial.IdEmpresa,
|
||||
MontoAjuste = h.Historial.MontoAjuste,
|
||||
SaldoAnterior = h.Historial.SaldoAnterior,
|
||||
SaldoNuevo = h.Historial.SaldoNuevo,
|
||||
Justificacion = h.Historial.Justificacion,
|
||||
FechaAjuste = h.Historial.FechaAjuste,
|
||||
Id_UsuarioAjuste = h.Historial.IdUsuarioAjuste,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico
|
||||
// TipoMod es implícito "AjusteManualSaldo"
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using GestionIntegral.Api.Data.Repositories.Contables;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Contables;
|
||||
using GestionIntegral.Api.Models.Contables; // Para TipoPago
|
||||
using GestionIntegral.Api.Services.Contables;
|
||||
@@ -101,8 +102,8 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
|
||||
if (!actualizado)
|
||||
{
|
||||
_logger.LogError("Falló la actualización del Tipo de Pago en el repositorio para el ID: {Id}", id);
|
||||
return (false, "Error al actualizar el tipo de pago en la base de datos.");
|
||||
_logger.LogError("Falló la actualización del Tipo de Pago en el repositorio para el ID: {Id}", id);
|
||||
return (false, "Error al actualizar el tipo de pago en la base de datos.");
|
||||
}
|
||||
return (true, null); // Éxito
|
||||
}
|
||||
@@ -130,5 +131,24 @@ namespace GestionIntegral.Api.Services.Contables
|
||||
}
|
||||
return (true, null); // Éxito
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TipoPagoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTipoPagoAfectado)
|
||||
{
|
||||
var historialData = await _tipoPagoRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idTipoPagoAfectado);
|
||||
|
||||
return historialData.Select(h => new TipoPagoHistorialDto
|
||||
{
|
||||
Id_TipoPago = h.Historial.Id_TipoPago,
|
||||
Nombre = h.Historial.Nombre,
|
||||
Detalle = h.Historial.Detalle,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user