feature/Creacion_Reporte_Archivo_Electronico_20240417
parent
e6c0ed26cb
commit
1a7db051eb
@ -0,0 +1,7 @@ |
||||
using CORRESPONSALBackend.DTO.Corresponsales; |
||||
|
||||
namespace CORRESPONSALBackend.Contracts.Reportes{ |
||||
public interface ITraficosClientesService{ |
||||
public Task<MemoryStream> GetExcel(IEnumerable<DTOCorresponsalTrafico> traficos); |
||||
} |
||||
} |
@ -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…
Reference in new issue