Continuación del módulo de reportes. -Backend
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// src/Services/Reportes/IReportesService.cs
|
||||
using GestionIntegral.Api.Dtos.Reportes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,6 +9,57 @@ namespace GestionIntegral.Api.Services.Reportes
|
||||
public interface IReportesService
|
||||
{
|
||||
Task<(IEnumerable<ExistenciaPapelDto> Data, string? Error)> ObtenerExistenciaPapelAsync(DateTime fechaDesde, DateTime fechaHasta, int? idPlanta, bool consolidado);
|
||||
// ...
|
||||
Task<(IEnumerable<MovimientoBobinasDto> Data, string? Error)> ObtenerMovimientoBobinasAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta);
|
||||
Task<(IEnumerable<MovimientoBobinaEstadoDetalleDto> Detalle, IEnumerable<MovimientoBobinaEstadoTotalDto> Totales, string? Error)> ObtenerMovimientoBobinasPorEstadoAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta);
|
||||
|
||||
// Reporte Listado Distribucion General (RR002)
|
||||
Task<(IEnumerable<ListadoDistribucionGeneralResumenDto> Resumen, IEnumerable<ListadoDistribucionGeneralPromedioDiaDto> Promedios, string? Error)> ObtenerListadoDistribucionGeneralAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Listado Distribucion Canillas (RR002)
|
||||
Task<(IEnumerable<ListadoDistribucionCanillasSimpleDto> Simple, IEnumerable<ListadoDistribucionCanillasPromedioDiaDto> Promedios, string? Error)> ObtenerListadoDistribucionCanillasAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Listado Distribucion Canillas con Importes (RR002)
|
||||
Task<(IEnumerable<ListadoDistribucionCanillasImporteDto> Data, string? Error)> ObtenerListadoDistribucionCanillasConImporteAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta, bool esAccionista);
|
||||
|
||||
// Reportes Venta Mensual Secretaria
|
||||
Task<(IEnumerable<VentaMensualSecretariaElDiaDto> Data, string? Error)> ObtenerVentaMensualSecretariaElDiaAsync(DateTime fechaDesde, DateTime fechaHasta);
|
||||
Task<(IEnumerable<VentaMensualSecretariaElPlataDto> Data, string? Error)> ObtenerVentaMensualSecretariaElPlataAsync(DateTime fechaDesde, DateTime fechaHasta);
|
||||
Task<(IEnumerable<VentaMensualSecretariaTirDevoDto> Data, string? Error)> ObtenerVentaMensualSecretariaTirDevoAsync(DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Distribucion Canillas (MC005) - Este es un reporte más complejo
|
||||
Task<(
|
||||
IEnumerable<DetalleDistribucionCanillaDto> Canillas,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasAcc,
|
||||
IEnumerable<DetalleDistribucionCanillaAllDto> CanillasAll,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasFechaLiq,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasAccFechaLiq,
|
||||
IEnumerable<ObtenerCtrlDevolucionesDto> CtrlDevoluciones,
|
||||
IEnumerable<ControlDevolucionesReporteDto> CtrlDevolucionesParaDistCan,
|
||||
string? Error
|
||||
)> ObtenerReporteDistribucionCanillasAsync(DateTime fecha, int idEmpresa); // ESTA ES LA FIRMA CORRECTA Y ÚNICA PARA ESTE MÉTODO
|
||||
|
||||
// Reporte Tiradas por Publicación y Secciones (RR008)
|
||||
Task<(IEnumerable<TiradasPublicacionesSeccionesDto> Data, string? Error)> ObtenerTiradasPublicacionesSeccionesAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta, int idPlanta);
|
||||
Task<(IEnumerable<TiradasPublicacionesSeccionesDto> Data, string? Error)> ObtenerTiradasPublicacionesSeccionesConsolidadoAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Consumo Bobinas por Seccion (RR007)
|
||||
Task<(IEnumerable<ConsumoBobinasSeccionDto> Data, string? Error)> ObtenerConsumoBobinasPorSeccionAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta);
|
||||
Task<(IEnumerable<ConsumoBobinasSeccionDto> Data, string? Error)> ObtenerConsumoBobinasPorSeccionConsolidadoAsync(DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Consumo Bobinas por Publicacion (RR007) - Consolidado
|
||||
Task<(IEnumerable<ConsumoBobinasPublicacionDto> Data, string? Error)> ObtenerConsumoBobinasPorPublicacionAsync(DateTime fechaDesde, DateTime fechaHasta);
|
||||
|
||||
// Reporte Comparativa Consumo Bobinas (RR007)
|
||||
Task<(IEnumerable<ComparativaConsumoBobinasDto> Data, string? Error)> ObtenerComparativaConsumoBobinasAsync(DateTime fechaInicioMesA, DateTime fechaFinMesA, DateTime fechaInicioMesB, DateTime fechaFinMesB, int idPlanta);
|
||||
Task<(IEnumerable<ComparativaConsumoBobinasDto> Data, string? Error)> ObtenerComparativaConsumoBobinasConsolidadoAsync(DateTime fechaInicioMesA, DateTime fechaFinMesA, DateTime fechaInicioMesB, DateTime fechaFinMesB);
|
||||
|
||||
// DTOs para ReporteCuentasDistribuidores
|
||||
Task<(
|
||||
IEnumerable<BalanceCuentaDistDto> EntradasSalidas,
|
||||
IEnumerable<BalanceCuentaDebCredDto> DebitosCreditos,
|
||||
IEnumerable<BalanceCuentaPagosDto> Pagos,
|
||||
IEnumerable<SaldoDto> Saldos,
|
||||
string? Error
|
||||
)> ObtenerReporteCuentasDistribuidorAsync(int idDistribuidor, int idEmpresa, DateTime fechaDesde, DateTime fechaHasta);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/Services/Reportes/ReportesService.cs
|
||||
using GestionIntegral.Api.Data.Repositories.Reportes;
|
||||
using GestionIntegral.Api.Dtos.Reportes;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -12,6 +13,7 @@ namespace GestionIntegral.Api.Services.Reportes
|
||||
{
|
||||
private readonly IReportesRepository _reportesRepository;
|
||||
private readonly ILogger<ReportesService> _logger;
|
||||
// No necesitas _connectionFactory aquí si toda la lógica de BD está en el repositorio.
|
||||
|
||||
public ReportesService(IReportesRepository reportesRepository, ILogger<ReportesService> logger)
|
||||
{
|
||||
@@ -20,7 +22,7 @@ namespace GestionIntegral.Api.Services.Reportes
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ExistenciaPapelDto> Data, string? Error)> ObtenerExistenciaPapelAsync(
|
||||
DateTime fechaDesde, DateTime fechaHasta, int? idPlanta, bool consolidado)
|
||||
DateTime fechaDesde, DateTime fechaHasta, int? idPlanta, bool consolidado)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
{
|
||||
@@ -35,34 +37,386 @@ namespace GestionIntegral.Api.Services.Reportes
|
||||
try
|
||||
{
|
||||
var dataFromRepo = await _reportesRepository.GetExistenciaPapelAsync(fechaDesde, fechaHasta, idPlanta, consolidado);
|
||||
|
||||
// Ajustar DateTimeKind a Utc aquí
|
||||
var dataWithUtcDates = dataFromRepo.Select(dto =>
|
||||
{
|
||||
if (dto.FechaEstimacionFinStock.HasValue)
|
||||
{
|
||||
// Aseguramos que solo tomamos la parte de la fecha y la especificamos como UTC
|
||||
// Si ya viene con hora 00:00:00 del SP, .Date no cambia nada.
|
||||
// Si viniera con hora, .Date la trunca a 00:00:00.
|
||||
dto.FechaEstimacionFinStock = DateTime.SpecifyKind(dto.FechaEstimacionFinStock.Value.Date, DateTimeKind.Utc);
|
||||
}
|
||||
return dto;
|
||||
}).ToList();
|
||||
|
||||
return (dataWithUtcDates, null);
|
||||
}
|
||||
catch (ArgumentNullException ex) when (ex.ParamName == "idPlanta") // Capturar la excepción del repositorio
|
||||
catch (ArgumentNullException ex) when (ex.ParamName == "idPlanta")
|
||||
{
|
||||
_logger.LogWarning(ex, "ArgumentNullException para idPlanta en ObtenerExistenciaPapelAsync.");
|
||||
return (Enumerable.Empty<ExistenciaPapelDto>(), ex.Message); // Devolver el mensaje de error del repo
|
||||
return (Enumerable.Empty<ExistenciaPapelDto>(), ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Existencia de Papel.");
|
||||
return (Enumerable.Empty<ExistenciaPapelDto>(), "Error interno al generar el reporte.");
|
||||
return (Enumerable.Empty<ExistenciaPapelDto>(), "Error interno al generar el reporte de existencia de papel.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<MovimientoBobinasDto> Data, string? Error)> ObtenerMovimientoBobinasAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
{
|
||||
return (Enumerable.Empty<MovimientoBobinasDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
}
|
||||
int diasPeriodo = (fechaHasta.Date - fechaDesde.Date).Days + 1;
|
||||
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetMovimientoBobinasAsync(fechaDesde.Date, diasPeriodo, idPlanta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Movimiento de Bobinas.");
|
||||
return (Enumerable.Empty<MovimientoBobinasDto>(), "Error interno al generar el reporte de movimiento de bobinas.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<MovimientoBobinaEstadoDetalleDto> Detalle, IEnumerable<MovimientoBobinaEstadoTotalDto> Totales, string? Error)> ObtenerMovimientoBobinasPorEstadoAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
{
|
||||
return (Enumerable.Empty<MovimientoBobinaEstadoDetalleDto>(), Enumerable.Empty<MovimientoBobinaEstadoTotalDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var detalle = await _reportesRepository.GetMovimientoBobinasEstadoDetalleAsync(fechaDesde.Date, fechaHasta.Date, idPlanta);
|
||||
var totales = await _reportesRepository.GetMovimientoBobinasEstadoTotalesAsync(fechaDesde.Date, fechaHasta.Date, idPlanta);
|
||||
|
||||
var detalleUtc = detalle.Select(d => {
|
||||
d.FechaMovimiento = DateTime.SpecifyKind(d.FechaMovimiento, DateTimeKind.Utc);
|
||||
return d;
|
||||
}).ToList();
|
||||
|
||||
return (detalleUtc, totales, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Movimiento de Bobinas por Estado.");
|
||||
return (Enumerable.Empty<MovimientoBobinaEstadoDetalleDto>(), Enumerable.Empty<MovimientoBobinaEstadoTotalDto>(), "Error interno al generar el reporte de movimiento de bobinas por estado.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ListadoDistribucionGeneralResumenDto> Resumen, IEnumerable<ListadoDistribucionGeneralPromedioDiaDto> Promedios, string? Error)> ObtenerListadoDistribucionGeneralAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
return (Enumerable.Empty<ListadoDistribucionGeneralResumenDto>(), Enumerable.Empty<ListadoDistribucionGeneralPromedioDiaDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
|
||||
try
|
||||
{
|
||||
// El SP SP_DistObtenerResumenMensual usa Mes y Año de fechaDesde.
|
||||
// El SP SP_DistObtenerResumenMensualPorDiaSemana también.
|
||||
var resumenData = await _reportesRepository.GetListadoDistribucionGeneralResumenAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
var promediosData = await _reportesRepository.GetListadoDistribucionGeneralPromedioDiaAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
|
||||
var resumenUtc = resumenData.Select(r => { r.Fecha = DateTime.SpecifyKind(r.Fecha, DateTimeKind.Utc); return r; }).ToList();
|
||||
|
||||
return (resumenUtc, promediosData, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Listado Distribucion General.");
|
||||
return (Enumerable.Empty<ListadoDistribucionGeneralResumenDto>(), Enumerable.Empty<ListadoDistribucionGeneralPromedioDiaDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ListadoDistribucionCanillasSimpleDto> Simple, IEnumerable<ListadoDistribucionCanillasPromedioDiaDto> Promedios, string? Error)> ObtenerListadoDistribucionCanillasAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
return (Enumerable.Empty<ListadoDistribucionCanillasSimpleDto>(), Enumerable.Empty<ListadoDistribucionCanillasPromedioDiaDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
|
||||
try
|
||||
{
|
||||
var simpleData = await _reportesRepository.GetListadoDistribucionCanillasSimpleAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
var promediosData = await _reportesRepository.GetListadoDistribucionCanillasPromedioDiaAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
return (simpleData, promediosData, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Listado Distribucion Canillas.");
|
||||
return (Enumerable.Empty<ListadoDistribucionCanillasSimpleDto>(), Enumerable.Empty<ListadoDistribucionCanillasPromedioDiaDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ListadoDistribucionCanillasImporteDto> Data, string? Error)> ObtenerListadoDistribucionCanillasConImporteAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta, bool esAccionista)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
return (Enumerable.Empty<ListadoDistribucionCanillasImporteDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetListadoDistribucionCanillasImporteAsync(idPublicacion, fechaDesde, fechaHasta, esAccionista);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Listado Distribucion Canillas con Importe.");
|
||||
return (Enumerable.Empty<ListadoDistribucionCanillasImporteDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<VentaMensualSecretariaElDiaDto> Data, string? Error)> ObtenerVentaMensualSecretariaElDiaAsync(DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<VentaMensualSecretariaElDiaDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetVentaMensualSecretariaElDiaAsync(fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Venta Mensual Secretaria El Dia.");
|
||||
return (Enumerable.Empty<VentaMensualSecretariaElDiaDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<VentaMensualSecretariaElPlataDto> Data, string? Error)> ObtenerVentaMensualSecretariaElPlataAsync(DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<VentaMensualSecretariaElPlataDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetVentaMensualSecretariaElPlataAsync(fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Venta Mensual Secretaria El Plata.");
|
||||
return (Enumerable.Empty<VentaMensualSecretariaElPlataDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<VentaMensualSecretariaTirDevoDto> Data, string? Error)> ObtenerVentaMensualSecretariaTirDevoAsync(DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<VentaMensualSecretariaTirDevoDto>(), "La fecha 'Desde' no puede ser mayor que la fecha 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetVentaMensualSecretariaTirDevoAsync(fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Venta Mensual Secretaria Tirada/Devolucion.");
|
||||
return (Enumerable.Empty<VentaMensualSecretariaTirDevoDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(
|
||||
IEnumerable<DetalleDistribucionCanillaDto> Canillas,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasAcc,
|
||||
IEnumerable<DetalleDistribucionCanillaAllDto> CanillasAll,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasFechaLiq,
|
||||
IEnumerable<DetalleDistribucionCanillaDto> CanillasAccFechaLiq,
|
||||
IEnumerable<ObtenerCtrlDevolucionesDto> CtrlDevoluciones,
|
||||
IEnumerable<ControlDevolucionesReporteDto> CtrlDevolucionesParaDistCan,
|
||||
string? Error
|
||||
)> ObtenerReporteDistribucionCanillasAsync(DateTime fecha, int idEmpresa)
|
||||
{
|
||||
try
|
||||
{
|
||||
var canillasTask = _reportesRepository.GetDetalleDistribucionCanillasPubliAsync(fecha, idEmpresa);
|
||||
var canillasAccTask = _reportesRepository.GetDetalleDistribucionCanillasAccPubliAsync(fecha, idEmpresa);
|
||||
var canillasAllTask = _reportesRepository.GetDetalleDistribucionCanillasAllPubliAsync(fecha, idEmpresa);
|
||||
var canillasFechaLiqTask = _reportesRepository.GetDetalleDistribucionCanillasPubliFechaLiqAsync(fecha, idEmpresa);
|
||||
var canillasAccFechaLiqTask = _reportesRepository.GetDetalleDistribucionCanillasAccPubliFechaLiqAsync(fecha, idEmpresa);
|
||||
var ctrlDevolucionesTask = _reportesRepository.GetReporteObtenerCtrlDevolucionesAsync(fecha, idEmpresa);
|
||||
var ctrlDevolucionesParaDistCanTask = _reportesRepository.GetReporteCtrlDevolucionesParaDistCanAsync(fecha, idEmpresa);
|
||||
|
||||
await Task.WhenAll(canillasTask, canillasAccTask, canillasAllTask, canillasFechaLiqTask, canillasAccFechaLiqTask, ctrlDevolucionesTask, ctrlDevolucionesParaDistCanTask);
|
||||
|
||||
Func<IEnumerable<DetalleDistribucionCanillaDto>, IEnumerable<DetalleDistribucionCanillaDto>> toUtc =
|
||||
items => items?.Select(c => { if(c.Fecha.HasValue) c.Fecha = DateTime.SpecifyKind(c.Fecha.Value.Date, DateTimeKind.Utc); return c; }).ToList()
|
||||
?? Enumerable.Empty<DetalleDistribucionCanillaDto>();
|
||||
|
||||
return (
|
||||
toUtc(await canillasTask),
|
||||
toUtc(await canillasAccTask),
|
||||
await canillasAllTask ?? Enumerable.Empty<DetalleDistribucionCanillaAllDto>(),
|
||||
toUtc(await canillasFechaLiqTask),
|
||||
toUtc(await canillasAccFechaLiqTask),
|
||||
await ctrlDevolucionesTask ?? Enumerable.Empty<ObtenerCtrlDevolucionesDto>(),
|
||||
await ctrlDevolucionesParaDistCanTask ?? Enumerable.Empty<ControlDevolucionesReporteDto>(),
|
||||
null
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Reporte Distribucion Canillas para fecha {Fecha} y empresa {IdEmpresa}.", fecha, idEmpresa);
|
||||
return (
|
||||
Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
Enumerable.Empty<DetalleDistribucionCanillaAllDto>(),
|
||||
Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
Enumerable.Empty<DetalleDistribucionCanillaDto>(),
|
||||
Enumerable.Empty<ObtenerCtrlDevolucionesDto>(),
|
||||
Enumerable.Empty<ControlDevolucionesReporteDto>(),
|
||||
"Error interno al generar el reporte de distribución de canillas."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<TiradasPublicacionesSeccionesDto> Data, string? Error)> ObtenerTiradasPublicacionesSeccionesAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta, int idPlanta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<TiradasPublicacionesSeccionesDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetTiradasPublicacionesSeccionesAsync(idPublicacion, fechaDesde, fechaHasta, idPlanta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Tiradas por Publicación y Secciones.");
|
||||
return (Enumerable.Empty<TiradasPublicacionesSeccionesDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<TiradasPublicacionesSeccionesDto> Data, string? Error)> ObtenerTiradasPublicacionesSeccionesConsolidadoAsync(int idPublicacion, DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<TiradasPublicacionesSeccionesDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetTiradasPublicacionesSeccionesConsolidadoAsync(idPublicacion, fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Tiradas por Publicación y Secciones (Consolidado).");
|
||||
return (Enumerable.Empty<TiradasPublicacionesSeccionesDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ConsumoBobinasSeccionDto> Data, string? Error)> ObtenerConsumoBobinasPorSeccionAsync(DateTime fechaDesde, DateTime fechaHasta, int idPlanta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<ConsumoBobinasSeccionDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetConsumoBobinasPorSeccionAsync(fechaDesde, fechaHasta, idPlanta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Consumo de Bobinas por Sección.");
|
||||
return (Enumerable.Empty<ConsumoBobinasSeccionDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ConsumoBobinasSeccionDto> Data, string? Error)> ObtenerConsumoBobinasPorSeccionConsolidadoAsync(DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<ConsumoBobinasSeccionDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetConsumoBobinasPorSeccionConsolidadoAsync(fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Consumo de Bobinas por Sección (Consolidado).");
|
||||
return (Enumerable.Empty<ConsumoBobinasSeccionDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ConsumoBobinasPublicacionDto> Data, string? Error)> ObtenerConsumoBobinasPorPublicacionAsync(DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta) return (Enumerable.Empty<ConsumoBobinasPublicacionDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetConsumoBobinasPorPublicacionAsync(fechaDesde, fechaHasta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Consumo de Bobinas por Publicación.");
|
||||
return (Enumerable.Empty<ConsumoBobinasPublicacionDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ComparativaConsumoBobinasDto> Data, string? Error)> ObtenerComparativaConsumoBobinasAsync(DateTime fechaInicioMesA, DateTime fechaFinMesA, DateTime fechaInicioMesB, DateTime fechaFinMesB, int idPlanta)
|
||||
{
|
||||
if (fechaInicioMesA > fechaFinMesA || fechaInicioMesB > fechaFinMesB) return (Enumerable.Empty<ComparativaConsumoBobinasDto>(), "Fechas de inicio no pueden ser mayores que las de fin para los meses.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetComparativaConsumoBobinasAsync(fechaInicioMesA, fechaFinMesA, fechaInicioMesB, fechaFinMesB, idPlanta);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Comparativa de Consumo de Bobinas.");
|
||||
return (Enumerable.Empty<ComparativaConsumoBobinasDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<ComparativaConsumoBobinasDto> Data, string? Error)> ObtenerComparativaConsumoBobinasConsolidadoAsync(DateTime fechaInicioMesA, DateTime fechaFinMesA, DateTime fechaInicioMesB, DateTime fechaFinMesB)
|
||||
{
|
||||
if (fechaInicioMesA > fechaFinMesA || fechaInicioMesB > fechaFinMesB) return (Enumerable.Empty<ComparativaConsumoBobinasDto>(), "Fechas de inicio no pueden ser mayores que las de fin para los meses.");
|
||||
try
|
||||
{
|
||||
var data = await _reportesRepository.GetComparativaConsumoBobinasConsolidadoAsync(fechaInicioMesA, fechaFinMesA, fechaInicioMesB, fechaFinMesB);
|
||||
return (data, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Comparativa de Consumo de Bobinas (Consolidado).");
|
||||
return (Enumerable.Empty<ComparativaConsumoBobinasDto>(), "Error interno al generar el reporte.");
|
||||
}
|
||||
}
|
||||
|
||||
// Implementación para ReporteCuentasDistribuidores
|
||||
public async Task<(
|
||||
IEnumerable<BalanceCuentaDistDto> EntradasSalidas,
|
||||
IEnumerable<BalanceCuentaDebCredDto> DebitosCreditos,
|
||||
IEnumerable<BalanceCuentaPagosDto> Pagos,
|
||||
IEnumerable<SaldoDto> Saldos,
|
||||
string? Error
|
||||
)> ObtenerReporteCuentasDistribuidorAsync(int idDistribuidor, int idEmpresa, DateTime fechaDesde, DateTime fechaHasta)
|
||||
{
|
||||
if (fechaDesde > fechaHasta)
|
||||
return (Enumerable.Empty<BalanceCuentaDistDto>(), Enumerable.Empty<BalanceCuentaDebCredDto>(), Enumerable.Empty<BalanceCuentaPagosDto>(), Enumerable.Empty<SaldoDto>(), "Fecha 'Desde' no puede ser mayor que 'Hasta'.");
|
||||
|
||||
try
|
||||
{
|
||||
var esTask = _reportesRepository.GetBalanceCuentaDistEntradaSalidaPorEmpresaAsync(idDistribuidor, idEmpresa, fechaDesde, fechaHasta);
|
||||
var dcTask = _reportesRepository.GetBalanceCuentDistDebCredEmpresaAsync(idDistribuidor, idEmpresa, fechaDesde, fechaHasta);
|
||||
var paTask = _reportesRepository.GetBalanceCuentDistPagosEmpresaAsync(idDistribuidor, idEmpresa, fechaDesde, fechaHasta);
|
||||
var saTask = _reportesRepository.GetBalanceCuentSaldosEmpresasAsync("Distribuidores", idDistribuidor, idEmpresa);
|
||||
|
||||
await Task.WhenAll(esTask, dcTask, paTask, saTask);
|
||||
|
||||
Func<IEnumerable<BalanceCuentaDistDto>, IEnumerable<BalanceCuentaDistDto>> esToUtc =
|
||||
items => items?.Select(i => { i.Fecha = DateTime.SpecifyKind(i.Fecha.Date, DateTimeKind.Utc); return i; }).ToList()
|
||||
?? Enumerable.Empty<BalanceCuentaDistDto>();
|
||||
Func<IEnumerable<BalanceCuentaDebCredDto>, IEnumerable<BalanceCuentaDebCredDto>> dcToUtc =
|
||||
items => items?.Select(i => { i.Fecha = DateTime.SpecifyKind(i.Fecha.Date, DateTimeKind.Utc); return i; }).ToList()
|
||||
?? Enumerable.Empty<BalanceCuentaDebCredDto>();
|
||||
Func<IEnumerable<BalanceCuentaPagosDto>, IEnumerable<BalanceCuentaPagosDto>> paToUtc =
|
||||
items => items?.Select(i => { i.Fecha = DateTime.SpecifyKind(i.Fecha.Date, DateTimeKind.Utc); return i; }).ToList()
|
||||
?? Enumerable.Empty<BalanceCuentaPagosDto>();
|
||||
|
||||
return (
|
||||
esToUtc(await esTask),
|
||||
dcToUtc(await dcTask),
|
||||
paToUtc(await paTask),
|
||||
await saTask ?? Enumerable.Empty<SaldoDto>(),
|
||||
null
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ReportesService al obtener Reporte Cuentas Distribuidor.");
|
||||
return (
|
||||
Enumerable.Empty<BalanceCuentaDistDto>(),
|
||||
Enumerable.Empty<BalanceCuentaDebCredDto>(),
|
||||
Enumerable.Empty<BalanceCuentaPagosDto>(),
|
||||
Enumerable.Empty<SaldoDto>(),
|
||||
"Error interno al generar el reporte."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user