diff --git a/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasRepository.cs b/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasRepository.cs new file mode 100644 index 0000000..7ad99d1 --- /dev/null +++ b/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasRepository.cs @@ -0,0 +1,7 @@ +using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas; + +namespace CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas{ + public interface IReporteCuentasCerradasRepository{ + public Task> GetCuentasCerradas(string Inicio, string Fin, int TipoOperacion, int NoCliente, int IdCorresponsal); + } +} \ No newline at end of file diff --git a/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasService.cs b/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasService.cs new file mode 100644 index 0000000..642141d --- /dev/null +++ b/Contracts/Reportes/CuentasCerradas/IReporteCuentasCerradasService.cs @@ -0,0 +1,7 @@ +using CORRESPONSALBackend.DTO.Reportes.CuentasCerradas; + +namespace CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas{ + public interface IReporteCuentasCerradasService{ + public Task GetExcel(IEnumerable cuentas); + } +} \ No newline at end of file diff --git a/Controllers/Reportes/ReporteCuentasCerradasController.cs b/Controllers/Reportes/ReporteCuentasCerradasController.cs new file mode 100644 index 0000000..a87847f --- /dev/null +++ b/Controllers/Reportes/ReporteCuentasCerradasController.cs @@ -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 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); + } + } + + } +} \ No newline at end of file diff --git a/DTO/Reportes/CuentasCerradas/DTOReporteCuentasCerradas.cs b/DTO/Reportes/CuentasCerradas/DTOReporteCuentasCerradas.cs new file mode 100644 index 0000000..7107ae9 --- /dev/null +++ b/DTO/Reportes/CuentasCerradas/DTOReporteCuentasCerradas.cs @@ -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; } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 2cb0a84..3cbd20b 100644 --- a/Program.cs +++ b/Program.cs @@ -47,6 +47,9 @@ using CORRESPONSALBackend.Services.Corresponsalias.Facturas; using CORRESPONSALBackend.Services.Corresponsalias.Traficos; using CORRESPONSALBackend.Contracts.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); @@ -71,6 +74,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); // Corresponsalias builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Repository/Reportes/CuentasCerradas/ReporteCuentasCerradasRepository.cs b/Repository/Reportes/CuentasCerradas/ReporteCuentasCerradasRepository.cs new file mode 100644 index 0000000..49c2d94 --- /dev/null +++ b/Repository/Reportes/CuentasCerradas/ReporteCuentasCerradasRepository.cs @@ -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> 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(query, new + { + @Inicio = Inicio, + @Fin = Fin, + @NoCliente = NoCliente, + @TipoOperacion = TipoOperacion, + @IdCorresponsal = IdCorresponsal + }, + commandType: CommandType.StoredProcedure); + return entrada; + } + } +} \ No newline at end of file diff --git a/Services/Reportes/CuentasCerradas/ReporteCuentasCerradasService.cs b/Services/Reportes/CuentasCerradas/ReporteCuentasCerradasService.cs new file mode 100644 index 0000000..a6c2e20 --- /dev/null +++ b/Services/Reportes/CuentasCerradas/ReporteCuentasCerradasService.cs @@ -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 GetExcel(IEnumerable 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); + } + } + } +} \ No newline at end of file