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,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user