| | | 1 | | using FAU.Entidades; |
| | | 2 | | using FAU.Logica.DTOs; |
| | | 3 | | |
| | | 4 | | namespace FAU.Logica.Services; |
| | | 5 | | |
| | | 6 | | public interface IMotorAcumuladoresService |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Crea una nueva instancia de acumulador inicializado en cero. |
| | | 10 | | /// </summary> |
| | | 11 | | Acumuladores CrearAcumulador(); |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Valida que la configuración del catálogo sea válida para el motor de acumuladores. |
| | | 15 | | /// Verifica que todos los items tengan ClasificacionSiif válida y no null. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <exception cref="InvalidOperationException"> |
| | | 18 | | /// Se lanza si se encuentran ítems con ClasificacionSiif inválida o null |
| | | 19 | | /// </exception> |
| | | 20 | | void ValidarConfiguracion(IEnumerable<CatalogoItem> catalogo); |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Obtiene un DTO con los subtotales SIIF del acumulador para reporting. |
| | | 24 | | /// </summary> |
| | | 25 | | ReporteSiifDto ObtenerReporteSiif(Acumuladores acumuladores); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public class MotorAcumuladoresService : IMotorAcumuladoresService |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Clasificaciones SIIF válidas |
| | | 32 | | /// </summary> |
| | 1 | 33 | | private static readonly HashSet<string> ClasificacionesSiifValidas = new() |
| | 1 | 34 | | { |
| | 1 | 35 | | "HabNorGrav", "HabsAnGrav", "HabsNoGrav", |
| | 1 | 36 | | "BenSocGrav", "BenSocNoGrav", |
| | 1 | 37 | | "DtoLegGrav", "DtoLegNoGrav", "DtoPerGrav" |
| | 1 | 38 | | }; |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Crea una nueva instancia de acumulador inicializado en cero. |
| | | 42 | | /// </summary> |
| | | 43 | | public Acumuladores CrearAcumulador() |
| | | 44 | | { |
| | 2 | 45 | | return new Acumuladores(); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Valida que la configuración del catálogo sea válida para el motor de acumuladores. |
| | | 50 | | /// Verifica que todos los items tengan ClasificacionSiif válida y no null. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <exception cref="InvalidOperationException"> |
| | | 53 | | /// Se lanza si se encuentran ítems con ClasificacionSiif inválida o null |
| | | 54 | | /// </exception> |
| | | 55 | | public void ValidarConfiguracion(IEnumerable<CatalogoItem> catalogo) |
| | | 56 | | { |
| | 5 | 57 | | var itemsInvalidos = new List<(int codigo, string? clasificacion)>(); |
| | | 58 | | |
| | 34 | 59 | | foreach (var item in catalogo) |
| | | 60 | | { |
| | 12 | 61 | | if (string.IsNullOrWhiteSpace(item.ClasificacionSiif)) |
| | | 62 | | { |
| | 2 | 63 | | itemsInvalidos.Add((item.Codigo, item.ClasificacionSiif)); |
| | | 64 | | } |
| | 10 | 65 | | else if (!ClasificacionesSiifValidas.Contains(item.ClasificacionSiif)) |
| | | 66 | | { |
| | 1 | 67 | | itemsInvalidos.Add((item.Codigo, item.ClasificacionSiif)); |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | |
| | 5 | 71 | | if (itemsInvalidos.Count > 0) |
| | | 72 | | { |
| | 3 | 73 | | var detalles = string.Join(", ", |
| | 6 | 74 | | itemsInvalidos.Select(x => $"código {x.codigo}='{x.clasificacion}'")); |
| | 3 | 75 | | throw new InvalidOperationException( |
| | 3 | 76 | | $"Configuración inválida en catálogo_items. " + |
| | 3 | 77 | | $"Ítems con ClasificacionSiif inválida o null: {detalles}. " + |
| | 3 | 78 | | $"Valores permitidos: {string.Join(", ", ClasificacionesSiifValidas)}"); |
| | | 79 | | } |
| | 2 | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Obtiene un DTO con los subtotales SIIF del acumulador para reporting. |
| | | 84 | | /// </summary> |
| | | 85 | | public ReporteSiifDto ObtenerReporteSiif(Acumuladores acumuladores) |
| | | 86 | | { |
| | 2 | 87 | | return new ReporteSiifDto |
| | 2 | 88 | | { |
| | 2 | 89 | | HabNorGrav = acumuladores.HabNorGrav, |
| | 2 | 90 | | HabsAnGrav = acumuladores.HabsAnGrav, |
| | 2 | 91 | | HabsNoGrav = acumuladores.HabsNoGrav, |
| | 2 | 92 | | BenSocGrav = acumuladores.BenSocGrav, |
| | 2 | 93 | | BenSocNoGrav = acumuladores.BenSocNoGrav, |
| | 2 | 94 | | DtoLegGrav = acumuladores.DtoLegGrav, |
| | 2 | 95 | | DtoLegNoGrav = acumuladores.DtoLegNoGrav, |
| | 2 | 96 | | DtoPerGrav = acumuladores.DtoPerGrav, |
| | 2 | 97 | | Liquido = acumuladores.Liquido |
| | 2 | 98 | | }; |
| | | 99 | | } |
| | | 100 | | } |