feature creacion del reporte mensual de newell

feature/Reporte_Relacion_Facturas_Alen
Felix Morales 1 year ago
parent 4f87a288e0
commit 09acc207fc
  1. 1
      CORRESPONSALBackend.csproj
  2. 13
      Contracts/Reportes/Newell/Mensual/IReporteMensualRepository.cs
  3. 5
      Contracts/Reportes/Newell/Mensual/IReporteMensualService.cs
  4. 1
      Contracts/Utils/IFileManagerRepository.cs
  5. 26
      Controllers/FileManagerController.cs
  6. 41
      Controllers/Reportes/ReportesNewell.cs
  7. 20
      DTO/Reportes/Newell/DTOOperacionesCdAcuna.cs
  8. 18
      DTO/Reportes/Newell/DTOOperacionesLazaroCardenas.cs
  9. 11
      DTO/Reportes/Newell/DTOReporteMensualCdAcuna.cs
  10. 8
      DTO/Reportes/Newell/DTOTrailasFile.cs
  11. 2
      Models/Corresponsales/ITrafico.cs
  12. 5
      Program.cs
  13. 4
      Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs
  14. 112
      Repository/Reportes/Newell/Mensual/ReporteMensualRepository.cs
  15. 13
      Repository/Utils/FileManagerRepository.cs
  16. 193
      Services/Reportes/Newell/Mensual/ReporteMensualService.cs

@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="7.0.5" />
<PackageReference Include="EPPlus" Version="6.2.9" />
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
namespace CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual
{
public interface IReporteMensualRepository
{
public Task CrearTablasReporteMensual();
public Task<DTOTrailas> PopulateTrailasTable(DTOTrailas record);
public Task<DTOOperacionesCdAcuna> PopulateOperacionesCdAcunaTable(DTOOperacionesCdAcuna record);
public Task<DTOOperacionesLazaroCardenas> PopulateOperacionesLazaroCardenasTable(DTOOperacionesLazaroCardenas record);
public Task<IEnumerable<DTOReporteMensualCdAcuna>> GetRptMensualCdAcuna();
public Task<IEnumerable<DTOOperacionesLazaroCardenas>> GetRptMensualLazaroCardenas();
public Task DropTempTables();
}
}

@ -0,0 +1,5 @@
namespace CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual{
public interface IReporteMensualService{
public Task<MemoryStream> GetReporteMensual(int idTrailasFile, int idRptCdAcunaFile, int idRptLazaroCardenasFile);
}
}

