Merge branch 'feature/Reporte_Relacion_Facturas_Alen'

feature/ReportesContabilidad_FacturasTraficosConsolidadosAlen_20240116
Felix Morales 9 months ago
commit c5afa9e7b7
  1. 1
      Contracts/Corresponsalias/ICorresponsaliasTraficosRepository.cs
  2. 5
      Contracts/Corresponsalias/Services/ICorresponsaliasTraficosService.cs
  3. 7
      Contracts/Reportes/Alen/IReportesAlenService.cs
  4. 69
      Controllers/Corresponsalias/TraficosController.cs
  5. 42
      Controllers/Reportes/ReportesAlenController.cs
  6. 5
      Models/Corresponsales/CorresponsalFacturas.cs
  7. 5
      Program.cs
  8. 7
      Repository/Corresponsalias/CorresponsaliasFacturasRepository.cs
  9. 12
      Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs
  10. 43
      Services/Corresponsalias/Traficos/CorresponsaliasTraficosService.cs
  11. 68
      Services/Reportes/Alen/ReportesAlenService.cs

@ -10,6 +10,7 @@ namespace CORRESPONSALBackend.Contracts.Corresponsalias
{ {
public Task<ITrafico> Get(int id); public Task<ITrafico> Get(int id);
public Task<DTOReporteSemanalNewell> GetByPedimento(int pedimento); public Task<DTOReporteSemanalNewell> GetByPedimento(int pedimento);
public Task<ITrafico> GetByReferencia(string referencia);
public Task<DashboardTotal> GetAll(int Mode); public Task<DashboardTotal> GetAll(int Mode);
public Task<IEnumerable<ICorRectificaciones>> GetRectificaciones(int id); public Task<IEnumerable<ICorRectificaciones>> GetRectificaciones(int id);
public Task<ICorRectificaciones> AddRectificacion(int id); public Task<ICorRectificaciones> AddRectificacion(int id);

@ -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);
}
}

@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Mvc;
using CORRESPONSALBackend.Services.C1896; using CORRESPONSALBackend.Services.C1896;
using CORRESPONSALBackend.Repository.Corresponsalias; using CORRESPONSALBackend.Repository.Corresponsalias;
using CORRESPONSALBackend.DTO.Reportes; using CORRESPONSALBackend.DTO.Reportes;
using CORRESPONSALBackend.Contracts.Corresponsalias.Services;
using CORRESPONSALBackend.Contracts.Catalogos;
namespace CORRESPONSALBackend.Controllers.Corresponsalias namespace CORRESPONSALBackend.Controllers.Corresponsalias
{ {
@ -19,14 +21,24 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias
private readonly ICorresponsaliasTraficosRepository _Repo; private readonly ICorresponsaliasTraficosRepository _Repo;
private readonly ICorresponsaliasFacturasRepository _RepoFacturas; private readonly ICorresponsaliasFacturasRepository _RepoFacturas;
private readonly ICorresponsaliasContenedoresRepository _RepoContenedores; private readonly ICorresponsaliasContenedoresRepository _RepoContenedores;
private readonly ICorresponsaliasTraficosService _traficosService;
private readonly IProveedoresRepository _proveedoresRepository;
private readonly ICorresponsaliasFacturasRepository _facturasRepository;
private readonly ICorresponsaliasContenedoresRepository _contenedoresRepository;
private readonly IConfiguration _config; private readonly IConfiguration _config;
public TraficosController(ICorresponsaliasTraficosRepository Repo, ICorresponsaliasFacturasRepository RepoFacturas, ICorresponsaliasContenedoresRepository RepoContenedores, IConfiguration config) public TraficosController(ICorresponsaliasTraficosRepository Repo, ICorresponsaliasFacturasRepository RepoFacturas,
ICorresponsaliasContenedoresRepository RepoContenedores, IConfiguration config, ICorresponsaliasTraficosService traficosService,
IProveedoresRepository proveedoresRepository, ICorresponsaliasFacturasRepository facturasRepository, ICorresponsaliasContenedoresRepository contenedoresRepository)
{ {
_config = config; _config = config;
_Repo = Repo; _Repo = Repo;
_RepoFacturas = RepoFacturas; _RepoFacturas = RepoFacturas;
_RepoContenedores = RepoContenedores; _RepoContenedores = RepoContenedores;
_traficosService = traficosService;
_proveedoresRepository = proveedoresRepository;
_facturasRepository = facturasRepository;
_contenedoresRepository = contenedoresRepository;
} }
/// Corresponsales: Traficos /// Corresponsales: Traficos
@ -144,5 +156,60 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias
var referencia = await _Repo.ValidaTraficoDuplicado(aduana, patente, pedimento, idTrafico); var referencia = await _Repo.ValidaTraficoDuplicado(aduana, patente, pedimento, idTrafico);
return referencia; return referencia;
} }
[HttpPost("Append/LayoutAlen")]
public async Task<IActionResult> AppendFacturasContenedoresAlen([FromQuery] int idTrafico, [FromQuery] int fileId){
try{
var trafico = await _Repo.Get(idTrafico);
var proveedores = await _proveedoresRepository.GetAll(0);
proveedores.ToList();
var facturas = await _traficosService.ReadTxtFacturasAlen(fileId);
{
trafico.Pedimento = int.Parse(facturas[0][6]);
trafico.FechaPago = DateTime.Parse(facturas[0][7]).ToString("yyyy/MM/dd");
trafico.Clave = facturas[0][8];
trafico.TipoCambio = double.Parse(facturas[0][15]);
trafico.CantidadFracciones = int.Parse(facturas[0][21]);
trafico.DescripcionMercancia = facturas[0][14];
trafico.Observaciones = facturas[0][48];
await _Repo.Append(trafico);
}
foreach(var factura in facturas){
//Crear modelo de contenedor y asignar los datos en la factura actual
CorresponsalesContenedores nuevoContenedor = new CorresponsalesContenedores(){
id = 0,
IdTrafico = idTrafico,
Contenedor = factura[32],
Semaforo = (byte?)(factura[45] == "VERDE" ? 2 : 1),
FSemaforo = factura[22]
};
var contenedorGuardado = await _contenedoresRepository.Append(nuevoContenedor);
//Crear modelo de factura y asignar los datos en la factura actual
var proveedorFactura = proveedores.FirstOrDefault(p => p.Nombre == factura[10]);
CorresponsalFacturas nuevaFactura = new CorresponsalFacturas(){
id = 0,
Factura = factura[13],
IdTrafico = idTrafico,
ValorFacturaDls = double.Parse(factura[16]),
Proveedor = proveedorFactura.id,
Pedido = factura[29],
FechaFactura = factura[7],
Activo = true,
Code = 0,
FolioGEMCO = "",
COVE = factura[50],
Entrega = factura[52],
Transporte = factura[51],
UUID = factura[33],
IdContenedor = contenedorGuardado.id
};
await _facturasRepository.Append(nuevaFactura);
}
return new OkObjectResult(new {trafico, facturas = await _facturasRepository.GetAll(idTrafico), contenedores = await _contenedoresRepository.GetAll(idTrafico)});
}catch(Exception ex){
return BadRequest(ex.Message);
}
}
} }
} }

