Creacion del funcionamiento para exportar traficos a un excel en la vista del cliente

feature/Creacion_Reporte_Archivo_Electronico_20240417
Felix Morales 5 months ago
parent e6c0ed26cb
commit 1a7db051eb
  1. 7
      Contracts/Reportes/ITraficosClientesService.cs
  2. 21
      Controllers/ClientesController.cs
  3. 3
      Program.cs
  4. 63
      Services/Reportes/TraficosClientesService.cs

@ -0,0 +1,7 @@
using CORRESPONSALBackend.DTO.Corresponsales;
namespace CORRESPONSALBackend.Contracts.Reportes{
public interface ITraficosClientesService{
public Task<MemoryStream> GetExcel(IEnumerable<DTOCorresponsalTrafico> traficos);
}
}

@ -1,4 +1,5 @@
using CORRESPONSALBackend.Contracts;
using CORRESPONSALBackend.Contracts.Reportes;
using CORRESPONSALBackend.DTO.Cliente;
using CORRESPONSALBackend.DTO.Corresponsales;
using CORRESPONSALBackend.DTO.Reportes;
@ -14,10 +15,12 @@ namespace CORRESPONSALBackend.Controllers
public class ClientesController : Controller
{
private readonly IClientesRepository _clientesRepo;
private readonly ITraficosClientesService _traficosClientesService;
public ClientesController(IClientesRepository clientesRepo)
public ClientesController(IClientesRepository clientesRepo, ITraficosClientesService traficosClientesService)
{
_clientesRepo = clientesRepo;
_traficosClientesService = traficosClientesService;
}
[Route("getAllClientes")]
@ -105,5 +108,21 @@ namespace CORRESPONSALBackend.Controllers
var entrada = await _clientesRepo.GetTraficos(data);
return entrada;
}
[HttpGet("Excel")]
public async Task<IActionResult> GetExcel([FromQuery] DTOFiltrosTraficosClientes data){
try{
var traficos = await _clientesRepo.GetTraficos(data);
var stream = await _traficosClientesService.GetExcel(traficos);
if(stream.Length > 0){
stream.Position = 0;
return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"Reporte_Operaciones.xlsx");
}else{
throw new Exception("Ocurrio un error al generar el reporte, intentelo de nuevo");
}
}catch(Exception ex){
return BadRequest(ex.Message);
}
}
}
}

@ -50,6 +50,8 @@ using CORRESPONSALBackend.Services.Reportes.Alen;
using CORRESPONSALBackend.Contracts.Reportes.CuentasCerradas;
using CORRESPONSALBackend.Repository.Reportes.CuentasCerradas;
using CORRESPONSALBackend.Services.Reportes.CuentasCerradas;
using CORRESPONSALBackend.Contracts.Reportes;
using CORRESPONSALBackend.Services.Reportes;
var builder = WebApplication.CreateBuilder(args);
@ -110,6 +112,7 @@ builder.Services.AddScoped<ITiposMercanciaRepository, TiposMercanciaRepository>(
builder.Services.AddScoped<ICatCentrosCostosRepository, CatCentrosCostosRepository>();
builder.Services.AddScoped<ICatClavesPedimentosRepository, CatClavesPedimentosRepository>();
builder.Services.AddScoped<ICatTiposContenedoresRepository, CatTiposContenedoresRepository>();
builder.Services.AddScoped<ITraficosClientesService, TraficosClientesService>();
//Utilerias
builder.Services.AddScoped<IFileManagerRepository, FileManagerRepository>();

@ -0,0 +1,63 @@
using CORRESPONSALBackend.Contracts.Reportes;
using CORRESPONSALBackend.DTO.Corresponsales;
using OfficeOpenXml;
using OfficeOpenXml.Table;
namespace CORRESPONSALBackend.Services.Reportes{
public class TraficosClientesService : ITraficosClientesService{
public TraficosClientesService(){
}
public async Task<MemoryStream> GetExcel(IEnumerable<DTOCorresponsalTrafico> traficos)
{
try{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (ExcelPackage excelPackage = new ExcelPackage()){
var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1");
worksheet.Cells["A1"].Value="Estado";
worksheet.Cells["B1"].Value="Trafico";
worksheet.Cells["C1"].Value="Fecha Registro";
worksheet.Cells["D1"].Value="Usuario";
worksheet.Cells["E1"].Value="Cliente";
worksheet.Cells["F1"].Value="Tipo Operación";
worksheet.Cells["G1"].Value="Estado Operación";
worksheet.Cells["H1"].Value="Patente";
worksheet.Cells["I1"].Value="Aduana";
worksheet.Cells["J1"].Value="Pedimento";
worksheet.Cells["K1"].Value="Fecha Pago";
worksheet.Cells["L1"].Value="Fecha Desaduanado";
worksheet.Cells["M1"].Value="Fecha Ultima Actualización";
int currentRow=2;
foreach(var trafico in traficos){
worksheet.Cells[$"A{currentRow}"].Value = trafico.Proceso == 1 ? "Por Terminar" : trafico.Proceso == 2 || trafico.Proceso == 3 ? "Despachado sin Facturar" : "Despachado y Facturado";
worksheet.Cells[$"B{currentRow}"].Value = trafico.Trafico;
worksheet.Cells[$"C{currentRow}"].Value = trafico.FechaRegistro;
worksheet.Cells[$"D{currentRow}"].Value = trafico.sUsuario;
worksheet.Cells[$"E{currentRow}"].Value = trafico.sCliente;
worksheet.Cells[$"F{currentRow}"].Value = trafico.sTipoOperacion;
worksheet.Cells[$"G{currentRow}"].Value = trafico.sEstatus;
worksheet.Cells[$"H{currentRow}"].Value = trafico.Patente;
worksheet.Cells[$"I{currentRow}"].Value = trafico.Aduana;
worksheet.Cells[$"J{currentRow}"].Value = trafico.Pedimento;
worksheet.Cells[$"K{currentRow}"].Value = trafico.FechaPago;
worksheet.Cells[$"L{currentRow}"].Value = trafico.FechaDesaduanamiento;
worksheet.Cells[$"M{currentRow}"].Value = trafico.UltimaActualizacion;
currentRow++;
}
ExcelRange range = worksheet.Cells[1, 1,traficos.Count() + 1, 13];
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