@ -9,6 +9,7 @@ namespace CORRESPONSALBackend.Contracts.Utils
public Task<List<FileManager>> getAllFilesByProcess(long Tags, int Proceso);
public Task<FileManager> getFileById(long id);
public Task deleteFileByProcess(long id, int Proceso);
public Task<FileManager> UpdateFileNameById(long id, string newFileName);
}
}

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Http.HttpResults;
namespace CORRESPONSALBackend.Controllers
{
/* [Authorize] */
[Authorize]
[Route("api/[controller]")]
// [ApiController]
public class FileManagerController : Controller
@ -117,7 +117,7 @@ namespace CORRESPONSALBackend.Controllers
{
try
{
if (System.IO.File.Exists(Path.Combine(fullPath, recFound.NombreArchivo)))
if (System.IO.File.Exists(fullPath + recFound.NombreArchivo))
{
ExisteEnDisco = true;
}
@ -148,7 +148,7 @@ namespace CORRESPONSALBackend.Controllers
public async Task<IActionResult> ConvertExcel2New([FromQuery] long id, int Proceso)
{
bool ExisteEnDisco = false;
FileManager recFound = await _Repo.getFileByProcess(id, Proceso);
FileManager recFound = await _Repo.getFileById(id);
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso);
string fullPath = "";
fullPath = RootPathCorresponsales + RelativePath.Path;
@ -156,7 +156,7 @@ namespace CORRESPONSALBackend.Controllers
{
try
{
if (System.IO.File.Exists(Path.Combine(fullPath, recFound.NombreArchivo)))
if (System.IO.File.Exists(fullPath+ recFound.NombreArchivo))
{
ExisteEnDisco = true;
}
@ -173,7 +173,15 @@ namespace CORRESPONSALBackend.Controllers
{
byte[] pdfBytes = System.IO.File.ReadAllBytes(targetFile);
MemoryStream ms = new MemoryStream(pdfBytes);
return await Convert2NewFormat("https://amazon-pyapi.gemcousa.solutions/convertXLS2XLSX", ms, recFound.NombreArchivo);
var file = await Convert2NewFormat("https://amazon-pyapi.gemcousa.solutions/convertXLS2XLSX", ms, recFound.NombreArchivo);
using( var newFileStream = System.IO.File.Create(targetFile+"x")){
await file.CopyToAsync(newFileStream);
var newFile = await _Repo.UpdateFileNameById(id, recFound.NombreArchivo+"x");
if(newFile.NombreArchivo != recFound.NombreArchivo){
System.IO.File.Delete(targetFile);
}
}
return Ok("Archivo subido con exito");
}
}
}
@ -181,7 +189,7 @@ namespace CORRESPONSALBackend.Controllers
}
private async Task<IActionResult> Convert2NewFormat(string actionUrl, Stream paramFileStream, string oldFilename)
private async Task<Stream> Convert2NewFormat(string actionUrl, Stream paramFileStream, string oldFilename)
{
HttpContent fileStreamContent = new StreamContent(paramFileStream);
using (var client = new HttpClient())
@ -193,7 +201,7 @@ namespace CORRESPONSALBackend.Controllers
{
System.Net.Http.HttpContent content = response.Content;
var contentStream = await content.ReadAsStreamAsync();
return File(contentStream, "application/octet-stream", oldFilename + "x");
return File(contentStream, "application/octet-stream", oldFilename + "x").FileStream;
}
else
{
@ -211,9 +219,9 @@ namespace CORRESPONSALBackend.Controllers
fullPath = RootPathCorresponsales + RelativePath.Path;
try
{
if (System.IO.File.Exists(Path.Combine(fullPath, Found.NombreArchivo)))
if (System.IO.File.Exists(fullPath + Found.NombreArchivo))
{
System.IO.File.Delete(Path.Combine(fullPath, Found.NombreArchivo));
System.IO.File.Delete(fullPath + Found.NombreArchivo);
await _Repo.deleteFileByProcess(Found.id, Found.Proceso);
}
else return new OkObjectResult(new { respuesta = "Ese archivo no existe" });

@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using CORRESPONSALBackend.Contracts.Utils;
using CORRESPONSALBackend.Models.Utils;
using OfficeOpenXml;
using OfficeOpenXml.Table;
using OfficeOpenXml.Style;
using CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual;
namespace CORRESPONSALBackend.Controllers.Reportes{
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ReportesNewellController : ControllerBase
{
private readonly IReporteMensualRepository _reporteMensualRepository;
private readonly IReporteMensualService _reporteMensualService;
public ReportesNewellController(IReporteMensualRepository reporteMensualRepository, IReporteMensualService reporteMensualService){
_reporteMensualRepository = reporteMensualRepository;
_reporteMensualService = reporteMensualService;
}
[HttpGet("ReporteMensual")]
public async Task<IActionResult> GetReporteMensual([FromQuery] int idTrailasFile, int idRptCdAcunaFile, int idRptLazaroCardenasFile){
try{
await _reporteMensualRepository.CrearTablasReporteMensual();
var stream = await _reporteMensualService.GetReporteMensual(idTrailasFile, idRptCdAcunaFile, idRptLazaroCardenasFile);
if(stream.Length > 0){
stream.Position = 0;
await _reporteMensualRepository.DropTempTables();
return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"ReporteMensual.xlsx");
}else{
throw new Exception("Ocurrio un error al generar el reporte, intentelo de nuevo");
}
}catch(Exception ex){
await _reporteMensualRepository.DropTempTables();
return StatusCode(500,ex.Message);
}
}
}
}

@ -0,0 +1,20 @@
public class DTOOperacionesCdAcuna{
public string? Aduana { get; set; }
public string? Patente { get; set; }
public string? Pedimento { get; set; }
/*public DateTime? FechaEntrega { get; set; }
public DateTime? FechaPago { get; set; }
public string ValorComercialMxn { get; set; }
public string ValorComercialDlls { get; set; }
public string ValorAduana { get; set; }*/
public string? Clave { get; set; }
/*public string Iva { get; set; }
public string Dta { get; set; }
public string Prv { get; set; }
public string Lgi { get; set; }*/
public string? Factura { get; set; }
public string? Tc { get; set; }
public string? Proveedor { get; set; }
public string? TaxId { get; set; }
public string? Producto { get; set; }
}

@ -0,0 +1,18 @@
public class DTOOperacionesLazaroCardenas{
public string? Pedimento { get; set; }
public string? NoContenedor { get; set; }
public int? CantidadContenedores { get; set; }
public string? Soia { get; set; }
public int? TiempoDespacho { get; set; }
public string? Clave { get; set; }
public string? PedimentoRectificado { get; set; }
public string? Causa { get; set; }
public string? CargoA { get; set; }
public int? TiempoProceso { get; set; }
public int? TiempoCruce { get; set; }
public string? Cumple { get; set; }
public string? NoCumple { get; set; }
public string? RazonNoCumple { get; set; }
public string? CargoDe { get; set; }
public string? MedioSalida { get; set; }
}

@ -0,0 +1,11 @@
public class DTOReporteMensualCdAcuna{
public string Pedimento { get; set; }
public string Traila { get; set; }
public int NoContenedores { get; set; }
public string Soia { get; set; }
public int TiempoDespacho { get; set; }
public string Clave { get; set; }
public string PedimentoRectificado { get; set; }
public string Causa { get; set; }
public string CargoA { get; set; }
}

@ -0,0 +1,8 @@
public class DTOTrailas{
public DateTime? Fecha { get; set; }
public string? Traila { get; set; }
public string? Pedimento { get; set; }
public string? Candado { get; set; }
public string? Doda { get; set; }
public string? Soia { get; set; }
}

@ -42,5 +42,7 @@
public double EstatusCode { get; set; } = 0;
public byte? Activo { get; set; } = 0;
public int? idTipoMercancia {get;set;} = null;
public int CargoA {get;set;} = 0;
public string CausaRectificacion {get;set;} = "";
}
}

@ -27,6 +27,9 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using Microsoft.OpenApi.Models;
using CORRESPONSALBackend.Repository.Reportes;
using CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual;
using CORRESPONSALBackend.Services.Reportes.Newell.Mensual;
var builder = WebApplication.CreateBuilder(args);
@ -38,6 +41,8 @@ builder.Services.AddScoped<IReportesRepository, ReportesRepository>();
builder.Services.AddScoped<IPerfilesRepository, PerfilesRepository>();
builder.Services.AddScoped<IClientesRepository, ClientesRepository>();
builder.Services.AddScoped<IBatteryRepository, BatteryRepository>();
builder.Services.AddScoped<IReporteMensualRepository, ReporteMensualRepository>();
builder.Services.AddScoped<IReporteMensualService, ReporteMensualService>();
// Corresponsalias
builder.Services.AddScoped<IContabilidadCorresponsaliasRepository, ContabilidadCorresponsaliasRepository>();

@ -113,7 +113,9 @@ namespace CORRESPONSALBackend.Repository.Corresponsalias
@TipoMercancia = data.TipoMercancia,
@Activo = true,
@IdTabulador = data.IdTabulador,
@IdTipoMercancia = data.idTipoMercancia
@IdTipoMercancia = data.idTipoMercancia,
@CargoA = data.CargoA,
@CausaRectificacion = data.CausaRectificacion
},
commandType: CommandType.StoredProcedure);
return entrada.First();

