Creacion del reporte de cuentas cerradas

feature/reporte_cuentas_cerradas_20240221
Felix Morales 7 months ago
parent 08e7c8f5ec
commit 102207c514
  1. 7
      Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasRepository.cs
  2. 7
      Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasService.cs
  3. 30
      Controllers/Reportes/ReporteCuentasCerradasController.cs
  4. 23
      DTO/Reportes/CuentasCerradas/DTOReporteCuentasCerradas.cs
  5. 5
      Program.cs
  6. 28
      Repository/Reportes/CuentasCerradas/ReporteCuentasCerradasRepository.cs
  7. 39
      Services/Reportes/CuentasCerradas/ReporteCuentasCerradasService.cs

@ -0,0 +1,7 @@
using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas;
namespace CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas{
public interface IReporteCuentasCerradasRepository{
public Task<IEnumerable<DTOCuentasCerradas>> GetCuentasCerradas(string Inicio, string Fin, int TipoOperacion, int NoCliente, int IdCorresponsal);
}
}

@ -0,0 +1,7 @@
using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas;
namespace CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas{
public interface IReporteCuentasCerradasService{
public Task<MemoryStream> GetExcel(IEnumerable<DTOCuentasCerradas> cuentas);
}
}

@ -0,0 +1,30 @@
using CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace CORRESPONSALBackend.Controllers.Reportes{
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ReporteCuentasCerradasController : ControllerBase{
private readonly IReporteCuentasCerradasService _service;
private readonly IReporteCuentasCerradasRepository _repository;
public ReporteCuentasCerradasController(IReporteCuentasCerradasService service, IReporteCuentasCerradasRepository repository){
_service = service;
_repository = repository;
}
[HttpGet("GetExcel")]
public async Task<IActionResult> ReporteCuentasCerradas([FromQuery] string Inicio, string Fin, int TipoOperacion, int NoCliente, int IdCorresponsal){
try{
var cuentas = await _repository.GetCuentasCerradas(Inicio, Fin, TipoOperacion, NoCliente, IdCorresponsal);
var stream = await _service.GetExcel(cuentas);
stream.Position = 0;
return File(stream, "application/octet-stream", $"Reporte.xlsx");
}catch(Exception ex){
return BadRequest(ex.Message);
}
}
}
}

@ -0,0 +1,23 @@
namespace CORRESPONSALBackend.DTO.Reportes.CuentasCerradas{
public class DTOCuentasCerradas{
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 string Aduana { get; set; }
public string Patente { get; set; }
public string Pedimento { get; set; }
public string FechaPago { get; set; }
public string Facturas { get; set; }
public string Descripcion { get; set; }
public string FechaAlta { get; set; }
public string Clave { get; set; }
public string ValorMn { get; set; }
public string ValorDls { get; set; }
public string TipoCambio { get; set; }
public string ValorComercial { get; set; }
public string Fracciones { get; set; }
public string Caja { get; set; }
}
}

@ -47,6 +47,9 @@ using CORRESPONSALBackend.Services.Corresponsalias.Facturas;
using CORRESPONSALBackend.Services.Corresponsalias.Traficos; using CORRESPONSALBackend.Services.Corresponsalias.Traficos;
using CORRESPONSALBackend.Contracts.Reportes.Alen; using CORRESPONSALBackend.Contracts.Reportes.Alen;
using CORRESPONSALBackend.Services.Reportes.Alen; using CORRESPONSALBackend.Services.Reportes.Alen;
using CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas;
using CORRESPONSALBackend.Repository.Reportes.CuentasCerradas;
using CORRESPONSALBackend.Services.Reportes.CuentasCerradas;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -71,6 +74,8 @@ builder.Services.AddScoped<ICorresponsaliasFacturasService, CorresponsaliasFactu
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>(); builder.Services.AddScoped<IReportesAlenRepository, ReportesAlenRepository>();
builder.Services.AddScoped<IReporteCuentasCerradasRepository, ReporteCuentasCerradasRepository>();
builder.Services.AddScoped<IReporteCuentasCerradasService, ReporteCuentasCerradasService>();
// 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,28 @@
using System.Data;
using CORRESPONSALBackend.Context;
using CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas;
using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas;
using Dapper;
namespace CORRESPONSALBackend.Repository.Reportes.CuentasCerradas{
public class ReporteCuentasCerradasRepository : IReporteCuentasCerradasRepository
{
private readonly DapperContext _context;
public ReporteCuentasCerradasRepository(DapperContext context) { _context = context; }
public async Task<IEnumerable<DTOCuentasCerradas>> GetCuentasCerradas(string Inicio, string Fin, int TipoOperacion, int NoCliente, int IdCorresponsal)
{
var query = "[Reportes.CuentasCerradas]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOCuentasCerradas>(query, new
{
@Inicio = Inicio,
@Fin = Fin,
@NoCliente = NoCliente,
@TipoOperacion = TipoOperacion,
@IdCorresponsal = IdCorresponsal
},
commandType: CommandType.StoredProcedure);
return entrada;
}
}
}

@ -0,0 +1,39 @@
using CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas;
using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
namespace CORRESPONSALBackend.Services.Reportes.CuentasCerradas{
public class ReporteCuentasCerradasService : IReporteCuentasCerradasService
{
public async Task<MemoryStream> GetExcel(IEnumerable<DTOCuentasCerradas> cuentas)
{
try{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (ExcelPackage excelPackage = new ExcelPackage()){
var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1");
worksheet.Cells["A1"].LoadFromCollection(cuentas, true);
//Se crea la tabla en el rango de celdas donde se mostrara la inforamcion.
ExcelRange range = worksheet.Cells[1, 1,cuentas.Count() + 1, 19];
ExcelTable tab = worksheet.Tables.Add(range, "Table1");
tab.TableStyle = TableStyles.Light1;
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
worksheet.Column(10).Width = 100;
worksheet.Column(10).Style.WrapText = true;
worksheet.Column(11).Width = 100;
worksheet.Column(11).Style.WrapText = true;
worksheet.Column(19).Width = 100;
worksheet.Column(19).Style.WrapText = true;
worksheet.Cells[worksheet.Dimension.Address].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
excelPackage.Workbook.Calculate();
var stream = new MemoryStream();
excelPackage.SaveAs(stream);
return stream;
}
}catch(Exception ex){
throw new Exception(ex.Message);
}
}
}
}
Loading…
Cancel
Save