Finalización de Endpoints para la gestión de Reportes. Se continúa con el Frontend.
This commit is contained in:
@@ -19,7 +19,7 @@ namespace GestionIntegral.Api.Controllers
|
||||
[Authorize]
|
||||
public class ReportesController : ControllerBase
|
||||
{
|
||||
private readonly IReportesService _reportesService; // <--- CORREGIDO
|
||||
private readonly IReportesService _reportesService;
|
||||
private readonly ILogger<ReportesController> _logger;
|
||||
private readonly IPlantaRepository _plantaRepository;
|
||||
private readonly IPublicacionRepository _publicacionRepository;
|
||||
@@ -217,6 +217,37 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/movimiento-bobinas-estado
|
||||
[HttpGet("movimiento-bobinas-estado")] // Endpoint para los datos JSON
|
||||
[ProducesResponseType(typeof(MovimientoBobinasPorEstadoResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteMovimientoBobinasPorEstado(
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta,
|
||||
[FromQuery] int idPlanta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerReporteMovimientoBobinas)) return Forbid(); // Reutilizar permiso
|
||||
|
||||
var (detalle, totales, error) = await _reportesService.ObtenerMovimientoBobinasPorEstadoAsync(fechaDesde, fechaHasta, idPlanta);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
|
||||
if ((detalle == null || !detalle.Any()) && (totales == null || !totales.Any()))
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para el reporte de movimiento de bobinas por estado." });
|
||||
}
|
||||
|
||||
var response = new MovimientoBobinasPorEstadoResponseDto
|
||||
{
|
||||
Detalle = detalle ?? Enumerable.Empty<MovimientoBobinaEstadoDetalleDto>(),
|
||||
Totales = totales ?? Enumerable.Empty<MovimientoBobinaEstadoTotalDto>()
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("movimiento-bobinas-estado/pdf")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
@@ -266,7 +297,35 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// --- Nuevos Endpoints ---
|
||||
// GET: api/reportes/listado-distribucion-general
|
||||
[HttpGet("listado-distribucion-general")]
|
||||
[ProducesResponseType(typeof(ListadoDistribucionGeneralResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetListadoDistribucionGeneral(
|
||||
[FromQuery] int idPublicacion,
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid();
|
||||
|
||||
var (resumen, promedios, error) = await _reportesService.ObtenerListadoDistribucionGeneralAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if ((resumen == null || !resumen.Any()) && (promedios == null || !promedios.Any()))
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para el listado de distribución general." });
|
||||
}
|
||||
|
||||
var response = new ListadoDistribucionGeneralResponseDto
|
||||
{
|
||||
Resumen = resumen ?? Enumerable.Empty<ListadoDistribucionGeneralResumenDto>(),
|
||||
PromediosPorDia = promedios ?? Enumerable.Empty<ListadoDistribucionGeneralPromedioDiaDto>()
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("listado-distribucion-general/pdf")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
@@ -318,6 +377,36 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/listado-distribucion-canillas
|
||||
[HttpGet("listado-distribucion-canillas")]
|
||||
[ProducesResponseType(typeof(ListadoDistribucionCanillasResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetListadoDistribucionCanillas(
|
||||
[FromQuery] int idPublicacion,
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid();
|
||||
|
||||
var (simple, promedios, error) = await _reportesService.ObtenerListadoDistribucionCanillasAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if ((simple == null || !simple.Any()) && (promedios == null || !promedios.Any()))
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para el listado de distribución de canillas." });
|
||||
}
|
||||
|
||||
var response = new ListadoDistribucionCanillasResponseDto
|
||||
{
|
||||
DetalleSimple = simple ?? Enumerable.Empty<ListadoDistribucionCanillasSimpleDto>(),
|
||||
PromediosPorDia = promedios ?? Enumerable.Empty<ListadoDistribucionCanillasPromedioDiaDto>()
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("listado-distribucion-canillas/pdf")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
@@ -367,6 +456,31 @@ namespace GestionIntegral.Api.Controllers
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Error interno al generar el PDF del reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/listado-distribucion-canillas-importe
|
||||
[HttpGet("listado-distribucion-canillas-importe")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ListadoDistribucionCanillasImporteDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetListadoDistribucionCanillasConImporte(
|
||||
[FromQuery] int idPublicacion,
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta,
|
||||
[FromQuery] bool esAccionista)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid();
|
||||
|
||||
var (data, error) = await _reportesService.ObtenerListadoDistribucionCanillasConImporteAsync(idPublicacion, fechaDesde, fechaHasta, esAccionista);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (data == null || !data.Any())
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para el listado de distribución de canillas con importe." });
|
||||
}
|
||||
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("listado-distribucion-canillas-importe/pdf")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
@@ -420,6 +534,21 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/venta-mensual-secretaria/el-dia
|
||||
[HttpGet("venta-mensual-secretaria/el-dia")]
|
||||
[ProducesResponseType(typeof(IEnumerable<VentaMensualSecretariaElDiaDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaElDia([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid(); // Asumiendo RR002 para todos estos
|
||||
var (data, error) = await _reportesService.ObtenerVentaMensualSecretariaElDiaAsync(fechaDesde, fechaHasta);
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para el reporte de ventas 'El Día'." });
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("venta-mensual-secretaria/el-dia/pdf")]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaElDiaPdf([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
@@ -446,6 +575,21 @@ namespace GestionIntegral.Api.Controllers
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF VentaMensualSecretariaElDia."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/venta-mensual-secretaria/el-plata
|
||||
[HttpGet("venta-mensual-secretaria/el-plata")]
|
||||
[ProducesResponseType(typeof(IEnumerable<VentaMensualSecretariaElPlataDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaElPlata([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid(); // Asumiendo RR002
|
||||
var (data, error) = await _reportesService.ObtenerVentaMensualSecretariaElPlataAsync(fechaDesde, fechaHasta);
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para el reporte de ventas 'El Plata'." });
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("venta-mensual-secretaria/el-plata/pdf")]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaElPlataPdf([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
@@ -471,6 +615,21 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF VentaMensualSecretariaElPlata."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/venta-mensual-secretaria/tirada-devolucion
|
||||
[HttpGet("venta-mensual-secretaria/tirada-devolucion")]
|
||||
[ProducesResponseType(typeof(IEnumerable<VentaMensualSecretariaTirDevoDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaTirDevo([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerListadoDistribucion)) return Forbid(); // Asumiendo RR002
|
||||
var (data, error) = await _reportesService.ObtenerVentaMensualSecretariaTirDevoAsync(fechaDesde, fechaHasta);
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para el reporte de tirada/devolución." });
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("venta-mensual-secretaria/tirada-devolucion/pdf")]
|
||||
public async Task<IActionResult> GetVentaMensualSecretariaTirDevoPdf([FromQuery] DateTime fechaDesde, [FromQuery] DateTime fechaHasta)
|
||||
@@ -497,20 +656,74 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF VentaMensualSecretariaTirDevo."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/distribucion-canillas
|
||||
[HttpGet("distribucion-canillas")] // Endpoint para los datos JSON
|
||||
[ProducesResponseType(typeof(ReporteDistribucionCanillasResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteDistribucionCanillasData([FromQuery] DateTime fecha, [FromQuery] int idEmpresa)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerComprobanteLiquidacionCanilla)) return Forbid();
|
||||
|
||||
var (canillas, canillasAcc, canillasAll, canillasFechaLiq, canillasAccFechaLiq,
|
||||
ctrlDevolucionesRemitos, ctrlDevolucionesParaDistCan, ctrlDevolucionesOtrosDias, error) =
|
||||
await _reportesService.ObtenerReporteDistribucionCanillasAsync(fecha, idEmpresa);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
|
||||
// Una validación simple, podrías hacerla más granular si es necesario
|
||||
bool noHayDatos = (canillas == null || !canillas.Any()) &&
|
||||
(canillasAcc == null || !canillasAcc.Any()) &&
|
||||
(canillasAll == null || !canillasAll.Any()) &&
|
||||
(ctrlDevolucionesParaDistCan == null || !ctrlDevolucionesParaDistCan.Any()); // Podrías añadir más aquí
|
||||
|
||||
if (noHayDatos)
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para el reporte de distribución de canillas." });
|
||||
}
|
||||
|
||||
var response = new ReporteDistribucionCanillasResponseDto
|
||||
{
|
||||
Canillas = canillas ?? Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
CanillasAccionistas = canillasAcc ?? Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
CanillasTodos = canillasAll ?? Enumerable.Empty<DetalleDistribucionCanillaAllDto>(),
|
||||
CanillasLiquidadasOtraFecha = canillasFechaLiq ?? Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
CanillasAccionistasLiquidadasOtraFecha = canillasAccFechaLiq ?? Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
ControlDevolucionesRemitos = ctrlDevolucionesRemitos ?? Enumerable.Empty<ObtenerCtrlDevolucionesDto>(),
|
||||
ControlDevolucionesDetalle = ctrlDevolucionesParaDistCan ?? Enumerable.Empty<ControlDevolucionesReporteDto>(),
|
||||
ControlDevolucionesOtrosDias = ctrlDevolucionesOtrosDias ?? Enumerable.Empty<DevueltosOtrosDiasDto>()
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("distribucion-canillas/pdf")]
|
||||
public async Task<IActionResult> GetReporteDistribucionCanillasPdf([FromQuery] DateTime fecha, [FromQuery] int idEmpresa, [FromQuery] bool soloTotales = false)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerComprobanteLiquidacionCanilla)) return Forbid();
|
||||
|
||||
var (canillas, canillasAcc, canillasAll, canillasFechaLiq, canillasAccFechaLiq, ctrlDevoluciones, ctrlDevolucionesParaDistCan, error) =
|
||||
await _reportesService.ObtenerReporteDistribucionCanillasAsync(fecha, idEmpresa);
|
||||
// CORRECCIÓN AQUÍ: Añadir la variable para el nuevo elemento de la tupla
|
||||
var (
|
||||
canillas,
|
||||
canillasAcc,
|
||||
canillasAll,
|
||||
canillasFechaLiq,
|
||||
canillasAccFechaLiq,
|
||||
ctrlDevolucionesRemitos, // Renombrado para claridad
|
||||
ctrlDevolucionesParaDistCan,
|
||||
_ , // Descartamos ctrlDevolucionesOtrosDias si no se usa aquí
|
||||
error
|
||||
) = await _reportesService.ObtenerReporteDistribucionCanillasAsync(fecha, idEmpresa);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
|
||||
// La lógica de noHayDatosParaTotales y noHayDatosParaDetalle debería usar los nombres correctos
|
||||
bool noHayDatosParaTotales = (canillasAll == null || !canillasAll.Any()) &&
|
||||
(ctrlDevoluciones == null || !ctrlDevoluciones.Any()) &&
|
||||
(ctrlDevolucionesRemitos == null || !ctrlDevolucionesRemitos.Any()) && // Usar ctrlDevolucionesRemitos o ctrlDevolucionesParaDistCan según el RDLC
|
||||
(ctrlDevolucionesParaDistCan == null || !ctrlDevolucionesParaDistCan.Any());
|
||||
|
||||
bool noHayDatosParaDetalle = noHayDatosParaTotales &&
|
||||
(canillas == null || !canillas.Any()) &&
|
||||
(canillasAcc == null || !canillasAcc.Any()) &&
|
||||
@@ -537,7 +750,7 @@ namespace GestionIntegral.Api.Controllers
|
||||
report.DataSources.Add(new ReportDataSource("DSListadoDistribucionCanALL", canillasAll ?? new List<DetalleDistribucionCanillaAllDto>()));
|
||||
report.DataSources.Add(new ReportDataSource("DSListadoDistribucionCanFechaLiq", canillasFechaLiq ?? new List<DetalleDistribucionCanillaDto>()));
|
||||
report.DataSources.Add(new ReportDataSource("DSListadoDistribucionCanAccFechaLiq", canillasAccFechaLiq ?? new List<DetalleDistribucionCanillaDto>()));
|
||||
report.DataSources.Add(new ReportDataSource("DSObtenerCtrlDevoluciones", ctrlDevoluciones ?? new List<ObtenerCtrlDevolucionesDto>()));
|
||||
report.DataSources.Add(new ReportDataSource("DSObtenerCtrlDevoluciones", ctrlDevolucionesRemitos ?? new List<ObtenerCtrlDevolucionesDto>())); // Usa el renombrado
|
||||
report.DataSources.Add(new ReportDataSource("DSCtrlDevoluciones", ctrlDevolucionesParaDistCan ?? new List<ControlDevolucionesReporteDto>()));
|
||||
|
||||
var empresa = await _empresaRepository.GetByIdAsync(idEmpresa);
|
||||
@@ -560,20 +773,69 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/control-devoluciones
|
||||
[HttpGet("control-devoluciones")]
|
||||
[ProducesResponseType(typeof(ControlDevolucionesDataResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetControlDevolucionesData([FromQuery] DateTime fecha, [FromQuery] int idEmpresa)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerControlDevoluciones)) return Forbid();
|
||||
|
||||
var (
|
||||
_, // canillas
|
||||
_, // canillasAcc
|
||||
_, // canillasAll
|
||||
_, // canillasFechaLiq
|
||||
_, // canillasAccFechaLiq
|
||||
ctrlDevolucionesRemitosData, // Para SP_ObtenerCtrlDevoluciones -> DataSet "DSObtenerCtrlDevoluciones"
|
||||
ctrlDevolucionesParaDistCanData, // Para SP_DistCanillasCantidadEntradaSalida -> DataSet "DSCtrlDevoluciones"
|
||||
ctrlDevolucionesOtrosDiasData, // Para SP_DistCanillasCantidadEntradaSalidaOtrosDias -> DataSet "DSCtrlDevolucionesOtrosDias"
|
||||
error
|
||||
) = await _reportesService.ObtenerReporteDistribucionCanillasAsync(fecha, idEmpresa); // Reutilizamos este método
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
|
||||
// Adaptar la condición de "no hay datos" a los DataSets que realmente usa este reporte
|
||||
if ((ctrlDevolucionesParaDistCanData == null || !ctrlDevolucionesParaDistCanData.Any()) &&
|
||||
(ctrlDevolucionesOtrosDiasData == null || !ctrlDevolucionesOtrosDiasData.Any()) &&
|
||||
(ctrlDevolucionesRemitosData == null || !ctrlDevolucionesRemitosData.Any()))
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para generar el reporte de control de devoluciones." });
|
||||
}
|
||||
|
||||
var response = new ControlDevolucionesDataResponseDto
|
||||
{
|
||||
DetallesCtrlDevoluciones = ctrlDevolucionesParaDistCanData ?? Enumerable.Empty<ControlDevolucionesReporteDto>(),
|
||||
DevolucionesOtrosDias = ctrlDevolucionesOtrosDiasData ?? Enumerable.Empty<DevueltosOtrosDiasDto>(),
|
||||
RemitosIngresados = ctrlDevolucionesRemitosData ?? Enumerable.Empty<ObtenerCtrlDevolucionesDto>()
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("control-devoluciones/pdf")]
|
||||
public async Task<IActionResult> GetReporteControlDevolucionesPdf([FromQuery] DateTime fecha, [FromQuery] int idEmpresa)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerControlDevoluciones)) return Forbid();
|
||||
|
||||
// La tupla ahora devuelve un campo más
|
||||
var (
|
||||
_, _, _, _, _,
|
||||
ctrlDevolucionesData, // Este es el que usa el DataSet "DSObtenerCtrlDevoluciones"
|
||||
ctrlDevolucionesParaDistCanData, // Este es el que usa el DataSet "DSCtrlDevoluciones"
|
||||
ctrlDevolucionesRemitosData, // Para DSObtenerCtrlDevoluciones
|
||||
ctrlDevolucionesParaDistCanData, // Para DSCtrlDevoluciones
|
||||
ctrlDevolucionesOtrosDiasData, // <--- NUEVO: Para DSCtrlDevolucionesOtrosDias
|
||||
error
|
||||
) = await _reportesService.ObtenerReporteDistribucionCanillasAsync(fecha, idEmpresa);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if ((ctrlDevolucionesData == null || !ctrlDevolucionesData.Any()) && (ctrlDevolucionesParaDistCanData == null || !ctrlDevolucionesParaDistCanData.Any()))
|
||||
|
||||
// Ajustamos la condición para verificar los DataSets que realmente usa este reporte específico
|
||||
if ((ctrlDevolucionesRemitosData == null || !ctrlDevolucionesRemitosData.Any()) &&
|
||||
(ctrlDevolucionesParaDistCanData == null || !ctrlDevolucionesParaDistCanData.Any()) &&
|
||||
(ctrlDevolucionesOtrosDiasData == null || !ctrlDevolucionesOtrosDiasData.Any()) // <--- AÑADIDO A LA VERIFICACIÓN
|
||||
)
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para generar el PDF para control de devoluciones." });
|
||||
}
|
||||
@@ -585,8 +847,15 @@ namespace GestionIntegral.Api.Controllers
|
||||
{
|
||||
report.LoadReportDefinition(fs);
|
||||
}
|
||||
|
||||
// DataSet que usa SP_DistCanillasCantidadEntradaSalida
|
||||
report.DataSources.Add(new ReportDataSource("DSCtrlDevoluciones", ctrlDevolucionesParaDistCanData ?? new List<ControlDevolucionesReporteDto>()));
|
||||
report.DataSources.Add(new ReportDataSource("DSObtenerCtrlDevoluciones", ctrlDevolucionesData ?? new List<ObtenerCtrlDevolucionesDto>()));
|
||||
|
||||
// DataSet que usa SP_DistCanillasCantidadEntradaSalidaOtrosDias
|
||||
report.DataSources.Add(new ReportDataSource("DSCtrlDevolucionesOtrosDias", ctrlDevolucionesOtrosDiasData ?? new List<DevueltosOtrosDiasDto>())); // <--- CORREGIDO
|
||||
|
||||
// DataSet que usa SP_ObtenerCtrlDevoluciones
|
||||
report.DataSources.Add(new ReportDataSource("DSObtenerCtrlDevoluciones", ctrlDevolucionesRemitosData ?? new List<ObtenerCtrlDevolucionesDto>()));
|
||||
|
||||
|
||||
var empresa = await _empresaRepository.GetByIdAsync(idEmpresa);
|
||||
@@ -608,6 +877,44 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/cuentas-distribuidores
|
||||
[HttpGet("cuentas-distribuidores")]
|
||||
[ProducesResponseType(typeof(ReporteCuentasDistribuidorResponseDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteCuentasDistribuidoresData(
|
||||
[FromQuery] int idDistribuidor,
|
||||
[FromQuery] int idEmpresa,
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerBalanceCuentas)) return Forbid();
|
||||
|
||||
var (entradasSalidas, debitosCreditos, pagos, saldos, error) =
|
||||
await _reportesService.ObtenerReporteCuentasDistribuidorAsync(idDistribuidor, idEmpresa, fechaDesde, fechaHasta);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (!entradasSalidas.Any() && !debitosCreditos.Any() && !pagos.Any() && !saldos.Any())
|
||||
{
|
||||
return NotFound(new { message = "No hay datos para generar el reporte de cuenta del distribuidor." });
|
||||
}
|
||||
|
||||
var distribuidor = await _distribuidorRepository.GetByIdAsync(idDistribuidor);
|
||||
var empresa = await _empresaRepository.GetByIdAsync(idEmpresa);
|
||||
|
||||
var response = new ReporteCuentasDistribuidorResponseDto
|
||||
{
|
||||
EntradasSalidas = entradasSalidas ?? Enumerable.Empty<BalanceCuentaDistDto>(),
|
||||
DebitosCreditos = debitosCreditos ?? Enumerable.Empty<BalanceCuentaDebCredDto>(),
|
||||
Pagos = pagos ?? Enumerable.Empty<BalanceCuentaPagosDto>(),
|
||||
Saldos = saldos ?? Enumerable.Empty<SaldoDto>(),
|
||||
NombreDistribuidor = distribuidor.Distribuidor?.Nombre,
|
||||
NombreEmpresa = empresa?.Nombre
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("cuentas-distribuidores/pdf")]
|
||||
public async Task<IActionResult> GetReporteCuentasDistribuidoresPdf(
|
||||
@@ -658,6 +965,40 @@ namespace GestionIntegral.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/reportes/tiradas-publicaciones-secciones
|
||||
[HttpGet("tiradas-publicaciones-secciones")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TiradasPublicacionesSeccionesDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteTiradasPublicacionesSeccionesData(
|
||||
[FromQuery] int idPublicacion,
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta,
|
||||
[FromQuery] int? idPlanta,
|
||||
[FromQuery] bool consolidado = false)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerReporteTiradas)) return Forbid();
|
||||
|
||||
IEnumerable<TiradasPublicacionesSeccionesDto> data;
|
||||
string? errorMsg;
|
||||
|
||||
if (consolidado)
|
||||
{
|
||||
(data, errorMsg) = await _reportesService.ObtenerTiradasPublicacionesSeccionesConsolidadoAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!idPlanta.HasValue) return BadRequest(new { message = "Se requiere IdPlanta para reportes no consolidados." });
|
||||
(data, errorMsg) = await _reportesService.ObtenerTiradasPublicacionesSeccionesAsync(idPublicacion, fechaDesde, fechaHasta, idPlanta.Value);
|
||||
}
|
||||
|
||||
if (errorMsg != null) return BadRequest(new { message = errorMsg });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para generar el reporte." });
|
||||
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("tiradas-publicaciones-secciones/pdf")]
|
||||
public async Task<IActionResult> GetReporteTiradasPublicacionesSeccionesPdf(
|
||||
[FromQuery] int idPublicacion,
|
||||
@@ -718,6 +1059,39 @@ namespace GestionIntegral.Api.Controllers
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF Tiradas Publicaciones Secciones."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/consumo-bobinas-seccion
|
||||
[HttpGet("consumo-bobinas-seccion")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ConsumoBobinasSeccionDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteConsumoBobinasSeccionData(
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta,
|
||||
[FromQuery] int? idPlanta,
|
||||
[FromQuery] bool consolidado = false)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerReporteConsumoBobinas)) return Forbid();
|
||||
|
||||
IEnumerable<ConsumoBobinasSeccionDto> data;
|
||||
string? errorMsg;
|
||||
|
||||
if (consolidado)
|
||||
{
|
||||
(data, errorMsg) = await _reportesService.ObtenerConsumoBobinasPorSeccionConsolidadoAsync(fechaDesde, fechaHasta);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!idPlanta.HasValue) return BadRequest(new { message = "Se requiere IdPlanta para reportes no consolidados." });
|
||||
(data, errorMsg) = await _reportesService.ObtenerConsumoBobinasPorSeccionAsync(fechaDesde, fechaHasta, idPlanta.Value);
|
||||
}
|
||||
|
||||
if (errorMsg != null) return BadRequest(new { message = errorMsg });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para generar el reporte." });
|
||||
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("consumo-bobinas-seccion/pdf")]
|
||||
public async Task<IActionResult> GetReporteConsumoBobinasSeccionPdf(
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
@@ -774,6 +1148,26 @@ namespace GestionIntegral.Api.Controllers
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF Consumo Bobinas por Seccion."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/consumo-bobinas-publicacion
|
||||
[HttpGet("consumo-bobinas-publicacion")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ConsumoBobinasPublicacionDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteConsumoBobinasPublicacionData(
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
[FromQuery] DateTime fechaHasta)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerReporteConsumoBobinas)) return Forbid();
|
||||
|
||||
var (data, error) = await _reportesService.ObtenerConsumoBobinasPorPublicacionAsync(fechaDesde, fechaHasta);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para generar el reporte." });
|
||||
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("consumo-bobinas-publicacion/pdf")]
|
||||
public async Task<IActionResult> GetReporteConsumoBobinasPublicacionPdf(
|
||||
[FromQuery] DateTime fechaDesde,
|
||||
@@ -809,6 +1203,39 @@ namespace GestionIntegral.Api.Controllers
|
||||
catch (Exception ex) { _logger.LogError(ex, "Error PDF Consumo Bobinas por Publicacion."); return StatusCode(500, "Error interno."); }
|
||||
}
|
||||
|
||||
// GET: api/reportes/comparativa-consumo-bobinas
|
||||
[HttpGet("comparativa-consumo-bobinas")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ComparativaConsumoBobinasDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetReporteComparativaConsumoBobinasData(
|
||||
[FromQuery] DateTime fechaInicioMesA, [FromQuery] DateTime fechaFinMesA,
|
||||
[FromQuery] DateTime fechaInicioMesB, [FromQuery] DateTime fechaFinMesB,
|
||||
[FromQuery] int? idPlanta,
|
||||
[FromQuery] bool consolidado = false)
|
||||
{
|
||||
if (!TienePermiso(PermisoVerReporteConsumoBobinas)) return Forbid();
|
||||
|
||||
IEnumerable<ComparativaConsumoBobinasDto> data;
|
||||
string? errorMsg;
|
||||
|
||||
if (consolidado)
|
||||
{
|
||||
(data, errorMsg) = await _reportesService.ObtenerComparativaConsumoBobinasConsolidadoAsync(fechaInicioMesA, fechaFinMesA, fechaInicioMesB, fechaFinMesB);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!idPlanta.HasValue) return BadRequest(new { message = "Se requiere IdPlanta para reportes no consolidados." });
|
||||
(data, errorMsg) = await _reportesService.ObtenerComparativaConsumoBobinasAsync(fechaInicioMesA, fechaFinMesA, fechaInicioMesB, fechaFinMesB, idPlanta.Value);
|
||||
}
|
||||
|
||||
if (errorMsg != null) return BadRequest(new { message = errorMsg });
|
||||
if (data == null || !data.Any()) return NotFound(new { message = "No hay datos para generar el reporte." });
|
||||
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[HttpGet("comparativa-consumo-bobinas/pdf")]
|
||||
public async Task<IActionResult> GetReporteComparativaConsumoBobinasPdf(
|
||||
[FromQuery] DateTime fechaInicioMesA, [FromQuery] DateTime fechaFinMesA,
|
||||
|
||||
Reference in New Issue
Block a user