< Summary

Information
Class: FAU.DataAccess.Repositories.IrpfRepository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/IrpfRepository.cs
Line coverage
100%
Covered lines: 67
Uncovered lines: 0
Coverable lines: 67
Total lines: 129
Line coverage: 100%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetFranjasVigentesAsync()50%22100%
GetFranjaByIdAsync()100%11100%
GetFranjaActivaByNumeroAsync()100%11100%
ExisteFranjaAsync()100%11100%
CreateFranjaAsync()100%11100%
UpdateFranjaAsync()100%11100%
DeleteFranjaAsync()100%22100%
GetDeduccionesPagedAsync()100%66100%
GetDeduccionByIdAsync()100%11100%
ExisteDeduccionActivaAsync()100%11100%
ContarDeduccionesActivasAsync()100%11100%
CreateDeduccionAsync()100%11100%
UpdateDeduccionAsync()100%11100%

File(s)

/home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/IrpfRepository.cs

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6public class IrpfRepository : IIrpfRepository
 7{
 8    private readonly ApplicationDbContext _context;
 9
 2510    public IrpfRepository(ApplicationDbContext context)
 11    {
 2512        _context = context;
 2513    }
 14
 15    // ── Franjas ──────────────────────────────────────────────────────────────
 16
 17    public async Task<IEnumerable<FranjaIrpf>> GetFranjasVigentesAsync(DateTime? fecha = null)
 18    {
 219        var fechaRef = fecha?.Date ?? DateTime.UtcNow.Date;
 220        return await _context.FranjasIrpf
 221            .Where(f => f.VigenteDesde <= fechaRef && (f.VigenteHasta == null || f.VigenteHasta >= fechaRef))
 222            .OrderBy(f => f.NumeroFranja)
 223            .ToListAsync();
 224    }
 25
 26    public async Task<FranjaIrpf?> GetFranjaByIdAsync(long id)
 27    {
 428        return await _context.FranjasIrpf.FindAsync(id);
 429    }
 30
 31    public async Task<FranjaIrpf?> GetFranjaActivaByNumeroAsync(short numeroFranja)
 32    {
 233        return await _context.FranjasIrpf
 234            .Where(f => f.NumeroFranja == numeroFranja && f.VigenteHasta == null)
 235            .FirstOrDefaultAsync();
 236    }
 37
 38    public async Task<bool> ExisteFranjaAsync(short numeroFranja, DateTime vigenteDesde)
 39    {
 240        return await _context.FranjasIrpf
 241            .AnyAsync(f => f.NumeroFranja == numeroFranja && f.VigenteDesde.Date == vigenteDesde.Date);
 242    }
 43
 44    public async Task<FranjaIrpf> CreateFranjaAsync(FranjaIrpf franja)
 45    {
 446        _context.FranjasIrpf.Add(franja);
 447        await _context.SaveChangesAsync();
 448        return franja;
 449    }
 50
 51    public async Task<FranjaIrpf> UpdateFranjaAsync(FranjaIrpf franja)
 52    {
 153        _context.FranjasIrpf.Update(franja);
 154        await _context.SaveChangesAsync();
 155        return franja;
 156    }
 57
 58    public async Task DeleteFranjaAsync(long id)
 59    {
 260        var franja = await _context.FranjasIrpf.FindAsync(id);
 261        if (franja != null)
 62        {
 163            _context.FranjasIrpf.Remove(franja);
 164            await _context.SaveChangesAsync();
 65        }
 266    }
 67
 68    // ── Deducciones ──────────────────────────────────────────────────────────
 69
 70    public async Task<(IEnumerable<DeduccionIrpf> Items, int TotalCount)> GetDeduccionesPagedAsync(
 71        int page, int pageSize, long? personaId = null, string? tipo = null, bool? activo = null)
 72    {
 473        var query = _context.DeduccionesIrpf
 474            .Include(d => d.Persona)
 475            .AsQueryable();
 76
 477        if (personaId.HasValue)
 178            query = query.Where(d => d.PersonaId == personaId.Value);
 79
 480        if (!string.IsNullOrWhiteSpace(tipo))
 181            query = query.Where(d => d.Tipo == tipo);
 82
 483        if (activo.HasValue)
 184            query = query.Where(d => d.Activo == activo.Value);
 85
 486        var totalCount = await query.CountAsync();
 487        var items = await query
 488            .OrderBy(d => d.PersonaId)
 489            .ThenBy(d => d.Tipo)
 490            .Skip((page - 1) * pageSize)
 491            .Take(pageSize)
 492            .ToListAsync();
 93
 494        return (items, totalCount);
 495    }
 96
 97    public async Task<DeduccionIrpf?> GetDeduccionByIdAsync(long id)
 98    {
 399        return await _context.DeduccionesIrpf
 3100            .Include(d => d.Persona)
 3101            .FirstOrDefaultAsync(d => d.Id == id);
 3102    }
 103
 104    public async Task<bool> ExisteDeduccionActivaAsync(long personaId, string tipo)
 105    {
 3106        return await _context.DeduccionesIrpf
 3107            .AnyAsync(d => d.PersonaId == personaId && d.Tipo == tipo && d.Activo);
 3108    }
 109
 110    public async Task<int> ContarDeduccionesActivasAsync(long personaId)
 111    {
 2112        return await _context.DeduccionesIrpf
 2113            .CountAsync(d => d.PersonaId == personaId && d.Activo);
 2114    }
 115
 116    public async Task<DeduccionIrpf> CreateDeduccionAsync(DeduccionIrpf deduccion)
 117    {
 3118        _context.DeduccionesIrpf.Add(deduccion);
 3119        await _context.SaveChangesAsync();
 3120        return deduccion;
 3121    }
 122
 123    public async Task<DeduccionIrpf> UpdateDeduccionAsync(DeduccionIrpf deduccion)
 124    {
 1125        _context.DeduccionesIrpf.Update(deduccion);
 1126        await _context.SaveChangesAsync();
 1127        return deduccion;
 1128    }
 129}