From 660fb99b8b352ad8c7279cf4533871dc34122907 Mon Sep 17 00:00:00 2001 From: Felix Morales Date: Tue, 28 Nov 2023 12:37:43 -0600 Subject: [PATCH] quitar generacion de reportes de los controladores y migragar al backend la creacion del reporte semanal de newell --- .../ICorresponsaliasAnticiposService.cs | 7 + .../Embarques/IReportesEmbarquesService.cs | 9 + .../Reportes/GC50/IReporteGC50Services.cs | 7 + .../Newell/Semanal/IReporteSemanalService.cs | 5 + .../Corresponsalias/AnticiposController.cs | 73 +-- Controllers/Reportes/ReporteGC50Controller.cs | 25 +- .../Reportes/ReportesEmbarquesController.cs | 475 +---------------- Controllers/Reportes/ReportesNewell.cs | 15 +- Program.cs | 10 + .../CorresponsaliasAnticiposService.cs | 88 ++++ .../Embarques/ReportesEmbarquesService.cs | 496 ++++++++++++++++++ Services/Reportes/GC50/ReporteGC50Service.cs | 31 ++ .../Newell/Semanal/ReporteSemanalService.cs | 63 +++ 13 files changed, 756 insertions(+), 548 deletions(-) create mode 100644 Contracts/Corresponsalias/Anticipos/ICorresponsaliasAnticiposService.cs create mode 100644 Contracts/Reportes/Embarques/IReportesEmbarquesService.cs create mode 100644 Contracts/Reportes/GC50/IReporteGC50Services.cs create mode 100644 Contracts/Reportes/Newell/Semanal/IReporteSemanalService.cs create mode 100644 Services/Corresponsalias/Anticipos/CorresponsaliasAnticiposService.cs create mode 100644 Services/Reportes/Embarques/ReportesEmbarquesService.cs create mode 100644 Services/Reportes/GC50/ReporteGC50Service.cs create mode 100644 Services/Reportes/Newell/Semanal/ReporteSemanalService.cs diff --git a/Contracts/Corresponsalias/Anticipos/ICorresponsaliasAnticiposService.cs b/Contracts/Corresponsalias/Anticipos/ICorresponsaliasAnticiposService.cs new file mode 100644 index 0000000..7801d75 --- /dev/null +++ b/Contracts/Corresponsalias/Anticipos/ICorresponsaliasAnticiposService.cs @@ -0,0 +1,7 @@ +using CORRESPONSALBackend.DTO.Corresponsales; + +namespace CORRESPONSALBackend.Contracts.Corresponsalias.Anticipos{ + public interface ICorresponsaliasAnticiposService{ + public Task GetPdf(DTOPdfAnticipo anticipo, string imageFile); + } +} \ No newline at end of file diff --git a/Contracts/Reportes/Embarques/IReportesEmbarquesService.cs b/Contracts/Reportes/Embarques/IReportesEmbarquesService.cs new file mode 100644 index 0000000..cf71514 --- /dev/null +++ b/Contracts/Reportes/Embarques/IReportesEmbarquesService.cs @@ -0,0 +1,9 @@ +using CORRESPONSALBackend.DTO.Reportes.Embarques; + +namespace CORRESPONSALBackend.Contracts.Reportes.Embarques{ + public interface IReportesEmbarquesService{ + public Task GetExcelEmbarquesPorImportar(IEnumerable embarques, string filePath); + public Task GetExcelEmbarquesDespachados(IEnumerable embarques, string filePath); + public Task GetExcelBusquedaEmbarques(IEnumerable embarques, string filePath); + } +} \ No newline at end of file diff --git a/Contracts/Reportes/GC50/IReporteGC50Services.cs b/Contracts/Reportes/GC50/IReporteGC50Services.cs new file mode 100644 index 0000000..f712c7a --- /dev/null +++ b/Contracts/Reportes/GC50/IReporteGC50Services.cs @@ -0,0 +1,7 @@ +using CORRESPONSALBackend.DTO.Reportes.GC50; + +namespace CORRESPONSALBackend.Contracts.Reportes.GC50{ + public interface IReporteGC50Service{ + public Task GetExcel(IEnumerable traficos); + } +} \ No newline at end of file diff --git a/Contracts/Reportes/Newell/Semanal/IReporteSemanalService.cs b/Contracts/Reportes/Newell/Semanal/IReporteSemanalService.cs new file mode 100644 index 0000000..b6a90ba --- /dev/null +++ b/Contracts/Reportes/Newell/Semanal/IReporteSemanalService.cs @@ -0,0 +1,5 @@ +namespace CORRESPONSALBackend.Contracts.Reportes.Newell.Semanal{ + public interface IReporteSemanalService{ + public Task GetReporteSemanal(int idRptSemanalFile); + } +} \ No newline at end of file diff --git a/Controllers/Corresponsalias/AnticiposController.cs b/Controllers/Corresponsalias/AnticiposController.cs index 90eb345..4916a2b 100644 --- a/Controllers/Corresponsalias/AnticiposController.cs +++ b/Controllers/Corresponsalias/AnticiposController.cs @@ -15,6 +15,7 @@ using iText.Kernel.Colors; using iText.Layout.Borders; using iText.Kernel.Font; using iText.IO.Font.Constants; +using CORRESPONSALBackend.Contracts.Corresponsalias.Anticipos; namespace CORRESPONSALBackend.Controllers.Corresponsalias { @@ -27,18 +28,18 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias private readonly ICorresponsaliasAnticiposRepository _Repo; private readonly IConfiguration _config; private readonly IFileManagerRepository _fileManager; - private readonly ICorresponsaliasTraficosRepository _traficoRepository; private readonly string _rootPathCorresponsales; private readonly string _logoGemcoPath; + private readonly ICorresponsaliasAnticiposService _Service; - public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager, ICorresponsaliasTraficosRepository traficoRepository) + public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager, ICorresponsaliasAnticiposService service) { _config = config; _Repo = Repo; _fileManager = fileManager; - _traficoRepository = traficoRepository; _rootPathCorresponsales = _config.GetValue("AllFiles"); _logoGemcoPath = _config.GetValue("LogoGemco"); + _Service = service; } [HttpPost] @@ -95,70 +96,10 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias try{ var anticipo = await _Repo.GetPdfAnticipo(idAnticipo); + String imageFile = $"{_rootPathCorresponsales}{_logoGemcoPath}LogoGemco.png"; + var byteStream = await _Service.GetPdf(anticipo, imageFile); MemoryStream ms = new MemoryStream(); - PdfWriter pw = new PdfWriter(ms); - PdfDocument pdfDocument = new PdfDocument(pw); - Document doc = new Document(pdfDocument, PageSize.LETTER);//En este punto ya se tiene creado un docuento en blanco - PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); - doc.SetFont(font); - doc.SetMargins(25, 25, 25, 25); - #region Encabezado - String imageFile = $"{_rootPathCorresponsales}{_logoGemcoPath}LogoGemco.png"; - ImageData data = ImageDataFactory.Create(imageFile); - Image img = new Image(data); - Table headerTable = new Table(3).UseAllAvailableWidth(); - headerTable.AddCell(new Cell(2,1).Add(img.SetAutoScale(true).SetWidth(30).SetHeight(20)).SetBorder(Border.NO_BORDER)); - headerTable.AddCell( - new Cell(2,2) - .Add( - new Paragraph("ANTICIPO PARA CORRESPONSALIAS") - .SetTextAlignment(TextAlignment.CENTER).SetPaddingRight(30) - ) - .SetVerticalAlignment(VerticalAlignment.BOTTOM) - .SetBorder(Border.NO_BORDER) - ); - headerTable.SetBorderBottom(new SolidBorder(ColorConstants.BLACK, 2)); - doc.Add(headerTable); - #endregion - #region datos de la cuenta - Table accountTable = new Table(1).UseAllAvailableWidth().SetMarginTop(15); - accountTable.AddCell(new Cell().Add(new Paragraph("NUMERO DE CHEQUE:")).SetBorder(Border.NO_BORDER)); - accountTable.AddCell(new Cell().Add(new Paragraph($"SOLICITUD: ").Add(new Text($"{anticipo.Id}").SetItalic())).SetBorder(Border.NO_BORDER)); - accountTable.AddCell(new Cell().Add(new Paragraph("DEPENDENCIA: ").Add(new Text("CORRESPONSALIA").SetItalic())).SetBorder(Border.NO_BORDER)); - accountTable.AddCell(new Cell().Add(new Paragraph($"IMPRESION: ").Add(new Text($"{DateTime.Now}").SetItalic())).SetVerticalAlignment(VerticalAlignment.BOTTOM).SetBorder(Border.NO_BORDER)); - doc.Add(accountTable); - #endregion - #region datos del anticipo - Table dataTable = new Table(7).UseAllAvailableWidth().SetMarginTop(15).SetFontSize(8f); - dataTable.AddCell(new Cell().Add(new Paragraph("GEMCO"))); - dataTable.AddCell(new Cell().Add(new Paragraph("PEDIMENTO"))); - dataTable.AddCell(new Cell().Add(new Paragraph("CLIENTE"))); - dataTable.AddCell(new Cell().Add(new Paragraph("PRODUCTO"))); - dataTable.AddCell(new Cell().Add(new Paragraph("FECHA DE CRUCE"))); - dataTable.AddCell(new Cell().Add(new Paragraph("PROVEEDOR"))); - dataTable.AddCell(new Cell().Add(new Paragraph("IMPORTE"))); - - dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.FolioGemco)).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.Pedimento)).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.Cliente.Substring(0, anticipo.Cliente.Length - 7))).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph("")).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.FechaCruce != null && anticipo.FechaCruce != "" ? anticipo.FechaCruce.Substring(0,10) : "")).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph("CORRESPONSAL")).SetBorder(Border.NO_BORDER)); - dataTable.AddCell(new Cell().Add(new Paragraph($"{anticipo.Anticipo}")).SetBorder(Border.NO_BORDER)); - dataTable.SetBorderBottom(new SolidBorder(ColorConstants.BLACK, 2)); - doc.Add(dataTable); - #endregion - #region Importe final - Table importeTable = new Table(7).UseAllAvailableWidth(); - importeTable.AddCell(new Cell(1,7) - .Add(new Paragraph($"SUMA IMPORTE: $ {anticipo.Anticipo}").SetTextAlignment(TextAlignment.RIGHT).SetFontSize(10f)).SetBorder(Border.NO_BORDER) - ); - doc.Add(importeTable); - #endregion - doc.Close();//Aqui se cierra el documento para poder enviarlo al front para ser descargado. - byte[] bytesStream = ms.ToArray(); - ms = new MemoryStream(); - ms.Write(bytesStream, 0, bytesStream.Length); + ms.Write(byteStream, 0, byteStream.Length); ms.Position = 0; return new FileStreamResult(ms, "application/pdf"); diff --git a/Controllers/Reportes/ReporteGC50Controller.cs b/Controllers/Reportes/ReporteGC50Controller.cs index 14a45cd..a2315b2 100644 --- a/Controllers/Reportes/ReporteGC50Controller.cs +++ b/Controllers/Reportes/ReporteGC50Controller.cs @@ -13,10 +13,11 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ [ApiController] public class ReporteGC50Controller : ControllerBase{ private readonly IReporteGC50Repository _reportesRepo; - - public ReporteGC50Controller(IReporteGC50Repository reportesRepo) + private readonly IReporteGC50Service _service; + public ReporteGC50Controller(IReporteGC50Repository reportesRepo, IReporteGC50Service service) { _reportesRepo = reportesRepo; + _service = service; } [HttpGet] @@ -30,22 +31,10 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ public async Task GetExcelGc50([FromQuery] DTOReporteCorresponsales data ){ try{ var traficos = await _reportesRepo.GetAllCorresponsalesTraficos(data); - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - using (ExcelPackage excelPackage = new ExcelPackage()){ - var today = DateTime.Now; - 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, 23]; - 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", $"ReporteGC50_{today.Day}-{today.Month}-{today.Year}.xlsx"); - } + var today = DateTime.Now; + var stream = await _service.GetExcel(traficos); + stream.Position = 0; + return File(stream, "application/octet-stream", $"ReporteGC50_{today.Day}-{today.Month}-{today.Year}.xlsx"); }catch(Exception ex){ return BadRequest(ex.Message); } diff --git a/Controllers/Reportes/ReportesEmbarquesController.cs b/Controllers/Reportes/ReportesEmbarquesController.cs index 25aa66a..808bc29 100644 --- a/Controllers/Reportes/ReportesEmbarquesController.cs +++ b/Controllers/Reportes/ReportesEmbarquesController.cs @@ -15,12 +15,14 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ public class ReportesEmbarquesController : ControllerBase{ private readonly IReportesEmbarquesRepository _repo; private readonly IConfiguration _config; + private readonly IReportesEmbarquesService _service; private readonly string RootPathCorresponsales; private readonly string PathLogoGemco; private readonly string LogoGemcoFileName = "LogoGemco.png"; - public ReportesEmbarquesController(IReportesEmbarquesRepository repo, IConfiguration config){ + public ReportesEmbarquesController(IReportesEmbarquesRepository repo, IConfiguration config, IReportesEmbarquesService service){ _repo = repo; _config = config; + _service = service; RootPathCorresponsales = _config.GetValue("AllFiles"); PathLogoGemco = _config.GetValue("LogoGemco"); } @@ -47,168 +49,9 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ public async Task GetExcelEmbarquesPorImportar(){ try{ var embarques = await _repo.GetReporteEmbarquesPorImportar(); - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - using (ExcelPackage excelPackage = new ExcelPackage()){ - var today = DateTime.Now; - var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); - //Se crean los encabezados - #region Encabezados - worksheet.Cells["A7"].Value = "ADUANA"; - worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; - worksheet.Cells["C7"].Value = "DESTINO"; - worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; - worksheet.Cells["E7"].Value = "NOMBRE"; - worksheet.Cells["F7"].Value = "TRAFICO"; - worksheet.Cells["G7"].Value = "REFERENCIA"; - worksheet.Cells["H7"].Value = "NO DE PEDIMENTO"; - worksheet.Cells["I7"].Value = "CLAVE DE PEDIMENTO"; - worksheet.Cells["J7"].Value = "TIPO"; - worksheet.Cells["K7"].Value = "ORDEN DE COMPRA"; - worksheet.Cells["L7"].Value = "FACTURA"; - worksheet.Cells["M7"].Value = "PROVEEDOR"; - worksheet.Cells["N7"].Value = "DESCRIPCION MERCANCIA"; - worksheet.Cells["O7"].Value = "LÍNEA TRANSPORTISTA INTERNACIONAL"; - worksheet.Cells["P7"].Value = "LINEA NAVIERA"; - worksheet.Cells["Q7"].Value = "MAWB"; - worksheet.Cells["R7"].Value = "HAWB"; - worksheet.Cells["S7"].Value = "FECHA DE NOTIFICACION"; - worksheet.Cells["T7"].Value = "BULTOS"; - worksheet.Cells["U7"].Value = "CANTIDAD CONTENEDORES"; - worksheet.Cells["V7"].Value = "NO. CONTENEDORES"; - worksheet.Cells["W7"].Value = "PESO BRUTO"; - worksheet.Cells["X7"].Value = "PESO NETO"; - worksheet.Cells["Y7"].Value = "INCOTERM"; - worksheet.Cells["Z7"].Value = "FECHA ETA"; - worksheet.Cells["AA7"].Value = "FECHA DE ENTRADA"; - worksheet.Cells["AB7"].Value = "FECHA DE REVALIDACION GUIA"; - worksheet.Cells["AC7"].Value = "MONTO USD"; - worksheet.Cells["AD7"].Value = "ORIGEN"; - worksheet.Cells["AE7"].Value = "FRACCION ARANCELARIA"; - worksheet.Cells["AF7"].Value = "DESCRIPCION"; - worksheet.Cells["AG7"].Value = "PPREFERENCIA ARANCELARIA"; - worksheet.Cells["AH7"].Value = "ESTATUS"; - worksheet.Cells["AI7"].Value = "OBSERVACIONES"; - worksheet.Cells["AJ7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; - worksheet.Cells["AK7"].Value = "COSTO DIARIO ALMACENAJE"; - worksheet.Cells["AL7"].Value = "COSTO DIARIO CONEXIÓN"; - worksheet.Cells["AM7"].Value = "TOTAL A PAGAR ALMACENAJE"; - worksheet.Cells["AN7"].Value = "TOTAL A PAGAR CONEXIÓN"; - worksheet.Cells["AO7"].Value = "FECHA DE PAGO PEDIMENTO"; - worksheet.Cells["AP7"].Value = "FECHA DE INSTRUCCIONES"; - worksheet.Cells["AQ7"].Value = "HORA DE INSTRUCCIONES"; - worksheet.Cells["AR7"].Value = "FECHA DE DESPACHO"; - worksheet.Cells["AS7"].Value = "DIAS C/PDTO PAGADO"; - worksheet.Cells["AT7"].Value = "FECHA SALIDA DE CONTENEDORES"; - worksheet.Cells["AU7"].Value = "NOMBRE DE PAQUETERIA O TRANSPORTISTA"; - worksheet.Cells["AV7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; - worksheet.Cells["AW7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; - worksheet.Cells["AX7"].Value = "HORA DE ENTREGA EN DESTINO FINAL"; - worksheet.Cells["AY7"].Value = "FACTURA CORRESPONSAL"; - worksheet.Cells["AZ7"].Value = "CERTIFICADO DE CALIDAD"; - worksheet.Cells["BA7"].Value = "PACKING LIST"; - worksheet.Cells["BB7"].Value = "HOJA TECNICA"; - worksheet.Cells["BC7"].Value = "BL"; - worksheet.Cells["BD7"].Value = "PEDIMENTO INFORMATIVO"; - worksheet.Cells["BE7"].Value = "PEDIMENTO SIMPLIFICADO"; - worksheet.Cells["BF7"].Value = "DODA"; - #endregion - #region Llenado de datos - int currentRow = 8; - foreach(var embarque in embarques){ - worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; - worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; - worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; - worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; - worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; - worksheet.Cells[$"F{currentRow}"].Value = embarque.Trafico; - worksheet.Cells[$"G{currentRow}"].Value = embarque.Referencia; - worksheet.Cells[$"H{currentRow}"].Value = embarque.NoPedimento; - worksheet.Cells[$"I{currentRow}"].Value = embarque.ClavePedimento; - worksheet.Cells[$"J{currentRow}"].Value = embarque.Tipo; - worksheet.Cells[$"K{currentRow}"].Value = embarque.OrdenCompra; - worksheet.Cells[$"L{currentRow}"].Value = embarque.Factura; - worksheet.Cells[$"M{currentRow}"].Value = embarque.Proveedor; - worksheet.Cells[$"N{currentRow}"].Value = embarque.DescripcionMercancia; - worksheet.Cells[$"O{currentRow}"].Value = embarque.LineaTransportistaInternacional; - worksheet.Cells[$"P{currentRow}"].Value = embarque.LineaNaviera; - worksheet.Cells[$"Q{currentRow}"].Value = embarque.MAWB; - worksheet.Cells[$"R{currentRow}"].Value = embarque.HAWB; - worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaNotificacion; - worksheet.Cells[$"T{currentRow}"].Value = embarque.Bultos; - worksheet.Cells[$"U{currentRow}"].Value = embarque.CantidadContenedores; - worksheet.Cells[$"V{currentRow}"].Value = embarque.NumerosContenedores; - worksheet.Cells[$"W{currentRow}"].Value = embarque.PesoBruto; - worksheet.Cells[$"X{currentRow}"].Value = embarque.PesoNeto; - worksheet.Cells[$"Y{currentRow}"].Value = embarque.Incoterm; - worksheet.Cells[$"Z{currentRow}"].Value = embarque.FechaETA; - worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntrada; - worksheet.Cells[$"AB{currentRow}"].Value = embarque.FechaRevalidacionGuia; - worksheet.Cells[$"AC{currentRow}"].Value = embarque.MontoUSD; - worksheet.Cells[$"AD{currentRow}"].Value = embarque.Origen; - worksheet.Cells[$"AE{currentRow}"].Value = embarque.FraccionArancelaria; - worksheet.Cells[$"AF{currentRow}"].Value = embarque.Descripcion; - worksheet.Cells[$"AG{currentRow}"].Value = embarque.PreferenciaArancelaria; - worksheet.Cells[$"AH{currentRow}"].Value = embarque.Estatus; - worksheet.Cells[$"AI{currentRow}"].Value = embarque.Observaciones; - worksheet.Cells[$"AJ{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; - worksheet.Cells[$"AK{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; - worksheet.Cells[$"AL{currentRow}"].Value = embarque.CostoDiarioConexion; - worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalPagar; - worksheet.Cells[$"AN{currentRow}"].Value = embarque.TotalPagarConexion; - worksheet.Cells[$"AO{currentRow}"].Value = embarque.FechaPagoPedimento; - worksheet.Cells[$"AP{currentRow}"].Value = embarque.FechaInstrucciones; - worksheet.Cells[$"AQ{currentRow}"].Value = embarque.HoraInstrucciones; - worksheet.Cells[$"AR{currentRow}"].Value = embarque.FechaDespacho; - worksheet.Cells[$"AS{currentRow}"].Value = embarque.DiasCPPagado; - worksheet.Cells[$"AT{currentRow}"].Value = embarque.FechaSalidaContenedores; - worksheet.Cells[$"AU{currentRow}"].Value = embarque.NombrePaqueteria; - worksheet.Cells[$"AV{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; - worksheet.Cells[$"AW{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; - worksheet.Cells[$"AX{currentRow}"].Value = embarque.HoraEntregaDestinoFinal; - worksheet.Cells[$"AY{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; - worksheet.Cells[$"AZ{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; - worksheet.Cells[$"BA{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; - worksheet.Cells[$"BB{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; - worksheet.Cells[$"BC{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; - worksheet.Cells[$"BD{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; - worksheet.Cells[$"BE{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; - worksheet.Cells[$"BF{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; - currentRow++; - } - #endregion - //Se crea la tabla en el rango de celdas donde se mostrara la inforamcion. - ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 58]; - ExcelTable tab = worksheet.Tables.Add(range, "Table1"); - tab.TableStyle = TableStyles.Light1; - worksheet.Cells["A1:A6"].Merge = true; - //Se agrega el logo de GEMCO al documento. - ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName)); - excelImage.SetPosition(0,0,1,0); - //Aqui comienza el encabezado del documento. - worksheet.Cells["B1:D6"].Merge = true; - worksheet.Cells["E1:J1"].Merge = true; - worksheet.Cells["E2:J2"].Merge = true; - worksheet.Cells["E3:J3"].Merge = true; - worksheet.Cells["E4:J4"].Merge = true; - worksheet.Cells["E5:J5"].Merge = true; - worksheet.Cells["E6:J6"].Merge = true; - worksheet.Cells["E1:J6"].Style.Font.Size = 16; - worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); - worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES POR IMPORTAR"; - worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; - worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; - worksheet.Cells["A1:BG6"].Style.Fill.PatternType = ExcelFillStyle.Solid; - worksheet.Cells["A1:BG6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); - worksheet.Cells["A7:BG7"].Style.Font.Bold = true; - worksheet.Cells["A7:BG7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; - worksheet.Cells["A7:BG7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; - 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", "ReporteEmbarquesSinImportar.xlsx"); - } + string filePath = RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName; + var stream = await _service.GetExcelEmbarquesPorImportar(embarques, filePath); + return File(stream, "application/octet-stream", "ReporteEmbarquesSinImportar.xlsx"); }catch(Exception ex){ return BadRequest(ex.Message); } @@ -218,179 +61,9 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ public async Task GetExcelEmbarquesDespachados([FromQuery] DateTime inicio, [FromQuery] DateTime fin){ try{ var embarques = await _repo.GetReporteEmbarquesDespachados(inicio, fin); - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - using (ExcelPackage excelPackage = new ExcelPackage()){ - var today = DateTime.Now; - var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); - //Se crean los encabezados - #region Encabezados - worksheet.Cells["A7"].Value = "ADUANA"; - worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; - worksheet.Cells["C7"].Value = "DESTINO"; - worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; - worksheet.Cells["E7"].Value = "NOMBRE"; - worksheet.Cells["F7"].Value = "TRAFICO"; - worksheet.Cells["G7"].Value = "REFERENCIA"; - worksheet.Cells["H7"].Value = "NO DE PEDIMENTO"; - worksheet.Cells["I7"].Value = "CLAVE DE PEDIMENTO"; - worksheet.Cells["J7"].Value = "TIPO"; - worksheet.Cells["K7"].Value = "ORDEN DE COMPRA"; - worksheet.Cells["L7"].Value = "FACTURA"; - worksheet.Cells["M7"].Value = "PROVEEDOR"; - worksheet.Cells["N7"].Value = "DESCRIPCION MERCANCIA"; - worksheet.Cells["O7"].Value = "LÍNEA TRANSPORTISTA INTERNACIONAL"; - worksheet.Cells["P7"].Value = "LINEA NAVIERA"; - worksheet.Cells["Q7"].Value = "MAWB"; - worksheet.Cells["R7"].Value = "HAWB"; - worksheet.Cells["S7"].Value = "FECHA DE NOTIFICACION"; - worksheet.Cells["T7"].Value = "BULTOS"; - worksheet.Cells["U7"].Value = "CANTIDAD CONTENEDORES"; - worksheet.Cells["V7"].Value = "NO. CONTENEDORES"; - worksheet.Cells["W7"].Value = "PESO BRUTO"; - worksheet.Cells["X7"].Value = "PESO NETO"; - worksheet.Cells["Y7"].Value = "INCOTERM"; - worksheet.Cells["Z7"].Value = "FECHA ETA"; - worksheet.Cells["AA7"].Value = "FECHA DE ENTRADA"; - worksheet.Cells["AB7"].Value = "FECHA DE REVALIDACION GUIA"; - worksheet.Cells["AC7"].Value = "MONTO USD"; - worksheet.Cells["AD7"].Value = "ORIGEN"; - worksheet.Cells["AE7"].Value = "FRACCION ARANCELARIA"; - worksheet.Cells["AF7"].Value = "DESCRIPCION"; - worksheet.Cells["AG7"].Value = "PPREFERENCIA ARANCELARIA"; - worksheet.Cells["AH7"].Value = "ESTATUS"; - worksheet.Cells["AI7"].Value = "OBSERVACIONES"; - worksheet.Cells["AJ7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; - worksheet.Cells["AK7"].Value = "COSTO DIARIO ALMACENAJE"; - worksheet.Cells["AL7"].Value = "COSTO DIARIO CONEXIÓN"; - worksheet.Cells["AM7"].Value = "TOTAL A PAGAR ALMACENAJE"; - worksheet.Cells["AN7"].Value = "TOTAL A PAGAR CONEXIÓN"; - worksheet.Cells["AO7"].Value = "FECHA DE PAGO PEDIMENTO"; - worksheet.Cells["AP7"].Value = "FECHA DE INSTRUCCIONES"; - worksheet.Cells["AQ7"].Value = "HORA DE INSTRUCCIONES"; - worksheet.Cells["AR7"].Value = "FECHA DE DESPACHO"; - worksheet.Cells["AS7"].Value = "DIAS C/PDTO PAGADO"; - worksheet.Cells["AT7"].Value = "FECHA SALIDA DE CONTENEDORES"; - worksheet.Cells["AU7"].Value = "NOMBRE DE PAQUETERIA O TRANSPORTISTA"; - worksheet.Cells["AV7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; - worksheet.Cells["AW7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; - worksheet.Cells["AX7"].Value = "HORA DE ENTREGA EN DESTINO FINAL"; - worksheet.Cells["AY7"].Value = "FACTURA CORRESPONSAL"; - worksheet.Cells["AZ7"].Value = "CERTIFICADO DE CALIDAD"; - worksheet.Cells["BA7"].Value = "PACKING LIST"; - worksheet.Cells["BB7"].Value = "HOJA TECNICA"; - worksheet.Cells["BC7"].Value = "BL"; - worksheet.Cells["BD7"].Value = "PEDIMENTO INFORMATIVO"; - worksheet.Cells["BE7"].Value = "PEDIMENTO SIMPLIFICADO"; - worksheet.Cells["BF7"].Value = "DODA"; - worksheet.Cells["BG7"].Value = "HONORARIOS AA"; - worksheet.Cells["BH7"].Value = "TOTAL HONORARIOS AA"; - worksheet.Cells["BI7"].Value = "GASTOS TERCEROS"; - worksheet.Cells["BJ7"].Value = "TOTAL GASTOS TERCEROS"; - worksheet.Cells["BK7"].Value = "COMPROBANTES GASTOS TERCEROS"; - #endregion - #region Llenado de datos - int currentRow = 8; - foreach(var embarque in embarques){ - worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; - worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; - worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; - worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; - worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; - worksheet.Cells[$"F{currentRow}"].Value = embarque.Trafico; - worksheet.Cells[$"G{currentRow}"].Value = embarque.Referencia; - worksheet.Cells[$"H{currentRow}"].Value = embarque.NoPedimento; - worksheet.Cells[$"I{currentRow}"].Value = embarque.ClavePedimento; - worksheet.Cells[$"J{currentRow}"].Value = embarque.Tipo; - worksheet.Cells[$"K{currentRow}"].Value = embarque.OrdenCompra; - worksheet.Cells[$"L{currentRow}"].Value = embarque.Factura; - worksheet.Cells[$"M{currentRow}"].Value = embarque.Proveedor; - worksheet.Cells[$"N{currentRow}"].Value = embarque.DescripcionMercancia; - worksheet.Cells[$"O{currentRow}"].Value = embarque.LineaTransportistaInternacional; - worksheet.Cells[$"P{currentRow}"].Value = embarque.LineaNaviera; - worksheet.Cells[$"Q{currentRow}"].Value = embarque.MAWB; - worksheet.Cells[$"R{currentRow}"].Value = embarque.HAWB; - worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaNotificacion; - worksheet.Cells[$"T{currentRow}"].Value = embarque.Bultos; - worksheet.Cells[$"U{currentRow}"].Value = embarque.CantidadContenedores; - worksheet.Cells[$"V{currentRow}"].Value = embarque.NumerosContenedores; - worksheet.Cells[$"W{currentRow}"].Value = embarque.PesoBruto; - worksheet.Cells[$"X{currentRow}"].Value = embarque.PesoNeto; - worksheet.Cells[$"Y{currentRow}"].Value = embarque.Incoterm; - worksheet.Cells[$"Z{currentRow}"].Value = embarque.FechaETA; - worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntrada; - worksheet.Cells[$"AB{currentRow}"].Value = embarque.FechaRevalidacionGuia; - worksheet.Cells[$"AC{currentRow}"].Value = embarque.MontoUSD; - worksheet.Cells[$"AD{currentRow}"].Value = embarque.Origen; - worksheet.Cells[$"AE{currentRow}"].Value = embarque.FraccionArancelaria; - worksheet.Cells[$"AF{currentRow}"].Value = embarque.Descripcion; - worksheet.Cells[$"AG{currentRow}"].Value = embarque.PreferenciaArancelaria; - worksheet.Cells[$"AH{currentRow}"].Value = embarque.Estatus; - worksheet.Cells[$"AI{currentRow}"].Value = embarque.Observaciones; - worksheet.Cells[$"AJ{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; - worksheet.Cells[$"AK{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; - worksheet.Cells[$"AL{currentRow}"].Value = embarque.CostoDiarioConexion; - worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalPagar; - worksheet.Cells[$"AN{currentRow}"].Value = embarque.TotalPagarConexion; - worksheet.Cells[$"AO{currentRow}"].Value = embarque.FechaPagoPedimento; - worksheet.Cells[$"AP{currentRow}"].Value = embarque.FechaInstrucciones; - worksheet.Cells[$"AQ{currentRow}"].Value = embarque.HoraInstrucciones; - worksheet.Cells[$"AR{currentRow}"].Value = embarque.FechaDespacho; - worksheet.Cells[$"AS{currentRow}"].Value = embarque.DiasCPPagado; - worksheet.Cells[$"AT{currentRow}"].Value = embarque.FechaSalidaContenedores; - worksheet.Cells[$"AU{currentRow}"].Value = embarque.NombrePaqueteria; - worksheet.Cells[$"AV{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; - worksheet.Cells[$"AW{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; - worksheet.Cells[$"AX{currentRow}"].Value = embarque.HoraEntregaDestinoFinal; - worksheet.Cells[$"AY{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; - worksheet.Cells[$"AZ{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; - worksheet.Cells[$"BA{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; - worksheet.Cells[$"BB{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; - worksheet.Cells[$"BC{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; - worksheet.Cells[$"BD{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; - worksheet.Cells[$"BE{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; - worksheet.Cells[$"BF{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; - worksheet.Cells[$"BG{currentRow}"].Value = embarque.Honorarios == 0 ? "NO" : "SI"; - worksheet.Cells[$"BH{currentRow}"].Value = embarque.TotalHonorarios; - worksheet.Cells[$"BI{currentRow}"].Value = embarque.GastosTerceros == 0 ? "NO" : "SI"; - worksheet.Cells[$"BJ{currentRow}"].Value = embarque.TotalGastosTerceros; - worksheet.Cells[$"BK{currentRow}"].Value = embarque.ComprobantesGastosTerceros == 0 ? "NO" : "SI"; - currentRow++; - } - #endregion - //Se crea el rango de celdas que abarcara la tabla. - ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 63]; - ExcelTable tab = worksheet.Tables.Add(range, "Table1"); - tab.TableStyle = TableStyles.Light1; - worksheet.Cells["A1:A6"].Merge = true; - //Se agrega el logo de GEMCO al documento. - ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName)); - excelImage.SetPosition(0,0,1,0); - //Aqui comienza el encabezado del documento. - worksheet.Cells["B1:D6"].Merge = true; - worksheet.Cells["E1:J1"].Merge = true; - worksheet.Cells["E2:J2"].Merge = true; - worksheet.Cells["E3:J3"].Merge = true; - worksheet.Cells["E4:J4"].Merge = true; - worksheet.Cells["E5:J5"].Merge = true; - worksheet.Cells["E6:J6"].Merge = true; - worksheet.Cells["E1:J6"].Style.Font.Size = 16; - worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); - worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES POR DESPACHADOS"; - worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; - worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; - worksheet.Cells["A1:BK6"].Style.Fill.PatternType = ExcelFillStyle.Solid; - worksheet.Cells["A1:BK6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); - worksheet.Cells["A7:BK7"].Style.Font.Bold = true; - worksheet.Cells["A7:BK7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; - worksheet.Cells["A7:BK7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; - 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", "ReporteEmbarquesDespachados.xlsx"); - } - + string filePath = RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName; + var stream = await _service.GetExcelEmbarquesDespachados(embarques, filePath); + return File(stream, "application/octet-stream", "ReporteEmbarquesSinImportar.xlsx"); }catch(Exception ex){ return BadRequest(ex.Message); } @@ -400,133 +73,9 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ public async Task GetExcelBusquedaEmbarques([FromQuery] string filtro){ try{ var embarques = await _repo.BuscarEmbarques(filtro); - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - using (ExcelPackage excelPackage = new ExcelPackage()){ - var today = DateTime.Now; - var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); - //Se crean los encabezados - #region Encabezados - worksheet.Cells["A7"].Value = "ADUANA"; - worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; - worksheet.Cells["C7"].Value = "DESTINO"; - worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; - worksheet.Cells["E7"].Value = "NOMBRE"; - worksheet.Cells["F7"].Value = "TIPO"; - worksheet.Cells["G7"].Value = "NO DE PEDIMENTO"; - worksheet.Cells["H7"].Value = "ORDEN DE COMPRA"; - worksheet.Cells["I7"].Value = "FACTURA"; - worksheet.Cells["J7"].Value = "PROVEEDOR"; - worksheet.Cells["K7"].Value = "DESCRIPCION"; - worksheet.Cells["L7"].Value = "BULTOS"; - worksheet.Cells["M7"].Value = "CANTIDAD CONTENEDORES"; - worksheet.Cells["N7"].Value = "PESO NETO"; - worksheet.Cells["O7"].Value = "INCOTERM"; - worksheet.Cells["P7"].Value = "FECHA ETA"; - worksheet.Cells["Q7"].Value = "ESTATUS"; - worksheet.Cells["R7"].Value = "OBSERVACIONES"; - worksheet.Cells["S7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; - worksheet.Cells["T7"].Value = "COSTO DIARIO ALMACENAJE"; - worksheet.Cells["U7"].Value = "COSTO DIARIO CONEXION"; - worksheet.Cells["V7"].Value = "TOTAL A PAGAR ALMACENAJE"; - worksheet.Cells["W7"].Value = "TOTAL A PAGAR CONEXION"; - worksheet.Cells["X7"].Value = "FECHA DE DESPACHO"; - worksheet.Cells["Y7"].Value = "NOMBRE DE PAQUETERIA O TRANPORTISTA"; - worksheet.Cells["Z7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; - worksheet.Cells["AA7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; - worksheet.Cells["AB7"].Value = "FACTURA CORREPSONSAL"; - worksheet.Cells["AC7"].Value = "CERTIFICADO DE CALIDAD"; - worksheet.Cells["AD7"].Value = "PACKING LIST"; - worksheet.Cells["AE7"].Value = "HOJA TECNICA"; - worksheet.Cells["AF7"].Value = "BL"; - worksheet.Cells["AG7"].Value = "PEDIMENTO INFORMATIVO"; - worksheet.Cells["AH7"].Value = "PEDIMENTO SIMPLIFICADO"; - worksheet.Cells["AI7"].Value = "DODA"; - worksheet.Cells["AJ7"].Value = "HONORARIOS AA"; - worksheet.Cells["AK7"].Value = "TOTAL HONORARIOS AA"; - worksheet.Cells["AL7"].Value = "GASTOS A TERCEROS"; - worksheet.Cells["AM7"].Value = "TOTAL GASTOS A TERCEROS"; - worksheet.Cells["AN7"].Value = "COMPROBANTES GASTOS A TERCEROS"; - #endregion - #region Llenado de datos - int currentRow = 8; - foreach(var embarque in embarques){ - worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; - worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; - worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; - worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; - worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; - worksheet.Cells[$"F{currentRow}"].Value = embarque.Tipo; - worksheet.Cells[$"G{currentRow}"].Value = embarque.NoPedimento; - worksheet.Cells[$"H{currentRow}"].Value = embarque.OrdenCompra; - worksheet.Cells[$"I{currentRow}"].Value = embarque.Factura; - worksheet.Cells[$"J{currentRow}"].Value = embarque.Proveedor; - worksheet.Cells[$"K{currentRow}"].Value = embarque.DescripcionMercancia; - worksheet.Cells[$"L{currentRow}"].Value = embarque.Bultos; - worksheet.Cells[$"M{currentRow}"].Value = embarque.CantidadContenedores; - worksheet.Cells[$"N{currentRow}"].Value = embarque.PesoNeto; - worksheet.Cells[$"O{currentRow}"].Value = embarque.Incoterm; - worksheet.Cells[$"P{currentRow}"].Value = embarque.FechaETA; - worksheet.Cells[$"Q{currentRow}"].Value = embarque.Estatus; - worksheet.Cells[$"R{currentRow}"].Value = embarque.Observaciones; - worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; - worksheet.Cells[$"T{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; - worksheet.Cells[$"U{currentRow}"].Value = embarque.CostoDiarioConexion; - worksheet.Cells[$"V{currentRow}"].Value = embarque.TotalPagar; - worksheet.Cells[$"W{currentRow}"].Value = embarque.TotalPagarConexion; - worksheet.Cells[$"X{currentRow}"].Value = embarque.FechaDespacho; - worksheet.Cells[$"Y{currentRow}"].Value = embarque.NombrePaqueteria; - worksheet.Cells[$"Z{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; - worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; - worksheet.Cells[$"AB{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; - worksheet.Cells[$"AC{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; - worksheet.Cells[$"AD{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; - worksheet.Cells[$"AE{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; - worksheet.Cells[$"AF{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; - worksheet.Cells[$"AG{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; - worksheet.Cells[$"AH{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; - worksheet.Cells[$"AI{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; - worksheet.Cells[$"AJ{currentRow}"].Value = embarque.Honorarios == 0 ? "NO" : "SI"; - worksheet.Cells[$"AK{currentRow}"].Value = embarque.TotalHonorarios; - worksheet.Cells[$"AL{currentRow}"].Value = embarque.GastosTerceros == 0 ? "NO" : "SI"; - worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalGastosTerceros; - worksheet.Cells[$"AN{currentRow}"].Value = embarque.ComprobantesGastosTerceros == 0 ? "NO" : "SI"; - currentRow++; - } - #endregion - //Se crea el rango de celdas que abarcara la tabla. - ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 40]; - ExcelTable tab = worksheet.Tables.Add(range, "Table1"); - tab.TableStyle = TableStyles.Light1; - worksheet.Cells["A1:A6"].Merge = true; - //Se agrega el logo de GEMCO al documento. - ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName)); - excelImage.SetPosition(0,0,1,0); - //Aqui comienza el encabezado del documento. - worksheet.Cells["B1:D6"].Merge = true; - worksheet.Cells["E1:J1"].Merge = true; - worksheet.Cells["E2:J2"].Merge = true; - worksheet.Cells["E3:J3"].Merge = true; - worksheet.Cells["E4:J4"].Merge = true; - worksheet.Cells["E5:J5"].Merge = true; - worksheet.Cells["E6:J6"].Merge = true; - worksheet.Cells["E1:J6"].Style.Font.Size = 16; - worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); - worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES"; - worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; - worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; - worksheet.Cells["A1:BK6"].Style.Fill.PatternType = ExcelFillStyle.Solid; - worksheet.Cells["A1:BK6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); - worksheet.Cells["A7:BK7"].Style.Font.Bold = true; - worksheet.Cells["A7:BK7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; - worksheet.Cells["A7:BK7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; - 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", "ReporteEmbarques.xlsx"); - } - + string filePath = RootPathCorresponsales + PathLogoGemco + LogoGemcoFileName; + var stream = await _service.GetExcelBusquedaEmbarques(embarques, filePath); + return File(stream, "application/octet-stream", "ReporteEmbarques.xlsx"); }catch(Exception ex){ return BadRequest(ex.Message); } diff --git a/Controllers/Reportes/ReportesNewell.cs b/Controllers/Reportes/ReportesNewell.cs index f7a5bc1..536c68f 100644 --- a/Controllers/Reportes/ReportesNewell.cs +++ b/Controllers/Reportes/ReportesNewell.cs @@ -6,6 +6,7 @@ using OfficeOpenXml; using OfficeOpenXml.Table; using OfficeOpenXml.Style; using CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual; +using CORRESPONSALBackend.Contracts.Reportes.Newell.Semanal; namespace CORRESPONSALBackend.Controllers.Reportes{ [Authorize] @@ -15,9 +16,11 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ { private readonly IReporteMensualRepository _reporteMensualRepository; private readonly IReporteMensualService _reporteMensualService; - public ReportesNewellController(IReporteMensualRepository reporteMensualRepository, IReporteMensualService reporteMensualService){ + private readonly IReporteSemanalService _reporteSemanalService; + public ReportesNewellController(IReporteMensualRepository reporteMensualRepository, IReporteMensualService reporteMensualService, IReporteSemanalService reporteSemanalService){ _reporteMensualRepository = reporteMensualRepository; _reporteMensualService = reporteMensualService; + _reporteSemanalService = reporteSemanalService; } [HttpGet("ReporteMensual")] @@ -37,5 +40,15 @@ namespace CORRESPONSALBackend.Controllers.Reportes{ return StatusCode(500,ex.Message); } } + + [HttpGet("ReporteSemanal")] + public async Task GetReporteSemanal([FromQuery] int idRptSemanalFile){ + try{ + var stream = await _reporteSemanalService.GetReporteSemanal(idRptSemanalFile); + return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"ReporteSemanal.xlsx"); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 05da3e0..d95f511 100644 --- a/Program.cs +++ b/Program.cs @@ -36,6 +36,12 @@ using CORRESPONSALBackend.Contracts.Reportes.Embarques; using CORRESPONSALBackend.Repository.Reportes.Embarques; using CORRESPONSALBackend.Contracts.Reportes.GC50; using CORRESPONSALBackend.Repository.Reportes.GC50; +using CORRESPONSALBackend.Contracts.Corresponsalias.Anticipos; +using CORRESPONSALBackend.Services.Corresponsalias.Anticipos; +using CORRESPONSALBackend.Services.Reportes.GC50; +using CORRESPONSALBackend.Services.Reportes.Embarques; +using CORRESPONSALBackend.Contracts.Reportes.Newell.Semanal; +using CORRESPONSALBackend.Services.Reportes.Newell.Semanal; var builder = WebApplication.CreateBuilder(args); @@ -49,7 +55,11 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Services/Corresponsalias/Anticipos/CorresponsaliasAnticiposService.cs b/Services/Corresponsalias/Anticipos/CorresponsaliasAnticiposService.cs new file mode 100644 index 0000000..eeef1e4 --- /dev/null +++ b/Services/Corresponsalias/Anticipos/CorresponsaliasAnticiposService.cs @@ -0,0 +1,88 @@ +using CORRESPONSALBackend.Contracts.Corresponsalias.Anticipos; +using CORRESPONSALBackend.DTO.Corresponsales; +using iText.IO.Font.Constants; +using iText.IO.Image; +using iText.Kernel.Colors; +using iText.Kernel.Font; +using iText.Kernel.Geom; +using iText.Kernel.Pdf; +using iText.Layout; +using iText.Layout.Borders; +using iText.Layout.Element; +using iText.Layout.Properties; + +namespace CORRESPONSALBackend.Services.Corresponsalias.Anticipos{ + public class CorresponsaliasAnticiposService : ICorresponsaliasAnticiposService + { + public async Task GetPdf(DTOPdfAnticipo anticipo, string imageFile) + { + try{ + MemoryStream ms = new MemoryStream(); + PdfWriter pw = new PdfWriter(ms); + PdfDocument pdfDocument = new PdfDocument(pw); + Document doc = new Document(pdfDocument, PageSize.LETTER);//En este punto ya se tiene creado un docuento en blanco + PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); + doc.SetFont(font); + doc.SetMargins(25, 25, 25, 25); + #region Encabezado + + ImageData data = ImageDataFactory.Create(imageFile); + Image img = new Image(data); + Table headerTable = new Table(3).UseAllAvailableWidth(); + headerTable.AddCell(new Cell(2,1).Add(img.SetAutoScale(true).SetWidth(30).SetHeight(20)).SetBorder(Border.NO_BORDER)); + headerTable.AddCell( + new Cell(2,2) + .Add( + new Paragraph("ANTICIPO PARA CORRESPONSALIAS") + .SetTextAlignment(TextAlignment.CENTER).SetPaddingRight(30) + ) + .SetVerticalAlignment(VerticalAlignment.BOTTOM) + .SetBorder(Border.NO_BORDER) + ); + headerTable.SetBorderBottom(new SolidBorder(ColorConstants.BLACK, 2)); + doc.Add(headerTable); + #endregion + #region datos de la cuenta + Table accountTable = new Table(1).UseAllAvailableWidth().SetMarginTop(15); + accountTable.AddCell(new Cell().Add(new Paragraph("NUMERO DE CHEQUE:")).SetBorder(Border.NO_BORDER)); + accountTable.AddCell(new Cell().Add(new Paragraph($"SOLICITUD: ").Add(new Text($"{anticipo.Id}").SetItalic())).SetBorder(Border.NO_BORDER)); + accountTable.AddCell(new Cell().Add(new Paragraph("DEPENDENCIA: ").Add(new Text("CORRESPONSALIA").SetItalic())).SetBorder(Border.NO_BORDER)); + accountTable.AddCell(new Cell().Add(new Paragraph($"IMPRESION: ").Add(new Text($"{DateTime.Now}").SetItalic())).SetVerticalAlignment(VerticalAlignment.BOTTOM).SetBorder(Border.NO_BORDER)); + doc.Add(accountTable); + #endregion + #region datos del anticipo + Table dataTable = new Table(7).UseAllAvailableWidth().SetMarginTop(15).SetFontSize(8f); + dataTable.AddCell(new Cell().Add(new Paragraph("GEMCO"))); + dataTable.AddCell(new Cell().Add(new Paragraph("PEDIMENTO"))); + dataTable.AddCell(new Cell().Add(new Paragraph("CLIENTE"))); + dataTable.AddCell(new Cell().Add(new Paragraph("PRODUCTO"))); + dataTable.AddCell(new Cell().Add(new Paragraph("FECHA DE CRUCE"))); + dataTable.AddCell(new Cell().Add(new Paragraph("PROVEEDOR"))); + dataTable.AddCell(new Cell().Add(new Paragraph("IMPORTE"))); + + dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.FolioGemco)).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.Pedimento)).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.Cliente.Substring(0, anticipo.Cliente.Length - 7))).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph("")).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph(anticipo.FechaCruce != null && anticipo.FechaCruce != "" ? anticipo.FechaCruce.Substring(0,10) : "")).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph("CORRESPONSAL")).SetBorder(Border.NO_BORDER)); + dataTable.AddCell(new Cell().Add(new Paragraph($"{anticipo.Anticipo}")).SetBorder(Border.NO_BORDER)); + dataTable.SetBorderBottom(new SolidBorder(ColorConstants.BLACK, 2)); + doc.Add(dataTable); + #endregion + #region Importe final + Table importeTable = new Table(7).UseAllAvailableWidth(); + importeTable.AddCell(new Cell(1,7) + .Add(new Paragraph($"SUMA IMPORTE: $ {anticipo.Anticipo}").SetTextAlignment(TextAlignment.RIGHT).SetFontSize(10f)).SetBorder(Border.NO_BORDER) + ); + doc.Add(importeTable); + #endregion + doc.Close();//Aqui se cierra el documento para poder enviarlo al front para ser descargado. + var bytesStream = ms.ToArray(); + return bytesStream; + }catch(Exception ex){ + throw new Exception(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/Services/Reportes/Embarques/ReportesEmbarquesService.cs b/Services/Reportes/Embarques/ReportesEmbarquesService.cs new file mode 100644 index 0000000..26adf95 --- /dev/null +++ b/Services/Reportes/Embarques/ReportesEmbarquesService.cs @@ -0,0 +1,496 @@ +using System.Drawing; +using CORRESPONSALBackend.Contracts.Reportes.Embarques; +using CORRESPONSALBackend.DTO.Reportes.Embarques; +using OfficeOpenXml; +using OfficeOpenXml.Drawing; +using OfficeOpenXml.Style; +using OfficeOpenXml.Table; + +namespace CORRESPONSALBackend.Services.Reportes.Embarques{ + public class ReportesEmbarquesService : IReportesEmbarquesService + { + public async Task GetExcelBusquedaEmbarques(IEnumerable embarques, string filePath) + { + try{ + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using (ExcelPackage excelPackage = new ExcelPackage()){ + var today = DateTime.Now; + var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); + //Se crean los encabezados + #region Encabezados + worksheet.Cells["A7"].Value = "ADUANA"; + worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; + worksheet.Cells["C7"].Value = "DESTINO"; + worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; + worksheet.Cells["E7"].Value = "NOMBRE"; + worksheet.Cells["F7"].Value = "TIPO"; + worksheet.Cells["G7"].Value = "NO DE PEDIMENTO"; + worksheet.Cells["H7"].Value = "ORDEN DE COMPRA"; + worksheet.Cells["I7"].Value = "FACTURA"; + worksheet.Cells["J7"].Value = "PROVEEDOR"; + worksheet.Cells["K7"].Value = "DESCRIPCION"; + worksheet.Cells["L7"].Value = "BULTOS"; + worksheet.Cells["M7"].Value = "CANTIDAD CONTENEDORES"; + worksheet.Cells["N7"].Value = "PESO NETO"; + worksheet.Cells["O7"].Value = "INCOTERM"; + worksheet.Cells["P7"].Value = "FECHA ETA"; + worksheet.Cells["Q7"].Value = "ESTATUS"; + worksheet.Cells["R7"].Value = "OBSERVACIONES"; + worksheet.Cells["S7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; + worksheet.Cells["T7"].Value = "COSTO DIARIO ALMACENAJE"; + worksheet.Cells["U7"].Value = "COSTO DIARIO CONEXION"; + worksheet.Cells["V7"].Value = "TOTAL A PAGAR ALMACENAJE"; + worksheet.Cells["W7"].Value = "TOTAL A PAGAR CONEXION"; + worksheet.Cells["X7"].Value = "FECHA DE DESPACHO"; + worksheet.Cells["Y7"].Value = "NOMBRE DE PAQUETERIA O TRANPORTISTA"; + worksheet.Cells["Z7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; + worksheet.Cells["AA7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; + worksheet.Cells["AB7"].Value = "FACTURA CORREPSONSAL"; + worksheet.Cells["AC7"].Value = "CERTIFICADO DE CALIDAD"; + worksheet.Cells["AD7"].Value = "PACKING LIST"; + worksheet.Cells["AE7"].Value = "HOJA TECNICA"; + worksheet.Cells["AF7"].Value = "BL"; + worksheet.Cells["AG7"].Value = "PEDIMENTO INFORMATIVO"; + worksheet.Cells["AH7"].Value = "PEDIMENTO SIMPLIFICADO"; + worksheet.Cells["AI7"].Value = "DODA"; + worksheet.Cells["AJ7"].Value = "HONORARIOS AA"; + worksheet.Cells["AK7"].Value = "TOTAL HONORARIOS AA"; + worksheet.Cells["AL7"].Value = "GASTOS A TERCEROS"; + worksheet.Cells["AM7"].Value = "TOTAL GASTOS A TERCEROS"; + worksheet.Cells["AN7"].Value = "COMPROBANTES GASTOS A TERCEROS"; + #endregion + #region Llenado de datos + int currentRow = 8; + foreach(var embarque in embarques){ + worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; + worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; + worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; + worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; + worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; + worksheet.Cells[$"F{currentRow}"].Value = embarque.Tipo; + worksheet.Cells[$"G{currentRow}"].Value = embarque.NoPedimento; + worksheet.Cells[$"H{currentRow}"].Value = embarque.OrdenCompra; + worksheet.Cells[$"I{currentRow}"].Value = embarque.Factura; + worksheet.Cells[$"J{currentRow}"].Value = embarque.Proveedor; + worksheet.Cells[$"K{currentRow}"].Value = embarque.DescripcionMercancia; + worksheet.Cells[$"L{currentRow}"].Value = embarque.Bultos; + worksheet.Cells[$"M{currentRow}"].Value = embarque.CantidadContenedores; + worksheet.Cells[$"N{currentRow}"].Value = embarque.PesoNeto; + worksheet.Cells[$"O{currentRow}"].Value = embarque.Incoterm; + worksheet.Cells[$"P{currentRow}"].Value = embarque.FechaETA; + worksheet.Cells[$"Q{currentRow}"].Value = embarque.Estatus; + worksheet.Cells[$"R{currentRow}"].Value = embarque.Observaciones; + worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; + worksheet.Cells[$"T{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; + worksheet.Cells[$"U{currentRow}"].Value = embarque.CostoDiarioConexion; + worksheet.Cells[$"V{currentRow}"].Value = embarque.TotalPagar; + worksheet.Cells[$"W{currentRow}"].Value = embarque.TotalPagarConexion; + worksheet.Cells[$"X{currentRow}"].Value = embarque.FechaDespacho; + worksheet.Cells[$"Y{currentRow}"].Value = embarque.NombrePaqueteria; + worksheet.Cells[$"Z{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; + worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; + worksheet.Cells[$"AB{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; + worksheet.Cells[$"AC{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; + worksheet.Cells[$"AD{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; + worksheet.Cells[$"AE{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; + worksheet.Cells[$"AF{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; + worksheet.Cells[$"AG{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; + worksheet.Cells[$"AH{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; + worksheet.Cells[$"AI{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; + worksheet.Cells[$"AJ{currentRow}"].Value = embarque.Honorarios == 0 ? "NO" : "SI"; + worksheet.Cells[$"AK{currentRow}"].Value = embarque.TotalHonorarios; + worksheet.Cells[$"AL{currentRow}"].Value = embarque.GastosTerceros == 0 ? "NO" : "SI"; + worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalGastosTerceros; + worksheet.Cells[$"AN{currentRow}"].Value = embarque.ComprobantesGastosTerceros == 0 ? "NO" : "SI"; + currentRow++; + } + #endregion + //Se crea el rango de celdas que abarcara la tabla. + ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 40]; + ExcelTable tab = worksheet.Tables.Add(range, "Table1"); + tab.TableStyle = TableStyles.Light1; + worksheet.Cells["A1:A6"].Merge = true; + //Se agrega el logo de GEMCO al documento. + ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(filePath)); + excelImage.SetPosition(0,0,1,0); + //Aqui comienza el encabezado del documento. + worksheet.Cells["B1:D6"].Merge = true; + worksheet.Cells["E1:J1"].Merge = true; + worksheet.Cells["E2:J2"].Merge = true; + worksheet.Cells["E3:J3"].Merge = true; + worksheet.Cells["E4:J4"].Merge = true; + worksheet.Cells["E5:J5"].Merge = true; + worksheet.Cells["E6:J6"].Merge = true; + worksheet.Cells["E1:J6"].Style.Font.Size = 16; + worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); + worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES"; + worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; + worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; + worksheet.Cells["A1:BK6"].Style.Fill.PatternType = ExcelFillStyle.Solid; + worksheet.Cells["A1:BK6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); + worksheet.Cells["A7:BK7"].Style.Font.Bold = true; + worksheet.Cells["A7:BK7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + worksheet.Cells["A7:BK7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; + 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); + } + } + + public async Task GetExcelEmbarquesDespachados(IEnumerable embarques, string filePath) + { + try{ + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using (ExcelPackage excelPackage = new ExcelPackage()){ + var today = DateTime.Now; + var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); + //Se crean los encabezados + #region Encabezados + worksheet.Cells["A7"].Value = "ADUANA"; + worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; + worksheet.Cells["C7"].Value = "DESTINO"; + worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; + worksheet.Cells["E7"].Value = "NOMBRE"; + worksheet.Cells["F7"].Value = "TRAFICO"; + worksheet.Cells["G7"].Value = "REFERENCIA"; + worksheet.Cells["H7"].Value = "NO DE PEDIMENTO"; + worksheet.Cells["I7"].Value = "CLAVE DE PEDIMENTO"; + worksheet.Cells["J7"].Value = "TIPO"; + worksheet.Cells["K7"].Value = "ORDEN DE COMPRA"; + worksheet.Cells["L7"].Value = "FACTURA"; + worksheet.Cells["M7"].Value = "PROVEEDOR"; + worksheet.Cells["N7"].Value = "DESCRIPCION MERCANCIA"; + worksheet.Cells["O7"].Value = "LÍNEA TRANSPORTISTA INTERNACIONAL"; + worksheet.Cells["P7"].Value = "LINEA NAVIERA"; + worksheet.Cells["Q7"].Value = "MAWB"; + worksheet.Cells["R7"].Value = "HAWB"; + worksheet.Cells["S7"].Value = "FECHA DE NOTIFICACION"; + worksheet.Cells["T7"].Value = "BULTOS"; + worksheet.Cells["U7"].Value = "CANTIDAD CONTENEDORES"; + worksheet.Cells["V7"].Value = "NO. CONTENEDORES"; + worksheet.Cells["W7"].Value = "PESO BRUTO"; + worksheet.Cells["X7"].Value = "PESO NETO"; + worksheet.Cells["Y7"].Value = "INCOTERM"; + worksheet.Cells["Z7"].Value = "FECHA ETA"; + worksheet.Cells["AA7"].Value = "FECHA DE ENTRADA"; + worksheet.Cells["AB7"].Value = "FECHA DE REVALIDACION GUIA"; + worksheet.Cells["AC7"].Value = "MONTO USD"; + worksheet.Cells["AD7"].Value = "ORIGEN"; + worksheet.Cells["AE7"].Value = "FRACCION ARANCELARIA"; + worksheet.Cells["AF7"].Value = "DESCRIPCION"; + worksheet.Cells["AG7"].Value = "PPREFERENCIA ARANCELARIA"; + worksheet.Cells["AH7"].Value = "ESTATUS"; + worksheet.Cells["AI7"].Value = "OBSERVACIONES"; + worksheet.Cells["AJ7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; + worksheet.Cells["AK7"].Value = "COSTO DIARIO ALMACENAJE"; + worksheet.Cells["AL7"].Value = "COSTO DIARIO CONEXIÓN"; + worksheet.Cells["AM7"].Value = "TOTAL A PAGAR ALMACENAJE"; + worksheet.Cells["AN7"].Value = "TOTAL A PAGAR CONEXIÓN"; + worksheet.Cells["AO7"].Value = "FECHA DE PAGO PEDIMENTO"; + worksheet.Cells["AP7"].Value = "FECHA DE INSTRUCCIONES"; + worksheet.Cells["AQ7"].Value = "HORA DE INSTRUCCIONES"; + worksheet.Cells["AR7"].Value = "FECHA DE DESPACHO"; + worksheet.Cells["AS7"].Value = "DIAS C/PDTO PAGADO"; + worksheet.Cells["AT7"].Value = "FECHA SALIDA DE CONTENEDORES"; + worksheet.Cells["AU7"].Value = "NOMBRE DE PAQUETERIA O TRANSPORTISTA"; + worksheet.Cells["AV7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; + worksheet.Cells["AW7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; + worksheet.Cells["AX7"].Value = "HORA DE ENTREGA EN DESTINO FINAL"; + worksheet.Cells["AY7"].Value = "FACTURA CORRESPONSAL"; + worksheet.Cells["AZ7"].Value = "CERTIFICADO DE CALIDAD"; + worksheet.Cells["BA7"].Value = "PACKING LIST"; + worksheet.Cells["BB7"].Value = "HOJA TECNICA"; + worksheet.Cells["BC7"].Value = "BL"; + worksheet.Cells["BD7"].Value = "PEDIMENTO INFORMATIVO"; + worksheet.Cells["BE7"].Value = "PEDIMENTO SIMPLIFICADO"; + worksheet.Cells["BF7"].Value = "DODA"; + worksheet.Cells["BG7"].Value = "HONORARIOS AA"; + worksheet.Cells["BH7"].Value = "TOTAL HONORARIOS AA"; + worksheet.Cells["BI7"].Value = "GASTOS TERCEROS"; + worksheet.Cells["BJ7"].Value = "TOTAL GASTOS TERCEROS"; + worksheet.Cells["BK7"].Value = "COMPROBANTES GASTOS TERCEROS"; + #endregion + #region Llenado de datos + int currentRow = 8; + foreach(var embarque in embarques){ + worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; + worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; + worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; + worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; + worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; + worksheet.Cells[$"F{currentRow}"].Value = embarque.Trafico; + worksheet.Cells[$"G{currentRow}"].Value = embarque.Referencia; + worksheet.Cells[$"H{currentRow}"].Value = embarque.NoPedimento; + worksheet.Cells[$"I{currentRow}"].Value = embarque.ClavePedimento; + worksheet.Cells[$"J{currentRow}"].Value = embarque.Tipo; + worksheet.Cells[$"K{currentRow}"].Value = embarque.OrdenCompra; + worksheet.Cells[$"L{currentRow}"].Value = embarque.Factura; + worksheet.Cells[$"M{currentRow}"].Value = embarque.Proveedor; + worksheet.Cells[$"N{currentRow}"].Value = embarque.DescripcionMercancia; + worksheet.Cells[$"O{currentRow}"].Value = embarque.LineaTransportistaInternacional; + worksheet.Cells[$"P{currentRow}"].Value = embarque.LineaNaviera; + worksheet.Cells[$"Q{currentRow}"].Value = embarque.MAWB; + worksheet.Cells[$"R{currentRow}"].Value = embarque.HAWB; + worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaNotificacion; + worksheet.Cells[$"T{currentRow}"].Value = embarque.Bultos; + worksheet.Cells[$"U{currentRow}"].Value = embarque.CantidadContenedores; + worksheet.Cells[$"V{currentRow}"].Value = embarque.NumerosContenedores; + worksheet.Cells[$"W{currentRow}"].Value = embarque.PesoBruto; + worksheet.Cells[$"X{currentRow}"].Value = embarque.PesoNeto; + worksheet.Cells[$"Y{currentRow}"].Value = embarque.Incoterm; + worksheet.Cells[$"Z{currentRow}"].Value = embarque.FechaETA; + worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntrada; + worksheet.Cells[$"AB{currentRow}"].Value = embarque.FechaRevalidacionGuia; + worksheet.Cells[$"AC{currentRow}"].Value = embarque.MontoUSD; + worksheet.Cells[$"AD{currentRow}"].Value = embarque.Origen; + worksheet.Cells[$"AE{currentRow}"].Value = embarque.FraccionArancelaria; + worksheet.Cells[$"AF{currentRow}"].Value = embarque.Descripcion; + worksheet.Cells[$"AG{currentRow}"].Value = embarque.PreferenciaArancelaria; + worksheet.Cells[$"AH{currentRow}"].Value = embarque.Estatus; + worksheet.Cells[$"AI{currentRow}"].Value = embarque.Observaciones; + worksheet.Cells[$"AJ{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; + worksheet.Cells[$"AK{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; + worksheet.Cells[$"AL{currentRow}"].Value = embarque.CostoDiarioConexion; + worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalPagar; + worksheet.Cells[$"AN{currentRow}"].Value = embarque.TotalPagarConexion; + worksheet.Cells[$"AO{currentRow}"].Value = embarque.FechaPagoPedimento; + worksheet.Cells[$"AP{currentRow}"].Value = embarque.FechaInstrucciones; + worksheet.Cells[$"AQ{currentRow}"].Value = embarque.HoraInstrucciones; + worksheet.Cells[$"AR{currentRow}"].Value = embarque.FechaDespacho; + worksheet.Cells[$"AS{currentRow}"].Value = embarque.DiasCPPagado; + worksheet.Cells[$"AT{currentRow}"].Value = embarque.FechaSalidaContenedores; + worksheet.Cells[$"AU{currentRow}"].Value = embarque.NombrePaqueteria; + worksheet.Cells[$"AV{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; + worksheet.Cells[$"AW{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; + worksheet.Cells[$"AX{currentRow}"].Value = embarque.HoraEntregaDestinoFinal; + worksheet.Cells[$"AY{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; + worksheet.Cells[$"AZ{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; + worksheet.Cells[$"BA{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; + worksheet.Cells[$"BB{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; + worksheet.Cells[$"BC{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; + worksheet.Cells[$"BD{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; + worksheet.Cells[$"BE{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; + worksheet.Cells[$"BF{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; + worksheet.Cells[$"BG{currentRow}"].Value = embarque.Honorarios == 0 ? "NO" : "SI"; + worksheet.Cells[$"BH{currentRow}"].Value = embarque.TotalHonorarios; + worksheet.Cells[$"BI{currentRow}"].Value = embarque.GastosTerceros == 0 ? "NO" : "SI"; + worksheet.Cells[$"BJ{currentRow}"].Value = embarque.TotalGastosTerceros; + worksheet.Cells[$"BK{currentRow}"].Value = embarque.ComprobantesGastosTerceros == 0 ? "NO" : "SI"; + currentRow++; + } + #endregion + //Se crea el rango de celdas que abarcara la tabla. + ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 63]; + ExcelTable tab = worksheet.Tables.Add(range, "Table1"); + tab.TableStyle = TableStyles.Light1; + worksheet.Cells["A1:A6"].Merge = true; + //Se agrega el logo de GEMCO al documento. + ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(filePath)); + excelImage.SetPosition(0,0,1,0); + //Aqui comienza el encabezado del documento. + worksheet.Cells["B1:D6"].Merge = true; + worksheet.Cells["E1:J1"].Merge = true; + worksheet.Cells["E2:J2"].Merge = true; + worksheet.Cells["E3:J3"].Merge = true; + worksheet.Cells["E4:J4"].Merge = true; + worksheet.Cells["E5:J5"].Merge = true; + worksheet.Cells["E6:J6"].Merge = true; + worksheet.Cells["E1:J6"].Style.Font.Size = 16; + worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); + worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES POR DESPACHADOS"; + worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; + worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; + worksheet.Cells["A1:BK6"].Style.Fill.PatternType = ExcelFillStyle.Solid; + worksheet.Cells["A1:BK6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); + worksheet.Cells["A7:BK7"].Style.Font.Bold = true; + worksheet.Cells["A7:BK7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + worksheet.Cells["A7:BK7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; + 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); + } + } + + public async Task GetExcelEmbarquesPorImportar(IEnumerable embarques, string filePath) + { + try{ + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using (ExcelPackage excelPackage = new ExcelPackage()){ + var today = DateTime.Now; + var worksheet = excelPackage.Workbook.Worksheets.Add($"EmbarquesPorImportar_{today.Day}-{today.Month}-{today.Year}"); + //Se crean los encabezados + #region Encabezados + worksheet.Cells["A7"].Value = "ADUANA"; + worksheet.Cells["B7"].Value = "TIPO DE EMBARQUE"; + worksheet.Cells["C7"].Value = "DESTINO"; + worksheet.Cells["D7"].Value = "DIAS EN ADUANA"; + worksheet.Cells["E7"].Value = "NOMBRE"; + worksheet.Cells["F7"].Value = "TRAFICO"; + worksheet.Cells["G7"].Value = "REFERENCIA"; + worksheet.Cells["H7"].Value = "NO DE PEDIMENTO"; + worksheet.Cells["I7"].Value = "CLAVE DE PEDIMENTO"; + worksheet.Cells["J7"].Value = "TIPO"; + worksheet.Cells["K7"].Value = "ORDEN DE COMPRA"; + worksheet.Cells["L7"].Value = "FACTURA"; + worksheet.Cells["M7"].Value = "PROVEEDOR"; + worksheet.Cells["N7"].Value = "DESCRIPCION MERCANCIA"; + worksheet.Cells["O7"].Value = "LÍNEA TRANSPORTISTA INTERNACIONAL"; + worksheet.Cells["P7"].Value = "LINEA NAVIERA"; + worksheet.Cells["Q7"].Value = "MAWB"; + worksheet.Cells["R7"].Value = "HAWB"; + worksheet.Cells["S7"].Value = "FECHA DE NOTIFICACION"; + worksheet.Cells["T7"].Value = "BULTOS"; + worksheet.Cells["U7"].Value = "CANTIDAD CONTENEDORES"; + worksheet.Cells["V7"].Value = "NO. CONTENEDORES"; + worksheet.Cells["W7"].Value = "PESO BRUTO"; + worksheet.Cells["X7"].Value = "PESO NETO"; + worksheet.Cells["Y7"].Value = "INCOTERM"; + worksheet.Cells["Z7"].Value = "FECHA ETA"; + worksheet.Cells["AA7"].Value = "FECHA DE ENTRADA"; + worksheet.Cells["AB7"].Value = "FECHA DE REVALIDACION GUIA"; + worksheet.Cells["AC7"].Value = "MONTO USD"; + worksheet.Cells["AD7"].Value = "ORIGEN"; + worksheet.Cells["AE7"].Value = "FRACCION ARANCELARIA"; + worksheet.Cells["AF7"].Value = "DESCRIPCION"; + worksheet.Cells["AG7"].Value = "PPREFERENCIA ARANCELARIA"; + worksheet.Cells["AH7"].Value = "ESTATUS"; + worksheet.Cells["AI7"].Value = "OBSERVACIONES"; + worksheet.Cells["AJ7"].Value = "FECHA DE INICIO DE GASTOS DE ALMACENAJE"; + worksheet.Cells["AK7"].Value = "COSTO DIARIO ALMACENAJE"; + worksheet.Cells["AL7"].Value = "COSTO DIARIO CONEXIÓN"; + worksheet.Cells["AM7"].Value = "TOTAL A PAGAR ALMACENAJE"; + worksheet.Cells["AN7"].Value = "TOTAL A PAGAR CONEXIÓN"; + worksheet.Cells["AO7"].Value = "FECHA DE PAGO PEDIMENTO"; + worksheet.Cells["AP7"].Value = "FECHA DE INSTRUCCIONES"; + worksheet.Cells["AQ7"].Value = "HORA DE INSTRUCCIONES"; + worksheet.Cells["AR7"].Value = "FECHA DE DESPACHO"; + worksheet.Cells["AS7"].Value = "DIAS C/PDTO PAGADO"; + worksheet.Cells["AT7"].Value = "FECHA SALIDA DE CONTENEDORES"; + worksheet.Cells["AU7"].Value = "NOMBRE DE PAQUETERIA O TRANSPORTISTA"; + worksheet.Cells["AV7"].Value = "NO. DE GUIA DE EMBARQUE A DESTINO"; + worksheet.Cells["AW7"].Value = "FECHA DE ENTREGA EN DESTINO FINAL"; + worksheet.Cells["AX7"].Value = "HORA DE ENTREGA EN DESTINO FINAL"; + worksheet.Cells["AY7"].Value = "FACTURA CORRESPONSAL"; + worksheet.Cells["AZ7"].Value = "CERTIFICADO DE CALIDAD"; + worksheet.Cells["BA7"].Value = "PACKING LIST"; + worksheet.Cells["BB7"].Value = "HOJA TECNICA"; + worksheet.Cells["BC7"].Value = "BL"; + worksheet.Cells["BD7"].Value = "PEDIMENTO INFORMATIVO"; + worksheet.Cells["BE7"].Value = "PEDIMENTO SIMPLIFICADO"; + worksheet.Cells["BF7"].Value = "DODA"; + #endregion + #region Llenado de datos + int currentRow = 8; + foreach(var embarque in embarques){ + worksheet.Cells[$"A{currentRow}"].Value = embarque.Aduana; + worksheet.Cells[$"B{currentRow}"].Value = embarque.TipoEmbarque; + worksheet.Cells[$"C{currentRow}"].Value = embarque.Destino; + worksheet.Cells[$"D{currentRow}"].Value = embarque.DiasEnAduana; + worksheet.Cells[$"E{currentRow}"].Value = embarque.Nombre; + worksheet.Cells[$"F{currentRow}"].Value = embarque.Trafico; + worksheet.Cells[$"G{currentRow}"].Value = embarque.Referencia; + worksheet.Cells[$"H{currentRow}"].Value = embarque.NoPedimento; + worksheet.Cells[$"I{currentRow}"].Value = embarque.ClavePedimento; + worksheet.Cells[$"J{currentRow}"].Value = embarque.Tipo; + worksheet.Cells[$"K{currentRow}"].Value = embarque.OrdenCompra; + worksheet.Cells[$"L{currentRow}"].Value = embarque.Factura; + worksheet.Cells[$"M{currentRow}"].Value = embarque.Proveedor; + worksheet.Cells[$"N{currentRow}"].Value = embarque.DescripcionMercancia; + worksheet.Cells[$"O{currentRow}"].Value = embarque.LineaTransportistaInternacional; + worksheet.Cells[$"P{currentRow}"].Value = embarque.LineaNaviera; + worksheet.Cells[$"Q{currentRow}"].Value = embarque.MAWB; + worksheet.Cells[$"R{currentRow}"].Value = embarque.HAWB; + worksheet.Cells[$"S{currentRow}"].Value = embarque.FechaNotificacion; + worksheet.Cells[$"T{currentRow}"].Value = embarque.Bultos; + worksheet.Cells[$"U{currentRow}"].Value = embarque.CantidadContenedores; + worksheet.Cells[$"V{currentRow}"].Value = embarque.NumerosContenedores; + worksheet.Cells[$"W{currentRow}"].Value = embarque.PesoBruto; + worksheet.Cells[$"X{currentRow}"].Value = embarque.PesoNeto; + worksheet.Cells[$"Y{currentRow}"].Value = embarque.Incoterm; + worksheet.Cells[$"Z{currentRow}"].Value = embarque.FechaETA; + worksheet.Cells[$"AA{currentRow}"].Value = embarque.FechaEntrada; + worksheet.Cells[$"AB{currentRow}"].Value = embarque.FechaRevalidacionGuia; + worksheet.Cells[$"AC{currentRow}"].Value = embarque.MontoUSD; + worksheet.Cells[$"AD{currentRow}"].Value = embarque.Origen; + worksheet.Cells[$"AE{currentRow}"].Value = embarque.FraccionArancelaria; + worksheet.Cells[$"AF{currentRow}"].Value = embarque.Descripcion; + worksheet.Cells[$"AG{currentRow}"].Value = embarque.PreferenciaArancelaria; + worksheet.Cells[$"AH{currentRow}"].Value = embarque.Estatus; + worksheet.Cells[$"AI{currentRow}"].Value = embarque.Observaciones; + worksheet.Cells[$"AJ{currentRow}"].Value = embarque.FechaInicioGastosAlmacenaje; + worksheet.Cells[$"AK{currentRow}"].Value = embarque.CostoDiarioAlmacenaje; + worksheet.Cells[$"AL{currentRow}"].Value = embarque.CostoDiarioConexion; + worksheet.Cells[$"AM{currentRow}"].Value = embarque.TotalPagar; + worksheet.Cells[$"AN{currentRow}"].Value = embarque.TotalPagarConexion; + worksheet.Cells[$"AO{currentRow}"].Value = embarque.FechaPagoPedimento; + worksheet.Cells[$"AP{currentRow}"].Value = embarque.FechaInstrucciones; + worksheet.Cells[$"AQ{currentRow}"].Value = embarque.HoraInstrucciones; + worksheet.Cells[$"AR{currentRow}"].Value = embarque.FechaDespacho; + worksheet.Cells[$"AS{currentRow}"].Value = embarque.DiasCPPagado; + worksheet.Cells[$"AT{currentRow}"].Value = embarque.FechaSalidaContenedores; + worksheet.Cells[$"AU{currentRow}"].Value = embarque.NombrePaqueteria; + worksheet.Cells[$"AV{currentRow}"].Value = embarque.NoGuiaEmbarqueDestino; + worksheet.Cells[$"AW{currentRow}"].Value = embarque.FechaEntregaDestinoFinal; + worksheet.Cells[$"AX{currentRow}"].Value = embarque.HoraEntregaDestinoFinal; + worksheet.Cells[$"AY{currentRow}"].Value = embarque.FacturaCorresponsal == 0 ? "NO" : "SI"; + worksheet.Cells[$"AZ{currentRow}"].Value = embarque.CertificadoCalidad == 0 ? "NO" : "SI"; + worksheet.Cells[$"BA{currentRow}"].Value = embarque.PackingList == 0 ? "NO" : "SI"; + worksheet.Cells[$"BB{currentRow}"].Value = embarque.HojaTecnica == 0 ? "NO" : "SI"; + worksheet.Cells[$"BC{currentRow}"].Value = embarque.BL == 0 ? "NO" : "SI"; + worksheet.Cells[$"BD{currentRow}"].Value = embarque.PedimentoInformativo == 0 ? "NO" : "SI"; + worksheet.Cells[$"BE{currentRow}"].Value = embarque.PedimentoSimplificado == 0 ? "NO" : "SI"; + worksheet.Cells[$"BF{currentRow}"].Value = embarque.DODA == 0 ? "NO" : "SI"; + currentRow++; + } + #endregion + //Se crea la tabla en el rango de celdas donde se mostrara la inforamcion. + ExcelRange range = worksheet.Cells[7, 1,embarques.Count() + 7, 58]; + ExcelTable tab = worksheet.Tables.Add(range, "Table1"); + tab.TableStyle = TableStyles.Light1; + worksheet.Cells["A1:A6"].Merge = true; + //Se agrega el logo de GEMCO al documento. + ExcelPicture excelImage = worksheet.Drawings.AddPicture("Logo", new FileInfo(filePath)); + excelImage.SetPosition(0,0,1,0); + //Aqui comienza el encabezado del documento. + worksheet.Cells["B1:D6"].Merge = true; + worksheet.Cells["E1:J1"].Merge = true; + worksheet.Cells["E2:J2"].Merge = true; + worksheet.Cells["E3:J3"].Merge = true; + worksheet.Cells["E4:J4"].Merge = true; + worksheet.Cells["E5:J5"].Merge = true; + worksheet.Cells["E6:J6"].Merge = true; + worksheet.Cells["E1:J6"].Style.Font.Size = 16; + worksheet.Cells["E1:J6"].Style.Font.Color.SetColor(Color.FromArgb(74,74,173)); + worksheet.Cells["E2"].Value = "REPORTE DE EMBARQUES POR IMPORTAR"; + worksheet.Cells["E3"].Value = $"Reporte Generado al: {today.Day}/{today.Month}/{today.Year}"; + worksheet.Cells["E4"].Value = $"Fecha y Hora de Creación: {today.Day}/{today.Month}/{today.Year} {today.Hour}:{today.Minute}:{today.Second}"; + worksheet.Cells["A1:BG6"].Style.Fill.PatternType = ExcelFillStyle.Solid; + worksheet.Cells["A1:BG6"].Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#FFFFFF")); + worksheet.Cells["A7:BG7"].Style.Font.Bold = true; + worksheet.Cells["A7:BG7"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + worksheet.Cells["A7:BG7"].Style.VerticalAlignment = ExcelVerticalAlignment.Center; + 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); + } + } + } +} \ No newline at end of file diff --git a/Services/Reportes/GC50/ReporteGC50Service.cs b/Services/Reportes/GC50/ReporteGC50Service.cs new file mode 100644 index 0000000..b3ac8bc --- /dev/null +++ b/Services/Reportes/GC50/ReporteGC50Service.cs @@ -0,0 +1,31 @@ +using CORRESPONSALBackend.Contracts.Reportes.GC50; +using CORRESPONSALBackend.DTO.Reportes.GC50; +using OfficeOpenXml; +using OfficeOpenXml.Table; + +namespace CORRESPONSALBackend.Services.Reportes.GC50{ + public class ReporteGC50Service : IReporteGC50Service + { + public async Task GetExcel(IEnumerable traficos) + { + try{ + 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, 23]; + 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); + return stream; + } + }catch(Exception ex){ + throw new Exception(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/Services/Reportes/Newell/Semanal/ReporteSemanalService.cs b/Services/Reportes/Newell/Semanal/ReporteSemanalService.cs new file mode 100644 index 0000000..a974793 --- /dev/null +++ b/Services/Reportes/Newell/Semanal/ReporteSemanalService.cs @@ -0,0 +1,63 @@ +using CORRESPONSALBackend.Contracts.Corresponsalias; +using CORRESPONSALBackend.Contracts.Reportes.Newell.Semanal; +using CORRESPONSALBackend.Contracts.Utils; +using CORRESPONSALBackend.DTO.Reportes; +using CORRESPONSALBackend.Models.Utils; +using OfficeOpenXml; + +namespace CORRESPONSALBackend.Services.Reportes.Newell.Semanal{ + public class ReporteSemanalService : IReporteSemanalService + { + private readonly IFileManagerRepository _Repo; + private readonly IFilePaths4ProcessRepository _RepoRelativePath; + private readonly ICorresponsaliasTraficosRepository _traficosRepository; + private readonly IConfiguration _config; + private readonly string RootPathCorresponsales; + public ReporteSemanalService(IFilePaths4ProcessRepository RepoRelativePath, IConfiguration config, IFileManagerRepository Repo, ICorresponsaliasTraficosRepository traficosRepository){ + _Repo = Repo; + _RepoRelativePath = RepoRelativePath; + _traficosRepository = traficosRepository; + _config = config; + RootPathCorresponsales = _config.GetValue("AllFiles"); + } + public async Task GetReporteSemanal(int idRptSemanalFile) + { + //Obtener la ruta del archivo + //Se obtiene la ruta del archivo + FileManager recFound = await _Repo.getFileById(idRptSemanalFile); + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(recFound.Proceso); + string filePath = RootPathCorresponsales + RelativePath.Path + recFound.NombreArchivo; + var file = new FileInfo(filePath); + //Leer el archivo con epplus + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using(ExcelPackage package = new ExcelPackage(file)){ + var worksheet = package.Workbook.Worksheets.FirstOrDefault(); + //mapear los renglones a un array + var start = worksheet.Dimension.Start; + var end = worksheet.Dimension.End; + int initialRow = start.Row+1; + for (int currentRow = initialRow; currentRow <= end.Row; currentRow++)// Recorrer renglon por renglon + { + if(!string.IsNullOrWhiteSpace(worksheet.Cells[$"C{currentRow}"].Value?.ToString()) && !string.IsNullOrEmpty(worksheet.Cells[$"C{currentRow}"].Value?.ToString())){ + var pedimento = worksheet.Cells[$"C{currentRow}"].Value.ToString(); + var dto = await _traficosRepository.GetByPedimento(int.Parse(pedimento)); + worksheet.Cells[$"S{currentRow}"].Value = dto.GC; + worksheet.Cells[$"T{currentRow}"].Value = dto.Contenedor; + worksheet.Cells[$"U{currentRow}"].Value = dto.CuentaDeGastos; + worksheet.Cells[$"V{currentRow}"].Value = dto.Razon; + worksheet.Cells[$"W{currentRow}"].Value = dto.Maniobras; + }else{ + continue; + } + } + //Devolver el MS del archivo. + worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + var stream = new MemoryStream(); + package.SaveAs(stream); + stream.Position = 0; + if(System.IO.File.Exists(filePath)) System.IO.File.Delete(filePath); + return stream; + } + } + } +} \ No newline at end of file