@ -0,0 +1,112 @@
using System.Data;
using CORRESPONSALBackend.Context;
using CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual;
using Dapper;
namespace CORRESPONSALBackend.Repository.Reportes
{
public class ReporteMensualRepository : IReporteMensualRepository
{
private readonly DapperContext _context;
public ReporteMensualRepository(DapperContext context) { _context = context; }
public async Task CrearTablasReporteMensual()
{
var query = "[Reportes.Newell.CreateTempTables]";
using var connection = _context.CreateConnection();
await connection.QueryAsync(query, new { }, commandType: CommandType.StoredProcedure);
return;
}
public async Task<DTOTrailas> PopulateTrailasTable(DTOTrailas record)
{
var query = "[Reportes.Newell.PopulateTrailas]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOTrailas>(query, new
{
@fecha = record.Fecha,
@traila = record.Traila,
@pedimento = record.Pedimento,
@candado = record.Candado,
@doda = record.Doda,
@estado = record.Soia
},
commandType: CommandType.StoredProcedure);
return entrada.FirstOrDefault();
}
public async Task<DTOOperacionesCdAcuna> PopulateOperacionesCdAcunaTable(DTOOperacionesCdAcuna record)
{
var query = "[Reportes.Newell.PopulateOperacionesCdAcuna]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOOperacionesCdAcuna>(query, new
{
@aduana = record.Aduana,
@patente = record.Patente,
@pedimento = record.Pedimento,
@clave = record.Clave,
@factura = record.Factura,
@tc = record.Tc,
@proveedor = record.Proveedor,
@taxId = record.TaxId,
@producto = record.Producto
},
commandType: CommandType.StoredProcedure);
return entrada.FirstOrDefault();
}
public async Task<DTOOperacionesLazaroCardenas> PopulateOperacionesLazaroCardenasTable(DTOOperacionesLazaroCardenas record)
{
var query = "[Reportes.Newell.PopulateOperacionesLazaroCardenas]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOOperacionesLazaroCardenas>(query, new
{
@pedimento = record.Pedimento,
@noContenedor = record.NoContenedor,
@cantidadContenedores = record.CantidadContenedores,
@soia = record.Soia,
@tiempodespacho = record.TiempoDespacho,
@clave = record.Clave,
@pedimentoRectificado = record.PedimentoRectificado,
@causa = record.Causa,
@cargoA = record.CargoA,
@tiempoProceso = record.TiempoProceso,
@tiempoCruce = record.TiempoCruce,
@cumple = record.Cumple,
@noCumple = record.NoCumple,
@razonNoCumple = record.RazonNoCumple,
@cargoDe = record.CargoDe,
@medioSalida = record.MedioSalida
},
commandType: CommandType.StoredProcedure);
return entrada.FirstOrDefault();
}
public async Task<IEnumerable<DTOReporteMensualCdAcuna>> GetRptMensualCdAcuna()
{
var query = "[Reportes.Newell.GetReporteMensualCdAcuna]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOReporteMensualCdAcuna>(query, new {}, commandType: CommandType.StoredProcedure);
return entrada.ToList();
}
public async Task<IEnumerable<DTOOperacionesLazaroCardenas>> GetRptMensualLazaroCardenas()
{
var query = "[Reportes.Newell.GetReporteMensualLazaroCardenas]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<DTOOperacionesLazaroCardenas>(query, new {}, commandType: CommandType.StoredProcedure);
return entrada.ToList();
}
public async Task DropTempTables()
{
var query = "[Reportes.Newell.DropReporteMensualTempTables]";
using var connection = _context.CreateConnection();
await connection.QueryAsync(query, new { }, commandType: CommandType.StoredProcedure);
return;
}
}
}

