|
|
@ -5,6 +5,16 @@ using CORRESPONSALBackend.Models.Corresponsales; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using CORRESPONSALBackend.Contracts.Utils; |
|
|
|
using CORRESPONSALBackend.Contracts.Utils; |
|
|
|
|
|
|
|
using iText.Kernel.Pdf; |
|
|
|
|
|
|
|
using iText.Layout; |
|
|
|
|
|
|
|
using iText.Kernel.Geom; |
|
|
|
|
|
|
|
using iText.Layout.Element; |
|
|
|
|
|
|
|
using iText.IO.Image; |
|
|
|
|
|
|
|
using iText.Layout.Properties; |
|
|
|
|
|
|
|
using iText.Kernel.Colors; |
|
|
|
|
|
|
|
using iText.Layout.Borders; |
|
|
|
|
|
|
|
using iText.Kernel.Font; |
|
|
|
|
|
|
|
using iText.IO.Font.Constants; |
|
|
|
|
|
|
|
|
|
|
|
namespace CORRESPONSALBackend.Controllers.Corresponsalias |
|
|
|
namespace CORRESPONSALBackend.Controllers.Corresponsalias |
|
|
|
{ |
|
|
|
{ |
|
|
@ -17,12 +27,14 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias |
|
|
|
private readonly ICorresponsaliasAnticiposRepository _Repo; |
|
|
|
private readonly ICorresponsaliasAnticiposRepository _Repo; |
|
|
|
private readonly IConfiguration _config; |
|
|
|
private readonly IConfiguration _config; |
|
|
|
private readonly IFileManagerRepository _fileManager; |
|
|
|
private readonly IFileManagerRepository _fileManager; |
|
|
|
|
|
|
|
private readonly ICorresponsaliasTraficosRepository _traficoRepository; |
|
|
|
|
|
|
|
|
|
|
|
public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager) |
|
|
|
public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager, ICorresponsaliasTraficosRepository traficoRepository) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_config = config; |
|
|
|
_config = config; |
|
|
|
_Repo = Repo; |
|
|
|
_Repo = Repo; |
|
|
|
_fileManager = fileManager; |
|
|
|
_fileManager = fileManager; |
|
|
|
|
|
|
|
_traficoRepository = traficoRepository; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
[HttpPost] |
|
|
@ -74,6 +86,79 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias |
|
|
|
return entrada; |
|
|
|
return entrada; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("Download")] |
|
|
|
|
|
|
|
public async Task<IActionResult> Download([FromQuery] int idTrafico, [FromQuery] int idAnticipo){ |
|
|
|
|
|
|
|
var trafico = await _traficoRepository.Get(idTrafico); |
|
|
|
|
|
|
|
var anticipos = await _Repo.getAll(idTrafico); |
|
|
|
|
|
|
|
var anticipo = anticipos.First(x => x.id == idAnticipo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "C:\\data\\Corresponsales\\Img\\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(trafico.FolioGemco)).SetBorder(Border.NO_BORDER)); |
|
|
|
|
|
|
|
dataTable.AddCell(new Cell().Add(new Paragraph($"{trafico.Aduana}-{trafico.Patente}-{trafico.Pedimento}")).SetBorder(Border.NO_BORDER)); |
|
|
|
|
|
|
|
dataTable.AddCell(new Cell().Add(new Paragraph($"ALEN DEL NORTE S.A. DE C.V.")).SetBorder(Border.NO_BORDER)); |
|
|
|
|
|
|
|
dataTable.AddCell(new Cell().Add(new Paragraph("")).SetBorder(Border.NO_BORDER)); |
|
|
|
|
|
|
|
dataTable.AddCell(new Cell().Add(new Paragraph(trafico.FechaDesaduanamiento != null && trafico.FechaDesaduanamiento != "" ? trafico.FechaDesaduanamiento.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.Position = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new FileStreamResult(ms, "application/pdf"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |