| | | 1 | | using System.Security.Cryptography; |
| | | 2 | | using System.Text; |
| | | 3 | | using System.Text.Json; |
| | | 4 | | using FAU.DataAccess; |
| | | 5 | | using FAU.DataAccess.Repositories; |
| | | 6 | | using FAU.Entidades; |
| | | 7 | | using Microsoft.EntityFrameworkCore; |
| | | 8 | | |
| | | 9 | | namespace FAU.Logica.Services; |
| | | 10 | | |
| | | 11 | | public class PeriodoService : IPeriodoService |
| | | 12 | | { |
| | | 13 | | private readonly IPeriodosRepository _periodosRepository; |
| | | 14 | | private readonly ISnapshotsRepository _snapshotsRepository; |
| | | 15 | | private readonly ApplicationDbContext _context; |
| | | 16 | | private readonly IAuditoriaService _auditoriaService; |
| | | 17 | | private readonly ICurrentUserContext _currentUser; |
| | | 18 | | |
| | 23 | 19 | | public PeriodoService( |
| | 23 | 20 | | IPeriodosRepository periodosRepository, |
| | 23 | 21 | | ISnapshotsRepository snapshotsRepository, |
| | 23 | 22 | | ApplicationDbContext context, |
| | 23 | 23 | | IAuditoriaService auditoriaService, |
| | 23 | 24 | | ICurrentUserContext currentUser) |
| | | 25 | | { |
| | 23 | 26 | | _periodosRepository = periodosRepository; |
| | 23 | 27 | | _snapshotsRepository = snapshotsRepository; |
| | 23 | 28 | | _context = context; |
| | 23 | 29 | | _auditoriaService = auditoriaService; |
| | 23 | 30 | | _currentUser = currentUser; |
| | 23 | 31 | | } |
| | | 32 | | |
| | | 33 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> AbrirPeriodoAsync(short anio, short mes) |
| | | 34 | | { |
| | 9 | 35 | | if (anio < 2000 || anio > 2100) |
| | | 36 | | { |
| | 0 | 37 | | return (false, null, "El año debe estar entre 2000 y 2100"); |
| | | 38 | | } |
| | | 39 | | |
| | 9 | 40 | | if (mes < 1 || mes > 12) |
| | | 41 | | { |
| | 0 | 42 | | return (false, null, "El mes debe estar entre 1 y 12"); |
| | | 43 | | } |
| | | 44 | | |
| | 9 | 45 | | var periodoExistente = await _periodosRepository.ObtenerPorAnioMesAsync(anio, mes); |
| | 9 | 46 | | if (periodoExistente is not null && periodoExistente.Estado == Periodo.EstadoAbierta && periodoExistente.Activo) |
| | | 47 | | { |
| | 1 | 48 | | return (true, periodoExistente, null); |
| | | 49 | | } |
| | | 50 | | |
| | 8 | 51 | | var periodoEnCurso = await _periodosRepository.ObtenerEnCursoAsync(); |
| | 8 | 52 | | if (periodoEnCurso is not null) |
| | | 53 | | { |
| | 1 | 54 | | return (false, null, $"Ya existe un período activo en estado {periodoEnCurso.Estado}"); |
| | | 55 | | } |
| | | 56 | | |
| | 7 | 57 | | var parametrosPeriodo = await _context.ParametrosPeriodo |
| | 7 | 58 | | .AsNoTracking() |
| | 7 | 59 | | .FirstOrDefaultAsync(p => p.Anio == anio && p.Mes == mes); |
| | | 60 | | |
| | 7 | 61 | | if (parametrosPeriodo is null) |
| | | 62 | | { |
| | 2 | 63 | | return (false, null, "No existen parámetros de liquidación para el período indicado"); |
| | | 64 | | } |
| | | 65 | | |
| | 5 | 66 | | var fechaInicioPeriodo = new DateTime(anio, mes, 1, 0, 0, 0, DateTimeKind.Utc); |
| | 5 | 67 | | var fechaFinPeriodo = fechaInicioPeriodo.AddMonths(1).AddTicks(-1); |
| | | 68 | | |
| | 5 | 69 | | var existeRemuneraciones = await _context.RemuneracionesGrado |
| | 5 | 70 | | .AsNoTracking() |
| | 5 | 71 | | .AnyAsync(r => r.VigenteDesde <= fechaInicioPeriodo && (r.VigenteHasta == null || r.VigenteHasta >= fechaIni |
| | | 72 | | |
| | 5 | 73 | | if (!existeRemuneraciones) |
| | | 74 | | { |
| | 0 | 75 | | return (false, null, "No existen remuneraciones de grado vigentes para el período"); |
| | | 76 | | } |
| | | 77 | | |
| | 5 | 78 | | var existeFranjaIrpf = await _context.FranjasIrpf |
| | 5 | 79 | | .AsNoTracking() |
| | 5 | 80 | | .AnyAsync(f => f.VigenteDesde <= fechaInicioPeriodo && (f.VigenteHasta == null || f.VigenteHasta >= fechaIni |
| | | 81 | | |
| | 5 | 82 | | if (!existeFranjaIrpf) |
| | | 83 | | { |
| | 0 | 84 | | return (false, null, "No existen franjas IRPF vigentes para el período"); |
| | | 85 | | } |
| | | 86 | | |
| | 5 | 87 | | var existeRelacionLaboral = await _context.RelacionesLaborales |
| | 5 | 88 | | .AsNoTracking() |
| | 5 | 89 | | .AnyAsync(r => r.Estado == EstadoRelacion.Activo); |
| | | 90 | | |
| | 5 | 91 | | if (!existeRelacionLaboral) |
| | | 92 | | { |
| | 0 | 93 | | return (false, null, "No hay funcionarios activos en el padrón"); |
| | | 94 | | } |
| | | 95 | | |
| | 5 | 96 | | var snapshotJson = await SerializarSnapshotAsync(anio, mes, parametrosPeriodo, fechaInicioPeriodo, fechaFinPerio |
| | 5 | 97 | | var hashSnapshot = CalcularHash(snapshotJson); |
| | | 98 | | |
| | 5 | 99 | | var snapshot = new SnapshotInsumos |
| | 5 | 100 | | { |
| | 5 | 101 | | ContenidoJson = snapshotJson, |
| | 5 | 102 | | HashIntegridad = hashSnapshot |
| | 5 | 103 | | }; |
| | | 104 | | |
| | 5 | 105 | | var snapshotCreado = await _snapshotsRepository.CrearAsync(snapshot); |
| | | 106 | | |
| | 5 | 107 | | var periodo = new Periodo |
| | 5 | 108 | | { |
| | 5 | 109 | | Anio = anio, |
| | 5 | 110 | | Mes = mes, |
| | 5 | 111 | | Estado = Periodo.EstadoAbierta, |
| | 5 | 112 | | SnapshotId = snapshotCreado.Id, |
| | 5 | 113 | | FechaApertura = DateTime.UtcNow, |
| | 5 | 114 | | UsuarioApertura = _currentUser.UserId ?? 0, |
| | 5 | 115 | | HashSnapshot = hashSnapshot, |
| | 5 | 116 | | Activo = true |
| | 5 | 117 | | }; |
| | | 118 | | |
| | 5 | 119 | | var periodoCreado = await _periodosRepository.CrearAsync(periodo); |
| | | 120 | | |
| | 5 | 121 | | await _auditoriaService.LogAuditoriaAsync( |
| | 5 | 122 | | _currentUser.UserId ?? 0, |
| | 5 | 123 | | AccionEnum.AbrirPeriodoLiquidacion, |
| | 5 | 124 | | ContextoEnum.Liquidaciones, |
| | 5 | 125 | | _currentUser.Host, |
| | 5 | 126 | | entidad: nameof(Periodo), |
| | 5 | 127 | | entidadId: periodoCreado.Id, |
| | 5 | 128 | | detalle: new |
| | 5 | 129 | | { |
| | 5 | 130 | | anio, |
| | 5 | 131 | | mes, |
| | 5 | 132 | | snapshotId = snapshotCreado.Id, |
| | 5 | 133 | | hashSnapshot |
| | 5 | 134 | | }); |
| | | 135 | | |
| | 5 | 136 | | return (true, periodoCreado, null); |
| | 9 | 137 | | } |
| | | 138 | | |
| | | 139 | | public Task<Periodo?> ObtenerActivoAsync() |
| | | 140 | | { |
| | 0 | 141 | | return _periodosRepository.ObtenerActivoAsync(); |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | public Task<Periodo?> ObtenerPorIdAsync(long id) |
| | | 145 | | { |
| | 0 | 146 | | return _periodosRepository.ObtenerPorIdAsync(id); |
| | | 147 | | } |
| | | 148 | | |
| | | 149 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> CerrarInsumosAsync(long periodoId) |
| | | 150 | | { |
| | 6 | 151 | | var periodo = await _periodosRepository.ObtenerPorIdAsync(periodoId); |
| | 6 | 152 | | if (periodo is null) |
| | 0 | 153 | | return (false, null, "Período no encontrado"); |
| | | 154 | | |
| | 6 | 155 | | if (periodo.Estado != Periodo.EstadoAbierta) |
| | 1 | 156 | | return (false, null, $"Solo se puede cerrar insumos desde estado ABIERTA. Estado actual: {periodo.Estado}"); |
| | | 157 | | |
| | 5 | 158 | | var anio = periodo.Anio; |
| | 5 | 159 | | var mes = periodo.Mes; |
| | 5 | 160 | | var fechaInicio = new DateTime(anio, mes, 1, 0, 0, 0, DateTimeKind.Utc); |
| | 5 | 161 | | var fechaFin = fechaInicio.AddMonths(1).AddTicks(-1); |
| | | 162 | | |
| | 5 | 163 | | var tieneLosteAprobado = await _context.LotesCompensacion |
| | 5 | 164 | | .AsNoTracking() |
| | 5 | 165 | | .AnyAsync(l => l.Periodo.Year == anio && l.Periodo.Month == mes && l.Estado == "aprobado"); |
| | 5 | 166 | | if (!tieneLosteAprobado) |
| | 1 | 167 | | return (false, null, "Debe existir al menos un lote de compensación aprobado"); |
| | | 168 | | |
| | 4 | 169 | | var countNovedadesBorrador = await _context.NovedadesPeriodo |
| | 4 | 170 | | .AsNoTracking() |
| | 4 | 171 | | .CountAsync(n => n.PeriodoId == periodoId && n.Estado == "borrador"); |
| | 4 | 172 | | if (countNovedadesBorrador > 0) |
| | 1 | 173 | | return (false, null, $"Existen {countNovedadesBorrador} novedad(es) sin confirmar para el período"); |
| | | 174 | | |
| | 3 | 175 | | var tieneBeneficios = await _context.BeneficiosSociales |
| | 3 | 176 | | .AsNoTracking() |
| | 3 | 177 | | .AnyAsync(b => b.Estado == "activo" && b.VigenteDesde <= fechaFin && (b.VigenteHasta == null || b.VigenteHas |
| | 3 | 178 | | if (!tieneBeneficios) |
| | 1 | 179 | | return (false, null, "Debe existir al menos un beneficio social activo vigente para el período"); |
| | | 180 | | |
| | 2 | 181 | | var tieneRemuneraciones = await _context.RemuneracionesGrado |
| | 2 | 182 | | .AsNoTracking() |
| | 2 | 183 | | .AnyAsync(r => r.VigenteDesde <= fechaInicio && (r.VigenteHasta == null || r.VigenteHasta >= fechaInicio)); |
| | 2 | 184 | | if (!tieneRemuneraciones) |
| | 0 | 185 | | return (false, null, "No existen remuneraciones de grado vigentes para el período"); |
| | | 186 | | |
| | 2 | 187 | | var tieneFranjas = await _context.FranjasIrpf |
| | 2 | 188 | | .AsNoTracking() |
| | 2 | 189 | | .AnyAsync(f => f.VigenteDesde <= fechaInicio && (f.VigenteHasta == null || f.VigenteHasta >= fechaInicio)); |
| | 2 | 190 | | if (!tieneFranjas) |
| | 0 | 191 | | return (false, null, "No existen franjas IRPF vigentes para el período"); |
| | | 192 | | |
| | 2 | 193 | | var tieneFuncionarios = await _context.RelacionesLaborales |
| | 2 | 194 | | .AsNoTracking() |
| | 2 | 195 | | .AnyAsync(r => r.Estado == EstadoRelacion.Activo); |
| | 2 | 196 | | if (!tieneFuncionarios) |
| | 0 | 197 | | return (false, null, "No hay funcionarios activos en el padrón"); |
| | | 198 | | |
| | 2 | 199 | | var usuarioId = _currentUser.UserId ?? 0; |
| | 2 | 200 | | periodo.Estado = Periodo.EstadoListaCalculo; |
| | 2 | 201 | | periodo.FechaCierreInsumos = DateTime.UtcNow; |
| | 2 | 202 | | periodo.UsuarioCierreInsumosId = usuarioId; |
| | 2 | 203 | | await _periodosRepository.ActualizarAsync(periodo); |
| | | 204 | | |
| | 2 | 205 | | await _auditoriaService.LogAuditoriaAsync( |
| | 2 | 206 | | usuarioId, |
| | 2 | 207 | | AccionEnum.CerrarInsumosPeriodo, |
| | 2 | 208 | | ContextoEnum.Liquidaciones, |
| | 2 | 209 | | _currentUser.Host, |
| | 2 | 210 | | entidad: nameof(Periodo), |
| | 2 | 211 | | entidadId: periodo.Id, |
| | 2 | 212 | | detalle: new { anio, mes }); |
| | | 213 | | |
| | 2 | 214 | | return (true, periodo, null); |
| | 6 | 215 | | } |
| | | 216 | | |
| | | 217 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> ReabrirInsumosAsync(long periodoId) |
| | | 218 | | { |
| | 3 | 219 | | var periodo = await _periodosRepository.ObtenerPorIdAsync(periodoId); |
| | 3 | 220 | | if (periodo is null) |
| | 0 | 221 | | return (false, null, "Período no encontrado"); |
| | | 222 | | |
| | 3 | 223 | | if (periodo.Estado != Periodo.EstadoListaCalculo) |
| | 1 | 224 | | return (false, null, $"Solo se puede reabrir desde estado LISTA_CALCULO. Estado actual: {periodo.Estado}"); |
| | | 225 | | |
| | 2 | 226 | | var usuarioId = _currentUser.UserId ?? 0; |
| | 2 | 227 | | periodo.Estado = Periodo.EstadoAbierta; |
| | 2 | 228 | | periodo.FechaCierreInsumos = null; |
| | 2 | 229 | | periodo.UsuarioCierreInsumosId = null; |
| | 2 | 230 | | await _periodosRepository.ActualizarAsync(periodo); |
| | | 231 | | |
| | 2 | 232 | | await _auditoriaService.LogAuditoriaAsync( |
| | 2 | 233 | | usuarioId, |
| | 2 | 234 | | AccionEnum.ReabrirInsumosPeriodo, |
| | 2 | 235 | | ContextoEnum.Liquidaciones, |
| | 2 | 236 | | _currentUser.Host, |
| | 2 | 237 | | entidad: nameof(Periodo), |
| | 2 | 238 | | entidadId: periodo.Id, |
| | 2 | 239 | | detalle: new { anio = periodo.Anio, mes = periodo.Mes }); |
| | | 240 | | |
| | 2 | 241 | | return (true, periodo, null); |
| | 3 | 242 | | } |
| | | 243 | | |
| | | 244 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> IniciarCalculoAsync(long periodoId) |
| | | 245 | | { |
| | 2 | 246 | | var periodo = await _periodosRepository.ObtenerPorIdAsync(periodoId); |
| | 2 | 247 | | if (periodo is null) |
| | 0 | 248 | | return (false, null, "Período no encontrado"); |
| | | 249 | | |
| | 2 | 250 | | if (periodo.Estado != Periodo.EstadoListaCalculo) |
| | 1 | 251 | | return (false, null, $"Solo se puede calcular desde estado LISTA_CALCULO. Estado actual: {periodo.Estado}"); |
| | | 252 | | |
| | 1 | 253 | | var usuarioId = _currentUser.UserId ?? 0; |
| | 1 | 254 | | periodo.Estado = Periodo.EstadoEnCalculo; |
| | 1 | 255 | | periodo.FechaCalculo = DateTime.UtcNow; |
| | 1 | 256 | | periodo.UsuarioCalculoId = usuarioId; |
| | 1 | 257 | | await _periodosRepository.ActualizarAsync(periodo); |
| | | 258 | | |
| | 1 | 259 | | await _auditoriaService.LogAuditoriaAsync( |
| | 1 | 260 | | usuarioId, |
| | 1 | 261 | | AccionEnum.IniciarCalculoPeriodo, |
| | 1 | 262 | | ContextoEnum.Liquidaciones, |
| | 1 | 263 | | _currentUser.Host, |
| | 1 | 264 | | entidad: nameof(Periodo), |
| | 1 | 265 | | entidadId: periodo.Id, |
| | 1 | 266 | | detalle: new { anio = periodo.Anio, mes = periodo.Mes }); |
| | | 267 | | |
| | 1 | 268 | | return (true, periodo, null); |
| | 2 | 269 | | } |
| | | 270 | | |
| | | 271 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> FinalizarCalculoAsync(long periodoId, bool exitoso, |
| | | 272 | | { |
| | 2 | 273 | | var periodo = await _periodosRepository.ObtenerPorIdAsync(periodoId); |
| | 2 | 274 | | if (periodo is null) |
| | 0 | 275 | | return (false, null, "Período no encontrado"); |
| | | 276 | | |
| | 2 | 277 | | if (periodo.Estado != Periodo.EstadoEnCalculo) |
| | 0 | 278 | | return (false, null, $"Solo se puede finalizar el cálculo desde estado EN_CALCULO. Estado actual: {periodo.E |
| | | 279 | | |
| | 2 | 280 | | var usuarioId = _currentUser.UserId ?? 0; |
| | 2 | 281 | | if (exitoso) |
| | | 282 | | { |
| | 1 | 283 | | periodo.Estado = Periodo.EstadoCalculada; |
| | 1 | 284 | | periodo.FechaCalculo = DateTime.UtcNow; |
| | | 285 | | } |
| | | 286 | | else |
| | | 287 | | { |
| | 1 | 288 | | periodo.Estado = Periodo.EstadoListaCalculo; |
| | | 289 | | } |
| | | 290 | | |
| | 2 | 291 | | await _periodosRepository.ActualizarAsync(periodo); |
| | | 292 | | |
| | 2 | 293 | | await _auditoriaService.LogAuditoriaAsync( |
| | 2 | 294 | | usuarioId, |
| | 2 | 295 | | AccionEnum.IniciarCalculoPeriodo, |
| | 2 | 296 | | ContextoEnum.Liquidaciones, |
| | 2 | 297 | | _currentUser.Host, |
| | 2 | 298 | | entidad: nameof(Periodo), |
| | 2 | 299 | | entidadId: periodo.Id, |
| | 2 | 300 | | detalle: new { exitoso, mensajeError }); |
| | | 301 | | |
| | 2 | 302 | | return (true, periodo, null); |
| | 2 | 303 | | } |
| | | 304 | | |
| | | 305 | | public async Task<(bool Exito, Periodo? Periodo, string? Error)> CerrarAsync(long periodoId) |
| | | 306 | | { |
| | 3 | 307 | | var periodo = await _periodosRepository.ObtenerPorIdAsync(periodoId); |
| | 3 | 308 | | if (periodo is null) |
| | 0 | 309 | | return (false, null, "Período no encontrado"); |
| | | 310 | | |
| | 3 | 311 | | if (periodo.Estado != Periodo.EstadoCalculada) |
| | 1 | 312 | | return (false, null, $"Solo se puede cerrar desde estado CALCULADA. Estado actual: {periodo.Estado}"); |
| | | 313 | | |
| | 2 | 314 | | var usuarioId = _currentUser.UserId ?? 0; |
| | 2 | 315 | | periodo.Estado = Periodo.EstadoCerrada; |
| | 2 | 316 | | periodo.FechaCierre = DateTime.UtcNow; |
| | 2 | 317 | | periodo.UsuarioCierreId = usuarioId; |
| | 2 | 318 | | await _periodosRepository.ActualizarAsync(periodo); |
| | | 319 | | |
| | 2 | 320 | | await _auditoriaService.LogAuditoriaAsync( |
| | 2 | 321 | | usuarioId, |
| | 2 | 322 | | AccionEnum.CerrarPeriodo, |
| | 2 | 323 | | ContextoEnum.Liquidaciones, |
| | 2 | 324 | | _currentUser.Host, |
| | 2 | 325 | | entidad: nameof(Periodo), |
| | 2 | 326 | | entidadId: periodo.Id, |
| | 2 | 327 | | detalle: new { anio = periodo.Anio, mes = periodo.Mes }); |
| | | 328 | | |
| | 2 | 329 | | return (true, periodo, null); |
| | 3 | 330 | | } |
| | | 331 | | |
| | | 332 | | private async Task<string> SerializarSnapshotAsync( |
| | | 333 | | short anio, |
| | | 334 | | short mes, |
| | | 335 | | ParametroPeriodo parametrosPeriodo, |
| | | 336 | | DateTime fechaInicioPeriodo, |
| | | 337 | | DateTime fechaFinPeriodo) |
| | | 338 | | { |
| | 5 | 339 | | var lotes = await _context.LotesCompensacion |
| | 5 | 340 | | .AsNoTracking() |
| | 5 | 341 | | .Where(l => l.Periodo.Year == anio && l.Periodo.Month == mes && l.Estado == "aprobado") |
| | 5 | 342 | | .Select(l => new |
| | 5 | 343 | | { |
| | 5 | 344 | | l.Id, |
| | 5 | 345 | | l.TipoCompensacionId, |
| | 5 | 346 | | l.Periodo, |
| | 5 | 347 | | l.Estado, |
| | 5 | 348 | | l.Fuente, |
| | 5 | 349 | | l.NombreArchivo, |
| | 5 | 350 | | l.HashArchivo, |
| | 5 | 351 | | l.UsuarioId, |
| | 5 | 352 | | l.AprobadoPor, |
| | 5 | 353 | | l.AprobadoEn |
| | 5 | 354 | | }) |
| | 5 | 355 | | .ToListAsync(); |
| | | 356 | | |
| | 5 | 357 | | var beneficios = await _context.BeneficiosSociales |
| | 5 | 358 | | .AsNoTracking() |
| | 5 | 359 | | .Where(b => b.Estado == "activo" && b.VigenteDesde <= fechaFinPeriodo && (b.VigenteHasta == null || b.Vigent |
| | 5 | 360 | | .Select(b => new |
| | 5 | 361 | | { |
| | 5 | 362 | | b.Id, |
| | 5 | 363 | | b.PersonaId, |
| | 5 | 364 | | b.TipoBeneficioId, |
| | 5 | 365 | | b.Cantidad, |
| | 5 | 366 | | b.VigenteDesde, |
| | 5 | 367 | | b.VigenteHasta, |
| | 5 | 368 | | b.Estado, |
| | 5 | 369 | | b.ClaveEvento, |
| | 5 | 370 | | b.FechaEvento, |
| | 5 | 371 | | b.RetroactividadPendiente |
| | 5 | 372 | | }) |
| | 5 | 373 | | .ToListAsync(); |
| | | 374 | | |
| | 5 | 375 | | var remuneraciones = await _context.RemuneracionesGrado |
| | 5 | 376 | | .AsNoTracking() |
| | 5 | 377 | | .Where(r => r.VigenteDesde <= fechaInicioPeriodo && (r.VigenteHasta == null || r.VigenteHasta >= fechaInicio |
| | 5 | 378 | | .Select(r => new |
| | 5 | 379 | | { |
| | 5 | 380 | | r.Id, |
| | 5 | 381 | | r.GradoId, |
| | 5 | 382 | | r.ItemId, |
| | 5 | 383 | | r.Monto, |
| | 5 | 384 | | r.VigenteDesde, |
| | 5 | 385 | | r.VigenteHasta |
| | 5 | 386 | | }) |
| | 5 | 387 | | .ToListAsync(); |
| | | 388 | | |
| | 5 | 389 | | var franjasIrpf = await _context.FranjasIrpf |
| | 5 | 390 | | .AsNoTracking() |
| | 5 | 391 | | .Where(f => f.VigenteDesde <= fechaInicioPeriodo && (f.VigenteHasta == null || f.VigenteHasta >= fechaInicio |
| | 5 | 392 | | .Select(f => new |
| | 5 | 393 | | { |
| | 5 | 394 | | f.Id, |
| | 5 | 395 | | f.NumeroFranja, |
| | 5 | 396 | | f.DesdeBpc, |
| | 5 | 397 | | f.HastaBpc, |
| | 5 | 398 | | f.Tasa, |
| | 5 | 399 | | f.VigenteDesde, |
| | 5 | 400 | | f.VigenteHasta |
| | 5 | 401 | | }) |
| | 5 | 402 | | .ToListAsync(); |
| | | 403 | | |
| | 5 | 404 | | var snapshot = new |
| | 5 | 405 | | { |
| | 5 | 406 | | anio, |
| | 5 | 407 | | mes, |
| | 5 | 408 | | fechaCreacion = DateTime.UtcNow, |
| | 5 | 409 | | parametros = new |
| | 5 | 410 | | { |
| | 5 | 411 | | parametrosPeriodo.Anio, |
| | 5 | 412 | | parametrosPeriodo.Mes, |
| | 5 | 413 | | parametrosPeriodo.BpcAnual, |
| | 5 | 414 | | parametrosPeriodo.TasaMontepioLeyVieja, |
| | 5 | 415 | | parametrosPeriodo.TasaMontepioLeyNueva, |
| | 5 | 416 | | parametrosPeriodo.TasaFonasa, |
| | 5 | 417 | | parametrosPeriodo.TasaFrl, |
| | 5 | 418 | | parametrosPeriodo.UmbralDeduccionBpc, |
| | 5 | 419 | | parametrosPeriodo.TasaDeduccionAlta, |
| | 5 | 420 | | parametrosPeriodo.TasaDeduccionBaja, |
| | 5 | 421 | | parametrosPeriodo.PorcentajeMinimoDeficit |
| | 5 | 422 | | }, |
| | 5 | 423 | | lotesCompensacion = lotes, |
| | 5 | 424 | | beneficiosSociales = beneficios, |
| | 5 | 425 | | remuneracionesGrado = remuneraciones, |
| | 5 | 426 | | franjasIrpf = franjasIrpf |
| | 5 | 427 | | }; |
| | | 428 | | |
| | 5 | 429 | | return JsonSerializer.Serialize(snapshot, new JsonSerializerOptions |
| | 5 | 430 | | { |
| | 5 | 431 | | PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
| | 5 | 432 | | WriteIndented = false |
| | 5 | 433 | | }); |
| | 5 | 434 | | } |
| | | 435 | | |
| | | 436 | | private static string CalcularHash(string contenidoJson) |
| | | 437 | | { |
| | 5 | 438 | | using var sha256 = SHA256.Create(); |
| | 5 | 439 | | var bytes = Encoding.UTF8.GetBytes(contenidoJson); |
| | 5 | 440 | | return Convert.ToHexString(sha256.ComputeHash(bytes)).ToLowerInvariant(); |
| | 5 | 441 | | } |
| | | 442 | | } |