1. Funcionalidad Principal: Auditoría General
Se creó una nueva sección de "Auditoría" en la aplicación, diseñada para ser accedida por SuperAdmins. Se implementó una página AuditoriaGeneralPage.tsx que actúa como un visor centralizado para el historial de cambios de múltiples entidades del sistema. 2. Backend: Nuevo Controlador (AuditoriaController.cs): Centraliza los endpoints para obtener datos de las tablas de historial (_H). Servicios y Repositorios Extendidos: Se añadieron métodos GetHistorialAsync y ObtenerHistorialAsync a las capas de repositorio y servicio para cada una de las siguientes entidades, permitiendo consultar sus tablas _H con filtros: 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) Tipos de Pago (cue_dtTipopago_H) Canillitas (Maestro) (dist_dtCanillas_H) Distribuidores (Maestro) (dist_dtDistribuidores_H) Empresas (Maestro) (dist_dtEmpresas_H) Zonas (Maestro) (dist_dtZonas_H) Otros Destinos (Maestro) (dist_dtOtrosDestinos_H) Publicaciones (Maestro) (dist_dtPublicaciones_H) Secciones de Publicación (dist_dtPubliSecciones_H) Precios de Publicación (dist_Precios_H) Recargos por Zona (dist_RecargoZona_H) Porcentajes Pago Distribuidores (dist_PorcPago_H) Porcentajes/Montos Canillita (dist_PorcMonPagoCanilla_H) Control de Devoluciones (dist_dtCtrlDevoluciones_H) Tipos de Bobina (bob_dtBobinas_H) Estados de Bobina (bob_dtEstadosBobinas_H) Plantas de Impresión (bob_dtPlantas_H) Stock de Bobinas (bob_StockBobinas_H) Tiradas (Registro Principal) (bob_RegTiradas_H) Secciones de Tirada (bob_RegPublicaciones_H) Cambios de Parada de Canillitas (dist_CambiosParadasCanillas_H) Ajustes Manuales de Saldo (cue_SaldoAjustesHistorial) DTOs de Historial: Se crearon DTOs específicos para cada tabla de historial (ej. UsuarioHistorialDto, PagoDistribuidorHistorialDto, etc.) para transferir los datos al frontend, incluyendo el nombre del usuario que realizó la modificación. Corrección de Lógica de Saldos: Se revisó y corrigió la lógica de afectación de saldos en los servicios PagoDistribuidorService y NotaCreditoDebitoService para asegurar que los débitos y créditos se apliquen correctamente. 3. Frontend: Nuevo Servicio (auditoriaService.ts): Contiene métodos para llamar a cada uno de los nuevos endpoints de auditoría del backend. Nueva Página (AuditoriaGeneralPage.tsx): Permite al SuperAdmin seleccionar el "Tipo de Entidad" a auditar desde un dropdown. Ofrece filtros comunes (rango de fechas, usuario modificador, tipo de acción) y filtros específicos que aparecen dinámicamente según la entidad seleccionada. Utiliza un DataGrid de Material-UI para mostrar el historial, con columnas que se adaptan dinámicamente al tipo de entidad consultada. Nuevos DTOs en TypeScript: Se crearon las interfaces correspondientes a los DTOs de historial del backend. Gestión de Permisos: La sección de Auditoría en MainLayout.tsx y su ruta en AppRoutes.tsx están protegidas para ser visibles y accesibles solo por SuperAdmins. Se añadió un permiso de ejemplo AU_GENERAL_VIEW para ser usado si se decide extender el acceso en el futuro. Corrección de Errores Menores: Se solucionó el problema del "parpadeo" del selector de fecha en GestionarNovedadesCanillaPage al adoptar un patrón de carga de datos más controlado, similar a otras páginas funcionales.
This commit is contained in:
@@ -7,11 +7,13 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Claims; // Para ClaimTypes
|
||||
using GestionIntegral.Api.Services.Contables; // Para IPagoDistribuidorService, etc.
|
||||
using GestionIntegral.Api.Dtos.Contables; // Para PagoDistribuidorHistorialDto, etc.
|
||||
using GestionIntegral.Api.Services.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Usuarios.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Zonas;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Services.Impresion;
|
||||
using GestionIntegral.Api.Dtos.Impresion;
|
||||
using GestionIntegral.Api.Dtos.Usuarios;
|
||||
|
||||
|
||||
namespace GestionIntegral.Api.Controllers
|
||||
@@ -32,6 +34,23 @@ namespace GestionIntegral.Api.Controllers
|
||||
private readonly ISaldoService _saldoService;
|
||||
private readonly ITipoPagoService _tipoPagoService;
|
||||
private readonly IEmpresaService _empresaService;
|
||||
private readonly IZonaService _zonaService;
|
||||
private readonly IOtroDestinoService _otroDestinoService;
|
||||
private readonly IPublicacionService _publicacionService;
|
||||
private readonly IPubliSeccionService _publiSeccionService;
|
||||
private readonly IPrecioService _precioService;
|
||||
private readonly IRecargoZonaService _recargoZonaService;
|
||||
private readonly IPorcPagoService _porcPagoService;
|
||||
private readonly IPorcMonCanillaService _porcMonCanillaService;
|
||||
private readonly IControlDevolucionesService _controlDevolucionesService;
|
||||
private readonly ITipoBobinaService _tipoBobinaService;
|
||||
private readonly IEstadoBobinaService _estadoBobinaService;
|
||||
private readonly IPlantaService _plantaService;
|
||||
private readonly IStockBobinaService _stockBobinaService;
|
||||
private readonly ITiradaService _tiradaService;
|
||||
private readonly IPerfilService _perfilService;
|
||||
private readonly IPermisoService _permisoService;
|
||||
private readonly ICambioParadaService _cambioParadaService;
|
||||
private readonly ILogger<AuditoriaController> _logger;
|
||||
|
||||
// Permiso general para ver cualquier auditoría.
|
||||
@@ -50,6 +69,23 @@ namespace GestionIntegral.Api.Controllers
|
||||
ISaldoService saldoService,
|
||||
ITipoPagoService tipoPagoService,
|
||||
IEmpresaService empresaService,
|
||||
IZonaService zonaService,
|
||||
IOtroDestinoService otroDestinoService,
|
||||
IPublicacionService publicacionService,
|
||||
IPubliSeccionService publiSeccionService,
|
||||
IPrecioService precioService,
|
||||
IRecargoZonaService recargoZonaService,
|
||||
IPorcPagoService porcPagoService,
|
||||
IPorcMonCanillaService porcMonCanillaService,
|
||||
IControlDevolucionesService controlDevolucionesService,
|
||||
ITipoBobinaService tipoBobinaService,
|
||||
IEstadoBobinaService estadoBobinaService,
|
||||
IPlantaService plantaService,
|
||||
IStockBobinaService stockBobinaService,
|
||||
ITiradaService tiradaService,
|
||||
IPerfilService perfilService,
|
||||
IPermisoService permisoService,
|
||||
ICambioParadaService cambioParadaService,
|
||||
ILogger<AuditoriaController> logger)
|
||||
{
|
||||
_usuarioService = usuarioService;
|
||||
@@ -63,6 +99,23 @@ namespace GestionIntegral.Api.Controllers
|
||||
_saldoService = saldoService;
|
||||
_tipoPagoService = tipoPagoService;
|
||||
_empresaService = empresaService;
|
||||
_zonaService = zonaService;
|
||||
_otroDestinoService = otroDestinoService;
|
||||
_publicacionService = publicacionService;
|
||||
_publiSeccionService = publiSeccionService;
|
||||
_precioService = precioService;
|
||||
_recargoZonaService = recargoZonaService;
|
||||
_porcPagoService = porcPagoService;
|
||||
_porcMonCanillaService = porcMonCanillaService;
|
||||
_controlDevolucionesService = controlDevolucionesService;
|
||||
_tipoBobinaService = tipoBobinaService;
|
||||
_estadoBobinaService = estadoBobinaService;
|
||||
_plantaService = plantaService;
|
||||
_stockBobinaService = stockBobinaService;
|
||||
_tiradaService = tiradaService;
|
||||
_perfilService = perfilService;
|
||||
_cambioParadaService = cambioParadaService;
|
||||
_permisoService = permisoService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -274,5 +327,389 @@ namespace GestionIntegral.Api.Controllers
|
||||
return StatusCode(500, "Error interno al obtener historial de Empresas (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("zonas-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ZonaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialZonasMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idZonaAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
// Asumiendo que _zonaService está inyectado
|
||||
var historial = await _zonaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idZonaAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<ZonaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Zonas (Maestro).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Zonas (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("otros-destinos-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<OtroDestinoHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialOtrosDestinosMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idOtroDestinoAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _otroDestinoService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idOtroDestinoAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<OtroDestinoHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Otros Destinos (Maestro).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Otros Destinos (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("publicaciones-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PublicacionHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPublicacionesMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPublicacionAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _publicacionService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPublicacionAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<PublicacionHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Publicaciones (Maestro).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Publicaciones (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("publi-secciones-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PubliSeccionHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPubliSeccionesMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idSeccionAfectada, [FromQuery] int? idPublicacionAfectada) // Nuevos filtros
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _publiSeccionService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idSeccionAfectada, idPublicacionAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<PubliSeccionHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Secciones de Publicación.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Secciones de Publicación.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("precios-publicacion-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PrecioHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPreciosMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPrecioAfectado, [FromQuery] int? idPublicacionAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _precioService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPrecioAfectado, idPublicacionAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<PrecioHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Precios de Publicación.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Precios de Publicación.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("recargos-zona-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<RecargoZonaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialRecargosZonaMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idRecargoAfectado, [FromQuery] int? idPublicacionAfectada, [FromQuery] int? idZonaAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _recargoZonaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idRecargoAfectado, idPublicacionAfectada, idZonaAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<RecargoZonaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Recargos por Zona.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Recargos por Zona.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("porc-pago-dist-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PorcPagoHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPorcPagoDistMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPorcentajeAfectado, [FromQuery] int? idPublicacionAfectada, [FromQuery] int? idDistribuidorAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _porcPagoService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPorcentajeAfectado, idPublicacionAfectada, idDistribuidorAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<PorcPagoHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Porcentajes de Pago (Dist).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Porcentajes de Pago (Dist).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("porc-mon-canilla-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PorcMonCanillaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPorcMonCanillaMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPorcMonAfectado, [FromQuery] int? idPublicacionAfectada, [FromQuery] int? idCanillaAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _porcMonCanillaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPorcMonAfectado, idPublicacionAfectada, idCanillaAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<PorcMonCanillaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Porc/Mon Canillita.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Porc/Mon Canillita.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("control-devoluciones-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ControlDevolucionesHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialControlDevolucionesMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idControlAfectado, [FromQuery] int? idEmpresaAfectada, [FromQuery] DateTime? fechaAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _controlDevolucionesService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idControlAfectado, idEmpresaAfectada, fechaAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<ControlDevolucionesHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Control de Devoluciones.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Control de Devoluciones.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("tipos-bobina-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TipoBobinaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialTiposBobinaMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idTipoBobinaAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _tipoBobinaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idTipoBobinaAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<TipoBobinaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Tipos de Bobina.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Tipos de Bobina.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("estados-bobina-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<EstadoBobinaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialEstadosBobinaMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idEstadoBobinaAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _estadoBobinaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idEstadoBobinaAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<EstadoBobinaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Estados de Bobina.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Estados de Bobina.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("plantas-impresion-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PlantaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPlantasMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPlantaAfectada)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _plantaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPlantaAfectada);
|
||||
return Ok(historial ?? Enumerable.Empty<PlantaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Plantas de Impresión.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Plantas de Impresión.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("stock-bobinas-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<StockBobinaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialStockBobinasMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idBobinaAfectada, [FromQuery] int? idTipoBobinaFiltro,
|
||||
[FromQuery] int? idPlantaFiltro, [FromQuery] int? idEstadoBobinaFiltro)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _stockBobinaService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idBobinaAfectada, idTipoBobinaFiltro, idPlantaFiltro, idEstadoBobinaFiltro);
|
||||
return Ok(historial ?? Enumerable.Empty<StockBobinaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Stock de Bobinas.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Stock de Bobinas.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("reg-tiradas-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<RegTiradaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialRegTiradasMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idRegistroAfectado, [FromQuery] int? idPublicacionFiltro,
|
||||
[FromQuery] int? idPlantaFiltro, [FromQuery] DateTime? fechaTiradaFiltro)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _tiradaService.ObtenerRegTiradasHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idRegistroAfectado, idPublicacionFiltro, idPlantaFiltro, fechaTiradaFiltro);
|
||||
return Ok(historial ?? Enumerable.Empty<RegTiradaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Registro de Tiradas.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Registro de Tiradas.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("reg-secciones-tirada-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<RegSeccionTiradaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialRegSeccionesTiradaMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idTiradaAfectada, [FromQuery] int? idPublicacionFiltro,
|
||||
[FromQuery] int? idSeccionFiltro, [FromQuery] int? idPlantaFiltro, [FromQuery] DateTime? fechaTiradaFiltro)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _tiradaService.ObtenerRegSeccionesTiradaHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idTiradaAfectada, idPublicacionFiltro, idSeccionFiltro, idPlantaFiltro, fechaTiradaFiltro);
|
||||
return Ok(historial ?? Enumerable.Empty<RegSeccionTiradaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Secciones de Tirada.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Secciones de Tirada.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("perfiles-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PerfilHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPerfilesMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPerfilAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _perfilService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPerfilAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<PerfilHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Perfiles (Maestro).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Perfiles (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("permisos-maestro")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PermisoHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPermisosMaestro(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPermisoAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _permisoService.ObtenerHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPermisoAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<PermisoHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Permisos (Maestro).");
|
||||
return StatusCode(500, "Error interno al obtener historial de Permisos (Maestro).");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("permisos-perfiles-historial")]
|
||||
[ProducesResponseType(typeof(IEnumerable<PermisosPerfilesHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialPermisosPerfiles(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idPerfilAfectado, [FromQuery] int? idPermisoAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _perfilService.ObtenerPermisosAsignadosHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPerfilAfectado, idPermisoAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<PermisosPerfilesHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Asignación de Permisos.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Asignación de Permisos.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("cambios-parada-canilla")]
|
||||
[ProducesResponseType(typeof(IEnumerable<CambioParadaHistorialDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetHistorialCambiosParada(
|
||||
[FromQuery] DateTime? fechaDesde, [FromQuery] DateTime? fechaHasta,
|
||||
[FromQuery] int? idUsuarioModifico, [FromQuery] string? tipoModificacion,
|
||||
[FromQuery] int? idCanillaAfectado)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerAuditoria)) return Forbid();
|
||||
try
|
||||
{
|
||||
var historial = await _cambioParadaService.ObtenerCambiosParadaHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idCanillaAfectado);
|
||||
return Ok(historial ?? Enumerable.Empty<CambioParadaHistorialDto>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error obteniendo historial de Cambios de Parada.");
|
||||
return StatusCode(500, "Error interno al obtener historial de Cambios de Parada.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,11 +124,15 @@ namespace GestionIntegral.Api.Controllers.Impresion
|
||||
public async Task<IActionResult> CambiarEstadoBobina(int idBobina, [FromBody] CambiarEstadoBobinaDto cambiarEstadoDto)
|
||||
{
|
||||
if (!TienePermiso(PermisoCambiarEstado)) return Forbid();
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState); // Validaciones de DTO (Required, Range, etc.)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null) return Unauthorized();
|
||||
|
||||
// Validación adicional en el controlador para el caso "En Uso"
|
||||
// La validación de que IdPublicacion/IdSeccion son requeridos para estado "En Uso"
|
||||
// ahora está más robusta en el servicio. Se puede quitar del controlador
|
||||
// si se prefiere que el servicio sea la única fuente de verdad para esa lógica.
|
||||
// Si la mantenés acá, es una validación temprana.
|
||||
/*
|
||||
if (cambiarEstadoDto.NuevoEstadoId == 2) // Asumiendo 2 = En Uso
|
||||
{
|
||||
if (!cambiarEstadoDto.IdPublicacion.HasValue || cambiarEstadoDto.IdPublicacion.Value <= 0)
|
||||
@@ -136,12 +140,13 @@ namespace GestionIntegral.Api.Controllers.Impresion
|
||||
if (!cambiarEstadoDto.IdSeccion.HasValue || cambiarEstadoDto.IdSeccion.Value <=0)
|
||||
return BadRequest(new { message = "Se requiere IdSeccion para el estado 'En Uso'."});
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
var (exito, error) = await _stockBobinaService.CambiarEstadoBobinaAsync(idBobina, cambiarEstadoDto, userId.Value);
|
||||
if (!exito)
|
||||
{
|
||||
if (error == "Bobina no encontrada.") return NotFound(new { message = error });
|
||||
// Otros errores específicos del servicio (ej. flujo de estado no permitido) vienen como BadRequest
|
||||
return BadRequest(new { message = error });
|
||||
}
|
||||
return NoContent();
|
||||
|
||||
@@ -106,11 +106,21 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
|
||||
public async Task<bool> UpdateVigenciaHAsync(int idRegistro, DateTime vigenciaH, int idUsuario, IDbTransaction transaction)
|
||||
{
|
||||
var paradaOriginal = await GetByIdAsync(idRegistro); // Obtener para el log
|
||||
var paradaOriginal = await GetByIdAsync(idRegistro);
|
||||
if (paradaOriginal == null) throw new KeyNotFoundException("Registro de parada no encontrado para actualizar VigenciaH.");
|
||||
|
||||
// Loggear ANTES de actualizar
|
||||
await LogHistorialAsync(paradaOriginal, idUsuario, "Cerrada", transaction.Connection!, transaction);
|
||||
var paradaParaHistorial = new CambioParadaCanilla
|
||||
{
|
||||
IdRegistro = paradaOriginal.IdRegistro,
|
||||
IdCanilla = paradaOriginal.IdCanilla,
|
||||
Parada = paradaOriginal.Parada,
|
||||
VigenciaD = paradaOriginal.VigenciaD,
|
||||
VigenciaH = vigenciaH.Date
|
||||
};
|
||||
|
||||
// Loggear el estado que QUEDARÁ en la tabla principal (con la VigenciaH actualizada)
|
||||
// El TipoMod debería reflejar la acción. "Cerrada".
|
||||
await LogHistorialAsync(paradaParaHistorial, idUsuario, "Cerrada", transaction.Connection!, transaction);
|
||||
|
||||
const string sqlUpdate = @"
|
||||
UPDATE dbo.dist_CambiosParadasCanillas
|
||||
@@ -135,5 +145,49 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlDelete, new { IdRegistro = idRegistro }, transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(CambioParadaCanillaHistorial Historial, string NombreUsuarioModifico, string NombreCanilla)>> GetCambiosParadaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idCanillaOriginal)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Registro, h.Id_Canilla, h.Parada, h.VigenciaD, h.VigenciaH,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico,
|
||||
c.NomApe AS NombreCanilla
|
||||
FROM dbo.dist_CambiosParadasCanillas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
JOIN dbo.dist_dtCanillas c ON h.Id_Canilla = c.Id_Canilla
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idCanillaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Canilla = @IdCanillaOriginalParam"); parameters.Add("IdCanillaOriginalParam", idCanillaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<CambioParadaCanillaHistorial, string, string, (CambioParadaCanillaHistorial, string, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userMod, canillaNombre) => (hist, userMod, canillaNombre),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico,NombreCanilla"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Cambios de Parada.");
|
||||
return Enumerable.Empty<(CambioParadaCanillaHistorial, string, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,10 +101,18 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
var inserted = await transaction.Connection!.QuerySingleAsync<ControlDevoluciones>(sqlInsert, nuevoControl, transaction);
|
||||
if (inserted == null || inserted.IdControl == 0) throw new DataException("Error al crear control de devoluciones o ID no generado.");
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdControlParam = inserted.IdControl, IdEmpresaParam = inserted.IdEmpresa, FechaParam = inserted.Fecha,
|
||||
EntradaParam = inserted.Entrada, SobrantesParam = inserted.Sobrantes, DetalleParam = inserted.Detalle, SinCargoParam = inserted.SinCargo,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Creado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdControlParam = inserted.IdControl,
|
||||
IdEmpresaParam = inserted.IdEmpresa,
|
||||
FechaParam = inserted.Fecha,
|
||||
EntradaParam = inserted.Entrada,
|
||||
SobrantesParam = inserted.Sobrantes,
|
||||
DetalleParam = inserted.Detalle,
|
||||
SinCargoParam = inserted.SinCargo,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Creado"
|
||||
}, transaction);
|
||||
return inserted;
|
||||
}
|
||||
@@ -126,10 +134,18 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
(Id_Control, Id_Empresa, Fecha, Entrada, Sobrantes, Detalle, SinCargo, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdControlParam, @IdEmpresaParam, @FechaParam, @EntradaParam, @SobrantesParam, @DetalleParam, @SinCargoParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdControlParam = actual.IdControl, IdEmpresaParam = actual.IdEmpresa, FechaParam = actual.Fecha, // Datos originales
|
||||
EntradaParam = actual.Entrada, SobrantesParam = actual.Sobrantes, DetalleParam = actual.Detalle, SinCargoParam = actual.SinCargo, // Valores ANTERIORES
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Actualizado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdControlParam = actual.IdControl,
|
||||
IdEmpresaParam = actual.IdEmpresa,
|
||||
FechaParam = actual.Fecha, // Datos originales
|
||||
EntradaParam = actual.Entrada,
|
||||
SobrantesParam = actual.Sobrantes,
|
||||
DetalleParam = actual.Detalle,
|
||||
SinCargoParam = actual.SinCargo, // Valores ANTERIORES
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Actualizado"
|
||||
}, transaction);
|
||||
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlUpdate, controlAActualizar, transaction);
|
||||
@@ -149,14 +165,66 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
(Id_Control, Id_Empresa, Fecha, Entrada, Sobrantes, Detalle, SinCargo, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdControlParam, @IdEmpresaParam, @FechaParam, @EntradaParam, @SobrantesParam, @DetalleParam, @SinCargoParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdControlParam = actual.IdControl, IdEmpresaParam = actual.IdEmpresa, FechaParam = actual.Fecha,
|
||||
EntradaParam = actual.Entrada, SobrantesParam = actual.Sobrantes, DetalleParam = actual.Detalle, SinCargoParam = actual.SinCargo,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Eliminado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdControlParam = actual.IdControl,
|
||||
IdEmpresaParam = actual.IdEmpresa,
|
||||
FechaParam = actual.Fecha,
|
||||
EntradaParam = actual.Entrada,
|
||||
SobrantesParam = actual.Sobrantes,
|
||||
DetalleParam = actual.Detalle,
|
||||
SinCargoParam = actual.SinCargo,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Eliminado"
|
||||
}, transaction);
|
||||
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlDelete, new { IdControlParam = idControl }, transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(ControlDevolucionesHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idControlOriginal, int? idEmpresaOriginal, DateTime? fechaOriginal)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Control, h.Id_Empresa, h.Fecha, h.Entrada, h.Sobrantes, h.Detalle, h.SinCargo,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_dtCtrlDevoluciones_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idControlOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Control = @IdControlOriginalParam"); parameters.Add("IdControlOriginalParam", idControlOriginal.Value); }
|
||||
if (idEmpresaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Empresa = @IdEmpresaOriginalParam"); parameters.Add("IdEmpresaOriginalParam", idEmpresaOriginal.Value); }
|
||||
if (fechaOriginal.HasValue) { sqlBuilder.Append(" AND h.Fecha = @FechaOriginalParam"); parameters.Add("FechaOriginalParam", fechaOriginal.Value.Date); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<ControlDevolucionesHistorico, string, (ControlDevolucionesHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Control de Devoluciones.");
|
||||
return Enumerable.Empty<(ControlDevolucionesHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<CambioParadaCanilla?> CreateAsync(CambioParadaCanilla nuevaParada, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> UpdateVigenciaHAsync(int idRegistro, DateTime vigenciaH, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteAsync(int idRegistro, int idUsuario, IDbTransaction transaction);
|
||||
Task<IEnumerable<(CambioParadaCanillaHistorial Historial, string NombreUsuarioModifico, string NombreCanilla)>> GetCambiosParadaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idCanillaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<ControlDevoluciones?> CreateAsync(ControlDevoluciones nuevoControl, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> UpdateAsync(ControlDevoluciones controlAActualizar, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteAsync(int idControl, int idUsuario, IDbTransaction transaction);
|
||||
Task<IEnumerable<(ControlDevolucionesHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idControlOriginal, int? idEmpresaOriginal, DateTime? fechaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<bool> DeleteAsync(int id, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> ExistsByNameAsync(string nombre, int? excludeId = null);
|
||||
Task<bool> IsInUseAsync(int id); // Verificar si se usa en dist_SalidasOtrosDestinos
|
||||
Task<IEnumerable<(OtroDestinoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idOtroDestinoOriginal);
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<bool> DeleteAsync(int idPorcMon, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteByPublicacionIdAsync(int idPublicacion, int idUsuarioAuditoria, IDbTransaction transaction);
|
||||
Task<PorcMonCanilla?> GetPreviousActiveAsync(int idPublicacion, int idCanilla, DateTime vigenciaDNuevo, IDbTransaction transaction);
|
||||
Task<IEnumerable<(PorcMonCanillaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcMonOriginal, int? idPublicacionOriginal, int? idCanillaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<bool> DeleteAsync(int idPorcentaje, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteByPublicacionIdAsync(int idPublicacion, int idUsuarioAuditoria, IDbTransaction transaction);
|
||||
Task<PorcPago?> GetPreviousActivePorcPagoAsync(int idPublicacion, int idDistribuidor, DateTime vigenciaDNuevo, IDbTransaction transaction);
|
||||
Task<IEnumerable<(PorcPagoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcentajeOriginal, int? idPublicacionOriginal, int? idDistribuidorOriginal);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
{
|
||||
Task<IEnumerable<Precio>> GetByPublicacionIdAsync(int idPublicacion);
|
||||
Task<Precio?> GetByIdAsync(int idPrecio);
|
||||
Task<bool> IsInUseAsync(int idPrecio, DateTime vigenciaD, DateTime? vigenciaH);
|
||||
Task<Precio?> GetActiveByPublicacionAndDateAsync(int idPublicacion, DateTime fecha, IDbTransaction? transaction = null);
|
||||
Task<Precio?> CreateAsync(Precio nuevoPrecio, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> UpdateAsync(Precio precioAActualizar, int idUsuario, IDbTransaction transaction);
|
||||
@@ -16,5 +17,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
// MODIFICADO: Añadir idUsuarioAuditoria
|
||||
Task<bool> DeleteByPublicacionIdAsync(int idPublicacion, int idUsuarioAuditoria, IDbTransaction transaction);
|
||||
Task<Precio?> GetPreviousActivePriceAsync(int idPublicacion, DateTime vigenciaDNuevo, IDbTransaction transaction);
|
||||
Task<IEnumerable<(PrecioHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPrecioOriginal, int? idPublicacionOriginal);
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<bool> DeleteByPublicacionIdAsync(int idPublicacion, int idUsuarioAuditoria, IDbTransaction transaction); // Ya existe
|
||||
Task<bool> ExistsByNameInPublicacionAsync(string nombre, int idPublicacion, int? excludeIdSeccion = null);
|
||||
Task<bool> IsInUseAsync(int idSeccion); // Verificar en bob_RegPublicaciones, bob_StockBobinas
|
||||
Task<IEnumerable<(PubliSeccionHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idSeccionOriginal, int? idPublicacionOriginal);
|
||||
}
|
||||
}
|
||||
@@ -18,5 +18,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<IEnumerable<PublicacionDiaSemana>> GetConfiguracionDiasAsync(int idPublicacion);
|
||||
Task<IEnumerable<int>> GetPublicacionesIdsPorDiaSemanaAsync(byte diaSemana); // Devuelve solo IDs
|
||||
Task UpdateConfiguracionDiasAsync(int idPublicacion, IEnumerable<byte> diasActivos, IDbTransaction transaction);
|
||||
Task<IEnumerable<(PublicacionHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPublicacionOriginal);
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,16 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
{
|
||||
Task<IEnumerable<(RecargoZona Recargo, string NombreZona)>> GetByPublicacionIdAsync(int idPublicacion);
|
||||
Task<RecargoZona?> GetByIdAsync(int idRecargo); // Para obtener un recargo específico
|
||||
Task<bool> IsInUseAsync(int idRecargo, DateTime vigenciaD, DateTime? vigenciaH);
|
||||
Task<RecargoZona?> GetActiveByPublicacionZonaAndDateAsync(int idPublicacion, int idZona, DateTime fecha, IDbTransaction? transaction = null);
|
||||
Task<RecargoZona?> CreateAsync(RecargoZona nuevoRecargo, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> UpdateAsync(RecargoZona recargoAActualizar, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteAsync(int idRecargo, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> DeleteByPublicacionIdAsync(int idPublicacion, int idUsuarioAuditoria, IDbTransaction transaction); // Ya existe
|
||||
Task<RecargoZona?> GetPreviousActiveRecargoAsync(int idPublicacion, int idZona, DateTime vigenciaDNuevo, IDbTransaction transaction);
|
||||
Task<IEnumerable<(RecargoZonaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRecargoOriginal, int? idPublicacionOriginal, int? idZonaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<bool> SoftDeleteAsync(int id, int idUsuario); // Cambiado de DeleteAsync a SoftDeleteAsync
|
||||
Task<bool> ExistsByNameAsync(string nombre, int? excludeId = null, bool soloActivas = true);
|
||||
Task<bool> IsInUseAsync(int id);
|
||||
Task<IEnumerable<(ZonaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idZonaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -185,5 +185,47 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
var rowsAffected = await connection.ExecuteAsync(sqlDelete, new { Id = id }, transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(OtroDestinoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idOtroDestinoOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Destino, h.Nombre, h.Obs,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_dtOtrosDestinos_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idOtroDestinoOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Destino = @IdOtroDestinoOriginalParam"); parameters.Add("IdOtroDestinoOriginalParam", idOtroDestinoOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<OtroDestinoHistorico, string, (OtroDestinoHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Otros Destinos (Maestro).");
|
||||
return Enumerable.Empty<(OtroDestinoHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
@@ -253,5 +254,50 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PorcMonCanillaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcMonOriginal, int? idPublicacionOriginal, int? idCanillaOriginal)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_PorcMon, h.Id_Publicacion, h.Id_Canilla,
|
||||
h.VigenciaD, h.VigenciaH, h.PorcMon, h.EsPorcentaje,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_PorcMonPagoCanilla_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPorcMonOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_PorcMon = @IdPorcMonOriginalParam"); parameters.Add("IdPorcMonOriginalParam", idPorcMonOriginal.Value); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
if (idCanillaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Canilla = @IdCanillaOriginalParam"); parameters.Add("IdCanillaOriginalParam", idCanillaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PorcMonCanillaHistorico, string, (PorcMonCanillaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Porcentajes/Montos Canillita.");
|
||||
return Enumerable.Empty<(PorcMonCanillaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
@@ -247,5 +248,50 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PorcPagoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcentajeOriginal, int? idPublicacionOriginal, int? idDistribuidorOriginal)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Porcentaje, h.Id_Publicacion, h.Id_Distribuidor,
|
||||
h.VigenciaD, h.VigenciaH, h.Porcentaje,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_PorcPago_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPorcentajeOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Porcentaje = @IdPorcentajeOriginalParam"); parameters.Add("IdPorcentajeOriginalParam", idPorcentajeOriginal.Value); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
if (idDistribuidorOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Distribuidor = @IdDistribuidorOriginalParam"); parameters.Add("IdDistribuidorOriginalParam", idDistribuidorOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PorcPagoHistorico, string, (PorcPagoHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Porcentajes de Pago (Distribuidores).");
|
||||
return Enumerable.Empty<(PorcPagoHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
@@ -138,8 +139,13 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
IdPublicacionHist = inserted.IdPublicacion,
|
||||
VigenciaDHist = inserted.VigenciaD,
|
||||
VigenciaHHist = inserted.VigenciaH,
|
||||
LunesHist = inserted.Lunes, MartesHist = inserted.Martes, MiercolesHist = inserted.Miercoles, JuevesHist = inserted.Jueves,
|
||||
ViernesHist = inserted.Viernes, SabadoHist = inserted.Sabado, DomingoHist = inserted.Domingo,
|
||||
LunesHist = inserted.Lunes,
|
||||
MartesHist = inserted.Martes,
|
||||
MiercolesHist = inserted.Miercoles,
|
||||
JuevesHist = inserted.Jueves,
|
||||
ViernesHist = inserted.Viernes,
|
||||
SabadoHist = inserted.Sabado,
|
||||
DomingoHist = inserted.Domingo,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Creado"
|
||||
@@ -171,8 +177,13 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
IdPublicacionHist = actual.IdPublicacion,
|
||||
VigenciaDHist = actual.VigenciaD,
|
||||
VigenciaHHist = actual.VigenciaH,
|
||||
LunesHist = actual.Lunes, MartesHist = actual.Martes, MiercolesHist = actual.Miercoles, JuevesHist = actual.Jueves,
|
||||
ViernesHist = actual.Viernes, SabadoHist = actual.Sabado, DomingoHist = actual.Domingo,
|
||||
LunesHist = actual.Lunes,
|
||||
MartesHist = actual.Martes,
|
||||
MiercolesHist = actual.Miercoles,
|
||||
JuevesHist = actual.Jueves,
|
||||
ViernesHist = actual.Viernes,
|
||||
SabadoHist = actual.Sabado,
|
||||
DomingoHist = actual.Domingo,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Actualizado"
|
||||
@@ -202,8 +213,13 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
IdPublicacionHist = actual.IdPublicacion,
|
||||
VigenciaDHist = actual.VigenciaD,
|
||||
VigenciaHHist = actual.VigenciaH,
|
||||
LunesHist = actual.Lunes, MartesHist = actual.Martes, MiercolesHist = actual.Miercoles, JuevesHist = actual.Jueves,
|
||||
ViernesHist = actual.Viernes, SabadoHist = actual.Sabado, DomingoHist = actual.Domingo,
|
||||
LunesHist = actual.Lunes,
|
||||
MartesHist = actual.Martes,
|
||||
MiercolesHist = actual.Miercoles,
|
||||
JuevesHist = actual.Jueves,
|
||||
ViernesHist = actual.Viernes,
|
||||
SabadoHist = actual.Sabado,
|
||||
DomingoHist = actual.Domingo,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Eliminado"
|
||||
@@ -237,8 +253,13 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
IdPublicacionHist = item.IdPublicacion,
|
||||
VigenciaDHist = item.VigenciaD,
|
||||
VigenciaHHist = item.VigenciaH,
|
||||
LunesHist = item.Lunes, MartesHist = item.Martes, MiercolesHist = item.Miercoles, JuevesHist = item.Jueves,
|
||||
ViernesHist = item.Viernes, SabadoHist = item.Sabado, DomingoHist = item.Domingo,
|
||||
LunesHist = item.Lunes,
|
||||
MartesHist = item.Martes,
|
||||
MiercolesHist = item.Miercoles,
|
||||
JuevesHist = item.Jueves,
|
||||
ViernesHist = item.Viernes,
|
||||
SabadoHist = item.Sabado,
|
||||
DomingoHist = item.Domingo,
|
||||
IdUsuarioHist = idUsuarioAuditoria,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Eliminado (Cascada)"
|
||||
@@ -257,5 +278,82 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> IsInUseAsync(int idPrecio, DateTime vigenciaD, DateTime? vigenciaH)
|
||||
{
|
||||
// Verificar si el Id_Precio se usa en movimientos DENTRO del rango de vigencia del precio
|
||||
// Si VigenciaH es NULL, significa que el precio está activo indefinidamente hacia el futuro.
|
||||
var sql = @"
|
||||
SELECT TOP 1 1
|
||||
FROM (
|
||||
SELECT Id_Precio, Fecha FROM dbo.dist_EntradasSalidas
|
||||
UNION ALL
|
||||
SELECT Id_Precio, Fecha FROM dbo.dist_EntradasSalidasCanillas
|
||||
) AS Movimientos
|
||||
WHERE Movimientos.Id_Precio = @IdPrecioParam
|
||||
AND Movimientos.Fecha >= @VigenciaDParam
|
||||
AND (@VigenciaHParam IS NULL OR Movimientos.Fecha <= @VigenciaHParam);";
|
||||
try
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var parameters = new
|
||||
{
|
||||
IdPrecioParam = idPrecio,
|
||||
VigenciaDParam = vigenciaD.Date,
|
||||
VigenciaHParam = vigenciaH?.Date
|
||||
};
|
||||
var inUse = await connection.ExecuteScalarAsync<int?>(sql, parameters);
|
||||
return inUse.HasValue && inUse.Value == 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en IsInUseAsync para Precio ID: {IdPrecio}", idPrecio);
|
||||
return true; // Asumir en uso si hay error, para ser cauteloso
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PrecioHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPrecioOriginal, int? idPublicacionOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Precio, h.Id_Publicacion, h.VigenciaD, h.VigenciaH,
|
||||
h.Lunes, h.Martes, h.Miercoles, h.Jueves, h.Viernes, h.Sabado, h.Domingo,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_Precios_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPrecioOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Precio = @IdPrecioOriginalParam"); parameters.Add("IdPrecioOriginalParam", idPrecioOriginal.Value); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PrecioHistorico, string, (PrecioHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Precios de Publicación.");
|
||||
return Enumerable.Empty<(PrecioHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,5 +235,48 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PubliSeccionHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idSeccionOriginal, int? idPublicacionOriginal)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Seccion, h.Id_Publicacion, h.Nombre, h.Estado,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_dtPubliSecciones_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idSeccionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Seccion = @IdSeccionOriginalParam"); parameters.Add("IdSeccionOriginalParam", idSeccionOriginal.Value); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PubliSeccionHistorico, string, (PubliSeccionHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Secciones de Publicación.");
|
||||
return Enumerable.Empty<(PubliSeccionHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,32 +139,33 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> IsInUseAsync(int id)
|
||||
public async Task<bool> IsInUseAsync(int idPublicacion)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
string[] checkQueries = {
|
||||
"SELECT TOP 1 1 FROM dbo.dist_EntradasSalidas WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_EntradasSalidasCanillas WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_Precios WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_RecargoZona WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_PorcPago WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_PorcMonPagoCanilla WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_dtPubliSecciones WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.dist_SalidasOtrosDestinos WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.bob_RegPublicaciones WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.bob_StockBobinas WHERE Id_Publicacion = @IdParam"
|
||||
"SELECT TOP 1 1 FROM dbo.bob_RegTiradas WHERE Id_Publicacion = @IdParam",
|
||||
"SELECT TOP 1 1 FROM dbo.bob_StockBobinas WHERE Id_Publicacion = @IdParam AND Id_EstadoBobina != 1" // Ejemplo: si una bobina EN USO o DAÑADA está asociada
|
||||
};
|
||||
try
|
||||
{
|
||||
foreach (var query in checkQueries)
|
||||
{
|
||||
if (await connection.ExecuteScalarAsync<int?>(query, new { IdParam = id }) == 1) return true;
|
||||
if (await connection.ExecuteScalarAsync<int?>(query, new { IdParam = idPublicacion }) == 1)
|
||||
{
|
||||
_logger.LogInformation("Publicacion ID {IdPublicacion} está en uso (Tabla: {Tabla})", idPublicacion, query.Split("FROM")[1].Split("WHERE")[0].Trim());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en IsInUseAsync para Publicacion ID: {IdPublicacion}", id);
|
||||
return true; // Asumir en uso si hay error de BD
|
||||
_logger.LogError(ex, "Error en IsInUseAsync para Publicacion ID: {IdPublicacion}", idPublicacion);
|
||||
return true; // Asumir en uso si hay error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +326,48 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
);
|
||||
await Task.WhenAll(insertTasks);
|
||||
}
|
||||
// No se necesita historial para esta tabla de configuración por ahora.
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PublicacionHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPublicacionOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection(); // Asumiendo _connectionFactory
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Publicacion, h.Nombre, h.Observacion, h.Id_Empresa, h.Habilitada,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_dtPublicaciones_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PublicacionHistorico, string, (PublicacionHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Publicaciones (Maestro)."); // Asumiendo _logger
|
||||
return Enumerable.Empty<(PublicacionHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq; // Necesario para .Any()
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
@@ -48,6 +49,39 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> IsInUseAsync(int idRecargo, DateTime vigenciaD, DateTime? vigenciaH)
|
||||
{
|
||||
// Similar a Precios, verificar en dist_EntradasSalidas y dist_EntradasSalidasCanillas
|
||||
// si Id_Recargo se usa en movimientos DENTRO del rango de vigencia del recargo.
|
||||
var sql = @"
|
||||
SELECT TOP 1 1
|
||||
FROM (
|
||||
SELECT Id_Recargo, Fecha FROM dbo.dist_EntradasSalidas
|
||||
UNION ALL
|
||||
SELECT Id_Recargo, Fecha FROM dbo.dist_EntradasSalidasCanillas
|
||||
) AS Movimientos
|
||||
WHERE Movimientos.Id_Recargo = @IdRecargoParam
|
||||
AND Movimientos.Fecha >= @VigenciaDParam
|
||||
AND (@VigenciaHParam IS NULL OR Movimientos.Fecha <= @VigenciaHParam);";
|
||||
try
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var parameters = new
|
||||
{
|
||||
IdRecargoParam = idRecargo,
|
||||
VigenciaDParam = vigenciaD.Date,
|
||||
VigenciaHParam = vigenciaH?.Date
|
||||
};
|
||||
var inUse = await connection.ExecuteScalarAsync<int?>(sql, parameters);
|
||||
return inUse.HasValue && inUse.Value == 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en IsInUseAsync para Recargo ID: {IdRecargo}", idRecargo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<RecargoZona?> GetByIdAsync(int idRecargo)
|
||||
{
|
||||
const string sql = @"
|
||||
@@ -260,5 +294,49 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(RecargoZonaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRecargoOriginal, int? idPublicacionOriginal, int? idZonaOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Recargo, h.Id_Publicacion, h.Id_Zona, h.VigenciaD, h.VigenciaH, h.Valor,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_RecargoZona_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idRecargoOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Recargo = @IdRecargoOriginalParam"); parameters.Add("IdRecargoOriginalParam", idRecargoOriginal.Value); }
|
||||
if (idPublicacionOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionOriginalParam"); parameters.Add("IdPublicacionOriginalParam", idPublicacionOriginal.Value); }
|
||||
if (idZonaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Zona = @IdZonaOriginalParam"); parameters.Add("IdZonaOriginalParam", idZonaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<RecargoZonaHistorico, string, (RecargoZonaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Recargos por Zona.");
|
||||
return Enumerable.Empty<(RecargoZonaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,5 +301,46 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
return true; // Asumir que está en uso si hay error
|
||||
}
|
||||
}
|
||||
public async Task<IEnumerable<(ZonaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idZonaOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Zona, h.Nombre, h.Descripcion, h.Estado,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.dist_dtZonas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idZonaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Zona = @IdZonaOriginalParam"); parameters.Add("IdZonaOriginalParam", idZonaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<ZonaHistorico, string, (ZonaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Zonas (Maestro).");
|
||||
return Enumerable.Empty<(ZonaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,5 +204,47 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(EstadoBobinaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idEstadoBobinaOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_EstadoBobina, h.Denominacion, h.Obs,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.bob_dtEstadosBobinas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idEstadoBobinaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_EstadoBobina = @IdEstadoBobinaOriginalParam"); parameters.Add("IdEstadoBobinaOriginalParam", idEstadoBobinaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<EstadoBobinaHistorico, string, (EstadoBobinaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Estados de Bobina.");
|
||||
return Enumerable.Empty<(EstadoBobinaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
Task<bool> DeleteAsync(int id, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> ExistsByDenominacionAsync(string denominacion, int? excludeId = null);
|
||||
Task<bool> IsInUseAsync(int id); // Verificar si se usa en bob_StockBobinas
|
||||
Task<IEnumerable<(EstadoBobinaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idEstadoBobinaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
Task<bool> DeleteAsync(int id, int idUsuario, IDbTransaction transaction); // Borrado físico con historial
|
||||
Task<bool> ExistsByNameAsync(string nombre, int? excludeId = null);
|
||||
Task<bool> IsInUseAsync(int id); // Verificar si se usa en bob_StockBobinas o bob_RegPublicaciones
|
||||
Task<IEnumerable<(PlantaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPlantaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,15 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
Task<bool> DeleteAsync(int idRegistro, int idUsuario, IDbTransaction transaction); // Si se borra el registro principal
|
||||
Task<bool> DeleteByFechaPublicacionPlantaAsync(DateTime fecha, int idPublicacion, int idPlanta, int idUsuario, IDbTransaction transaction);
|
||||
Task<RegTirada?> GetByFechaPublicacionPlantaAsync(DateTime fecha, int idPublicacion, int idPlanta, IDbTransaction? transaction = null);
|
||||
|
||||
Task<IEnumerable<(RegTiradaHistorico Historial, string NombreUsuarioModifico, string NombrePublicacion, string NombrePlanta)>> GetRegTiradasHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRegistroOriginal, int? idPublicacionFiltro, int? idPlantaFiltro, DateTime? fechaTiradaFiltro);
|
||||
Task<IEnumerable<(RegPublicacionSeccionHistorico Historial, string NombreUsuarioModifico, string NombrePublicacion, string NombreSeccion, string NombrePlanta)>> GetRegSeccionesTiradaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTiradaOriginal, // ID del registro en bob_RegPublicaciones
|
||||
int? idPublicacionFiltro, int? idSeccionFiltro, int? idPlantaFiltro, DateTime? fechaTiradaFiltro);
|
||||
}
|
||||
|
||||
public interface IRegPublicacionSeccionRepository // Para bob_RegPublicaciones
|
||||
|
||||
@@ -22,5 +22,9 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
Task<StockBobina?> CreateAsync(StockBobina nuevaBobina, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> UpdateAsync(StockBobina bobinaAActualizar, int idUsuario, IDbTransaction transaction, string tipoMod = "Actualizada"); // tipoMod para historial
|
||||
Task<bool> DeleteAsync(int idBobina, int idUsuario, IDbTransaction transaction); // Solo si está en estado "Disponible"
|
||||
Task<IEnumerable<(StockBobinaHistorico Historial, string NombreUsuarioModifico, string? NombreTipoBobina, string? NombrePlanta, string? NombreEstadoBobina, string? NombrePublicacion, string? NombreSeccion)>> GetHistorialDetalladoAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idBobinaOriginal, int? idTipoBobinaFiltro, int? idPlantaFiltro, int? idEstadoBobinaFiltro);
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,9 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
Task<bool> DeleteAsync(int id, int idUsuario, IDbTransaction transaction);
|
||||
Task<bool> ExistsByDenominacionAsync(string denominacion, int? excludeId = null);
|
||||
Task<bool> IsInUseAsync(int id); // Verificar si se usa en bob_StockBobinas
|
||||
Task<IEnumerable<(TipoBobinaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTipoBobinaOriginal);
|
||||
}
|
||||
}
|
||||
@@ -225,5 +225,47 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PlantaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPlantaOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Planta, h.Nombre, h.Detalle,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.bob_dtPlantas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPlantaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Planta = @IdPlantaOriginalParam"); parameters.Add("IdPlantaOriginalParam", idPlantaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PlantaHistorico, string, (PlantaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Plantas de Impresión.");
|
||||
return Enumerable.Empty<(PlantaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,9 +69,16 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
|
||||
const string sqlHistorico = @"INSERT INTO dbo.bob_RegTiradas_H (Id_Registro, Ejemplares, Id_Publicacion, Fecha, Id_Planta, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdRegistroParam, @EjemplaresParam, @IdPublicacionParam, @FechaParam, @IdPlantaParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdRegistroParam = inserted.IdRegistro, EjemplaresParam = inserted.Ejemplares, IdPublicacionParam = inserted.IdPublicacion, FechaParam = inserted.Fecha, IdPlantaParam = inserted.IdPlanta,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Creado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdRegistroParam = inserted.IdRegistro,
|
||||
EjemplaresParam = inserted.Ejemplares,
|
||||
IdPublicacionParam = inserted.IdPublicacion,
|
||||
FechaParam = inserted.Fecha,
|
||||
IdPlantaParam = inserted.IdPlanta,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Creado"
|
||||
}, transaction);
|
||||
return inserted;
|
||||
}
|
||||
@@ -84,9 +91,16 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
const string sqlDelete = "DELETE FROM dbo.bob_RegTiradas WHERE Id_Registro = @IdRegistroParam";
|
||||
const string sqlHistorico = @"INSERT INTO dbo.bob_RegTiradas_H (Id_Registro, Ejemplares, Id_Publicacion, Fecha, Id_Planta, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdRegistroParam, @EjemplaresParam, @IdPublicacionParam, @FechaParam, @IdPlantaParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdRegistroParam = actual.IdRegistro, EjemplaresParam = actual.Ejemplares, IdPublicacionParam = actual.IdPublicacion, FechaParam = actual.Fecha, IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Eliminado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdRegistroParam = actual.IdRegistro,
|
||||
EjemplaresParam = actual.Ejemplares,
|
||||
IdPublicacionParam = actual.IdPublicacion,
|
||||
FechaParam = actual.Fecha,
|
||||
IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Eliminado"
|
||||
}, transaction);
|
||||
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlDelete, new { IdRegistroParam = idRegistro }, transaction);
|
||||
@@ -100,9 +114,16 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
{
|
||||
const string sqlHistorico = @"INSERT INTO dbo.bob_RegTiradas_H (Id_Registro, Ejemplares, Id_Publicacion, Fecha, Id_Planta, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdRegistroParam, @EjemplaresParam, @IdPublicacionParam, @FechaParam, @IdPlantaParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdRegistroParam = actual.IdRegistro, EjemplaresParam = actual.Ejemplares, IdPublicacionParam = actual.IdPublicacion, FechaParam = actual.Fecha, IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Eliminado (Por Fecha/Pub/Planta)"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdRegistroParam = actual.IdRegistro,
|
||||
EjemplaresParam = actual.Ejemplares,
|
||||
IdPublicacionParam = actual.IdPublicacion,
|
||||
FechaParam = actual.Fecha,
|
||||
IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Eliminado (Por Fecha/Pub/Planta)"
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
@@ -111,6 +132,108 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
new { FechaParam = fecha.Date, IdPublicacionParam = idPublicacion, IdPlantaParam = idPlanta }, transaction);
|
||||
return rowsAffected > 0; // Devuelve true si se borró al menos una fila
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(RegTiradaHistorico Historial, string NombreUsuarioModifico, string NombrePublicacion, string NombrePlanta)>> GetRegTiradasHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRegistroOriginal, int? idPublicacionFiltro, int? idPlantaFiltro, DateTime? fechaTiradaFiltro)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Registro, h.Ejemplares, h.Id_Publicacion, h.Fecha, h.Id_Planta,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico,
|
||||
pub.Nombre AS NombrePublicacion,
|
||||
p.Nombre AS NombrePlanta
|
||||
FROM dbo.bob_RegTiradas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
JOIN dbo.dist_dtPublicaciones pub ON h.Id_Publicacion = pub.Id_Publicacion
|
||||
JOIN dbo.bob_dtPlantas p ON h.Id_Planta = p.Id_Planta
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idRegistroOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Registro = @IdRegistroOriginalParam"); parameters.Add("IdRegistroOriginalParam", idRegistroOriginal.Value); }
|
||||
if (idPublicacionFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionFiltroParam"); parameters.Add("IdPublicacionFiltroParam", idPublicacionFiltro.Value); }
|
||||
if (idPlantaFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Planta = @IdPlantaFiltroParam"); parameters.Add("IdPlantaFiltroParam", idPlantaFiltro.Value); }
|
||||
if (fechaTiradaFiltro.HasValue) { sqlBuilder.Append(" AND h.Fecha = @FechaTiradaFiltroParam"); parameters.Add("FechaTiradaFiltroParam", fechaTiradaFiltro.Value.Date); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<RegTiradaHistorico, string, string, string, (RegTiradaHistorico, string, string, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userMod, pubNombre, plantaNombre) => (hist, userMod, pubNombre, plantaNombre),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico,NombrePublicacion,NombrePlanta"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Registro de Tiradas.");
|
||||
return Enumerable.Empty<(RegTiradaHistorico, string, string, string)>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(RegPublicacionSeccionHistorico Historial, string NombreUsuarioModifico, string NombrePublicacion, string NombreSeccion, string NombrePlanta)>> GetRegSeccionesTiradaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTiradaOriginal, int? idPublicacionFiltro, int? idSeccionFiltro, int? idPlantaFiltro, DateTime? fechaTiradaFiltro)
|
||||
{
|
||||
using var connection = _cf.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Tirada, h.Id_Publicacion, h.Id_Seccion, h.CantPag, h.Fecha, h.Id_Planta,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico,
|
||||
pub.Nombre AS NombrePublicacion,
|
||||
sec.Nombre AS NombreSeccion,
|
||||
p.Nombre AS NombrePlanta
|
||||
FROM dbo.bob_RegPublicaciones_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
JOIN dbo.dist_dtPublicaciones pub ON h.Id_Publicacion = pub.Id_Publicacion
|
||||
JOIN dbo.dist_dtPubliSecciones sec ON h.Id_Seccion = sec.Id_Seccion
|
||||
AND h.Id_Publicacion = sec.Id_Publicacion -- Crucial para el JOIN correcto de sección
|
||||
JOIN dbo.bob_dtPlantas p ON h.Id_Planta = p.Id_Planta
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idTiradaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Tirada = @IdTiradaOriginalParam"); parameters.Add("IdTiradaOriginalParam", idTiradaOriginal.Value); }
|
||||
if (idPublicacionFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Publicacion = @IdPublicacionFiltroParam"); parameters.Add("IdPublicacionFiltroParam", idPublicacionFiltro.Value); }
|
||||
if (idSeccionFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Seccion = @IdSeccionFiltroParam"); parameters.Add("IdSeccionFiltroParam", idSeccionFiltro.Value); }
|
||||
if (idPlantaFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Planta = @IdPlantaFiltroParam"); parameters.Add("IdPlantaFiltroParam", idPlantaFiltro.Value); }
|
||||
if (fechaTiradaFiltro.HasValue) { sqlBuilder.Append(" AND h.Fecha = @FechaTiradaFiltroParam"); parameters.Add("FechaTiradaFiltroParam", fechaTiradaFiltro.Value.Date); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<RegPublicacionSeccionHistorico, string, string, string, string, (RegPublicacionSeccionHistorico, string, string, string, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userMod, pubNombre, secNombre, plantaNombre) => (hist, userMod, pubNombre, secNombre, plantaNombre),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico,NombrePublicacion,NombreSeccion,NombrePlanta"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error al obtener historial de Secciones de Tirada.");
|
||||
return Enumerable.Empty<(RegPublicacionSeccionHistorico, string, string, string, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RegPublicacionSeccionRepository : IRegPublicacionSeccionRepository
|
||||
@@ -138,9 +261,17 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
|
||||
const string sqlHistorico = @"INSERT INTO dbo.bob_RegPublicaciones_H (Id_Tirada, Id_Publicacion, Id_Seccion, CantPag, Fecha, Id_Planta, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdTiradaParam, @IdPublicacionParam, @IdSeccionParam, @CantPagParam, @FechaParam, @IdPlantaParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdTiradaParam = inserted.IdTirada, IdPublicacionParam = inserted.IdPublicacion, IdSeccionParam = inserted.IdSeccion, CantPagParam = inserted.CantPag, FechaParam = inserted.Fecha, IdPlantaParam = inserted.IdPlanta,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Creado"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdTiradaParam = inserted.IdTirada,
|
||||
IdPublicacionParam = inserted.IdPublicacion,
|
||||
IdSeccionParam = inserted.IdSeccion,
|
||||
CantPagParam = inserted.CantPag,
|
||||
FechaParam = inserted.Fecha,
|
||||
IdPlantaParam = inserted.IdPlanta,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Creado"
|
||||
}, transaction);
|
||||
return inserted;
|
||||
}
|
||||
@@ -153,9 +284,17 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
{
|
||||
const string sqlHistorico = @"INSERT INTO dbo.bob_RegPublicaciones_H (Id_Tirada, Id_Publicacion, Id_Seccion, CantPag, Fecha, Id_Planta, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdTiradaParam, @IdPublicacionParam, @IdSeccionParam, @CantPagParam, @FechaParam, @IdPlantaParam, @IdUsuarioParam, @FechaModParam, @TipoModParam);";
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new {
|
||||
IdTiradaParam = actual.IdTirada, IdPublicacionParam = actual.IdPublicacion, IdSeccionParam = actual.IdSeccion, CantPagParam = actual.CantPag, FechaParam = actual.Fecha, IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario, FechaModParam = DateTime.Now, TipoModParam = "Eliminado (Por Fecha/Pub/Planta)"
|
||||
await transaction.Connection!.ExecuteAsync(sqlHistorico, new
|
||||
{
|
||||
IdTiradaParam = actual.IdTirada,
|
||||
IdPublicacionParam = actual.IdPublicacion,
|
||||
IdSeccionParam = actual.IdSeccion,
|
||||
CantPagParam = actual.CantPag,
|
||||
FechaParam = actual.Fecha,
|
||||
IdPlantaParam = actual.IdPlanta,
|
||||
IdUsuarioParam = idUsuario,
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Eliminado (Por Fecha/Pub/Planta)"
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,10 +147,21 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdBobinaHist = inserted.IdBobina, IdTipoBobinaHist = inserted.IdTipoBobina, NroBobinaHist = inserted.NroBobina, PesoHist = inserted.Peso,
|
||||
IdPlantaHist = inserted.IdPlanta, IdEstadoBobinaHist = inserted.IdEstadoBobina, RemitoHist = inserted.Remito, FechaRemitoHist = inserted.FechaRemito,
|
||||
FechaEstadoHist = inserted.FechaEstado, IdPublicacionHist = inserted.IdPublicacion, IdSeccionHist = inserted.IdSeccion, ObsHist = inserted.Obs,
|
||||
IdUsuarioHist = idUsuario, FechaModHist = DateTime.Now, TipoModHist = "Ingreso"
|
||||
IdBobinaHist = inserted.IdBobina,
|
||||
IdTipoBobinaHist = inserted.IdTipoBobina,
|
||||
NroBobinaHist = inserted.NroBobina,
|
||||
PesoHist = inserted.Peso,
|
||||
IdPlantaHist = inserted.IdPlanta,
|
||||
IdEstadoBobinaHist = inserted.IdEstadoBobina,
|
||||
RemitoHist = inserted.Remito,
|
||||
FechaRemitoHist = inserted.FechaRemito,
|
||||
FechaEstadoHist = inserted.FechaEstado,
|
||||
IdPublicacionHist = inserted.IdPublicacion,
|
||||
IdSeccionHist = inserted.IdSeccion,
|
||||
ObsHist = inserted.Obs,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Ingreso"
|
||||
}, transaction);
|
||||
return inserted;
|
||||
}
|
||||
@@ -180,10 +191,21 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdBobinaHist = actual.IdBobina, IdTipoBobinaHist = actual.IdTipoBobina, NroBobinaHist = actual.NroBobina, PesoHist = actual.Peso,
|
||||
IdPlantaHist = actual.IdPlanta, IdEstadoBobinaHist = actual.IdEstadoBobina, RemitoHist = actual.Remito, FechaRemitoHist = actual.FechaRemito,
|
||||
FechaEstadoHist = actual.FechaEstado, IdPublicacionHist = actual.IdPublicacion, IdSeccionHist = actual.IdSeccion, ObsHist = actual.Obs,
|
||||
IdUsuarioHist = idUsuario, FechaModHist = DateTime.Now, TipoModHist = tipoMod // "Actualizada" o "Estado Cambiado"
|
||||
IdBobinaHist = actual.IdBobina,
|
||||
IdTipoBobinaHist = actual.IdTipoBobina,
|
||||
NroBobinaHist = actual.NroBobina,
|
||||
PesoHist = actual.Peso,
|
||||
IdPlantaHist = actual.IdPlanta,
|
||||
IdEstadoBobinaHist = actual.IdEstadoBobina,
|
||||
RemitoHist = actual.Remito,
|
||||
FechaRemitoHist = actual.FechaRemito,
|
||||
FechaEstadoHist = actual.FechaEstado,
|
||||
IdPublicacionHist = actual.IdPublicacion,
|
||||
IdSeccionHist = actual.IdSeccion,
|
||||
ObsHist = actual.Obs,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = tipoMod // "Actualizada" o "Estado Cambiado"
|
||||
}, transaction);
|
||||
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlUpdate, bobinaAActualizar, transaction);
|
||||
@@ -192,23 +214,24 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
|
||||
public async Task<bool> DeleteAsync(int idBobina, int idUsuario, IDbTransaction transaction)
|
||||
{
|
||||
// Normalmente, una bobina en stock no se "elimina" físicamente si ya tuvo movimientos.
|
||||
// Este método sería para borrar un ingreso erróneo que aún esté "Disponible".
|
||||
var actual = await transaction.Connection!.QuerySingleOrDefaultAsync<StockBobina>(
|
||||
var connection = transaction.Connection!; // Asegurar que la conexión no es null
|
||||
var actual = await connection.QuerySingleOrDefaultAsync<StockBobina>(
|
||||
@"SELECT Id_Bobina AS IdBobina, Id_TipoBobina AS IdTipoBobina, NroBobina, Peso,
|
||||
Id_Planta AS IdPlanta, Id_EstadoBobina AS IdEstadoBobina, Remito, FechaRemito,
|
||||
FechaEstado, Id_Publicacion AS IdPublicacion, Id_Seccion AS IdSeccion, Obs
|
||||
FROM dbo.bob_StockBobinas WHERE Id_Bobina = @IdBobinaParam",
|
||||
new { IdBobinaParam = idBobina }, transaction);
|
||||
|
||||
if (actual == null) throw new KeyNotFoundException("Bobina no encontrada para eliminar.");
|
||||
|
||||
// VALIDACIÓN IMPORTANTE: Solo permitir borrar si está en estado "Disponible" (o el que se defina)
|
||||
if (actual.IdEstadoBobina != 1) // Asumiendo 1 = Disponible
|
||||
// --- INICIO DE CAMBIO EN VALIDACIÓN ---
|
||||
// Permitir eliminar si está Disponible (1) o Dañada (3)
|
||||
if (actual.IdEstadoBobina != 1 && actual.IdEstadoBobina != 3)
|
||||
{
|
||||
_logger.LogWarning("Intento de eliminar bobina {IdBobina} que no está en estado 'Disponible'. Estado actual: {EstadoActual}", idBobina, actual.IdEstadoBobina);
|
||||
// No lanzar excepción para que la transacción no falle si es una validación de negocio
|
||||
return false;
|
||||
_logger.LogWarning("Intento de eliminar bobina {IdBobina} que no está en estado 'Disponible' o 'Dañada'. Estado actual: {EstadoActual}", idBobina, actual.IdEstadoBobina);
|
||||
return false; // Devolver false si no cumple la condición para ser eliminada
|
||||
}
|
||||
// --- FIN DE CAMBIO EN VALIDACIÓN ---
|
||||
|
||||
const string sqlDelete = "DELETE FROM dbo.bob_StockBobinas WHERE Id_Bobina = @IdBobinaParam";
|
||||
const string sqlInsertHistorico = @"
|
||||
@@ -216,17 +239,84 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
(Id_Bobina, Id_TipoBobina, NroBobina, Peso, Id_Planta, Id_EstadoBobina, Remito, FechaRemito, FechaEstado, Id_Publicacion, Id_Seccion, Obs, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdBobinaHist, @IdTipoBobinaHist, @NroBobinaHist, @PesoHist, @IdPlantaHist, @IdEstadoBobinaHist, @RemitoHist, @FechaRemitoHist, @FechaEstadoHist, @IdPublicacionHist, @IdSeccionHist, @ObsHist, @IdUsuarioHist, @FechaModHist, @TipoModHist);";
|
||||
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
await connection.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdBobinaHist = actual.IdBobina, IdTipoBobinaHist = actual.IdTipoBobina, NroBobinaHist = actual.NroBobina, PesoHist = actual.Peso,
|
||||
IdPlantaHist = actual.IdPlanta, IdEstadoBobinaHist = actual.IdEstadoBobina, RemitoHist = actual.Remito, FechaRemitoHist = actual.FechaRemito,
|
||||
FechaEstadoHist = actual.FechaEstado, IdPublicacionHist = actual.IdPublicacion, IdSeccionHist = actual.IdSeccion, ObsHist = actual.Obs,
|
||||
IdUsuarioHist = idUsuario, FechaModHist = DateTime.Now, TipoModHist = "Eliminada"
|
||||
IdBobinaHist = actual.IdBobina,
|
||||
IdTipoBobinaHist = actual.IdTipoBobina,
|
||||
NroBobinaHist = actual.NroBobina,
|
||||
PesoHist = actual.Peso,
|
||||
IdPlantaHist = actual.IdPlanta,
|
||||
IdEstadoBobinaHist = actual.IdEstadoBobina,
|
||||
RemitoHist = actual.Remito,
|
||||
FechaRemitoHist = actual.FechaRemito,
|
||||
FechaEstadoHist = actual.FechaEstado,
|
||||
IdPublicacionHist = actual.IdPublicacion,
|
||||
IdSeccionHist = actual.IdSeccion,
|
||||
ObsHist = actual.Obs,
|
||||
IdUsuarioHist = idUsuario,
|
||||
FechaModHist = DateTime.Now,
|
||||
TipoModHist = "Eliminada"
|
||||
}, transaction);
|
||||
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlDelete, new { IdBobinaParam = idBobina }, transaction);
|
||||
var rowsAffected = await connection.ExecuteAsync(sqlDelete, new { IdBobinaParam = idBobina }, transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(StockBobinaHistorico Historial, string NombreUsuarioModifico, string? NombreTipoBobina, string? NombrePlanta, string? NombreEstadoBobina, string? NombrePublicacion, string? NombreSeccion)>> GetHistorialDetalladoAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idBobinaOriginal, int? idTipoBobinaFiltro, int? idPlantaFiltro, int? idEstadoBobinaFiltro)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_Bobina, h.Id_TipoBobina, h.NroBobina, h.Peso, h.Id_Planta, h.Id_EstadoBobina,
|
||||
h.Remito, h.FechaRemito, h.FechaEstado, h.Id_Publicacion, h.Id_Seccion, h.Obs,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico,
|
||||
tb.Denominacion AS NombreTipoBobina,
|
||||
p.Nombre AS NombrePlanta,
|
||||
eb.Denominacion AS NombreEstadoBobina,
|
||||
pub.Nombre AS NombrePublicacion,
|
||||
sec.Nombre AS NombreSeccion
|
||||
FROM dbo.bob_StockBobinas_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
LEFT JOIN dbo.bob_dtBobinas tb ON h.Id_TipoBobina = tb.Id_TipoBobina
|
||||
LEFT JOIN dbo.bob_dtPlantas p ON h.Id_Planta = p.Id_Planta
|
||||
LEFT JOIN dbo.bob_dtEstadosBobinas eb ON h.Id_EstadoBobina = eb.Id_EstadoBobina
|
||||
LEFT JOIN dbo.dist_dtPublicaciones pub ON h.Id_Publicacion = pub.Id_Publicacion
|
||||
LEFT JOIN dbo.dist_dtPubliSecciones sec ON h.Id_Seccion = sec.Id_Seccion
|
||||
AND h.Id_Publicacion = sec.Id_Publicacion -- Asegurar que la sección pertenezca a la publicación
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idBobinaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_Bobina = @IdBobinaOriginalParam"); parameters.Add("IdBobinaOriginalParam", idBobinaOriginal.Value); }
|
||||
if (idTipoBobinaFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_TipoBobina = @IdTipoBobinaFiltroParam"); parameters.Add("IdTipoBobinaFiltroParam", idTipoBobinaFiltro.Value); }
|
||||
if (idPlantaFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_Planta = @IdPlantaFiltroParam"); parameters.Add("IdPlantaFiltroParam", idPlantaFiltro.Value); }
|
||||
if (idEstadoBobinaFiltro.HasValue) { sqlBuilder.Append(" AND h.Id_EstadoBobina = @IdEstadoBobinaFiltroParam"); parameters.Add("IdEstadoBobinaFiltroParam", idEstadoBobinaFiltro.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<StockBobinaHistorico, string, string, string, string, string, string, (StockBobinaHistorico, string, string?, string?, string?, string?, string?)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userMod, tipoBob, planta, estadoBob, pub, secc) => (hist, userMod, tipoBob, planta, estadoBob, pub, secc),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico,NombreTipoBobina,NombrePlanta,NombreEstadoBobina,NombrePublicacion,NombreSeccion"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial detallado de Stock de Bobinas.");
|
||||
return Enumerable.Empty<(StockBobinaHistorico, string, string?, string?, string?, string?, string?)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,6 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
}
|
||||
}
|
||||
|
||||
// --- Métodos de Escritura (USAN TRANSACCIÓN) ---
|
||||
|
||||
public async Task<TipoBobina?> CreateAsync(TipoBobina nuevoTipoBobina, int idUsuario, IDbTransaction transaction)
|
||||
{
|
||||
const string sqlInsert = @"
|
||||
@@ -199,5 +197,47 @@ namespace GestionIntegral.Api.Data.Repositories.Impresion
|
||||
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(TipoBobinaHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTipoBobinaOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.Id_TipoBobina, h.Denominacion,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.bob_dtBobinas_H h -- Nombre de tabla de historial correcto
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idTipoBobinaOriginal.HasValue) { sqlBuilder.Append(" AND h.Id_TipoBobina = @IdTipoBobinaOriginalParam"); parameters.Add("IdTipoBobinaOriginalParam", idTipoBobinaOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<TipoBobinaHistorico, string, (TipoBobinaHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Tipos de Bobina.");
|
||||
return Enumerable.Empty<(TipoBobinaHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,14 @@ namespace GestionIntegral.Api.Data.Repositories.Usuarios
|
||||
Task<bool> IsInUseAsync(int id);
|
||||
Task<IEnumerable<int>> GetPermisoIdsByPerfilIdAsync(int idPerfil);
|
||||
Task UpdatePermisosByPerfilIdAsync(int idPerfil, IEnumerable<int> nuevosPermisosIds, IDbTransaction transaction);
|
||||
Task LogPermisoAsignacionHistorialAsync(int idPerfil, int idPermiso, int idUsuario, string tipoMod, IDbTransaction transaction);
|
||||
Task<IEnumerable<(PerfilHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPerfilOriginal);
|
||||
Task<IEnumerable<(PermisosPerfilesHistorico Historial, string NombreUsuarioModifico, string NombrePerfil, string DescPermiso, string CodAccPermiso)>> GetPermisosAsignadosHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPerfilAfectado, int? idPermisoAfectado);
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,9 @@ namespace GestionIntegral.Api.Data.Repositories.Usuarios
|
||||
Task<bool> ExistsByCodAccAsync(string codAcc, int? excludeId = null);
|
||||
Task<bool> IsInUseAsync(int id);
|
||||
Task<IEnumerable<Permiso>> GetPermisosByIdsAsync(IEnumerable<int> ids);
|
||||
Task<IEnumerable<(PermisoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPermisoOriginal);
|
||||
}
|
||||
}
|
||||
@@ -240,11 +240,112 @@ namespace GestionIntegral.Api.Data.Repositories.Usuarios
|
||||
var permisosParaInsertar = nuevosPermisosIds.Select(idPermiso => new { IdPerfil = idPerfil, IdPermiso = idPermiso });
|
||||
await connection.ExecuteAsync(sqlInsert, permisosParaInsertar, transaction: transaction);
|
||||
}
|
||||
// No hay tabla _H para gral_PermisosPerfiles directamente en este diseño.
|
||||
// La auditoría de qué usuario cambió los permisos de un perfil se podría registrar
|
||||
// en una tabla de log de acciones más general si fuera necesario, o deducir
|
||||
// indirectamente si la interfaz de usuario solo permite a SuperAdmin hacer esto.
|
||||
}
|
||||
|
||||
public async Task LogPermisoAsignacionHistorialAsync(int idPerfil, int idPermiso, int idUsuario, string tipoMod, IDbTransaction transaction)
|
||||
{
|
||||
const string sql = @"
|
||||
INSERT INTO dbo.gral_PermisosPerfiles_H (idPerfil, idPermiso, Id_Usuario, FechaMod, TipoMod)
|
||||
VALUES (@IdPerfil, @IdPermiso, @IdUsuario, @FechaMod, @TipoMod);";
|
||||
|
||||
await transaction.Connection!.ExecuteAsync(sql, new
|
||||
{
|
||||
IdPerfil = idPerfil,
|
||||
IdPermiso = idPermiso,
|
||||
IdUsuario = idUsuario,
|
||||
FechaMod = DateTime.Now,
|
||||
TipoMod = tipoMod
|
||||
}, transaction: transaction);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PerfilHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPerfilOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.idPerfil, h.perfil, h.descPerfil, -- Campos de gral_Perfiles_H
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.gral_Perfiles_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPerfilOriginal.HasValue) { sqlBuilder.Append(" AND h.idPerfil = @IdPerfilOriginalParam"); parameters.Add("IdPerfilOriginalParam", idPerfilOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PerfilHistorico, string, (PerfilHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Perfiles.");
|
||||
return Enumerable.Empty<(PerfilHistorico, string)>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PermisosPerfilesHistorico Historial, string NombreUsuarioModifico, string NombrePerfil, string DescPermiso, string CodAccPermiso)>> GetPermisosAsignadosHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPerfilAfectado, int? idPermisoAfectado)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.IdHist, h.idPerfil, h.idPermiso,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico,
|
||||
pf.perfil AS NombrePerfil,
|
||||
p.descPermiso AS DescPermiso,
|
||||
p.codAcc AS CodAccPermiso
|
||||
FROM dbo.gral_PermisosPerfiles_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
JOIN dbo.gral_Perfiles pf ON h.idPerfil = pf.id
|
||||
JOIN dbo.gral_Permisos p ON h.idPermiso = p.id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPerfilAfectado.HasValue) { sqlBuilder.Append(" AND h.idPerfil = @IdPerfilAfectadoParam"); parameters.Add("IdPerfilAfectadoParam", idPerfilAfectado.Value); }
|
||||
if (idPermisoAfectado.HasValue) { sqlBuilder.Append(" AND h.idPermiso = @IdPermisoAfectadoParam"); parameters.Add("IdPermisoAfectadoParam", idPermisoAfectado.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PermisosPerfilesHistorico, string, string, string, string, (PermisosPerfilesHistorico, string, string, string, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userMod, perf, desc, cod) => (hist, userMod, perf, desc, cod),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico,NombrePerfil,DescPermiso,CodAccPermiso"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Asignación de Permisos.");
|
||||
return Enumerable.Empty<(PermisosPerfilesHistorico, string, string, string, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,5 +227,47 @@ namespace GestionIntegral.Api.Data.Repositories.Usuarios
|
||||
var rowsAffected = await connection.ExecuteAsync(sqlDelete, new { Id = id }, transaction: transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<(PermisoHistorico Historial, string NombreUsuarioModifico)>> GetHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPermisoOriginal)
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
var sqlBuilder = new StringBuilder(@"
|
||||
SELECT
|
||||
h.IdHist, h.idPermiso, h.modulo, h.descPermiso, h.codAcc,
|
||||
h.Id_Usuario, h.FechaMod, h.TipoMod,
|
||||
u.Nombre + ' ' + u.Apellido AS NombreUsuarioModifico
|
||||
FROM dbo.gral_Permisos_H h
|
||||
JOIN dbo.gral_Usuarios u ON h.Id_Usuario = u.Id
|
||||
WHERE 1=1");
|
||||
|
||||
var parameters = new DynamicParameters();
|
||||
|
||||
if (fechaDesde.HasValue) { sqlBuilder.Append(" AND h.FechaMod >= @FechaDesdeParam"); parameters.Add("FechaDesdeParam", fechaDesde.Value.Date); }
|
||||
if (fechaHasta.HasValue) { sqlBuilder.Append(" AND h.FechaMod <= @FechaHastaParam"); parameters.Add("FechaHastaParam", fechaHasta.Value.Date.AddDays(1).AddTicks(-1)); }
|
||||
if (idUsuarioModifico.HasValue) { sqlBuilder.Append(" AND h.Id_Usuario = @IdUsuarioModificoParam"); parameters.Add("IdUsuarioModificoParam", idUsuarioModifico.Value); }
|
||||
if (!string.IsNullOrWhiteSpace(tipoModificacion)) { sqlBuilder.Append(" AND h.TipoMod = @TipoModParam"); parameters.Add("TipoModParam", tipoModificacion); }
|
||||
if (idPermisoOriginal.HasValue) { sqlBuilder.Append(" AND h.idPermiso = @IdPermisoOriginalParam"); parameters.Add("IdPermisoOriginalParam", idPermisoOriginal.Value); }
|
||||
|
||||
sqlBuilder.Append(" ORDER BY h.FechaMod DESC;");
|
||||
|
||||
try
|
||||
{
|
||||
var result = await connection.QueryAsync<PermisoHistorico, string, (PermisoHistorico, string)>(
|
||||
sqlBuilder.ToString(),
|
||||
(hist, userName) => (hist, userName),
|
||||
parameters,
|
||||
splitOn: "NombreUsuarioModifico"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener historial de Permisos (Maestro).");
|
||||
return Enumerable.Empty<(PermisoHistorico, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class ControlDevolucionesHistorico // Corresponde a dist_dtCtrlDevoluciones_H
|
||||
{
|
||||
// No hay PK explícita en _H
|
||||
public int Id_Control { get; set; } // Coincide con columna en _H
|
||||
public int Id_Control { get; set; } // ID del ControlDevoluciones original
|
||||
public int Id_Empresa { get; set; }
|
||||
public DateTime Fecha { get; set; }
|
||||
public int Entrada { get; set; }
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class OtroDestinoHistorico
|
||||
public class OtroDestinoHistorico // Corresponde a dist_dtOtrosDestinos_H
|
||||
{
|
||||
// Columna: Id_Destino (int, FK)
|
||||
public int IdDestino { get; set; }
|
||||
|
||||
// Columna: Nombre (varchar(100), NOT NULL)
|
||||
public int Id_Destino { get; set; } // ID del OtroDestino original
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
|
||||
// Columna: Obs (varchar(250), NULL)
|
||||
public string? Obs { get; set; }
|
||||
|
||||
// Columnas de Auditoría
|
||||
public int IdUsuario { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Insertada", "Modificada", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class PorcMonCanillaHistorico
|
||||
public class PorcMonCanillaHistorico // Corresponde a dist_PorcMonPagoCanilla_H
|
||||
{
|
||||
public int Id_PorcMon { get; set; } // Coincide con la columna
|
||||
public int Id_PorcMon { get; set; } // ID del PorcMon original
|
||||
public int Id_Publicacion { get; set; }
|
||||
public int Id_Canilla { get; set; }
|
||||
public DateTime VigenciaD { get; set; }
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class PorcPagoHistorico
|
||||
public class PorcPagoHistorico // Corresponde a dist_PorcPago_H
|
||||
{
|
||||
public int IdPorcentaje { get; set; } // Id_Porcentaje
|
||||
public int IdPublicacion { get; set; }
|
||||
public int IdDistribuidor { get; set; }
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public int Id_Porcentaje { get; set; } // ID del PorcPago original
|
||||
public int Id_Publicacion { get; set; }
|
||||
public int Id_Distribuidor { get; set; }
|
||||
public DateTime VigenciaD { get; set; } // smalldatetime en BD, DateTime en C# está bien
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal Porcentaje { get; set; }
|
||||
public int IdUsuario { get; set; } // Coincide con Id_Usuario en la tabla _H
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class PrecioHistorico
|
||||
public class PrecioHistorico // Corresponde a dist_Precios_H
|
||||
{
|
||||
public int IdPrecio { get; set; } // FK a dist_Precios.Id_Precio
|
||||
public int IdPublicacion { get; set; }
|
||||
public int Id_Precio { get; set; } // ID del Precio original
|
||||
public int Id_Publicacion { get; set; }
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal? Lunes { get; set; }
|
||||
@@ -13,8 +15,6 @@ namespace GestionIntegral.Api.Models.Distribucion
|
||||
public decimal? Viernes { get; set; }
|
||||
public decimal? Sabado { get; set; }
|
||||
public decimal? Domingo { get; set; }
|
||||
|
||||
// Campos de Auditoría
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
|
||||
@@ -2,10 +2,10 @@ using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class PubliSeccionHistorico
|
||||
public class PubliSeccionHistorico // Corresponde a dist_dtPubliSecciones_H
|
||||
{
|
||||
public int Id_Seccion { get; set; } // Coincide con la columna
|
||||
public int Id_Publicacion { get; set; }
|
||||
public int Id_Seccion { get; set; } // ID de la Sección original
|
||||
public int Id_Publicacion { get; set; } // A qué publicación pertenecía en ese momento
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public bool Estado { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class PublicacionHistorico
|
||||
public class PublicacionHistorico // Corresponde a dist_dtPublicaciones_H
|
||||
{
|
||||
// No hay PK autoincremental explícita en el script de _H
|
||||
public int IdPublicacion { get; set; }
|
||||
public int Id_Publicacion { get; set; } // ID de la Publicacion original
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string? Observacion { get; set; }
|
||||
public int IdEmpresa { get; set; }
|
||||
public bool? Habilitada { get; set; } // Coincide con la tabla _H
|
||||
|
||||
// Campos de Auditoría
|
||||
public int Id_Empresa { get; set; }
|
||||
// public bool CtrlDevoluciones { get; set; } // Parece que no está en _H
|
||||
public bool? Habilitada { get; set; } // Es nullable en _H
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class RecargoZonaHistorico
|
||||
public class RecargoZonaHistorico // Corresponde a dist_RecargoZona_H
|
||||
{
|
||||
public int IdRecargo { get; set; }
|
||||
public int IdPublicacion { get; set; }
|
||||
public int IdZona { get; set; }
|
||||
public int Id_Recargo { get; set; } // ID del Recargo original
|
||||
public int Id_Publicacion { get; set; }
|
||||
public int Id_Zona { get; set; }
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal Valor { get; set; }
|
||||
public int IdUsuario { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Distribucion
|
||||
{
|
||||
public class ZonaHistorico
|
||||
{
|
||||
public int IdZona { get; set; } // NO es IDENTITY
|
||||
public int Id_Zona { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string? Descripcion { get; set; }
|
||||
public bool Estado { get; set; } // Importante para registrar el estado al momento del cambio
|
||||
public int IdUsuario { get; set; }
|
||||
public bool Estado { get; set; } // El estado de la zona en ese momento del historial
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Distribucion // O Auditoria
|
||||
{
|
||||
public class CambioParadaHistorialDto
|
||||
{
|
||||
public int Id_Registro { get; set; }
|
||||
public int Id_Canilla { get; set; }
|
||||
public string NombreCanilla { get; set; } = string.Empty; // Para mostrar
|
||||
public string Parada { get; set; } = string.Empty; // Dirección de la parada en ese momento
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria // O Auditoria
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class CanillaHistorialDto
|
||||
{
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class ControlDevolucionesHistorialDto
|
||||
{
|
||||
public int Id_Control { get; set; }
|
||||
public int Id_Empresa { get; set; }
|
||||
// public string NombreEmpresa { get; set; } // Opcional
|
||||
public DateTime Fecha { get; set; } // Fecha original del control
|
||||
public int Entrada { get; set; }
|
||||
public int Sobrantes { get; set; }
|
||||
public string? Detalle { get; set; }
|
||||
public int SinCargo { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria // O Auditoria
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class EmpresaHistorialDto
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class EstadoBobinaHistorialDto
|
||||
{
|
||||
public int Id_EstadoBobina { get; set; }
|
||||
public string Denominacion { get; set; } = string.Empty;
|
||||
public string? Obs { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class OtroDestinoHistorialDto
|
||||
{
|
||||
public int Id_Destino { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string? Obs { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PerfilHistorialDto
|
||||
{
|
||||
public int IdPerfil { get; set; } // ID del Perfil original
|
||||
public string Perfil { get; set; } = string.Empty; // Nombre del perfil
|
||||
public string? DescPerfil { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; } // Quién hizo el cambio
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
// El IdHist (PK de _H) no es estrictamente necesario en el DTO para mostrar,
|
||||
// pero se puede incluir un identificador único para cada entrada de historial.
|
||||
// public int IdHistorial { get; set;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PermisoHistorialDto
|
||||
{
|
||||
public int IdPermiso { get; set; } // ID del Permiso original
|
||||
public string Modulo { get; set; } = string.Empty;
|
||||
public string DescPermiso { get; set; } = string.Empty;
|
||||
public string CodAcc { get; set; } = string.Empty;
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
// El IdHist de la tabla _H puede ser útil para la key en el frontend
|
||||
public int IdHistorial { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PermisosPerfilesHistorialDto
|
||||
{
|
||||
public int IdHistorial { get; set; } // El ID de la entrada de historial
|
||||
public int IdPerfil { get; set; }
|
||||
public string NombrePerfil { get; set; } = string.Empty;
|
||||
public int IdPermiso { get; set; }
|
||||
public string DescPermiso { get; set; } = string.Empty;
|
||||
public string CodAccPermiso { get; set; } = string.Empty;
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Asignado", "Removido"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PlantaHistorialDto
|
||||
{
|
||||
public int Id_Planta { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string Detalle { get; set; } = string.Empty;
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PorcMonCanillaHistorialDto
|
||||
{
|
||||
public int Id_PorcMon { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
// public string NombrePublicacion { get; set; } // Opcional
|
||||
public int Id_Canilla { get; set; }
|
||||
// public string NombreCanilla { get; set; } // Opcional
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal PorcMon { get; set; }
|
||||
public bool EsPorcentaje { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PorcPagoHistorialDto
|
||||
{
|
||||
public int Id_Porcentaje { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
// public string NombrePublicacion { get; set; } // Opcional
|
||||
public int Id_Distribuidor { get; set; }
|
||||
// public string NombreDistribuidor { get; set; } // Opcional
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal Porcentaje { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PrecioHistorialDto
|
||||
{
|
||||
public int Id_Precio { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
// public string NombrePublicacion { get; set; } // Opcional
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal? Lunes { get; set; }
|
||||
public decimal? Martes { get; set; }
|
||||
public decimal? Miercoles { get; set; }
|
||||
public decimal? Jueves { get; set; }
|
||||
public decimal? Viernes { get; set; }
|
||||
public decimal? Sabado { get; set; }
|
||||
public decimal? Domingo { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PubliSeccionHistorialDto
|
||||
{
|
||||
public int Id_Seccion { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
// public string NombrePublicacion { get; set; } // Opcional, si quieres traerlo con JOIN
|
||||
public string Nombre { get; set; } = string.Empty; // Nombre de la sección
|
||||
public bool Estado { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class PublicacionHistorialDto
|
||||
{
|
||||
public int Id_Publicacion { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string? Observacion { get; set; }
|
||||
public int Id_Empresa { get; set; }
|
||||
// public string NombreEmpresa { get; set; } // Opcional
|
||||
// public bool CtrlDevoluciones { get; set; } // Si la añades a _H y al modelo
|
||||
public bool? Habilitada { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class RecargoZonaHistorialDto
|
||||
{
|
||||
public int Id_Recargo { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
// public string NombrePublicacion { get; set; } // Opcional
|
||||
public int Id_Zona { get; set; }
|
||||
// public string NombreZona { get; set; } // Opcional
|
||||
public DateTime VigenciaD { get; set; }
|
||||
public DateTime? VigenciaH { get; set; }
|
||||
public decimal Valor { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class RegSeccionTiradaHistorialDto
|
||||
{
|
||||
public int Id_Tirada { get; set; } // ID del registro original de la sección de la tirada
|
||||
public int Id_Publicacion { get; set; }
|
||||
public string NombrePublicacion { get; set; } = string.Empty;
|
||||
public int Id_Seccion { get; set; }
|
||||
public string NombreSeccion { get; set; } = string.Empty;
|
||||
public int CantPag { get; set; }
|
||||
public DateTime Fecha { get; set; } // Fecha original de la tirada
|
||||
public int Id_Planta { get; set; }
|
||||
public string NombrePlanta { get; set; } = string.Empty;
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class RegTiradaHistorialDto
|
||||
{
|
||||
public int Id_Registro { get; set; }
|
||||
public int Ejemplares { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
public string NombrePublicacion { get; set; } = string.Empty; // Para mostrar
|
||||
public DateTime Fecha { get; set; }
|
||||
public int Id_Planta { get; set; }
|
||||
public string NombrePlanta { get; set; } = string.Empty; // Para mostrar
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class StockBobinaHistorialDto
|
||||
{
|
||||
public int Id_Bobina { get; set; }
|
||||
public int Id_TipoBobina { get; set; }
|
||||
public string NombreTipoBobina { get; set; } = string.Empty; // Para mostrar
|
||||
public string NroBobina { get; set; } = string.Empty;
|
||||
public int Peso { get; set; }
|
||||
public int Id_Planta { get; set; }
|
||||
public string NombrePlanta { get; set; } = string.Empty; // Para mostrar
|
||||
public int Id_EstadoBobina { get; set; }
|
||||
public string NombreEstadoBobina { get; set; } = string.Empty; // Para mostrar
|
||||
public string Remito { get; set; } = string.Empty;
|
||||
public DateTime FechaRemito { get; set; }
|
||||
public DateTime? FechaEstado { get; set; }
|
||||
public int? Id_Publicacion { get; set; }
|
||||
public string? NombrePublicacion { get; set; } // Para mostrar
|
||||
public int? Id_Seccion { get; set; }
|
||||
public string? NombreSeccion { get; set; } // Para mostrar
|
||||
public string? Obs { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class TipoBobinaHistorialDto
|
||||
{
|
||||
public int Id_TipoBobina { get; set; }
|
||||
public string Denominacion { get; set; } = string.Empty;
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Dtos.Auditoria
|
||||
{
|
||||
public class ZonaHistorialDto
|
||||
{
|
||||
public int Id_Zona { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string? Descripcion { get; set; }
|
||||
public bool Estado { get; set; }
|
||||
|
||||
public int Id_Usuario { get; set; }
|
||||
public string NombreUsuarioModifico { get; set; } = string.Empty;
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ namespace GestionIntegral.Api.Dtos.Distribucion
|
||||
{
|
||||
// IdPublicacion no se puede cambiar una vez creado el precio (se borraría y crearía uno nuevo)
|
||||
// VigenciaD tampoco se debería cambiar directamente, se maneja creando nuevos periodos.
|
||||
|
||||
[Required(ErrorMessage = "La fecha de Vigencia Hasta es obligatoria si se modifica un periodo existente para cerrarlo.")]
|
||||
public DateTime? VigenciaH { get; set; } // Para cerrar un periodo
|
||||
|
||||
[Range(0, 999999.99, ErrorMessage = "El precio debe ser un valor positivo.")]
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Impresion
|
||||
{
|
||||
public class EstadoBobinaHistorico
|
||||
public class EstadoBobinaHistorico // Corresponde a bob_dtEstadosBobinas_H
|
||||
{
|
||||
// Columna: Id_EstadoBobina (int, FK)
|
||||
public int IdEstadoBobina { get; set; }
|
||||
|
||||
// Columna: Denominacion (varchar(50), NOT NULL)
|
||||
public int Id_EstadoBobina { get; set; } // ID del EstadoBobina original
|
||||
public string Denominacion { get; set; } = string.Empty;
|
||||
|
||||
// Columna: Obs (varchar(150), NULL)
|
||||
public string? Obs { get; set; }
|
||||
|
||||
// Columnas de Auditoría
|
||||
public int IdUsuario { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Insertada", "Modificada", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Impresion
|
||||
{
|
||||
public class PlantaHistorico
|
||||
public class PlantaHistorico // Corresponde a bob_dtPlantas_H
|
||||
{
|
||||
public int IdPlanta { get; set; } // FK a bob_dtPlantas
|
||||
public int Id_Planta { get; set; } // ID de la Planta original
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string Detalle { get; set; } = string.Empty;
|
||||
public int IdUsuario { get; set; }
|
||||
public string Detalle { get; set; } = string.Empty; // No es nullable en _H
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Insertada", "Modificada", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Impresion
|
||||
{
|
||||
public class RegTiradaHistorico
|
||||
public class RegTiradaHistorico // Corresponde a bob_RegTiradas_H
|
||||
{
|
||||
public int Id_Registro { get; set; } // Nombre de columna en _H
|
||||
public int Id_Registro { get; set; } // ID del RegTirada original
|
||||
public int Ejemplares { get; set; }
|
||||
public int Id_Publicacion { get; set; }
|
||||
public DateTime Fecha { get; set; }
|
||||
public DateTime Fecha { get; set; } // Fecha original de la tirada
|
||||
public int Id_Planta { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
|
||||
@@ -2,9 +2,9 @@ using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Impresion
|
||||
{
|
||||
public class StockBobinaHistorico
|
||||
public class StockBobinaHistorico // Corresponde a bob_StockBobinas_H
|
||||
{
|
||||
public int Id_Bobina { get; set; } // Columna en _H
|
||||
public int Id_Bobina { get; set; } // ID de la Bobina en Stock original
|
||||
public int Id_TipoBobina { get; set; }
|
||||
public string NroBobina { get; set; } = string.Empty;
|
||||
public int Peso { get; set; }
|
||||
@@ -16,10 +16,8 @@ namespace GestionIntegral.Api.Models.Impresion
|
||||
public int? Id_Publicacion { get; set; }
|
||||
public int? Id_Seccion { get; set; }
|
||||
public string? Obs { get; set; }
|
||||
|
||||
// Auditoría
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Ingreso", "Estado Cambiado", "Actualizacion", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Impresion
|
||||
{
|
||||
public class TipoBobinaHistorico
|
||||
public class TipoBobinaHistorico // Corresponde a bob_dtBobinas_H
|
||||
{
|
||||
// Columna: Id_TipoBobina (int, FK)
|
||||
public int IdTipoBobina { get; set; }
|
||||
|
||||
// Columna: Denominacion (varchar(150), NOT NULL)
|
||||
public int Id_TipoBobina { get; set; } // ID del TipoBobina original
|
||||
public string Denominacion { get; set; } = string.Empty;
|
||||
|
||||
// Columnas de Auditoría
|
||||
public int IdUsuario { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Insertada", "Modificada", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Usuarios
|
||||
{
|
||||
public class PerfilHistorico
|
||||
public class PerfilHistorico // Corresponde a gral_Perfiles_H
|
||||
{
|
||||
public int IdPerfil { get; set; } // FK a gral_Perfiles.id
|
||||
public string NombrePerfil { get; set; } = string.Empty;
|
||||
public string? Descripcion { get; set; }
|
||||
public int IdUsuario { get; set; }
|
||||
// La tabla gral_Perfiles_H tiene un Id IDENTITY(1,1) propio,
|
||||
// pero también tiene idPerfil que es el FK al perfil original.
|
||||
// Usamos idPerfil para identificar el perfil afectado.
|
||||
// El Id de la tabla _H es más para la unicidad del registro de historial.
|
||||
public int Id {get; set;} // PK de la tabla _H
|
||||
public int IdPerfil { get; set; } // ID del Perfil original
|
||||
public string Perfil { get; set; } = string.Empty; // Nombre del perfil en ese momento
|
||||
public string? DescPerfil { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Insertada", "Modificada", "Eliminada"
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Usuarios
|
||||
{
|
||||
public class PermisoHistorico
|
||||
public class PermisoHistorico // Corresponde a gral_Permisos_H
|
||||
{
|
||||
public int IdHist { get; set; } // PK de la tabla de historial
|
||||
public int IdPermiso { get; set; } // FK a gral_Permisos.id
|
||||
public int IdHist { get; set; } // PK de la tabla _H
|
||||
public int IdPermiso { get; set; } // ID del Permiso original
|
||||
public string Modulo { get; set; } = string.Empty;
|
||||
public string DescPermiso { get; set; } = string.Empty;
|
||||
public string CodAcc { get; set; } = string.Empty;
|
||||
public int IdUsuario { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace GestionIntegral.Api.Models.Usuarios
|
||||
{
|
||||
public class PermisosPerfilesHistorico // Corresponde a gral_PermisosPerfiles_H
|
||||
{
|
||||
// Esta tabla registra cada asignación individualmente como un evento.
|
||||
// El id de la tabla _H es el identificador único del evento de historial.
|
||||
public int Id { get; set; } // PK de la tabla _H
|
||||
public int idPerfil { get; set; }
|
||||
public int idPermiso { get; set; }
|
||||
public int Id_Usuario { get; set; }
|
||||
public DateTime FechaMod { get; set; }
|
||||
public string TipoMod { get; set; } = string.Empty; // "Asignado", "Removido" (o "Creado"/"Eliminado")
|
||||
}
|
||||
}
|
||||
@@ -181,5 +181,27 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
}
|
||||
finally { if (connection.State == ConnectionState.Open) { if (connection is System.Data.Common.DbConnection dbConn) await dbConn.CloseAsync(); else connection.Close(); } }
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CambioParadaHistorialDto>> ObtenerCambiosParadaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idCanillaAfectado)
|
||||
{
|
||||
var historialData = await _paradaRepo.GetCambiosParadaHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idCanillaAfectado);
|
||||
|
||||
return historialData.Select(h => new CambioParadaHistorialDto
|
||||
{
|
||||
Id_Registro = h.Historial.Id_Registro,
|
||||
Id_Canilla = h.Historial.Id_Canilla,
|
||||
NombreCanilla = h.NombreCanilla,
|
||||
Parada = h.Historial.Parada,
|
||||
VigenciaD = h.Historial.VigenciaD,
|
||||
VigenciaH = h.Historial.VigenciaH ?? default(DateTime),
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -167,5 +168,29 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ControlDevolucionesHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idControlAfectado, int? idEmpresaAfectada, DateTime? fechaAfectada)
|
||||
{
|
||||
var historialData = await _controlDevRepo.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idControlAfectado, idEmpresaAfectada, fechaAfectada);
|
||||
|
||||
return historialData.Select(h => new ControlDevolucionesHistorialDto
|
||||
{
|
||||
Id_Control = h.Historial.Id_Control,
|
||||
Id_Empresa = h.Historial.Id_Empresa,
|
||||
Fecha = h.Historial.Fecha,
|
||||
Entrada = h.Historial.Entrada,
|
||||
Sobrantes = h.Historial.Sobrantes,
|
||||
Detalle = h.Historial.Detalle,
|
||||
SinCargo = h.Historial.SinCargo,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
// Mapear NombreEmpresa aquí si lo añades al DTO y lo obtienes
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
// Update podría ser solo para cerrar la vigencia, no para cambiar la dirección de una parada histórica.
|
||||
Task<(bool Exito, string? Error)> CerrarParadaAsync(int idRegistro, UpdateCambioParadaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarParadaAsync(int idRegistro, int idUsuario); // Si se permite
|
||||
Task<IEnumerable<CambioParadaHistorialDto>> ObtenerCambiosParadaHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idCanillaAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,5 +13,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(ControlDevolucionesDto? Control, string? Error)> CrearAsync(CreateControlDevolucionesDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idControl, UpdateControlDevolucionesDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idControl, int idUsuario);
|
||||
Task<IEnumerable<ControlDevolucionesHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idControlAfectado, int? idEmpresaAfectada, DateTime? fechaAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(OtroDestinoDto? Destino, string? Error)> CrearAsync(CreateOtroDestinoDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdateOtroDestinoDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario);
|
||||
Task<IEnumerable<OtroDestinoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idOtroDestinoAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,5 +13,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(PorcMonCanillaDto? Item, string? Error)> CrearAsync(CreatePorcMonCanillaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idPorcMon, UpdatePorcMonCanillaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idPorcMon, int idUsuario);
|
||||
Task<IEnumerable<PorcMonCanillaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcMonAfectado, int? idPublicacionAfectada, int? idCanillaAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,5 +14,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(PorcPagoDto? PorcPago, string? Error)> CrearAsync(CreatePorcPagoDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idPorcentaje, UpdatePorcPagoDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idPorcentaje, int idUsuario);
|
||||
Task<IEnumerable<PorcPagoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcentajeAfectado, int? idPublicacionAfectada, int? idDistribuidorAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,5 +13,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(PrecioDto? Precio, string? Error)> CrearAsync(CreatePrecioDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idPrecio, UpdatePrecioDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idPrecio, int idUsuario);
|
||||
Task<IEnumerable<PrecioHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPrecioAfectado, int? idPublicacionAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(PubliSeccionDto? Seccion, string? Error)> CrearAsync(CreatePubliSeccionDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idSeccion, UpdatePubliSeccionDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idSeccion, int idUsuario);
|
||||
Task<IEnumerable<PubliSeccionHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idSeccionAfectada, int? idPublicacionAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -15,5 +16,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<IEnumerable<PublicacionDto>> ObtenerPublicacionesPorDiaSemanaAsync(byte diaSemana); // Devolvemos el DTO completo
|
||||
Task<(bool Exito, string? Error)> ActualizarConfiguracionDiasAsync(int idPublicacion, UpdatePublicacionDiasSemanaRequestDto requestDto, int idUsuario);
|
||||
Task<IEnumerable<PublicacionDropdownDto>> ObtenerParaDropdownAsync(bool soloHabilitadas = true);
|
||||
Task<IEnumerable<PublicacionHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPublicacionAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,5 +13,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(RecargoZonaDto? Recargo, string? Error)> CrearAsync(CreateRecargoZonaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int idRecargo, UpdateRecargoZonaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int idRecargo, int idUsuario);
|
||||
Task<IEnumerable<RecargoZonaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRecargoAfectado, int? idPublicacionAfectada, int? idZonaAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Zonas; // Para los DTOs de Zonas
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
Task<(ZonaDto? Zona, string? Error)> CrearAsync(CreateZonaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdateZonaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario); // Eliminar lógico (cambiar estado)
|
||||
Task<IEnumerable<ZonaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idZonaAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -139,5 +140,24 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno al eliminar el destino: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<OtroDestinoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idOtroDestinoAfectado)
|
||||
{
|
||||
var historialData = await _otroDestinoRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idOtroDestinoAfectado);
|
||||
|
||||
return historialData.Select(h => new OtroDestinoHistorialDto
|
||||
{
|
||||
Id_Destino = h.Historial.Id_Destino,
|
||||
Nombre = h.Historial.Nombre,
|
||||
Obs = h.Historial.Obs,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -236,5 +237,28 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PorcMonCanillaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcMonAfectado, int? idPublicacionAfectada, int? idCanillaAfectado)
|
||||
{
|
||||
var historialData = await _porcMonCanillaRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPorcMonAfectado, idPublicacionAfectada, idCanillaAfectado);
|
||||
|
||||
return historialData.Select(h => new PorcMonCanillaHistorialDto
|
||||
{
|
||||
Id_PorcMon = h.Historial.Id_PorcMon,
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
Id_Canilla = h.Historial.Id_Canilla,
|
||||
VigenciaD = h.Historial.VigenciaD,
|
||||
VigenciaH = h.Historial.VigenciaH,
|
||||
PorcMon = h.Historial.PorcMon,
|
||||
EsPorcentaje = h.Historial.EsPorcentaje,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -117,7 +118,8 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
|
||||
transaction.Commit();
|
||||
_logger.LogInformation("PorcPago ID {Id} creado por Usuario ID {UserId}.", porcPagoCreado.IdPorcentaje, idUsuario);
|
||||
return (new PorcPagoDto { // Construir DTO manualmente ya que tenemos NombreDistribuidor
|
||||
return (new PorcPagoDto
|
||||
{ // Construir DTO manualmente ya que tenemos NombreDistribuidor
|
||||
IdPorcentaje = porcPagoCreado.IdPorcentaje,
|
||||
IdPublicacion = porcPagoCreado.IdPublicacion,
|
||||
IdDistribuidor = porcPagoCreado.IdDistribuidor,
|
||||
@@ -230,5 +232,27 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PorcPagoHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPorcentajeAfectado, int? idPublicacionAfectada, int? idDistribuidorAfectado)
|
||||
{
|
||||
var historialData = await _porcPagoRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPorcentajeAfectado, idPublicacionAfectada, idDistribuidorAfectado);
|
||||
|
||||
return historialData.Select(h => new PorcPagoHistorialDto
|
||||
{
|
||||
Id_Porcentaje = h.Historial.Id_Porcentaje,
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
Id_Distribuidor = h.Historial.Id_Distribuidor,
|
||||
VigenciaD = h.Historial.VigenciaD,
|
||||
VigenciaH = h.Historial.VigenciaH,
|
||||
Porcentaje = h.Historial.Porcentaje,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -37,8 +38,13 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
IdPublicacion = precio.IdPublicacion,
|
||||
VigenciaD = precio.VigenciaD.ToString("yyyy-MM-dd"),
|
||||
VigenciaH = precio.VigenciaH?.ToString("yyyy-MM-dd"),
|
||||
Lunes = precio.Lunes, Martes = precio.Martes, Miercoles = precio.Miercoles,
|
||||
Jueves = precio.Jueves, Viernes = precio.Viernes, Sabado = precio.Sabado, Domingo = precio.Domingo
|
||||
Lunes = precio.Lunes,
|
||||
Martes = precio.Martes,
|
||||
Miercoles = precio.Miercoles,
|
||||
Jueves = precio.Jueves,
|
||||
Viernes = precio.Viernes,
|
||||
Sabado = precio.Sabado,
|
||||
Domingo = precio.Domingo
|
||||
};
|
||||
|
||||
public async Task<IEnumerable<PrecioDto>> ObtenerPorPublicacionIdAsync(int idPublicacion)
|
||||
@@ -73,8 +79,13 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
IdPublicacion = createDto.IdPublicacion,
|
||||
VigenciaD = createDto.VigenciaD.Date, // Asegurar que solo sea fecha
|
||||
VigenciaH = null, // Se establece al crear el siguiente o al cerrar manualmente
|
||||
Lunes = createDto.Lunes ?? 0, Martes = createDto.Martes ?? 0, Miercoles = createDto.Miercoles ?? 0,
|
||||
Jueves = createDto.Jueves ?? 0, Viernes = createDto.Viernes ?? 0, Sabado = createDto.Sabado ?? 0, Domingo = createDto.Domingo ?? 0
|
||||
Lunes = createDto.Lunes ?? 0,
|
||||
Martes = createDto.Martes ?? 0,
|
||||
Miercoles = createDto.Miercoles ?? 0,
|
||||
Jueves = createDto.Jueves ?? 0,
|
||||
Viernes = createDto.Viernes ?? 0,
|
||||
Sabado = createDto.Sabado ?? 0,
|
||||
Domingo = createDto.Domingo ?? 0
|
||||
};
|
||||
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
@@ -126,28 +137,67 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
|
||||
try
|
||||
{
|
||||
var precioExistente = await _precioRepository.GetByIdAsync(idPrecio); // Obtener dentro de la TX por si acaso
|
||||
if (precioExistente == null) return (false, "Período de precio no encontrado.");
|
||||
|
||||
// En una actualización, principalmente actualizamos los montos de los días.
|
||||
// VigenciaH se puede actualizar para cerrar un período explícitamente.
|
||||
// No se permite cambiar IdPublicacion ni VigenciaD aquí.
|
||||
// Si VigenciaH se establece, debe ser >= VigenciaD
|
||||
if (updateDto.VigenciaH.HasValue && updateDto.VigenciaH.Value.Date < precioExistente.VigenciaD.Date)
|
||||
var precioExistente = await _precioRepository.GetByIdAsync(idPrecio); // Obtener dentro de TX
|
||||
if (precioExistente == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "Período de precio no encontrado.");
|
||||
}
|
||||
|
||||
bool preciosDiasCambiaron =
|
||||
(updateDto.Lunes.HasValue && updateDto.Lunes != precioExistente.Lunes) ||
|
||||
(updateDto.Martes.HasValue && updateDto.Martes != precioExistente.Martes) ||
|
||||
(updateDto.Miercoles.HasValue && updateDto.Miercoles != precioExistente.Miercoles) ||
|
||||
(updateDto.Jueves.HasValue && updateDto.Jueves != precioExistente.Jueves) ||
|
||||
(updateDto.Viernes.HasValue && updateDto.Viernes != precioExistente.Viernes) ||
|
||||
(updateDto.Sabado.HasValue && updateDto.Sabado != precioExistente.Sabado) ||
|
||||
(updateDto.Domingo.HasValue && updateDto.Domingo != precioExistente.Domingo);
|
||||
|
||||
if (precioExistente.VigenciaH != null && preciosDiasCambiaron)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "No se pueden modificar los precios de los días de un período que ya ha sido cerrado.");
|
||||
}
|
||||
|
||||
// Validación 2: No modificar precios de días si el período está en uso
|
||||
if (preciosDiasCambiaron && await _precioRepository.IsInUseAsync(idPrecio, precioExistente.VigenciaD, precioExistente.VigenciaH))
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "No se pueden modificar los precios de los días de este período porque ya existen movimientos asociados.");
|
||||
}
|
||||
|
||||
// Solo realizar validaciones de VigenciaH si se está intentando SETEAR o CAMBIAR VigenciaH
|
||||
if (updateDto.VigenciaH.HasValue) // <<--- CHEQUEO IMPORTANTE
|
||||
{
|
||||
// Validación 3: Nueva VigenciaH debe ser >= VigenciaD
|
||||
if (updateDto.VigenciaH.Value.Date < precioExistente.VigenciaD.Date)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "La Vigencia Hasta no puede ser anterior a la Vigencia Desde.");
|
||||
}
|
||||
// Adicional: si se establece VigenciaH, verificar que no haya precios posteriores que se solapen
|
||||
if (updateDto.VigenciaH.HasValue)
|
||||
{
|
||||
var preciosPosteriores = await _precioRepository.GetByPublicacionIdAsync(precioExistente.IdPublicacion);
|
||||
if (preciosPosteriores.Any(p => p.IdPrecio != idPrecio && p.VigenciaD.Date <= updateDto.VigenciaH.Value.Date && p.VigenciaD.Date > precioExistente.VigenciaD.Date ))
|
||||
{
|
||||
return (false, "No se puede cerrar este período porque existen períodos de precios posteriores que se solaparían. Elimine o ajuste los períodos posteriores primero.");
|
||||
}
|
||||
}
|
||||
|
||||
// Validación 4: Nueva VigenciaH no debe solaparse con períodos posteriores
|
||||
var todosLosPreciosPub = await _precioRepository.GetByPublicacionIdAsync(precioExistente.IdPublicacion);
|
||||
if (todosLosPreciosPub.Any(p =>
|
||||
p.IdPrecio != idPrecio &&
|
||||
p.VigenciaD.Date <= updateDto.VigenciaH.Value.Date &&
|
||||
p.VigenciaD.Date > precioExistente.VigenciaD.Date &&
|
||||
(p.VigenciaH == null || p.VigenciaH.Value.Date >= p.VigenciaD.Date)
|
||||
))
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "No se puede cerrar este período con la Vigencia Hasta especificada porque se solaparía con un período posterior existente. Ajuste los períodos posteriores primero.");
|
||||
}
|
||||
// Si pasa las validaciones, se asigna la nueva VigenciaH más abajo
|
||||
}
|
||||
// Si updateDto.VigenciaH es null, estas validaciones de fecha no aplican.
|
||||
|
||||
// Aplicar actualizaciones
|
||||
bool seRealizoAlgunaActualizacion = false;
|
||||
|
||||
// Aplicar actualizaciones
|
||||
if (preciosDiasCambiaron)
|
||||
{
|
||||
precioExistente.Lunes = updateDto.Lunes ?? precioExistente.Lunes;
|
||||
precioExistente.Martes = updateDto.Martes ?? precioExistente.Martes;
|
||||
precioExistente.Miercoles = updateDto.Miercoles ?? precioExistente.Miercoles;
|
||||
@@ -155,26 +205,46 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
precioExistente.Viernes = updateDto.Viernes ?? precioExistente.Viernes;
|
||||
precioExistente.Sabado = updateDto.Sabado ?? precioExistente.Sabado;
|
||||
precioExistente.Domingo = updateDto.Domingo ?? precioExistente.Domingo;
|
||||
if (updateDto.VigenciaH.HasValue) // Solo actualizar VigenciaH si se proporciona
|
||||
{
|
||||
precioExistente.VigenciaH = updateDto.VigenciaH.Value.Date;
|
||||
seRealizoAlgunaActualizacion = true;
|
||||
}
|
||||
|
||||
// Actualizar VigenciaH solo si el valor recibido en el DTO es diferente al existente,
|
||||
// o si se quiere pasar de un valor a null (reabrir) o de null a un valor (cerrar).
|
||||
if ((updateDto.VigenciaH.HasValue && (!precioExistente.VigenciaH.HasValue || updateDto.VigenciaH.Value.Date != precioExistente.VigenciaH.Value.Date)) ||
|
||||
(!updateDto.VigenciaH.HasValue && precioExistente.VigenciaH.HasValue))
|
||||
{
|
||||
precioExistente.VigenciaH = updateDto.VigenciaH.HasValue ? updateDto.VigenciaH.Value.Date : (DateTime?)null;
|
||||
seRealizoAlgunaActualizacion = true;
|
||||
}
|
||||
|
||||
if (seRealizoAlgunaActualizacion)
|
||||
{
|
||||
var actualizado = await _precioRepository.UpdateAsync(precioExistente, idUsuario, transaction);
|
||||
if (!actualizado) throw new DataException("Error al actualizar el período de precio.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("No se detectaron cambios para Precio ID {IdPrecio}. No se realizó actualización.", idPrecio);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
_logger.LogInformation("Precio ID {IdPrecio} actualizado por Usuario ID {IdUsuario}.", idPrecio, idUsuario);
|
||||
_logger.LogInformation("Precio ID {IdPrecio} procesado (actualizado si hubo cambios) por Usuario ID {IdUsuario}.", idPrecio, idUsuario);
|
||||
return (true, null);
|
||||
}
|
||||
catch (KeyNotFoundException) { try { transaction.Rollback(); } catch {} return (false, "Período de precio no encontrado.");}
|
||||
catch (KeyNotFoundException) { try { transaction?.Rollback(); } catch { } return (false, "Período de precio no encontrado."); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { transaction.Rollback(); } catch {}
|
||||
try { transaction?.Rollback(); } catch { }
|
||||
_logger.LogError(ex, "Error ActualizarAsync Precio ID: {IdPrecio}", idPrecio);
|
||||
return (false, $"Error interno al actualizar el período de precio: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (connection.State == ConnectionState.Open)
|
||||
{
|
||||
if (connection is System.Data.Common.DbConnection dbConnClose) await dbConnClose.CloseAsync(); else connection.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(bool Exito, string? Error)> EliminarAsync(int idPrecio, int idUsuario)
|
||||
@@ -184,33 +254,33 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
using var transaction = connection.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var precioAEliminar = await _precioRepository.GetByIdAsync(idPrecio);
|
||||
var precioAEliminar = await _precioRepository.GetByIdAsync(idPrecio); // Obtener dentro de TX
|
||||
if (precioAEliminar == null) return (false, "Período de precio no encontrado.");
|
||||
|
||||
// Lógica de ajuste de VigenciaH del período anterior si este que se elimina era el "último" abierto.
|
||||
// Si el precio a eliminar tiene un VigenciaH == null (estaba activo indefinidamente)
|
||||
// Y existe un precio anterior para la misma publicación.
|
||||
// Entonces, el VigenciaH de ese precio anterior debe volver a ser NULL.
|
||||
// --- VERIFICACIÓN DE USO ---
|
||||
if (await _precioRepository.IsInUseAsync(idPrecio, precioAEliminar.VigenciaD, precioAEliminar.VigenciaH))
|
||||
{
|
||||
transaction.Rollback(); // No olvidar rollback si la verificación falla
|
||||
return (false, "No se puede eliminar. Este período de precio está referenciado en movimientos existentes.");
|
||||
}
|
||||
if (precioAEliminar.VigenciaH == null)
|
||||
{
|
||||
var todosLosPreciosPub = (await _precioRepository.GetByPublicacionIdAsync(precioAEliminar.IdPublicacion))
|
||||
.OrderByDescending(p => p.VigenciaD).ToList();
|
||||
|
||||
var indiceActual = todosLosPreciosPub.FindIndex(p => p.IdPrecio == idPrecio);
|
||||
if (indiceActual != -1 && (indiceActual + 1) < todosLosPreciosPub.Count)
|
||||
{
|
||||
var precioAnteriorDirecto = todosLosPreciosPub[indiceActual + 1];
|
||||
// Solo si el precioAnteriorDirecto fue cerrado por este que se elimina
|
||||
if (precioAnteriorDirecto.VigenciaH.HasValue && precioAnteriorDirecto.VigenciaH.Value.Date == precioAEliminar.VigenciaD.AddDays(-1).Date)
|
||||
{
|
||||
precioAnteriorDirecto.VigenciaH = null;
|
||||
await _precioRepository.UpdateAsync(precioAnteriorDirecto, idUsuario, transaction); // Usar un ID de auditoría adecuado
|
||||
_logger.LogInformation("Precio anterior ID {IdPrecioAnterior} reabierto (VigenciaH a NULL) tras eliminación de Precio ID {IdPrecioEliminado}.", precioAnteriorDirecto.IdPrecio, idPrecio);
|
||||
// Asegurar que UpdateAsync tome la transacción
|
||||
await _precioRepository.UpdateAsync(precioAnteriorDirecto, idUsuario, transaction);
|
||||
_logger.LogInformation("Precio anterior ID {IdPrecioAnterior} reabierto tras eliminación de Precio ID {IdPrecioEliminado}.", precioAnteriorDirecto.IdPrecio, idPrecio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var eliminado = await _precioRepository.DeleteAsync(idPrecio, idUsuario, transaction);
|
||||
if (!eliminado) throw new DataException("Error al eliminar el período de precio.");
|
||||
|
||||
@@ -226,5 +296,32 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno al eliminar el período de precio: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PrecioHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPrecioAfectado, int? idPublicacionAfectada)
|
||||
{
|
||||
var historialData = await _precioRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPrecioAfectado, idPublicacionAfectada);
|
||||
|
||||
return historialData.Select(h => new PrecioHistorialDto
|
||||
{
|
||||
Id_Precio = h.Historial.Id_Precio,
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
VigenciaD = h.Historial.VigenciaD,
|
||||
VigenciaH = h.Historial.VigenciaH,
|
||||
Lunes = h.Historial.Lunes,
|
||||
Martes = h.Historial.Martes,
|
||||
Miercoles = h.Historial.Miercoles,
|
||||
Jueves = h.Historial.Jueves,
|
||||
Viernes = h.Historial.Viernes,
|
||||
Sabado = h.Historial.Sabado,
|
||||
Domingo = h.Historial.Domingo,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -149,5 +150,26 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PubliSeccionHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idSeccionAfectada, int? idPublicacionAfectada)
|
||||
{
|
||||
var historialData = await _publiSeccionRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idSeccionAfectada, idPublicacionAfectada);
|
||||
|
||||
// Si necesitas NombrePublicacion, harías la llamada a _publicacionRepository aquí.
|
||||
return historialData.Select(h => new PubliSeccionHistorialDto
|
||||
{
|
||||
Id_Seccion = h.Historial.Id_Seccion,
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
Nombre = h.Historial.Nombre,
|
||||
Estado = h.Historial.Estado,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// src/Services/Distribucion/PublicacionService.cs
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -284,5 +285,28 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno al actualizar la configuración de días: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PublicacionHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPublicacionAfectada)
|
||||
{
|
||||
var historialData = await _publicacionRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idPublicacionAfectada);
|
||||
|
||||
// Si necesitas NombreEmpresa, harías el JOIN en repo o llamada a _empresaRepository aquí.
|
||||
return historialData.Select(h => new PublicacionHistorialDto
|
||||
{
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
Nombre = h.Historial.Nombre,
|
||||
Observacion = h.Historial.Observacion,
|
||||
Id_Empresa = h.Historial.Id_Empresa,
|
||||
Habilitada = h.Historial.Habilitada,
|
||||
// CtrlDevoluciones no está en _H, si se añade, mapearla aquí
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Distribucion;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -76,7 +77,8 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
if (recargo == null) return null;
|
||||
|
||||
var zona = await _zonaRepository.GetByIdAsync(recargo.IdZona); // Obtiene ZonaDto
|
||||
return new RecargoZonaDto {
|
||||
return new RecargoZonaDto
|
||||
{
|
||||
IdRecargo = recargo.IdRecargo,
|
||||
IdPublicacion = recargo.IdPublicacion,
|
||||
IdZona = recargo.IdZona,
|
||||
@@ -134,10 +136,15 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
transaction.Commit();
|
||||
_logger.LogInformation("Recargo ID {Id} creado por Usuario ID {UserId}.", recargoCreado.IdRecargo, idUsuario);
|
||||
// Pasar el nombre de la zona ya obtenido
|
||||
return (new RecargoZonaDto {
|
||||
IdRecargo = recargoCreado.IdRecargo, IdPublicacion = recargoCreado.IdPublicacion, IdZona = recargoCreado.IdZona,
|
||||
NombreZona = zona.Nombre, VigenciaD = recargoCreado.VigenciaD.ToString("yyyy-MM-dd"),
|
||||
VigenciaH = recargoCreado.VigenciaH?.ToString("yyyy-MM-dd"), Valor = recargoCreado.Valor
|
||||
return (new RecargoZonaDto
|
||||
{
|
||||
IdRecargo = recargoCreado.IdRecargo,
|
||||
IdPublicacion = recargoCreado.IdPublicacion,
|
||||
IdZona = recargoCreado.IdZona,
|
||||
NombreZona = zona.Nombre,
|
||||
VigenciaD = recargoCreado.VigenciaD.ToString("yyyy-MM-dd"),
|
||||
VigenciaH = recargoCreado.VigenciaH?.ToString("yyyy-MM-dd"),
|
||||
Valor = recargoCreado.Valor
|
||||
}, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -158,6 +165,13 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
var recargoExistente = await _recargoZonaRepository.GetByIdAsync(idRecargo);
|
||||
if (recargoExistente == null) return (false, "Recargo por zona no encontrado.");
|
||||
|
||||
// --- VERIFICACIÓN PERÍODO CERRADO ---
|
||||
if (recargoExistente.VigenciaH != null && updateDto.Valor != recargoExistente.Valor)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "No se puede modificar el valor de un recargo que ya ha sido cerrado (tiene Vigencia Hasta).");
|
||||
}
|
||||
|
||||
if (updateDto.VigenciaH.HasValue && updateDto.VigenciaH.Value.Date < recargoExistente.VigenciaD.Date)
|
||||
return (false, "Vigencia Hasta no puede ser anterior a Vigencia Desde.");
|
||||
|
||||
@@ -207,6 +221,13 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
var recargoAEliminar = await _recargoZonaRepository.GetByIdAsync(idRecargo);
|
||||
if (recargoAEliminar == null) return (false, "Recargo no encontrado.");
|
||||
|
||||
// --- VERIFICACIÓN DE USO ---
|
||||
if (await _recargoZonaRepository.IsInUseAsync(idRecargo, recargoAEliminar.VigenciaD, recargoAEliminar.VigenciaH))
|
||||
{
|
||||
transaction.Rollback();
|
||||
return (false, "No se puede eliminar. Este recargo está referenciado en movimientos existentes.");
|
||||
}
|
||||
|
||||
if (recargoAEliminar.VigenciaH == null)
|
||||
{
|
||||
var todosRecargosPubZonaData = await _recargoZonaRepository.GetByPublicacionIdAsync(recargoAEliminar.IdPublicacion);
|
||||
@@ -243,5 +264,28 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, $"Error interno: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RecargoZonaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idRecargoAfectado, int? idPublicacionAfectada, int? idZonaAfectada)
|
||||
{
|
||||
var historialData = await _recargoZonaRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idRecargoAfectado, idPublicacionAfectada, idZonaAfectada);
|
||||
|
||||
return historialData.Select(h => new RecargoZonaHistorialDto
|
||||
{
|
||||
Id_Recargo = h.Historial.Id_Recargo,
|
||||
Id_Publicacion = h.Historial.Id_Publicacion,
|
||||
Id_Zona = h.Historial.Id_Zona,
|
||||
VigenciaD = h.Historial.VigenciaD,
|
||||
VigenciaH = h.Historial.VigenciaH,
|
||||
Valor = h.Historial.Valor,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
// Mapear NombrePublicacion y NombreZona si se añaden al DTO
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data.Repositories; // Para IZonaRepository
|
||||
using GestionIntegral.Api.Data.Repositories.Distribucion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Zonas;
|
||||
using GestionIntegral.Api.Models.Distribucion; // Para Zona
|
||||
using System.Collections.Generic;
|
||||
@@ -123,7 +124,8 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
return (false, "Zona no encontrada.");
|
||||
}
|
||||
// Si ya está inactiva, consideramos la operación exitosa (idempotencia)
|
||||
if (!zonaExistente.Estado) {
|
||||
if (!zonaExistente.Estado)
|
||||
{
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
@@ -142,5 +144,25 @@ namespace GestionIntegral.Api.Services.Distribucion
|
||||
}
|
||||
return (true, null); // Éxito
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ZonaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idZonaAfectada)
|
||||
{
|
||||
var historialData = await _zonaRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idZonaAfectada);
|
||||
|
||||
return historialData.Select(h => new ZonaHistorialDto
|
||||
{
|
||||
Id_Zona = h.Historial.Id_Zona,
|
||||
Nombre = h.Historial.Nombre,
|
||||
Descripcion = h.Historial.Descripcion,
|
||||
Estado = h.Historial.Estado,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using GestionIntegral.Api.Data;
|
||||
using GestionIntegral.Api.Data.Repositories.Impresion;
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Impresion;
|
||||
using GestionIntegral.Api.Models.Impresion;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -148,5 +149,24 @@ namespace GestionIntegral.Api.Services.Impresion
|
||||
return (false, $"Error interno al eliminar el estado de bobina: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<EstadoBobinaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idEstadoBobinaAfectado)
|
||||
{
|
||||
var historialData = await _estadoBobinaRepository.GetHistorialAsync(fechaDesde, fechaHasta, idUsuarioModifico, tipoModificacion, idEstadoBobinaAfectado);
|
||||
|
||||
return historialData.Select(h => new EstadoBobinaHistorialDto
|
||||
{
|
||||
Id_EstadoBobina = h.Historial.Id_EstadoBobina,
|
||||
Denominacion = h.Historial.Denominacion,
|
||||
Obs = h.Historial.Obs,
|
||||
Id_Usuario = h.Historial.Id_Usuario,
|
||||
NombreUsuarioModifico = h.NombreUsuarioModifico,
|
||||
FechaMod = h.Historial.FechaMod,
|
||||
TipoMod = h.Historial.TipoMod
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Impresion;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Impresion
|
||||
Task<(EstadoBobinaDto? EstadoBobina, string? Error)> CrearAsync(CreateEstadoBobinaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdateEstadoBobinaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario);
|
||||
Task<IEnumerable<EstadoBobinaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idEstadoBobinaAfectado);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Impresion; // Para los DTOs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,5 +13,9 @@ namespace GestionIntegral.Api.Services.Impresion
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdatePlantaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario);
|
||||
Task<IEnumerable<PlantaDropdownDto>> ObtenerParaDropdownAsync();
|
||||
Task<IEnumerable<PlantaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idPlantaAfectada);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Impresion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,5 +17,9 @@ namespace GestionIntegral.Api.Services.Impresion
|
||||
Task<(bool Exito, string? Error)> ActualizarDatosBobinaDisponibleAsync(int idBobina, UpdateStockBobinaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> CambiarEstadoBobinaAsync(int idBobina, CambiarEstadoBobinaDto cambiarEstadoDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarIngresoErroneoAsync(int idBobina, int idUsuario);
|
||||
Task<IEnumerable<StockBobinaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idBobinaAfectada, int? idTipoBobinaFiltro, int? idPlantaFiltro, int? idEstadoBobinaFiltro);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using GestionIntegral.Api.Dtos.Auditoria;
|
||||
using GestionIntegral.Api.Dtos.Impresion;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,5 +12,9 @@ namespace GestionIntegral.Api.Services.Impresion
|
||||
Task<(TipoBobinaDto? TipoBobina, string? Error)> CrearAsync(CreateTipoBobinaDto createDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> ActualizarAsync(int id, UpdateTipoBobinaDto updateDto, int idUsuario);
|
||||
Task<(bool Exito, string? Error)> EliminarAsync(int id, int idUsuario);
|
||||
Task<IEnumerable<TipoBobinaHistorialDto>> ObtenerHistorialAsync(
|
||||
DateTime? fechaDesde, DateTime? fechaHasta,
|
||||
int? idUsuarioModifico, string? tipoModificacion,
|
||||
int? idTipoBobinaAfectado);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user