@ -84,5 +84,18 @@ namespace CORRESPONSALBackend.Repository.Utils
},
commandType: CommandType.StoredProcedure);
}
public async Task<FileManager> UpdateFileNameById(long id, string newFileName)
{
string query = "[Utils.FileManager.UpdateFileName]";
using var connection = _context.CreateConnection();
var entrada = await connection.QueryAsync<FileManager>(query, new
{
@id = id,
@newFileName = newFileName
},
commandType: CommandType.StoredProcedure);
return entrada.FirstOrDefault();
}
}
}

@ -0,0 +1,193 @@
using CORRESPONSALBackend.Contracts.Reportes.Newell.Mensual;
using CORRESPONSALBackend.Contracts.Utils;
using CORRESPONSALBackend.Models.Utils;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
namespace CORRESPONSALBackend.Services.Reportes.Newell.Mensual{
public class ReporteMensualService : IReporteMensualService
{
private readonly IFileManagerRepository _Repo;
private readonly IReporteMensualRepository _reporteMensualRepository;
private readonly IFilePaths4ProcessRepository _RepoRelativePath;
private readonly IConfiguration _config;
private readonly string RootPathCorresponsales;
public ReporteMensualService(IReporteMensualRepository reporteMensualRepository, IFilePaths4ProcessRepository RepoRelativePath, IConfiguration config, IFileManagerRepository Repo){
_reporteMensualRepository = reporteMensualRepository;
_RepoRelativePath = RepoRelativePath;
_config = config;
_Repo = Repo;
RootPathCorresponsales = _config.GetValue<string>("AllFiles");
}
public async Task<MemoryStream> GetReporteMensual(int idTrailasFile, int idRptCdAcunaFile, int idRptLazaroCardenasFile){
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
//Comienza la lectura de los archivos cargados.
await PopulateTrailasTable(idTrailasFile);
await PopulateOperacionesCdAcunaTable(idRptCdAcunaFile);
await PopulateOperacionesLazaroCardenasTable(idRptLazaroCardenasFile);
//Comienza la escritura del reporte mensual.
using(ExcelPackage package = new ExcelPackage()){
//Se obtienen los datos del reporte.
var rptCdAcuna = await _reporteMensualRepository.GetRptMensualCdAcuna();
var rptLazaroCardenas = await _reporteMensualRepository.GetRptMensualLazaroCardenas();
if(rptCdAcuna.Count() <= 0 || rptLazaroCardenas.Count() <= 0) throw new Exception("No se encontraron los datos necesarios para generar el reporte, intentelo de nuevo.");
//Se crea la primer hoja del reporte.
{
var totalRows = rptCdAcuna.Count();
var worksheetCdAcuna = package.Workbook.Worksheets.Add("Cd. Acuña");
//Se crean los encabezados de la primer hoja.
worksheetCdAcuna.Cells["A1"].Value = "PEDIMENTO";
worksheetCdAcuna.Cells["B1"].Value = "TRAILA";
worksheetCdAcuna.Cells["C1"].Value = "NUMERO DE CONTENEDORES";
worksheetCdAcuna.Cells["D1"].Value = "SOIA";
worksheetCdAcuna.Cells["E1"].Value = "TIEMPO DE DESPACHO DIAS DE ARRIBO VS DESADUANADO";
worksheetCdAcuna.Cells["F1"].Value = "CLAVE";
worksheetCdAcuna.Cells["G1"].Value = "PEDIMENTO RECTIFICADO";
worksheetCdAcuna.Cells["H1"].Value = "CAUSA";
worksheetCdAcuna.Cells["I1"].Value = "CARGO A";
//Se crea el rango de celdas que abarcara la tabla.
ExcelRange range = worksheetCdAcuna.Cells[1, 1,rptCdAcuna.Count() + 1, 9];
//Se vacian los datos obtenidos en el excel.
worksheetCdAcuna.Cells["A2"].LoadFromCollection(rptCdAcuna, false);
ExcelTable tab = worksheetCdAcuna.Tables.Add(range, "Table1");
//tab.TableStyle = TableStyles.Light1;
worksheetCdAcuna.Cells[$"A{totalRows+2}"].Value = $"{totalRows} PEDIMENTOS";
worksheetCdAcuna.Cells[$"C{totalRows+2}"].Value = $"{totalRows} CONTENEDORES";
worksheetCdAcuna.Cells[$"D{totalRows+2}"].Value = $"{rptCdAcuna.Where(x => x.Soia.ToUpper() == "ROJO").ToList().Count()} ROJOS";
worksheetCdAcuna.Cells[$"E{totalRows+2}"].Value = $"1 DIA PROMEDIO";
worksheetCdAcuna.Cells[worksheetCdAcuna.Dimension.Address].AutoFitColumns();
worksheetCdAcuna.Cells[worksheetCdAcuna.Dimension.Address].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
}
{
var totalRows = rptLazaroCardenas.Count();
var worksheetLazaroCardenas = package.Workbook.Worksheets.Add("Lazaro Cardenas");
//Se crean los encabezados de la segunda hoja.
worksheetLazaroCardenas.Cells["A1"].Value = "PEDIMENTO";
worksheetLazaroCardenas.Cells["B1"].Value = "NO.CONTEN";
worksheetLazaroCardenas.Cells["C1"].Value = "CANTIDAD DE CONTENEDORES";
worksheetLazaroCardenas.Cells["D1"].Value = "SOIA ROJO";
worksheetLazaroCardenas.Cells["E1"].Value = "TIEMPO DE DESPACHO DIAS DE ARRIBO VS DESADUANAMIENTO";
worksheetLazaroCardenas.Cells["F1"].Value = "CLAVE";
worksheetLazaroCardenas.Cells["G1"].Value = "PEDIMENTO RECTIFICADO";
worksheetLazaroCardenas.Cells["H1"].Value = "CAUSA";
worksheetLazaroCardenas.Cells["I1"].Value = "CARGO A";
worksheetLazaroCardenas.Cells["J1"].Value = "TIEMPOS DE PROCESO";
worksheetLazaroCardenas.Cells["K1"].Value = "TIEMPOS DE CRUCE";
worksheetLazaroCardenas.Cells["L1"].Value = "1 A 3 DIAS CUMPLE";
worksheetLazaroCardenas.Cells["M1"].Value = "3 A 5 DIAS NO CUMPLE";
worksheetLazaroCardenas.Cells["N1"].Value = "RAZON POR LA QUE NO CUMPLE";
worksheetLazaroCardenas.Cells["O1"].Value = "A CARGO DE";
worksheetLazaroCardenas.Cells["P1"].Value = "MEDIO DE SALIDA";
//Se crea el rango de celdas que abarcara la tabla.
ExcelRange range = worksheetLazaroCardenas.Cells[1, 1,rptLazaroCardenas.Count() + 1, 16];
//Se vacian los datos obtenidos en el excel.
worksheetLazaroCardenas.Cells["A2"].LoadFromCollection(rptLazaroCardenas, false);
ExcelTable tab = worksheetLazaroCardenas.Tables.Add(range, "Table2");
//tab.TableStyle = TableStyles.Light1;
worksheetLazaroCardenas.Cells[$"A{totalRows+2}"].Value = $"{totalRows} PEDIMENTOS";
worksheetLazaroCardenas.Cells[$"C{totalRows+2}"].Value = $"{rptLazaroCardenas.Sum(x => Convert.ToInt32(x.CantidadContenedores))} CONTENEDORES";
worksheetLazaroCardenas.Cells[$"D{totalRows+2}"].Value = $"{rptLazaroCardenas.Where(x => !string.IsNullOrWhiteSpace(x.Soia) && x.Soia.ToUpper() == "ROJO").ToList().Count()} ROJOS";
worksheetLazaroCardenas.Cells[$"E{totalRows+2}"].Value = $"{Math.Round(rptLazaroCardenas.Average(x => Convert.ToInt32(x.TiempoDespacho)),0)} DIAS PROMEDIO";
worksheetLazaroCardenas.Cells[$"J{totalRows+2}"].Value = $"{Math.Round(rptLazaroCardenas.Average(x => Convert.ToInt32(x.TiempoProceso)),0)} DIAS PROMEDIO";
worksheetLazaroCardenas.Cells[$"K{totalRows+2}"].Value = $"{Math.Round(rptLazaroCardenas.Average(x => Convert.ToInt32(x.TiempoCruce)),0)} DIAS PROMEDIO";
worksheetLazaroCardenas.Cells[worksheetLazaroCardenas.Dimension.Address].AutoFitColumns();
worksheetLazaroCardenas.Cells[worksheetLazaroCardenas.Dimension.Address].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
}
package.Workbook.Calculate();
var stream = new MemoryStream();
package.SaveAs(stream);
return stream;
}
}
private async Task<string> getFilePath(int id){
//Se obtiene la ruta del archivo
FileManager recFound = await _Repo.getFileById(id);
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(recFound.Proceso);
return RootPathCorresponsales + RelativePath.Path + recFound.NombreArchivo;
}
private async Task PopulateTrailasTable(int fileId){
//Se obtiene la ruta del archivo
string targetFile = await getFilePath(fileId);
//Aqui comienza la lectura del archivo.
var file = new FileInfo(targetFile);
using(ExcelPackage package = new ExcelPackage(file)){
var worksheet = package.Workbook.Worksheets.FirstOrDefault();
int rowCount = 2;
while(string.IsNullOrWhiteSpace(worksheet?.Cells[rowCount, 3].Value?.ToString()) == false){//Se valida si la columna del pedimento no esta vacia.
var resp = await _reporteMensualRepository.PopulateTrailasTable(new DTOTrailas(){
Fecha = worksheet.Cells[rowCount, 1].Value != null ? DateTime.FromOADate(long.Parse(worksheet.Cells[rowCount, 1].Value?.ToString())) : null,
Traila = worksheet.Cells[rowCount, 2].Value != null ? worksheet.Cells[rowCount, 2].Value?.ToString() : null,
Pedimento = worksheet.Cells[rowCount, 3].Value != null ? worksheet.Cells[rowCount, 3].Value?.ToString() : null,
Candado = worksheet.Cells[rowCount, 4].Value != null ? worksheet.Cells[rowCount, 4].Value?.ToString() : null,
Doda = worksheet.Cells[rowCount, 5].Value != null ? worksheet.Cells[rowCount, 5].Value?.ToString() : null,
Soia = worksheet.Cells[rowCount, 6].Value != null ? worksheet.Cells[rowCount, 6].Value?.ToString() : null,
});
if(resp == null) throw new Exception("Ocurrio un error al generar el reporte. Asegurese que los datos del archivo sean correctors.");
rowCount++;
}
if(System.IO.File.Exists(targetFile)) System.IO.File.Delete(targetFile);
}
}
private async Task PopulateOperacionesCdAcunaTable(int fileId){
//Se obtiene la ruta del archivo
string targetFile = await getFilePath(fileId);
//Aqui comienza la lectura del archivo.
var file = new FileInfo(targetFile);
using(ExcelPackage package = new ExcelPackage(file)){
var worksheet = package.Workbook.Worksheets.FirstOrDefault();
int rowCount = 2;
while(string.IsNullOrWhiteSpace(worksheet?.Cells[rowCount, 3].Value?.ToString()) == false){//Se valida si la columna del pedimento no esta vacia.
var resp = await _reporteMensualRepository.PopulateOperacionesCdAcunaTable(new DTOOperacionesCdAcuna(){
Aduana = worksheet.Cells[rowCount, 1].Value != null ? worksheet.Cells[rowCount, 1].Value?.ToString() : null,
Patente = worksheet.Cells[rowCount, 2].Value != null ? worksheet.Cells[rowCount, 2].Value?.ToString() : null,
Pedimento = worksheet.Cells[rowCount, 3].Value != null ? worksheet.Cells[rowCount, 3].Value?.ToString() : null,
Clave = worksheet.Cells[rowCount, 9].Value != null ? worksheet.Cells[rowCount, 9].Value?.ToString() : null,
Factura = worksheet.Cells[rowCount, 14].Value != null ? worksheet.Cells[rowCount, 14].Value?.ToString() : null,
Tc = worksheet.Cells[rowCount, 15].Value != null ? worksheet.Cells[rowCount, 15].Value?.ToString() : null,
Proveedor = worksheet.Cells[rowCount, 16].Value != null ? worksheet.Cells[rowCount, 16].Value?.ToString() : null,
TaxId = worksheet.Cells[rowCount, 17].Value != null ? worksheet.Cells[rowCount, 17].Value?.ToString() : null,
Producto = worksheet.Cells[rowCount, 18].Value != null ? worksheet.Cells[rowCount, 18].Value?.ToString() : null,
});
if(resp == null) throw new Exception("Ocurrio un error al generar el reporte. Asegurese que los datos del archivo sean correctors.");
rowCount++;
}
if(System.IO.File.Exists(targetFile)) System.IO.File.Delete(targetFile);
}
}
private async Task PopulateOperacionesLazaroCardenasTable(int fileId){
//Se obtiene la ruta del archivo
string targetFile = await getFilePath(fileId);
//Aqui comienza la lectura del archivo.
var file = new FileInfo(targetFile);
using(ExcelPackage package = new ExcelPackage(file)){
var worksheet = package.Workbook.Worksheets.FirstOrDefault();
int rowCount = 7;
while(string.IsNullOrWhiteSpace(worksheet?.Cells[rowCount, 4].Value?.ToString()) == false){
var resp = await _reporteMensualRepository.PopulateOperacionesLazaroCardenasTable(new DTOOperacionesLazaroCardenas(){
Pedimento = worksheet.Cells[rowCount, 4].Value != null ? worksheet.Cells[rowCount, 4].Value?.ToString() : null,
NoContenedor = worksheet.Cells[rowCount, 8].Value != null ? worksheet.Cells[rowCount, 8].Value?.ToString() : null,
CantidadContenedores = worksheet.Cells[rowCount, 9].Value != null ? int.Parse(worksheet.Cells[rowCount, 9].Value?.ToString()) : null,
Soia = worksheet.Cells[rowCount, 10].Value != null ? worksheet.Cells[rowCount, 10].Value?.ToString() : null,
TiempoDespacho = worksheet.Cells[rowCount, 11].Value != null ? int.Parse(worksheet.Cells[rowCount, 11].Value?.ToString()) : null,
Clave = worksheet.Cells[rowCount, 14].Value != null ? worksheet.Cells[rowCount, 14].Value?.ToString() : null,
PedimentoRectificado = worksheet.Cells[rowCount, 15].Value != null ? worksheet.Cells[rowCount, 15].Value?.ToString() : null,
Causa = worksheet.Cells[rowCount, 16].Value != null ? worksheet.Cells[rowCount, 16].Value?.ToString() : null,
CargoA = worksheet.Cells[rowCount, 17].Value != null ? worksheet.Cells[rowCount, 17].Value?.ToString() : null,
TiempoProceso = worksheet.Cells[rowCount, 18].Value != null ? int.Parse(worksheet.Cells[rowCount, 18].Value?.ToString()) : null,
TiempoCruce = worksheet.Cells[rowCount, 19].Value != null ? int.Parse(worksheet.Cells[rowCount, 19].Value?.ToString()) : null,
Cumple = worksheet.Cells[rowCount, 20].Value != null ? worksheet.Cells[rowCount, 20].Value?.ToString() : null,
NoCumple = worksheet.Cells[rowCount, 21].Value != null ? worksheet.Cells[rowCount, 21].Value?.ToString() : null,
RazonNoCumple = worksheet.Cells[rowCount, 22].Value != null ? worksheet.Cells[rowCount, 22].Value?.ToString() : null,
CargoDe = worksheet.Cells[rowCount, 23].Value != null ? worksheet.Cells[rowCount, 23].Value?.ToString() : null,
MedioSalida = worksheet.Cells[rowCount, 24].Value != null ? worksheet.Cells[rowCount, 24].Value?.ToString() : null,
});
if(resp == null) throw new Exception("Ocurrio un error al generar el reporte. Asegurese que los datos del archivo sean correctors.");
rowCount++;
}
if(System.IO.File.Exists(targetFile)) System.IO.File.Delete(targetFile);
}
}
}
}
Loading…
Cancel
Save