From aad941897f845fbbfb9e456ac42015108cb4118f Mon Sep 17 00:00:00 2001 From: Felix Morales Date: Fri, 28 Jun 2024 13:30:01 -0500 Subject: [PATCH] Functionality is created to handle requests from the Alen account statements component on the client side --- .../Alen/IEstadosCuentaAlenRepository.cs | 16 ++ Controllers/FileManagerController.cs | 20 ++ .../ReporteEstadosCuentaAlenController.cs | 252 ++++++++++++++++++ DTO/Reportes/Alen/DTOEstadosCuentaAlen.cs | 50 ++++ .../Alen/DTOEstadosCuentaAlenFilters.cs | 12 + Models/Clientes/Alen/EstadosCuenta.cs | 39 +++ Program.cs | 4 +- .../Alen/EstadosCuentaAlenRepository.cs | 137 ++++++++++ 8 files changed, 529 insertions(+), 1 deletion(-) create mode 100644 Contracts/Reportes/Alen/IEstadosCuentaAlenRepository.cs create mode 100644 Controllers/Reportes/Alen/ReporteEstadosCuentaAlenController.cs create mode 100644 DTO/Reportes/Alen/DTOEstadosCuentaAlen.cs create mode 100644 DTO/Reportes/Alen/DTOEstadosCuentaAlenFilters.cs create mode 100644 Models/Clientes/Alen/EstadosCuenta.cs create mode 100644 Repository/Reportes/Alen/EstadosCuentaAlenRepository.cs diff --git a/Contracts/Reportes/Alen/IEstadosCuentaAlenRepository.cs b/Contracts/Reportes/Alen/IEstadosCuentaAlenRepository.cs new file mode 100644 index 0000000..0b655b8 --- /dev/null +++ b/Contracts/Reportes/Alen/IEstadosCuentaAlenRepository.cs @@ -0,0 +1,16 @@ +using CORRESPONSALBackend.DTO.Reportes.Alen; +using CORRESPONSALBackend.Models.Clientes.Alen; + +namespace CORRESPONSALBackend.Contracts.Reportes.Alen{ + public interface IEstadosCuentaAlenRepository{ + public Task ClearData(); + public Task> GetAll(DTOEstadosCuentaAlenFilters filters); + public Task Append (EstadosCuenta data); + + public Task GetByFolio (string Folio); + + public Task MarkAsProgramado (string NoMovimiento, string NoSerie); + public Task AppendOrdenCompra(DTOEstadosCuentaAlen data); + public Task AppendObservaciones(DTOEstadosCuentaAlen data); + } +} \ No newline at end of file diff --git a/Controllers/FileManagerController.cs b/Controllers/FileManagerController.cs index 77713b1..7d9a0fb 100644 --- a/Controllers/FileManagerController.cs +++ b/Controllers/FileManagerController.cs @@ -441,5 +441,25 @@ namespace CORRESPONSALBackend.Controllers return BadRequest(ex.Message); } } + + [HttpGet("GetAEO")] + public async Task GetArchivoElectronicoOficial([FromQuery] string serie, string noMovimiento, string fileMime, string trafico){ + try{ + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(47); + string folderPath = RootPathCorresponsales + RelativePath.Path + trafico + "\\"; + string fileName = $"RGMS960730IL9_{serie}-00000{noMovimiento}.{fileMime}"; + string fullPath = folderPath + fileName; + if (!System.IO.File.Exists(fullPath)) + { + throw new Exception("No se encontrĂ³ el archivo solicitado."); + } + var mime = "application/" + fileMime.ToLower(); + byte[] pdfBytes = System.IO.File.ReadAllBytes(fullPath); + MemoryStream ms = new MemoryStream(pdfBytes); + return new FileStreamResult(ms, mime);//D:\data\ArchivoElectronicoSIR\www.gemcousa.com\SIR-GEMCO\DOCS-SIR\ALEN DEL NORTE SA DE CV\2024\24-00665E + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } } } \ No newline at end of file diff --git a/Controllers/Reportes/Alen/ReporteEstadosCuentaAlenController.cs b/Controllers/Reportes/Alen/ReporteEstadosCuentaAlenController.cs new file mode 100644 index 0000000..ab560a6 --- /dev/null +++ b/Controllers/Reportes/Alen/ReporteEstadosCuentaAlenController.cs @@ -0,0 +1,252 @@ +using System.Globalization; +using CORRESPONSALBackend.Contracts.Reportes.Alen; +using CORRESPONSALBackend.Contracts.Utils; +using CORRESPONSALBackend.DTO.Reportes.Alen; +using CORRESPONSALBackend.Models.Clientes.Alen; +using CORRESPONSALBackend.Models.Utils; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OfficeOpenXml; +using OfficeOpenXml.Style; +using OfficeOpenXml.Table; + +namespace CORRESPONSALBackend.Controllers.Reportes.Alen{ + [Authorize] + [ApiController] + [Route("api/[controller]")] + public class ReporteEstadosCuentaAlenController : ControllerBase{ + + private readonly IFileManagerRepository _Repo; + private readonly IFilePaths4ProcessRepository _RepoRelativePath; + private readonly IConfiguration _config; + private readonly string RootPathCorresponsales; + private readonly IEstadosCuentaAlenRepository _EstadosCuentaAlenRepo; + public ReporteEstadosCuentaAlenController(IFilePaths4ProcessRepository RepoRelativePath, IConfiguration config, IFileManagerRepository Repo, IEstadosCuentaAlenRepository EstadosCuentaAlenRepo){ + _Repo = Repo; + _RepoRelativePath = RepoRelativePath; + _config = config; + RootPathCorresponsales = _config.GetValue("AllFiles"); + _EstadosCuentaAlenRepo = EstadosCuentaAlenRepo; + } + + [HttpPost("Append")] + public async Task Append(IFormFile file){ + try{ + await _EstadosCuentaAlenRepo.ClearData(); + //Obtener la ruta del archivo + //Se obtiene la ruta del archivo + //FileManager recFound = await _Repo.getFileById(45); + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(45); + + if(!System.IO.Directory.Exists(RootPathCorresponsales + RelativePath.Path)){ + System.IO.Directory.CreateDirectory(RootPathCorresponsales + RelativePath.Path); + } + + string filePath = RootPathCorresponsales + RelativePath.Path + file.FileName; + if(System.IO.File.Exists(filePath)){ + System.IO.File.Delete(filePath); + } + //Si es un archivo nuevo se guarda + using(var stream = System.IO.File.Create(filePath)){ + await file.CopyToAsync(stream); + } + //Leer el archivo con epplus + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using(ExcelPackage package = new ExcelPackage(filePath)){ + var worksheet = package.Workbook.Worksheets.FirstOrDefault(); + int rowCount = 2; + worksheet.Column(18).Style.Numberformat.Format = "yyyy-mm-dd"; + worksheet.Column(19).Style.Numberformat.Format = "yyyy-mm-dd"; + worksheet.Column(20).Style.Numberformat.Format = "yyyy-mm-dd"; + while(string.IsNullOrWhiteSpace(worksheet?.Cells[rowCount, 4].Value?.ToString()) == false){ + EstadosCuenta estadoCuenta = new EstadosCuenta(){ + id=0, + TipoMovimiento = worksheet.Cells[rowCount, 1].Value != null ? worksheet.Cells[rowCount, 1].Value?.ToString() : "", + NoSerie = worksheet.Cells[rowCount, 2].Value != null ? worksheet.Cells[rowCount, 2].Value?.ToString() : "", + NoMovimiento = worksheet.Cells[rowCount, 3].Value != null ? worksheet.Cells[rowCount, 3].Value?.ToString() : "", + Trafico = worksheet.Cells[rowCount, 4].Value != null ? worksheet.Cells[rowCount, 4].Value?.ToString() : "", + Impexp = worksheet.Cells[rowCount, 5].Value != null ? worksheet.Cells[rowCount, 5].Value?.ToString() : "", + Aduana = worksheet.Cells[rowCount, 6].Value != null ? worksheet.Cells[rowCount, 6].Value?.ToString() : "", + Patente = worksheet.Cells[rowCount, 7].Value != null ? worksheet.Cells[rowCount, 7].Value?.ToString() : "", + Pedimento = worksheet.Cells[rowCount, 8].Value != null ? worksheet.Cells[rowCount, 8].Value?.ToString() : "", + Clave = worksheet.Cells[rowCount, 9].Value != null ? worksheet.Cells[rowCount, 9].Value?.ToString() : "", + NoCliente = worksheet.Cells[rowCount, 10].Value != null ? worksheet.Cells[rowCount, 10].Value?.ToString() : "", + NoCentro = worksheet.Cells[rowCount, 11].Value != null ? worksheet.Cells[rowCount, 11].Value?.ToString() : "", + SubCentro = worksheet.Cells[rowCount, 12].Value != null ? worksheet.Cells[rowCount, 12].Value?.ToString() : "", + Nombre = worksheet.Cells[rowCount, 13].Value != null ? worksheet.Cells[rowCount, 13].Value?.ToString() : "", + SubCtaNombre = worksheet.Cells[rowCount, 14].Value != null ? worksheet.Cells[rowCount, 14].Value?.ToString() : "", + TipoRangos = worksheet.Cells[rowCount, 15].Value != null ? worksheet.Cells[rowCount, 15].Value?.ToString() : "", + Cargos = worksheet.Cells[rowCount, 16].Value != null ? worksheet.Cells[rowCount, 16].Value?.ToString() : "", + Abonos = worksheet.Cells[rowCount, 17].Value != null ? worksheet.Cells[rowCount, 17].Value?.ToString() : "", + Fecha = worksheet.Cells[rowCount, 18].Value != null ? StringToDateTime(worksheet.Cells[rowCount, 18].Value?.ToString().Substring(0,10)) : "", + FechaPedimento = worksheet.Cells[rowCount, 19].Value != null ? StringToDateTime(worksheet.Cells[rowCount, 19].Value?.ToString().Substring(0,10)) : "", + FechaRev = worksheet.Cells[rowCount, 20].Value != null ? StringToDateTime(worksheet.Cells[rowCount, 20].Value?.ToString().Substring(0,10)) : "", + DiasPedimCta = worksheet.Cells[rowCount, 21].Value != null ? worksheet.Cells[rowCount, 21].Value?.ToString() : "", + DiasCtaRev = worksheet.Cells[rowCount, 22].Value != null ? worksheet.Cells[rowCount, 22].Value?.ToString() : "", + DiasRev = worksheet.Cells[rowCount, 23].Value != null ? worksheet.Cells[rowCount, 23].Value?.ToString() : "", + IvaAl = worksheet.Cells[rowCount, 24].Value != null ? worksheet.Cells[rowCount, 24].Value?.ToString() : "", + TotalFacturado = worksheet.Cells[rowCount, 25].Value != null ? worksheet.Cells[rowCount, 25].Value?.ToString() : "", + SaldoFinal = worksheet.Cells[rowCount, 26].Value != null ? worksheet.Cells[rowCount, 26].Value?.ToString() : "", + Anticipo = worksheet.Cells[rowCount, 27].Value != null ? worksheet.Cells[rowCount, 27].Value?.ToString() : "", + UUID = worksheet.Cells[rowCount, 28].Value != null ? worksheet.Cells[rowCount, 28].Value?.ToString() : "", + Descripcion = worksheet.Cells[rowCount, 29].Value != null ? worksheet.Cells[rowCount, 29].Value?.ToString() : "", + Remitente = worksheet.Cells[rowCount, 30].Value != null ? worksheet.Cells[rowCount, 30].Value?.ToString() : "", + Pedido = worksheet.Cells[rowCount, 31].Value != null ? worksheet.Cells[rowCount, 31].Value?.ToString() : "", + TipoMercancia = worksheet.Cells[rowCount, 32].Value != null ? worksheet.Cells[rowCount, 32].Value?.ToString() : "", + CampoAdicional5 = worksheet.Cells[rowCount, 33].Value != null ? worksheet.Cells[rowCount, 33].Value?.ToString() : "", + }; + var resp = await _EstadosCuentaAlenRepo.Append(estadoCuenta); + rowCount++; + } + } + return Ok(); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + private string StringToDateTime(string s){ + return DateTime.ParseExact(s, "dd/MM/yyyy",CultureInfo.InvariantCulture).ToString("yyyy-MM-dd"); + } + + [HttpGet("GetAll")] + public async Task GetAll([FromQuery] DTOEstadosCuentaAlenFilters filters){ + try{ + var estados = await _EstadosCuentaAlenRepo.GetAll(filters); + return Ok(estados); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + [HttpPost("Export")] + public async Task Export([FromBody] DTOEstadosCuentaAlen[] estados){ + try{ + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using (ExcelPackage excelPackage = new ExcelPackage()){ + var worksheet = excelPackage.Workbook.Worksheets.Add("sheet1"); + int rowCount = 2; + worksheet.Cells[$"A1"].Value = "Serie"; + worksheet.Cells[$"B1"].Value = "Movimiento"; + worksheet.Cells[$"C1"].Value = "Fecha"; + worksheet.Cells[$"D1"].Value = "Trafico"; + worksheet.Cells[$"E1"].Value = "Aduana"; + worksheet.Cells[$"F1"].Value = "Patente"; + worksheet.Cells[$"G1"].Value = "Pedimento"; + worksheet.Cells[$"H1"].Value = "Cve. Pedim."; + worksheet.Cells[$"I1"].Value = "Impo/Expo"; + worksheet.Cells[$"J1"].Value = "No. Cte."; + worksheet.Cells[$"K1"].Value = "Nombre Cliente"; + worksheet.Cells[$"L1"].Value = "Cargos"; + worksheet.Cells[$"M1"].Value = "Abonos"; + worksheet.Cells[$"N1"].Value = "SaldoFinal"; + worksheet.Cells[$"O1"].Value = "% IVA"; + worksheet.Cells[$"P1"].Value = "Descripcion"; + worksheet.Cells[$"Q1"].Value = "Remitente"; + worksheet.Cells[$"R1"].Value = "Pedido"; + worksheet.Cells[$"S1"].Value = "Orden Compra"; + worksheet.Cells[$"T1"].Value = "Tipo Mcia"; + foreach (var estado in estados){ + worksheet.Cells[$"A{rowCount}"].Value = estado.Serie; + worksheet.Cells[$"B{rowCount}"].Value = estado.NoMovimiento; + worksheet.Cells[$"C{rowCount}"].Value = estado.Fecha; + worksheet.Cells[$"D{rowCount}"].Value = estado.Trafico; + worksheet.Cells[$"E{rowCount}"].Value = estado.Aduana; + worksheet.Cells[$"F{rowCount}"].Value = estado.Patente; + worksheet.Cells[$"G{rowCount}"].Value = estado.Pedimento; + worksheet.Cells[$"H{rowCount}"].Value = estado.Clave; + worksheet.Cells[$"I{rowCount}"].Value = estado.Impexp; + worksheet.Cells[$"J{rowCount}"].Value = estado.NoCliente; + worksheet.Cells[$"K{rowCount}"].Value = estado.Nombre; + worksheet.Cells[$"L{rowCount}"].Value = estado.Cargos; + worksheet.Cells[$"M{rowCount}"].Value = estado.Abonos; + worksheet.Cells[$"N{rowCount}"].Value = estado.SaldoFinal; + worksheet.Cells[$"O{rowCount}"].Value = estado.IvaAl; + worksheet.Cells[$"P{rowCount}"].Value = estado.Descripcion; + worksheet.Cells[$"Q{rowCount}"].Value = estado.Remitente; + worksheet.Cells[$"R{rowCount}"].Value = estado.Pedido; + worksheet.Cells[$"S{rowCount}"].Value = estado.OrdenCompra; + worksheet.Cells[$"T{rowCount}"].Value = estado.TipoMercancia; + rowCount++; + } + ExcelRange range = worksheet.Cells[1, 1,estados.Count() + 1, 20]; + ExcelTable tab = worksheet.Tables.Add(range, "Table1"); + tab.TableStyle = TableStyles.Light1; + worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + worksheet.Cells[worksheet.Dimension.Address].Style.VerticalAlignment = ExcelVerticalAlignment.Center; + excelPackage.Workbook.Calculate(); + var stream = new MemoryStream(); + excelPackage.SaveAs(stream); + if(stream.Length > 0){ + stream.Position = 0; + return File(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", $"Reporte_Operaciones.xlsx"); + }else{ + throw new Exception("Ocurrio un error al generar el reporte, intentelo de nuevo"); + } + } + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + [HttpPost("AppendProgramacionesPago")] + public async Task AppendProgramacionesPago(IFormFile file){ + try{ + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(46); + + if(!System.IO.Directory.Exists(RootPathCorresponsales + RelativePath.Path)){ + System.IO.Directory.CreateDirectory(RootPathCorresponsales + RelativePath.Path); + } + + string filePath = RootPathCorresponsales + RelativePath.Path + file.FileName; + if(System.IO.File.Exists(filePath)){ + System.IO.File.Delete(filePath); + } + //Si es un archivo nuevo se guarda + using(var stream = System.IO.File.Create(filePath)){ + await file.CopyToAsync(stream); + } + //Leer el archivo con epplus + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + using(ExcelPackage package = new ExcelPackage(filePath)){ + var worksheet = package.Workbook.Worksheets.FirstOrDefault(); + int rowCount = 3; + while(string.IsNullOrWhiteSpace(worksheet?.Cells[rowCount, 2].Value?.ToString()) == false){ + //Quitar el prefijo de la serie del numero de cuenta. + string folio = worksheet.Cells[rowCount, 2].Value != null ? worksheet.Cells[rowCount, 2].Value?.ToString().Substring(1,5) : ""; + //Buscar el registro de la cuenta + var cuenta = await _EstadosCuentaAlenRepo.GetByFolio(folio); + if(cuenta.id != 0){ + //Hacer la llamada a al base de datos para actualizar el registro + cuenta = await _EstadosCuentaAlenRepo.MarkAsProgramado(cuenta.NoMovimiento, cuenta.NoSerie); + } + rowCount++; + } + } + return Ok(); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + [HttpPost("AppendOrdenCompra")] + public async Task AppendOrdenCompra([FromBody] DTOEstadosCuentaAlen data){ + try{ + var trafico = await _EstadosCuentaAlenRepo.AppendOrdenCompra(data); + return Ok(trafico); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + + [HttpPost("AppendObservaciones")] + public async Task AppendObservaciones([FromBody] DTOEstadosCuentaAlen data){ + try{ + var trafico = await _EstadosCuentaAlenRepo.AppendObservaciones(data); + return Ok(trafico); + }catch(Exception ex){ + return BadRequest(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/DTO/Reportes/Alen/DTOEstadosCuentaAlen.cs b/DTO/Reportes/Alen/DTOEstadosCuentaAlen.cs new file mode 100644 index 0000000..a84c42e --- /dev/null +++ b/DTO/Reportes/Alen/DTOEstadosCuentaAlen.cs @@ -0,0 +1,50 @@ +namespace CORRESPONSALBackend.DTO.Reportes.Alen{ + public class DTOEstadosCuentaAlen{ + public int id { get; set; } + public string? TipoMovimiento { get; set; } = ""; + public string? NoSerie { get; set; } = ""; + public string? NoMovimiento {get;set;} = ""; + public string? Trafico {get;set;} = ""; + public string? Impexp {get;set;} = ""; + public string? Aduana {get;set;} = ""; + public string? Patente {get;set;} = ""; + public string? Pedimento {get;set;} = ""; + public string? Clave {get;set;} = ""; + public string? NoCliente {get;set;} = ""; + public string? NoCentro {get;set;} = ""; + public string? SubCentro {get;set;} = ""; + public string? Nombre {get;set;} = ""; + public string? SubCtaNombre {get;set;} = ""; + public string? TipoRangos {get;set;} = ""; + public string? Cargos {get;set;} = ""; + public string? Abonos {get;set;} = ""; + public string? Fecha {get;set;} = ""; + public string? FechaPedimento {get;set;} = ""; + public string? FechaRev {get;set;} = ""; + public string? DiasPedimCta {get;set;} = ""; + public string? DiasCtaRev {get;set;} = ""; + public string? DiasRev {get;set;} = ""; + public string? IvaAl {get;set;} = ""; + public string? TotalFacturado {get;set;} = ""; + public string? SaldoFinal {get;set;} = ""; + public string? Anticipo {get;set;} = ""; + public string? UUID {get;set;} = ""; + public string? Descripcion {get;set;} = ""; + public string? Remitente {get;set;} = ""; + public string? Pedido {get;set;} = ""; + public string? TipoMercancia {get;set;} = ""; + public string? CampoAdicional5 {get;set;} = ""; + public int? IdPdf {get;set;}=0; + public string? Pdf {get;set;}=""; + public int? IdXml {get;set;}=0; + public string? Xml {get;set;}=""; + public int? IdNotasCargo {get;set;}=0; + public string? NotasCargo {get;set;}=""; + public bool? Programado {get;set;} = false; + public string? Serie {get;set;} = ""; + public int? IdOrdenCompra {get;set;} = 0; + public string? OrdenCompra {get;set;} = ""; + public int? IdObservaciones {get;set;} = 0; + public string? Observaciones {get;set;} = ""; + } +} \ No newline at end of file diff --git a/DTO/Reportes/Alen/DTOEstadosCuentaAlenFilters.cs b/DTO/Reportes/Alen/DTOEstadosCuentaAlenFilters.cs new file mode 100644 index 0000000..0f45c4d --- /dev/null +++ b/DTO/Reportes/Alen/DTOEstadosCuentaAlenFilters.cs @@ -0,0 +1,12 @@ +namespace CORRESPONSALBackend.DTO.Reportes.Alen{ + public class DTOEstadosCuentaAlenFilters{ + public string? Trafico {get;set;}=""; + public string? Impexp {get;set;}=""; + public string? Aduana {get;set;}=""; + public string? Patente {get;set;}=""; + public string? Pedimento {get;set;}=""; + public string? Fecha {get;set;}=""; + public string? Remitente {get;set;}=""; + public string? Programado {get;set;} = ""; + } +} \ No newline at end of file diff --git a/Models/Clientes/Alen/EstadosCuenta.cs b/Models/Clientes/Alen/EstadosCuenta.cs new file mode 100644 index 0000000..b00d671 --- /dev/null +++ b/Models/Clientes/Alen/EstadosCuenta.cs @@ -0,0 +1,39 @@ +namespace CORRESPONSALBackend.Models.Clientes.Alen{ + public class EstadosCuenta{ + public int id { get; set; } + public string? TipoMovimiento { get; set; } = ""; + public string? NoSerie { get; set; } = ""; + public string? NoMovimiento {get;set;} = ""; + public string? Trafico {get;set;} = ""; + public string? Impexp {get;set;} = ""; + public string? Aduana {get;set;} = ""; + public string? Patente {get;set;} = ""; + public string? Pedimento {get;set;} = ""; + public string? Clave {get;set;} = ""; + public string? NoCliente {get;set;} = ""; + public string? NoCentro {get;set;} = ""; + public string? SubCentro {get;set;} = ""; + public string? Nombre {get;set;} = ""; + public string? SubCtaNombre {get;set;} = ""; + public string? TipoRangos {get;set;} = ""; + public string? Cargos {get;set;} = ""; + public string? Abonos {get;set;} = ""; + public string? Fecha {get;set;} = ""; + public string? FechaPedimento {get;set;} = ""; + public string? FechaRev {get;set;} = ""; + public string? DiasPedimCta {get;set;} = ""; + public string? DiasCtaRev {get;set;} = ""; + public string? DiasRev {get;set;} = ""; + public string? IvaAl {get;set;} = ""; + public string? TotalFacturado {get;set;} = ""; + public string? SaldoFinal {get;set;} = ""; + public string? Anticipo {get;set;} = ""; + public string? UUID {get;set;} = ""; + public string? Descripcion {get;set;} = ""; + public string? Remitente {get;set;} = ""; + public string? Pedido {get;set;} = ""; + public string? TipoMercancia {get;set;} = ""; + public string? CampoAdicional5 {get;set;} = ""; + public bool? Programado = false; + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index c33a083..5a04953 100644 --- a/Program.cs +++ b/Program.cs @@ -54,6 +54,7 @@ using CORRESPONSALBackend.Contracts.Reportes; using CORRESPONSALBackend.Services.Reportes; using CORRESPONSALBackend.Contracts.ArchivoElectronico; using CORRESPONSALBackend.Services; +using CORRESPONSALBackend.Repository.Reportes.Alen; var builder = WebApplication.CreateBuilder(args); @@ -99,7 +100,8 @@ builder.Services.AddScoped(); //Clientes builder.Services.AddScoped(); - +//Estados de Cuenta +builder.Services.AddScoped(); // Dashboards builder.Services.AddScoped(); diff --git a/Repository/Reportes/Alen/EstadosCuentaAlenRepository.cs b/Repository/Reportes/Alen/EstadosCuentaAlenRepository.cs new file mode 100644 index 0000000..9e861cd --- /dev/null +++ b/Repository/Reportes/Alen/EstadosCuentaAlenRepository.cs @@ -0,0 +1,137 @@ +using System.Data; +using CORRESPONSALBackend.Context; +using CORRESPONSALBackend.Contracts.Reportes.Alen; +using CORRESPONSALBackend.DTO.Reportes.Alen; +using CORRESPONSALBackend.Models.Clientes.Alen; +using Dapper; + +namespace CORRESPONSALBackend.Repository.Reportes.Alen{ + public class EstadosCuentaAlenRepository : IEstadosCuentaAlenRepository + { + + private readonly DapperContext _context; + private readonly IConfiguration _config; + public EstadosCuentaAlenRepository(DapperContext context, IConfiguration config) + { + _context = context; + _config = config; + } + public async Task Append(EstadosCuenta data) + { + var query = "[EstadosCuenta.Alen.Append]"; + using (var connection = _context.CreateConnection()) + { + var estado = await connection.QueryAsync(query, new + { + data.TipoMovimiento, + data.NoSerie, + data.NoMovimiento, + data.Trafico, + data.Impexp, + data.Aduana, + data.Patente, + data.Pedimento, + data.Clave, + data.NoCliente, + data.NoCentro, + data.SubCentro, + data.Nombre, + data.SubCtaNombre, + data.TipoRangos, + data.Cargos, + data.Abonos, + data.Fecha, + data.FechaPedimento, + data.FechaRev, + data.DiasPedimCta, + data.DiasCtaRev, + data.DiasRev, + data.IvaAl, + data.TotalFacturado, + data.SaldoFinal, + data.Anticipo, + data.UUID, + data.Descripcion, + data.Remitente, + data.Pedido, + data.TipoMercancia, + data.CampoAdicional5, + }, commandType: CommandType.StoredProcedure); + return estado.First(); + } + } + + public async Task AppendObservaciones(DTOEstadosCuentaAlen data) + { + var query = "[EstadosCuenta.Alen.AppendObservaciones]"; + using (var connection = _context.CreateConnection()) + { + var cuenta = await connection.QueryAsync(query, new {data.IdObservaciones, @NoCuenta = data.NoMovimiento, data.Observaciones}, commandType: CommandType.StoredProcedure); + return cuenta.First(); + } + } + + public async Task AppendOrdenCompra(DTOEstadosCuentaAlen data) + { + var query = "[EstadosCuenta.Alen.AppendOrdenCompra]"; + using (var connection = _context.CreateConnection()) + { + var cuenta = await connection.QueryAsync(query, new {data.IdOrdenCompra, @NoCuenta = data.NoMovimiento, data.OrdenCompra}, commandType: CommandType.StoredProcedure); + return cuenta.First(); + } + } + + public async Task ClearData() + { + var query = "[EstadosCuenta.Alen.Clear]"; + using (var connection = _context.CreateConnection()) + { + await connection.QueryAsync(query, new {}, commandType: CommandType.StoredProcedure); + } + } + + public async Task> GetAll(DTOEstadosCuentaAlenFilters filters) + { + var query = "[EstadosCuenta.Alen.GetAll]"; + using (var connection = _context.CreateConnection()) + { + var estados = await connection.QueryAsync(query, new { + filters.Trafico, + filters.Impexp, + filters.Aduana, + filters.Patente, + filters.Pedimento, + filters.Fecha, + filters.Remitente, + filters.Programado + }, commandType: CommandType.StoredProcedure); + return estados; + } + } + + public async Task GetByFolio(string Folio) + { + var query = "[EstadosCuenta.Alen.GetByFolio]"; + using (var connection = _context.CreateConnection()) + { + var cuenta= await connection.QueryAsync(query, new { + @Folio + }, commandType: CommandType.StoredProcedure); + return cuenta.FirstOrDefault(new EstadosCuenta(){id=0}); + } + } + + public async Task MarkAsProgramado(string NoMovimiento, string NoSerie) + { + var query = "[EstadosCuenta.Alen.MarkAsProgramado]"; + using (var connection = _context.CreateConnection()) + { + var cuenta= await connection.QueryFirstOrDefaultAsync(query, new { + @NoCuenta = NoMovimiento, + @NoSerie = NoSerie + }, commandType: CommandType.StoredProcedure); + return cuenta; + } + } + } +} \ No newline at end of file