@ -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);
}
}
}
}

@ -12,5 +12,10 @@
public Boolean? Activo { get; set; } = true; public Boolean? Activo { get; set; } = true;
public int? Code { get; set; } = 0; public int? Code { get; set; } = 0;
public string? FolioGEMCO { get; set; } = null!; public string? FolioGEMCO { get; set; } = null!;
public string? COVE {get;set;} = null!;
public string? Entrega {get;set;}=null!;
public string? Transporte {get;set;}=null!;
public string? UUID {get;set;}= null!;
public int? IdContenedor {get;set;} = 0;
} }
} }

@ -44,6 +44,9 @@ using CORRESPONSALBackend.Contracts.Reportes.Newell.Semanal;
using CORRESPONSALBackend.Services.Reportes.Newell.Semanal; using CORRESPONSALBackend.Services.Reportes.Newell.Semanal;
using CORRESPONSALBackend.Contracts.Corresponsalias.Services; using CORRESPONSALBackend.Contracts.Corresponsalias.Services;
using CORRESPONSALBackend.Services.Corresponsalias.Facturas; using CORRESPONSALBackend.Services.Corresponsalias.Facturas;
using CORRESPONSALBackend.Services.Corresponsalias.Traficos;
using CORRESPONSALBackend.Contracts.Reportes.Alen;
using CORRESPONSALBackend.Services.Reportes.Alen;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -65,6 +68,8 @@ builder.Services.AddScoped<IReportesEmbarquesService, ReportesEmbarquesService>(
builder.Services.AddScoped<IReportesEmbarquesRepository, ReportesEmbarquesRepository>(); builder.Services.AddScoped<IReportesEmbarquesRepository, ReportesEmbarquesRepository>();
builder.Services.AddScoped<IReporteGC50Repository, ReporteGC50Repository>(); builder.Services.AddScoped<IReporteGC50Repository, ReporteGC50Repository>();
builder.Services.AddScoped<ICorresponsaliasFacturasService, CorresponsaliasFactuasService>(); builder.Services.AddScoped<ICorresponsaliasFacturasService, CorresponsaliasFactuasService>();
builder.Services.AddScoped<ICorresponsaliasTraficosService, CorresponsaliasTraficosService>();
builder.Services.AddScoped<IReportesAlenService, ReportesAlenService>();
// Corresponsalias // Corresponsalias
builder.Services.AddScoped<IContabilidadCorresponsaliasRepository, ContabilidadCorresponsaliasRepository>(); builder.Services.AddScoped<IContabilidadCorresponsaliasRepository, ContabilidadCorresponsaliasRepository>();

@ -36,7 +36,12 @@ namespace CORRESPONSALBackend.Repository.Corresponsalias
data.Proveedor, data.Proveedor,
data.ValorFacturaDls, data.ValorFacturaDls,
data.Pedido, data.Pedido,
data.FechaFactura data.FechaFactura,
data.UUID,
data.COVE,
data.Entrega,
data.Transporte,
data.IdContenedor
}, },
commandType: CommandType.StoredProcedure); commandType: CommandType.StoredProcedure);
return entrada.First(); return entrada.First();

@ -51,6 +51,18 @@ namespace CORRESPONSALBackend.Repository.Corresponsalias
return entrada.FirstOrDefault(new DTOReporteSemanalNewell { }); return entrada.FirstOrDefault(new DTOReporteSemanalNewell { });
} }
public async Task<ITrafico> GetByReferencia(string referencia)
{
var query = "[Corresponsales.Trafico.GetByReferencia]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<ITrafico>(query, new
{
@referencia=referencia
},
commandType: CommandType.StoredProcedure);
return entrada.FirstOrDefault(new ITrafico { });
}
public async Task<IEnumerable<ICorRectificaciones>> GetRectificaciones(int id) public async Task<IEnumerable<ICorRectificaciones>> GetRectificaciones(int id)
{ {
var query = "[Corresponsales.Trafico.Rectificacion.GetAll]"; var query = "[Corresponsales.Trafico.Rectificacion.GetAll]";

@ -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…
Cancel
Save