feature/ReportesContabilidad_FacturasTraficosConsolidadosAlen_20240116
commit
c5afa9e7b7
@ -0,0 +1,5 @@ |
|||||||
|
namespace CORRESPONSALBackend.Contracts.Corresponsalias.Services{ |
||||||
|
public interface ICorresponsaliasTraficosService{ |
||||||
|
public Task<List<string[]>> ReadTxtFacturasAlen(int fileId); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
using CORRESPONSALBackend.Models.Corresponsales; |
||||||
|
|
||||||
|
namespace CORRESPONSALBackend.Contracts.Reportes.Alen{ |
||||||
|
public interface IReportesAlenService{ |
||||||
|
public Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
using CORRESPONSALBackend.Contracts.Corresponsalias; |
||||||
|
using CORRESPONSALBackend.Contracts.Reportes.Alen; |
||||||
|
using Microsoft.AspNetCore.Authorization; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace CORRESPONSALBackend.Controllers.Reportes{ |
||||||
|
[Authorize] |
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController] |
||||||
|
public class ReportesAlenController : ControllerBase{ |
||||||
|
|
||||||
|
private readonly ICorresponsaliasTraficosRepository _traficosRepository; |
||||||
|
private readonly ICorresponsaliasFacturasRepository _facturasRepository; |
||||||
|
private readonly ICorresponsaliasContenedoresRepository _contenedoresRepository; |
||||||
|
private readonly IReportesAlenService _reportesAlenService; |
||||||
|
public ReportesAlenController(ICorresponsaliasTraficosRepository traficosRepository, ICorresponsaliasFacturasRepository facturasRepository, |
||||||
|
IReportesAlenService reportesAlenService, ICorresponsaliasContenedoresRepository contenedoresRepository){ |
||||||
|
_traficosRepository = traficosRepository; |
||||||
|
_facturasRepository = facturasRepository; |
||||||
|
_contenedoresRepository = contenedoresRepository; |
||||||
|
_reportesAlenService = reportesAlenService; |
||||||
|
} |
||||||
|
|
||||||
|
[HttpGet("RelacionFacturas")] |
||||||
|
public async Task<IActionResult> GetRelacionFacturas([FromQuery] string referencia){ |
||||||
|
try{ |
||||||
|
var trafico = await _traficosRepository.GetByReferencia(referencia); |
||||||
|
var facturas = await _facturasRepository.GetAll(trafico.id); |
||||||
|
var contenedores = await _contenedoresRepository.GetAll(trafico.id); |
||||||
|
var stream = await _reportesAlenService.GetRelacionFacturas(trafico, facturas, contenedores); |
||||||
|
if(stream.Length > 0){ |
||||||
|
stream.Position = 0; |
||||||
|
return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"RelacionFacturas.xlsx"); |
||||||
|
}else{ |
||||||
|
throw new Exception("Ocurrio un error al generar el reporte, intentelo de nuevo"); |
||||||
|
} |
||||||
|
}catch(Exception ex){ |
||||||
|
return BadRequest(ex.Message); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
using CORRESPONSALBackend.Contracts.Corresponsalias.Services; |
||||||
|
using CORRESPONSALBackend.Contracts.Utils; |
||||||
|
using CORRESPONSALBackend.Models.Utils; |
||||||
|
|
||||||
|
namespace CORRESPONSALBackend.Services.Corresponsalias.Traficos{ |
||||||
|
public class CorresponsaliasTraficosService : ICorresponsaliasTraficosService |
||||||
|
{ |
||||||
|
private readonly IFileManagerRepository _fileManagerRepo; |
||||||
|
private readonly IFilePaths4ProcessRepository _RepoRelativePath; |
||||||
|
private readonly IConfiguration _config; |
||||||
|
private readonly string RootPathCorresponsales; |
||||||
|
|
||||||
|
public CorresponsaliasTraficosService(IFileManagerRepository fileManagerRepo, IFilePaths4ProcessRepository RepoRelativePath, IConfiguration config){ |
||||||
|
_fileManagerRepo = fileManagerRepo; |
||||||
|
_RepoRelativePath = RepoRelativePath; |
||||||
|
_config = config; |
||||||
|
RootPathCorresponsales = _config.GetValue<string>("AllFiles"); |
||||||
|
} |
||||||
|
public async Task<List<string[]>> ReadTxtFacturasAlen(int fileId) |
||||||
|
{ |
||||||
|
FileManager recFound = await _fileManagerRepo.getFileById(fileId); |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(recFound.Proceso); |
||||||
|
string filePath = RootPathCorresponsales + RelativePath.Path + recFound.NombreArchivo; |
||||||
|
if(System.IO.File.Exists(filePath)){ |
||||||
|
try{ |
||||||
|
var fileContent = File.ReadAllText(filePath); |
||||||
|
string[] GCs = fileContent.Split("\r\n"); |
||||||
|
List<string[]> facturas = new List<string[]>(); |
||||||
|
foreach(var gc in GCs){ |
||||||
|
facturas.Add(gc.Split('|')); |
||||||
|
} |
||||||
|
File.Delete(filePath); |
||||||
|
return facturas; |
||||||
|
}catch(Exception ex){ |
||||||
|
File.Delete(filePath); |
||||||
|
throw new Exception(ex.Message); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
return new List<string[]>(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
using CORRESPONSALBackend.Contracts.Reportes.Alen; |
||||||
|
using CORRESPONSALBackend.Models.Corresponsales; |
||||||
|
using OfficeOpenXml; |
||||||
|
using OfficeOpenXml.Table; |
||||||
|
|
||||||
|
namespace CORRESPONSALBackend.Services.Reportes.Alen{ |
||||||
|
public class ReportesAlenService : IReportesAlenService |
||||||
|
{ |
||||||
|
public async Task<MemoryStream> GetRelacionFacturas(ITrafico trafico, IEnumerable<CorresponsalFacturas> facturas, IEnumerable<CorresponsalesContenedores> contenedores) |
||||||
|
{ |
||||||
|
try{ |
||||||
|
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; |
||||||
|
using (ExcelPackage excelPackage = new ExcelPackage()){ |
||||||
|
var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1"); |
||||||
|
worksheet.Cells["A1"].Value = "Numero de Factura"; |
||||||
|
worksheet.Cells["B1"].Value = "Folio Fiscal"; |
||||||
|
worksheet.Cells["C1"].Value = "Fecha de Factura"; |
||||||
|
worksheet.Cells["D1"].Value = "Numero de COVE"; |
||||||
|
worksheet.Cells["E1"].Value = "Valor Factura"; |
||||||
|
worksheet.Cells["F1"].Value = "Entrega"; |
||||||
|
worksheet.Cells["G1"].Value = "Transporte"; |
||||||
|
worksheet.Cells["H1"].Value = "Pedimento"; |
||||||
|
worksheet.Cells["I1"].Value = "Fecha-Hora Cruce"; |
||||||
|
worksheet.Cells["J1"].Value = "Fecha Cuenta Corresponsal"; |
||||||
|
worksheet.Cells["K1"].Value = "Honorarios"; |
||||||
|
worksheet.Cells["L1"].Value = "Maniobras"; |
||||||
|
worksheet.Cells["M1"].Value = "Validacion"; |
||||||
|
worksheet.Cells["N1"].Value = "Prevalidacion"; |
||||||
|
worksheet.Cells["O1"].Value = "IVA"; |
||||||
|
worksheet.Cells["P1"].Value = "Total M.N. por Operacion"; |
||||||
|
int currentRow = 2; |
||||||
|
foreach(var factura in facturas){ |
||||||
|
var fechaCruce = factura.IdContenedor != null && factura.IdContenedor != 0 ? contenedores.FirstOrDefault(x => x.id == factura.IdContenedor).FSemaforo : ""; |
||||||
|
worksheet.Cells[$"A{currentRow}"].Value = factura.Factura; |
||||||
|
worksheet.Cells[$"B{currentRow}"].Value = factura.UUID; |
||||||
|
worksheet.Cells[$"C{currentRow}"].Value = factura.FechaFactura; |
||||||
|
worksheet.Cells[$"D{currentRow}"].Value = factura.COVE; |
||||||
|
worksheet.Cells[$"E{currentRow}"].Value = factura.ValorFacturaDls; |
||||||
|
worksheet.Cells[$"F{currentRow}"].Value = factura.Entrega; |
||||||
|
worksheet.Cells[$"G{currentRow}"].Value = factura.Transporte; |
||||||
|
worksheet.Cells[$"H{currentRow}"].Value = trafico.Pedimento; |
||||||
|
worksheet.Cells[$"I{currentRow}"].Value = fechaCruce; |
||||||
|
worksheet.Cells[$"J{currentRow}"].Value = trafico.FechaCuenta; |
||||||
|
worksheet.Cells[$"K{currentRow}"].Value = "$0.00"; |
||||||
|
worksheet.Cells[$"L{currentRow}"].Value = "$0.00"; |
||||||
|
worksheet.Cells[$"M{currentRow}"].Value = "$0.00"; |
||||||
|
worksheet.Cells[$"N{currentRow}"].Value = "$0.00"; |
||||||
|
worksheet.Cells[$"O{currentRow}"].Value = "$0.00"; |
||||||
|
worksheet.Cells[$"P{currentRow}"].Value = "$0.00"; |
||||||
|
currentRow++; |
||||||
|
} |
||||||
|
//Se crea la tabla en el rango de celdas donde se mostrara la inforamcion. |
||||||
|
ExcelRange range = worksheet.Cells[1, 1,facturas.Count() + 1, 16]; |
||||||
|
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