| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Threading; |
| | | 3 | | using System.Threading.Tasks; |
| | | 4 | | using FAU.Entidades; |
| | | 5 | | using Microsoft.EntityFrameworkCore; |
| | | 6 | | |
| | | 7 | | namespace FAU.DataAccess.Repositories; |
| | | 8 | | |
| | | 9 | | public class ReporteDeficitRepository : IReporteDeficitRepository |
| | | 10 | | { |
| | | 11 | | private readonly ApplicationDbContext _context; |
| | | 12 | | |
| | 0 | 13 | | public ReporteDeficitRepository(ApplicationDbContext context) |
| | | 14 | | { |
| | 0 | 15 | | _context = context; |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | public async Task<IEnumerable<PlanillaAjusteConRelacionRow>> ObtenerPlanillaAjusteConRelacionAsync( |
| | | 19 | | long periodoId, CancellationToken ct = default) |
| | | 20 | | { |
| | 0 | 21 | | return await _context.Database |
| | 0 | 22 | | .SqlQuery<PlanillaAjusteConRelacionRow>($""" |
| | 0 | 23 | | SELECT |
| | 0 | 24 | | pa.periodo_id AS PeriodoId, |
| | 0 | 25 | | pa.persona_id AS PersonaId, |
| | 0 | 26 | | pa.cedula AS Cedula, |
| | 0 | 27 | | COALESCE(p.primer_apellido || ', ' || p.primer_nombre, pa.cedula) |
| | 0 | 28 | | AS PersonaNombre, |
| | 0 | 29 | | COALESCE(sit.denominacion, '') AS SituacionNombre, |
| | 0 | 30 | | COALESCE(u.denominacion, '') AS UnidadNombre, |
| | 0 | 31 | | COALESCE(su.denominacion, '') AS CompaniaNombre, |
| | 0 | 32 | | pa.acreedor_id AS AcreedorId, |
| | 0 | 33 | | pa.acreedor_codigo AS AcreedorCodigo, |
| | 0 | 34 | | pa.acreedor_nombre AS AcreedorNombre, |
| | 0 | 35 | | pa.monto_solicitado AS MontoSolicitado, |
| | 0 | 36 | | pa.monto_aplicado_calculado AS MontoAplicado, |
| | 0 | 37 | | pa.monto_no_aplicado_calculado AS MontoNoAplicado, |
| | 0 | 38 | | pa.estado AS Estado, |
| | 0 | 39 | | pa.observaciones AS Observaciones |
| | 0 | 40 | | FROM v_planilla_ajuste pa |
| | 0 | 41 | | JOIN personas p ON p.id = pa.persona_id |
| | 0 | 42 | | LEFT JOIN LATERAL ( |
| | 0 | 43 | | SELECT rl.situacion_id, rl.unidad_id, rl.sub_unidad_id |
| | 0 | 44 | | FROM relaciones_laborales rl |
| | 0 | 45 | | WHERE rl.persona_id = pa.persona_id AND rl.estado = 'activo' |
| | 0 | 46 | | ORDER BY rl.fecha_inicio DESC |
| | 0 | 47 | | LIMIT 1 |
| | 0 | 48 | | ) rl ON true |
| | 0 | 49 | | LEFT JOIN situaciones sit ON sit.id = rl.situacion_id |
| | 0 | 50 | | LEFT JOIN unidades u ON u.id = rl.unidad_id |
| | 0 | 51 | | LEFT JOIN sub_unidades su ON su.id = rl.sub_unidad_id |
| | 0 | 52 | | WHERE pa.periodo_id = {periodoId} |
| | 0 | 53 | | AND pa.estado IN ('parcial', 'deficit', 'no_revista') |
| | 0 | 54 | | ORDER BY |
| | 0 | 55 | | COALESCE(sit.denominacion, ''), |
| | 0 | 56 | | COALESCE(u.denominacion, ''), |
| | 0 | 57 | | COALESCE(su.denominacion, ''), |
| | 0 | 58 | | p.primer_apellido, |
| | 0 | 59 | | pa.acreedor_nombre |
| | 0 | 60 | | """) |
| | 0 | 61 | | .ToListAsync(ct); |
| | 0 | 62 | | } |
| | | 63 | | } |