Creacion del reporte de facturas de traficos consolidados de Alen

feature/ReportesContabilidad_FacturasTraficosConsolidadosAlen_20240116
Felix Morales 8 months ago
parent b9f26944fb
commit 2d2819ba97
  1. 5
      Contracts/Reportes/Alen/IReportesAlenRepository.cs
  2. 1
      Contracts/Reportes/Alen/IReportesAlenService.cs
  3. 16
      Controllers/Reportes/ReportesAlenController.cs
  4. 20
      DTO/Reportes/Alen/DTOReporteFacturasTraficosConsolidados.cs
  5. 2
      Program.cs
  6. 22
      Repository/Reportes/Alen/ReportesAlenRepository.cs
  7. 31
      Services/Reportes/Alen/ReportesAlenService.cs

@ -0,0 +1,5 @@
namespace CORRESPONSALBackend.Contracts.Reportes.Alen{
public interface IReportesAlenRepository{
public Task<IEnumerable<DTOReporteFacturasTraficosConsolidados>> GetFacturasTraficoConsolidado(int idTrafico, string referencia);
}
}

@ -3,5 +3,6 @@ using CORRESPONSALBackend.Models.Corresponsales;
namespace CORRESPONSALBackend.Contracts.Reportes.Alen{ namespace CORRESPONSALBackend.Contracts.Reportes.Alen{
public interface IReportesAlenService{ public interface IReportesAlenService{
public Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores); public Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores);
public Task<MemoryStream> GetReporteFacturasTraficoConsolidado(string referencia);
} }
} }

@ -38,5 +38,21 @@ namespace CORRESPONSALBackend.Controllers.Reportes{
return BadRequest(ex.Message); return BadRequest(ex.Message);
} }
} }
[HttpGet("FacturasConsolidados")]
public async Task<IActionResult> FacturasConsolidados([FromQuery] string referencia){
try{
var trafico = await _traficosRepository.GetByReferencia(referencia);
var stream = await _reportesAlenService.GetReporteFacturasTraficoConsolidado(referencia);
if(stream.Length > 0){
stream.Position = 0;
return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"FacturasConsolidado_{trafico.FolioGemco}.xlsx");
}else{
throw new Exception("Ocurrio un error al generar el reporte, intentelo de nuevo");
}
}catch(Exception ex){
return BadRequest(ex.Message);
}
}
} }
} }

@ -0,0 +1,20 @@
public class DTOReporteFacturasTraficosConsolidados{
public string trafico { get; set; }
public string TipoOperacion { get; set; }
public string Cliente { get; set; }
public string Proveedor { get; set; }
public string Corresponsal { get; set; }
public int Aduana { get; set; }
public int Patente { get; set; }
public string Pedimento { get; set; }
public int PedimentoMaster { get; set; }
public string Fecha { get; set; }
public string Cuenta { get; set; }
public string Factura { get; set; }
public string Descripcion { get; set; }
public string Semaforo { get; set; }
public string ClavePedimento { get; set; }
public string TipoCambio { get; set; }
public string Operacion { get; set; }
public string Contenedor { get; set; }
}

@ -70,7 +70,7 @@ builder.Services.AddScoped<IReporteGC50Repository, ReporteGC50Repository>();
builder.Services.AddScoped<ICorresponsaliasFacturasService, CorresponsaliasFactuasService>(); builder.Services.AddScoped<ICorresponsaliasFacturasService, CorresponsaliasFactuasService>();
builder.Services.AddScoped<ICorresponsaliasTraficosService, CorresponsaliasTraficosService>(); builder.Services.AddScoped<ICorresponsaliasTraficosService, CorresponsaliasTraficosService>();
builder.Services.AddScoped<IReportesAlenService, ReportesAlenService>(); builder.Services.AddScoped<IReportesAlenService, ReportesAlenService>();
builder.Services.AddScoped<IReportesAlenRepository, ReportesAlenRepository>();
// Corresponsalias // Corresponsalias
builder.Services.AddScoped<IContabilidadCorresponsaliasRepository, ContabilidadCorresponsaliasRepository>(); builder.Services.AddScoped<IContabilidadCorresponsaliasRepository, ContabilidadCorresponsaliasRepository>();
builder.Services.AddScoped<ICorresponsaliasContenedoresRepository, CorresponsaliasContenedoresRepository>(); builder.Services.AddScoped<ICorresponsaliasContenedoresRepository, CorresponsaliasContenedoresRepository>();

@ -0,0 +1,22 @@
using System.Data;
using CORRESPONSALBackend.Context;
using CORRESPONSALBackend.Contracts.Reportes.Alen;
using Dapper;
public class ReportesAlenRepository : IReportesAlenRepository
{
private readonly DapperContext _context;
public ReportesAlenRepository(DapperContext context) { _context = context; }
public async Task<IEnumerable<DTOReporteFacturasTraficosConsolidados>> GetFacturasTraficoConsolidado(int idTrafico, string referencia)
{
var query = "[Reportes.Alen.FacturasTraficosConsolidados]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOReporteFacturasTraficosConsolidados>(query, new
{
@IdTrafico = idTrafico,
@Referencia = referencia
},
commandType: CommandType.StoredProcedure);
return entrada;
}
}

@ -1,3 +1,4 @@
using CORRESPONSALBackend.Contracts.Corresponsalias;
using CORRESPONSALBackend.Contracts.Reportes.Alen; using CORRESPONSALBackend.Contracts.Reportes.Alen;
using CORRESPONSALBackend.Models.Corresponsales; using CORRESPONSALBackend.Models.Corresponsales;
using OfficeOpenXml; using OfficeOpenXml;
@ -6,6 +7,12 @@ using OfficeOpenXml.Table;
namespace CORRESPONSALBackend.Services.Reportes.Alen{ namespace CORRESPONSALBackend.Services.Reportes.Alen{
public class ReportesAlenService : IReportesAlenService public class ReportesAlenService : IReportesAlenService
{ {
private readonly ICorresponsaliasTraficosRepository _traficosRepo;
private readonly IReportesAlenRepository _repo;
public ReportesAlenService(ICorresponsaliasTraficosRepository traficosRepo, IReportesAlenRepository repo){
_traficosRepo = traficosRepo;
_repo = repo;
}
public async Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores) public async Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores)
{ {
try{ try{
@ -64,5 +71,29 @@ namespace CORRESPONSALBackend.Services.Reportes.Alen{
throw new Exception(ex.Message); throw new Exception(ex.Message);
} }
} }
public async Task<MemoryStream> GetReporteFacturasTraficoConsolidado(string referencia)
{
try{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (ExcelPackage excelPackage = new ExcelPackage()){
var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1");
var trafico = await _traficosRepo.GetByReferencia(referencia);
var facturas = await _repo.GetFacturasTraficoConsolidado(trafico.id, referencia);
worksheet.Cells["A1"].LoadFromCollection(facturas, true);
ExcelRange range = worksheet.Cells[1, 1,facturas.Count() + 1, 18];
ExcelTable tab = worksheet.Tables.Add(range, "Table1");
tab.TableStyle = TableStyles.Light1;
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
excelPackage.Workbook.Calculate();
var stream = new MemoryStream();
excelPackage.SaveAs(stream);
stream.Position = 0;
return stream;
}
}catch(Exception ex){
throw new Exception(ex.Message);
}
}
} }
} }
Loading…
Cancel
Save