Finalización de Reportes y arreglos varios de controles y comportamientos...
This commit is contained in:
@@ -1384,5 +1384,78 @@ namespace GestionIntegral.Api.Controllers
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Error interno al generar el PDF del reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("ticket-liquidacion-canilla/pdf")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetTicketLiquidacionCanillaPdf(
|
||||
[FromQuery] DateTime fecha,
|
||||
[FromQuery] int idCanilla,
|
||||
[FromQuery] bool esAccionista = false) // Añadir esAccionista
|
||||
{
|
||||
// Usar PermisoVerComprobanteLiquidacionCanilla o uno específico si lo creas
|
||||
if (!TienePermiso(PermisoVerComprobanteLiquidacionCanilla)) return Forbid();
|
||||
|
||||
var (detalles, ganancias, error) = await _reportesService.ObtenerDatosTicketLiquidacionAsync(fecha, idCanilla);
|
||||
|
||||
if (error != null) return BadRequest(new { message = error });
|
||||
|
||||
// El PDF podría funcionar incluso si solo uno de los datasets tiene datos,
|
||||
// pero es bueno verificar si al menos hay detalles.
|
||||
if (detalles == null || !detalles.Any())
|
||||
{
|
||||
return NotFound(new { message = "No hay detalles de liquidación para generar el PDF." });
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LocalReport report = new LocalReport();
|
||||
string rdlcPath = esAccionista ?
|
||||
"Controllers/Reportes/RDLC/ReporteLiquidacionCanillasAcc.rdlc" :
|
||||
"Controllers/Reportes/RDLC/ReporteLiquidacionCanillas.rdlc";
|
||||
|
||||
if (!System.IO.File.Exists(rdlcPath))
|
||||
{
|
||||
_logger.LogError("Archivo RDLC no encontrado: {Path}", rdlcPath);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, $"Archivo de reporte no encontrado: {System.IO.Path.GetFileName(rdlcPath)}");
|
||||
}
|
||||
|
||||
using (var fs = new FileStream(rdlcPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
report.LoadReportDefinition(fs);
|
||||
}
|
||||
|
||||
report.DataSources.Add(new ReportDataSource("DSLiquidacionCanillas", detalles));
|
||||
if (!esAccionista) // El reporte de accionistas podría no usar el dataset de ganancias, o usar uno diferente
|
||||
{
|
||||
report.DataSources.Add(new ReportDataSource("DSLiquidacionCanillasGanancias", ganancias ?? new List<LiquidacionCanillaGananciaDto>()));
|
||||
}
|
||||
|
||||
|
||||
var parameters = new List<ReportParameter>
|
||||
{
|
||||
// El RDLC espera "FechaLiqui"
|
||||
new ReportParameter("FechaLiqui", fecha.ToString("dd/MM/yyyy"))
|
||||
};
|
||||
// El nombre del canilla ya está en el DataSet "DSLiquidacionCanillas" (campo "Canilla")
|
||||
// Si el RDLC lo espera como parámetro, lo añadiríamos aquí.
|
||||
// var canilla = await _canillaRepository.GetByIdAsync(idCanilla);
|
||||
// parameters.Add(new ReportParameter("NombreCanillaParam", canilla?.NomApe ?? "N/A"));
|
||||
|
||||
report.SetParameters(parameters);
|
||||
|
||||
byte[] pdfBytes = report.Render("PDF");
|
||||
string tipo = esAccionista ? "Accionista" : "Canillita";
|
||||
string fileName = $"TicketLiquidacion_{tipo}_{idCanilla}_{fecha:yyyyMMdd}.pdf";
|
||||
return File(pdfBytes, "application/pdf", fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al generar PDF para Ticket Liquidación Canilla. Fecha: {Fecha}, Canilla: {IdCanilla}", fecha, idCanilla);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Error interno al generar el PDF del ticket.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user