diff --git a/Contracts/Reportes/Facturacion/IReportesFacturacionRepository.cs b/Contracts/Reportes/Facturacion/IReportesFacturacionRepository.cs new file mode 100644 index 0000000..df9ba50 --- /dev/null +++ b/Contracts/Reportes/Facturacion/IReportesFacturacionRepository.cs @@ -0,0 +1,8 @@ +using CORRESPONSALBackend.DTO.Reportes; +using CORRESPONSALBackend.DTO.Reportes.Facturacion; + +namespace CORRESPONSALBackend.Contracts.Reportes.Facturacion{ + public interface IReportesFacturacionRepository{ + public Task> GetCuentasFacturadas(DTOReporteCorresponsales data); + } +} \ No newline at end of file diff --git a/Controllers/Reportes/Facturacion/ReportesFacturacionController.cs b/Controllers/Reportes/Facturacion/ReportesFacturacionController.cs new file mode 100644 index 0000000..db318e7 --- /dev/null +++ b/Controllers/Reportes/Facturacion/ReportesFacturacionController.cs @@ -0,0 +1,54 @@ +using CORRESPONSALBackend.Contracts.Reportes.Facturacion; +using CORRESPONSALBackend.DTO.Reportes; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OfficeOpenXml; +using OfficeOpenXml.Table; + +namespace CORRESPONSALBackend.Controllers.Reportes.Facturacion{ + [Authorize] + [ApiController] + [Route("api/[controller]")] + public class ReportesFacturacionController : ControllerBase{ + private readonly IReportesFacturacionRepository _cuentasRepo; + + public ReportesFacturacionController(IReportesFacturacionRepository cuentasRepo){ + _cuentasRepo = cuentasRepo; + } + + [HttpGet("CuentasFacturadas")] + public async Task GetCuentasFacturadas([FromQuery] DTOReporteCorresponsales data){ + try{ + var cuentas = await _cuentasRepo.GetCuentasFacturadas(data); + return Ok(cuentas); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + [HttpGet("FacturacionExcel")] + public async Task GetFacturacionExcel([FromQuery] DTOReporteCorresponsales data ){ + try{ + var traficos = await _cuentasRepo.GetCuentasFacturadas(data); + var today = DateTime.Now; + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using (ExcelPackage excelPackage = new ExcelPackage()){ + var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1"); + worksheet.Cells["A1"].LoadFromCollection(traficos, true); + //Se crea la tabla en el rango de celdas donde se mostrara la inforamcion. + ExcelRange range = worksheet.Cells[1, 1,traficos.Count() + 1, 27]; + 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 File(stream, "application/octet-stream", $"ReporteFacturacion_{today.Day}-{today.Month}-{today.Year}.xlsx"); + } + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/Controllers/Utils/ReportesController.cs b/Controllers/Utils/ReportesController.cs index 43e0546..28fedf5 100644 --- a/Controllers/Utils/ReportesController.cs +++ b/Controllers/Utils/ReportesController.cs @@ -6,6 +6,7 @@ using CORRESPONSALBackend.DTO.Corresponsales; namespace CORRESPONSALBackend.Controllers { + [Authorize] [Route("api/[controller]")] [ApiController] public class ReportesController : ControllerBase diff --git a/DTO/Reportes/Facturacion/DTOReporteGeneralFacturacion.cs b/DTO/Reportes/Facturacion/DTOReporteGeneralFacturacion.cs new file mode 100644 index 0000000..9ad336b --- /dev/null +++ b/DTO/Reportes/Facturacion/DTOReporteGeneralFacturacion.cs @@ -0,0 +1,32 @@ +namespace CORRESPONSALBackend.DTO.Reportes.Facturacion{ + public class DTOReporteGeneralFacturacion + { + public string Trafico { get; set; } + public string Corresponsal { get; set; } + public string Aduana { get; set; } + public int Patente { get; set; } + public string PedimentoCorreponsal { get; set; } + public string PedimentoCorresponsalR1 { get; set; } + public string FechaPago { get; set; } + public string FechaAnticipo { get; set; } + public double SumaAnticipoCorresponsalFinanciado { get; set; } + public string FechaAlta { get; set; } + public string UsuarioAlta { get; set; } + public int Cliente { get; set; } + public string Nombrecliente { get; set; } + public string Cuenta { get; set; } + public string TipoOperacion { get; set; } + public string Terminado { get; set; } + public string FechaRegistroContabilizar { get; set; } + public string FechaContabilizado { get; set; } + public string FechaFacturado { get; set; } + public string FechaFacturaCorresponsal { get; set; } + public string FechaCruce { get; set; } + public string MotivoCuentaRechazadaContabilidad { get; set; } + public string MotivoCuentaRechazadaFacturacion { get; set; } + public string MotivoSolicitaReapertura { get; set; } + public string SolicitudReaperturaAutorizada { get; set; } + public string EstatusOperacion { get; set; } + public string CargoShipper { get; set; } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 5a04953..3e2dfa7 100644 --- a/Program.cs +++ b/Program.cs @@ -55,6 +55,8 @@ using CORRESPONSALBackend.Services.Reportes; using CORRESPONSALBackend.Contracts.ArchivoElectronico; using CORRESPONSALBackend.Services; using CORRESPONSALBackend.Repository.Reportes.Alen; +using CORRESPONSALBackend.Contracts.Reportes.Facturacion; +using CORRESPONSALBackend.Repository.Reportes.Facturacion; var builder = WebApplication.CreateBuilder(args); @@ -81,6 +83,7 @@ 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/Facturacion/ReportesFacturacionRepository.cs b/Repository/Reportes/Facturacion/ReportesFacturacionRepository.cs new file mode 100644 index 0000000..ae660b0 --- /dev/null +++ b/Repository/Reportes/Facturacion/ReportesFacturacionRepository.cs @@ -0,0 +1,34 @@ +using System.Data; +using CORRESPONSALBackend.Context; +using CORRESPONSALBackend.Contracts.Reportes.Facturacion; +using CORRESPONSALBackend.DTO.Reportes; +using CORRESPONSALBackend.DTO.Reportes.Facturacion; +using Dapper; + +namespace CORRESPONSALBackend.Repository.Reportes.Facturacion{ + public class ReportesFacturacionRepository : IReportesFacturacionRepository + { + private readonly DapperContext _context; + public ReportesFacturacionRepository(DapperContext context) { _context = context; } + public async Task> GetCuentasFacturadas(DTOReporteCorresponsales data) + { + var query = "[Reportes.Facturacion.GetCuentasFacturadas]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(query, new + { + @Inicio = data.Inicio, + @Fin = data.Fin, + @NoCliente = data.NoCliente, + @TipoOperacion = data.TipoOperacion, + @IdCorresponsal = data.IdCorresponsal, + @Patente = data.Patente, + @Aduana = data.Aduana, + @Pedimento = data.Pedimento, + @Proceso = data.Proceso, + @Modo = data.Modo + }, + commandType: CommandType.StoredProcedure); + return entrada; + } + } +} \ No newline at end of file