| | | 1 | | using FAU.DataAccess; |
| | | 2 | | using FAU.Entidades; |
| | | 3 | | using FAU.Logica.DTOs; |
| | | 4 | | using Microsoft.EntityFrameworkCore; |
| | | 5 | | |
| | | 6 | | namespace FAU.Logica.Services.InsumoValidators; |
| | | 7 | | |
| | | 8 | | public class LotesCompensacionValidator : InsumoValidatorBase |
| | | 9 | | { |
| | | 10 | | private readonly ApplicationDbContext _context; |
| | | 11 | | |
| | 29 | 12 | | public LotesCompensacionValidator(ApplicationDbContext context) |
| | | 13 | | { |
| | 29 | 14 | | _context = context; |
| | 29 | 15 | | } |
| | | 16 | | |
| | | 17 | | public override async Task<List<ItemInsumoDto>> ValidarAsync(Periodo periodo) |
| | | 18 | | { |
| | 11 | 19 | | var items = new List<ItemInsumoDto>(); |
| | | 20 | | |
| | 11 | 21 | | var tipos = await _context.TiposCompensacion |
| | 11 | 22 | | .AsNoTracking() |
| | 11 | 23 | | .Where(t => t.Vigente) |
| | 11 | 24 | | .Select(t => new { t.Id, t.Nombre }) |
| | 11 | 25 | | .ToListAsync(); |
| | | 26 | | |
| | 42 | 27 | | foreach (var tipo in tipos) |
| | | 28 | | { |
| | 10 | 29 | | var tieneAprobado = await _context.LotesCompensacion |
| | 10 | 30 | | .AsNoTracking() |
| | 10 | 31 | | .AnyAsync(l => |
| | 10 | 32 | | l.TipoCompensacionId == tipo.Id && |
| | 10 | 33 | | l.Periodo.Year == periodo.Anio && |
| | 10 | 34 | | l.Periodo.Month == periodo.Mes && |
| | 10 | 35 | | l.Estado == "aprobado"); |
| | | 36 | | |
| | 10 | 37 | | if (!tieneAprobado) |
| | 5 | 38 | | items.Add(Confirmable( |
| | 5 | 39 | | clave: $"LoteFaltante:{tipo.Nombre}", |
| | 5 | 40 | | tipo: "lote_faltante", |
| | 5 | 41 | | descripcion: $"{tipo.Nombre} no tiene lote aprobado para el período")); |
| | 10 | 42 | | } |
| | | 43 | | |
| | 11 | 44 | | return items; |
| | 11 | 45 | | } |
| | | 46 | | } |