| | | 1 | | using System.Globalization; |
| | | 2 | | using System.IO.Compression; |
| | | 3 | | using System.Reflection; |
| | | 4 | | using FAU.DataAccess; |
| | | 5 | | using FAU.Entidades; |
| | | 6 | | using Microsoft.EntityFrameworkCore; |
| | | 7 | | using QuestPDF.Fluent; |
| | | 8 | | using QuestPDF.Helpers; |
| | | 9 | | using QuestPDF.Infrastructure; |
| | | 10 | | |
| | | 11 | | namespace FAU.Logica.Services; |
| | | 12 | | |
| | | 13 | | public class AguinaldoReciboService : IAguinaldoReciboService |
| | | 14 | | { |
| | | 15 | | private readonly ApplicationDbContext _context; |
| | | 16 | | |
| | 0 | 17 | | public AguinaldoReciboService(ApplicationDbContext context) |
| | | 18 | | { |
| | 0 | 19 | | _context = context; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | // ── SEMESTRAL ──────────────────────────────────────────────────────────── |
| | | 23 | | |
| | | 24 | | public async Task<(byte[] Pdf, string FileName)> GenerarPdfSemestralAsync(long personaId, int anio, short semestre) |
| | | 25 | | { |
| | 0 | 26 | | var (aguinaldo, relacion) = await CargarDatosSemestralAsync(personaId, anio, semestre); |
| | 0 | 27 | | var mes = semestre == 1 ? 6 : 12; |
| | 0 | 28 | | var fileName = $"aguinaldo_{anio}_{mes:D2}_{relacion.Persona.Cedula}.pdf"; |
| | 0 | 29 | | return (GenerarPdfSemestral(aguinaldo, relacion), fileName); |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | public async Task<(Stream Zip, string FileName)> GenerarLoteSemestralZipAsync(int anio, short semestre, IEnumerable< |
| | | 33 | | { |
| | 0 | 34 | | var query = _context.Aguinaldos |
| | 0 | 35 | | .Where(a => a.Anio == anio && a.Semestre == semestre); |
| | | 36 | | |
| | 0 | 37 | | if (personaIds != null) |
| | | 38 | | { |
| | 0 | 39 | | var ids = personaIds.ToList(); |
| | 0 | 40 | | query = query.Where(a => ids.Contains(a.PersonaId)); |
| | | 41 | | } |
| | | 42 | | |
| | 0 | 43 | | var aguinaldos = await query.ToListAsync(); |
| | | 44 | | var personaIdsUsados = aguinaldos.Select(a => a.PersonaId).ToList(); |
| | 0 | 45 | | var relacionesPorPersona = await CargarRelacionesPorPersonaAsync(personaIdsUsados); |
| | | 46 | | |
| | 0 | 47 | | var mes = semestre == 1 ? 6 : 12; |
| | 0 | 48 | | var memoryStream = new MemoryStream(); |
| | 0 | 49 | | using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, leaveOpen: true)) |
| | | 50 | | { |
| | 0 | 51 | | foreach (var aguinaldo in aguinaldos) |
| | | 52 | | { |
| | 0 | 53 | | if (!relacionesPorPersona.TryGetValue(aguinaldo.PersonaId, out var relacion)) |
| | | 54 | | continue; |
| | | 55 | | |
| | 0 | 56 | | var pdfBytes = GenerarPdfSemestral(aguinaldo, relacion); |
| | 0 | 57 | | var entryName = $"aguinaldo_{anio}_{mes:D2}_{relacion.Persona.Cedula}.pdf"; |
| | 0 | 58 | | var entry = zip.CreateEntry(entryName, CompressionLevel.Fastest); |
| | 0 | 59 | | using var entryStream = entry.Open(); |
| | 0 | 60 | | await entryStream.WriteAsync(pdfBytes); |
| | 0 | 61 | | } |
| | 0 | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | memoryStream.Position = 0; |
| | 0 | 65 | | return (memoryStream, $"aguinaldos_{anio}_{mes:D2}.zip"); |
| | 0 | 66 | | } |
| | | 67 | | |
| | | 68 | | // ── BAJA ───────────────────────────────────────────────────────────────── |
| | | 69 | | |
| | | 70 | | public async Task<(byte[] Pdf, string FileName)> GenerarPdfBajaAsync(long aguinaldoBajaId) |
| | | 71 | | { |
| | 0 | 72 | | var baja = await CargarAguinaldoBajaAsync(aguinaldoBajaId); |
| | 0 | 73 | | var relacion = await CargarRelacionActivaPorPersonaIdAsync(baja.PersonaId); |
| | 0 | 74 | | var fileName = $"aguinaldo_{baja.Anio}_{baja.Mes:D2}_{baja.Cedula}.pdf"; |
| | 0 | 75 | | return (GenerarPdfBaja(baja, relacion), fileName); |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | public async Task<(Stream Zip, string FileName)> GenerarLoteBajaZipAsync(IEnumerable<long> aguinaldoBajaIds) |
| | | 79 | | { |
| | 0 | 80 | | var ids = aguinaldoBajaIds.ToList(); |
| | 0 | 81 | | var bajas = await _context.AguinaldosBaja |
| | 0 | 82 | | .Include(b => b.Items) |
| | 0 | 83 | | .Where(b => ids.Contains(b.Id)) |
| | 0 | 84 | | .ToListAsync(); |
| | | 85 | | |
| | | 86 | | var personaIdsUsados = bajas.Select(b => b.PersonaId).ToList(); |
| | 0 | 87 | | var relacionesPorPersona = await CargarRelacionesPorPersonaAsync(personaIdsUsados); |
| | | 88 | | |
| | 0 | 89 | | var memoryStream = new MemoryStream(); |
| | 0 | 90 | | using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, leaveOpen: true)) |
| | | 91 | | { |
| | 0 | 92 | | foreach (var baja in bajas) |
| | | 93 | | { |
| | 0 | 94 | | relacionesPorPersona.TryGetValue(baja.PersonaId, out var relacion); |
| | 0 | 95 | | var pdfBytes = GenerarPdfBaja(baja, relacion); |
| | 0 | 96 | | var entryName = $"aguinaldo_{baja.Anio}_{baja.Mes:D2}_{baja.Cedula}.pdf"; |
| | 0 | 97 | | var entry = zip.CreateEntry(entryName, CompressionLevel.Fastest); |
| | 0 | 98 | | using var entryStream = entry.Open(); |
| | 0 | 99 | | await entryStream.WriteAsync(pdfBytes); |
| | 0 | 100 | | } |
| | 0 | 101 | | } |
| | | 102 | | |
| | 0 | 103 | | memoryStream.Position = 0; |
| | 0 | 104 | | var zipName = bajas.Count > 0 |
| | 0 | 105 | | ? $"aguinaldos_{bajas[0].Anio}_{bajas[0].Mes:D2}.zip" |
| | 0 | 106 | | : "aguinaldos_baja.zip"; |
| | 0 | 107 | | return (memoryStream, zipName); |
| | 0 | 108 | | } |
| | | 109 | | |
| | | 110 | | // ── DATA LOADING ────────────────────────────────────────────────────────── |
| | | 111 | | |
| | | 112 | | private async Task<(Aguinaldo aguinaldo, RelacionLaboral relacion)> CargarDatosSemestralAsync( |
| | | 113 | | long personaId, int anio, short semestre) |
| | | 114 | | { |
| | 0 | 115 | | var aguinaldo = await _context.Aguinaldos |
| | 0 | 116 | | .FirstOrDefaultAsync(a => a.PersonaId == personaId && a.Anio == anio && a.Semestre == semestre) |
| | 0 | 117 | | ?? throw new KeyNotFoundException( |
| | 0 | 118 | | $"No se encontró aguinaldo para persona {personaId}, año {anio}, semestre {semestre}."); |
| | | 119 | | |
| | 0 | 120 | | var relacion = await CargarRelacionActivaPorPersonaIdAsync(personaId); |
| | 0 | 121 | | return (aguinaldo, relacion); |
| | 0 | 122 | | } |
| | | 123 | | |
| | | 124 | | private async Task<RelacionLaboral> CargarRelacionActivaPorPersonaIdAsync(long personaId) |
| | | 125 | | { |
| | 0 | 126 | | return await _context.RelacionesLaborales |
| | 0 | 127 | | .Include(rl => rl.Persona) |
| | 0 | 128 | | .Include(rl => rl.Grado) |
| | 0 | 129 | | .Include(rl => rl.Escalafon) |
| | 0 | 130 | | .Include(rl => rl.Unidad) |
| | 0 | 131 | | .Where(rl => rl.PersonaId == personaId && rl.Estado == EstadoRelacion.Activo) |
| | 0 | 132 | | .FirstOrDefaultAsync() |
| | 0 | 133 | | ?? throw new KeyNotFoundException($"No se encontró relación laboral activa para persona {personaId}."); |
| | 0 | 134 | | } |
| | | 135 | | |
| | | 136 | | private async Task<Dictionary<long, RelacionLaboral>> CargarRelacionesPorPersonaAsync(List<long> personaIds) |
| | | 137 | | { |
| | 0 | 138 | | var relaciones = await _context.RelacionesLaborales |
| | 0 | 139 | | .Include(rl => rl.Persona) |
| | 0 | 140 | | .Include(rl => rl.Grado) |
| | 0 | 141 | | .Include(rl => rl.Escalafon) |
| | 0 | 142 | | .Include(rl => rl.Unidad) |
| | 0 | 143 | | .Where(rl => personaIds.Contains(rl.PersonaId) && rl.Estado == EstadoRelacion.Activo) |
| | 0 | 144 | | .ToListAsync(); |
| | | 145 | | |
| | | 146 | | return relaciones.ToDictionary(rl => rl.PersonaId); |
| | 0 | 147 | | } |
| | | 148 | | |
| | | 149 | | private async Task<AguinaldoBaja> CargarAguinaldoBajaAsync(long aguinaldoBajaId) |
| | | 150 | | { |
| | 0 | 151 | | return await _context.AguinaldosBaja |
| | 0 | 152 | | .Include(b => b.Items) |
| | 0 | 153 | | .FirstOrDefaultAsync(b => b.Id == aguinaldoBajaId) |
| | 0 | 154 | | ?? throw new KeyNotFoundException($"No se encontró aguinaldo por baja con id {aguinaldoBajaId}."); |
| | 0 | 155 | | } |
| | | 156 | | |
| | | 157 | | // ── PDF BUILDERS ────────────────────────────────────────────────────────── |
| | | 158 | | |
| | | 159 | | private static byte[] GenerarPdfSemestral(Aguinaldo ag, RelacionLaboral relacion) |
| | | 160 | | { |
| | 0 | 161 | | var ci = CultureInfo.GetCultureInfo("es-UY"); |
| | | 162 | | // Semestre 1 → junio (mes 6), Semestre 2 → diciembre (mes 12) |
| | 0 | 163 | | var mes = ag.Semestre == 1 ? 6 : 12; |
| | 0 | 164 | | var nombreMes = ci.TextInfo.ToTitleCase(ci.DateTimeFormat.GetMonthName(mes)); |
| | 0 | 165 | | var tituloPeriodo = $"MES DE : {nombreMes} {ag.Anio}"; |
| | | 166 | | |
| | 0 | 167 | | var nominal = ag.Nominal ?? 0m; |
| | 0 | 168 | | var irpf = ag.IrpfAguinaldo; |
| | 0 | 169 | | var montepio = ag.Montepio ?? 0m; |
| | 0 | 170 | | var sanidad = ag.Sanidad ?? 0m; |
| | 0 | 171 | | var totalDescuentos = ag.TotalDescuentos ?? 0m; |
| | 0 | 172 | | var liquido = ag.Liquido ?? 0m; |
| | 0 | 173 | | var redondeo = ag.Redondeo; |
| | | 174 | | |
| | 0 | 175 | | var haberes = new List<(string Desc, decimal Monto)> |
| | 0 | 176 | | { |
| | 0 | 177 | | ("AGUINALDO MILITAR", nominal) |
| | 0 | 178 | | }; |
| | | 179 | | |
| | 0 | 180 | | var descuentos = new List<(string Desc, decimal Monto)> |
| | 0 | 181 | | { |
| | 0 | 182 | | ("IRPF", irpf), |
| | 0 | 183 | | ("MONTEPÍO", montepio), |
| | 0 | 184 | | ("D.N.S.FF.AA.", sanidad) |
| | 0 | 185 | | }; |
| | | 186 | | |
| | 0 | 187 | | return GenerarPdfAguinaldo( |
| | 0 | 188 | | tituloPeriodo, relacion, |
| | 0 | 189 | | haberes, descuentos, |
| | 0 | 190 | | totalHaberes: nominal, |
| | 0 | 191 | | totalDescuentos: totalDescuentos, |
| | 0 | 192 | | redondeo: redondeo, |
| | 0 | 193 | | aCobrar: liquido, |
| | 0 | 194 | | fechaIngreso: relacion.FechaInicio); |
| | | 195 | | } |
| | | 196 | | |
| | | 197 | | private static byte[] GenerarPdfBaja(AguinaldoBaja baja, RelacionLaboral? relacion) |
| | | 198 | | { |
| | 0 | 199 | | var ci = CultureInfo.GetCultureInfo("es-UY"); |
| | 0 | 200 | | var nombreMes = ci.TextInfo.ToTitleCase(ci.DateTimeFormat.GetMonthName(baja.Mes)); |
| | 0 | 201 | | var tituloPeriodo = $"MES DE : {nombreMes} {baja.Anio}"; |
| | | 202 | | |
| | 0 | 203 | | var haberes = baja.Items |
| | 0 | 204 | | .Where(i => i.Tipo == "haber") |
| | 0 | 205 | | .Select(i => (i.NombreConcepto, Math.Abs(i.Importe))) |
| | 0 | 206 | | .ToList(); |
| | | 207 | | |
| | 0 | 208 | | var descuentos = baja.Items |
| | 0 | 209 | | .Where(i => i.Tipo == "descuento") |
| | 0 | 210 | | .Select(i => (i.NombreConcepto, Math.Abs(i.Importe))) |
| | 0 | 211 | | .ToList(); |
| | | 212 | | |
| | | 213 | | // fallback si no hay items registrados |
| | 0 | 214 | | if (!haberes.Any()) |
| | 0 | 215 | | haberes = new List<(string, decimal)> { ("AGUINALDO MILITAR", baja.Nominal) }; |
| | 0 | 216 | | if (!descuentos.Any()) |
| | 0 | 217 | | descuentos = new List<(string, decimal)> |
| | 0 | 218 | | { |
| | 0 | 219 | | ("IRPF", baja.Irpf), |
| | 0 | 220 | | ("MONTEPÍO", baja.Montepio), |
| | 0 | 221 | | ("D.N.S.FF.AA.", baja.Sanidad) |
| | 0 | 222 | | }; |
| | | 223 | | |
| | 0 | 224 | | return GenerarPdfAguinaldo( |
| | 0 | 225 | | tituloPeriodo, relacion, |
| | 0 | 226 | | haberes, descuentos, |
| | 0 | 227 | | totalHaberes: baja.Nominal, |
| | 0 | 228 | | totalDescuentos: baja.TotalDescuentos, |
| | 0 | 229 | | redondeo: baja.Redondeo, |
| | 0 | 230 | | aCobrar: baja.Liquido, |
| | 0 | 231 | | fechaIngreso: relacion?.FechaInicio, |
| | 0 | 232 | | cedula: baja.Cedula, |
| | 0 | 233 | | nombreCompleto: baja.NombreCompleto); |
| | | 234 | | } |
| | | 235 | | |
| | | 236 | | // ── CORE PDF ────────────────────────────────────────────────────────────── |
| | | 237 | | |
| | 0 | 238 | | private static readonly byte[]? _logoBytes = CargarLogo(); |
| | | 239 | | |
| | | 240 | | private static byte[]? CargarLogo() |
| | | 241 | | { |
| | 0 | 242 | | var asm = Assembly.GetExecutingAssembly(); |
| | 0 | 243 | | var nombre = asm.GetManifestResourceNames() |
| | 0 | 244 | | .FirstOrDefault(n => n.EndsWith("fau-logo.png", StringComparison.OrdinalIgnoreCase)); |
| | 0 | 245 | | if (nombre is null) return null; |
| | 0 | 246 | | using var stream = asm.GetManifestResourceStream(nombre)!; |
| | 0 | 247 | | using var ms = new MemoryStream(); |
| | 0 | 248 | | stream.CopyTo(ms); |
| | 0 | 249 | | return ms.ToArray(); |
| | 0 | 250 | | } |
| | | 251 | | |
| | | 252 | | private static byte[] GenerarPdfAguinaldo( |
| | | 253 | | string tituloPeriodo, |
| | | 254 | | RelacionLaboral? relacion, |
| | | 255 | | List<(string Desc, decimal Monto)> haberes, |
| | | 256 | | List<(string Desc, decimal Monto)> descuentos, |
| | | 257 | | decimal totalHaberes, |
| | | 258 | | decimal totalDescuentos, |
| | | 259 | | decimal redondeo, |
| | | 260 | | decimal aCobrar, |
| | | 261 | | DateTime? fechaIngreso, |
| | | 262 | | string? cedula = null, |
| | | 263 | | string? nombreCompleto = null) |
| | | 264 | | { |
| | 0 | 265 | | var cedulaMostrar = cedula ?? relacion?.Persona.Cedula ?? "-"; |
| | 0 | 266 | | var gradoCodigo = relacion?.Grado.Codigo ?? "-"; |
| | 0 | 267 | | var escalafonCodigo = relacion?.Escalafon.Codigo ?? "-"; |
| | 0 | 268 | | var unidadCodigo = relacion?.Unidad.Codigo ?? "-"; |
| | | 269 | | |
| | | 270 | | string apellidoNombre; |
| | 0 | 271 | | if (nombreCompleto != null) |
| | | 272 | | { |
| | 0 | 273 | | apellidoNombre = nombreCompleto.ToUpper(); |
| | | 274 | | } |
| | 0 | 275 | | else if (relacion != null) |
| | | 276 | | { |
| | 0 | 277 | | var p = relacion.Persona; |
| | 0 | 278 | | var apellidos = string.IsNullOrWhiteSpace(p.SegundoApellido) |
| | 0 | 279 | | ? p.PrimerApellido |
| | 0 | 280 | | : $"{p.PrimerApellido} {p.SegundoApellido}"; |
| | 0 | 281 | | var nombres = string.IsNullOrWhiteSpace(p.SegundoNombre) |
| | 0 | 282 | | ? p.PrimerNombre |
| | 0 | 283 | | : $"{p.PrimerNombre} {p.SegundoNombre}"; |
| | 0 | 284 | | apellidoNombre = $"{apellidos.ToUpper()}, {nombres.ToUpper()}"; |
| | | 285 | | } |
| | | 286 | | else |
| | | 287 | | { |
| | 0 | 288 | | apellidoNombre = "-"; |
| | | 289 | | } |
| | | 290 | | |
| | 0 | 291 | | var fechaIngresoStr = fechaIngreso.HasValue |
| | 0 | 292 | | ? fechaIngreso.Value.ToString("dd/MM/yyyy") |
| | 0 | 293 | | : string.Empty; |
| | | 294 | | |
| | 0 | 295 | | return Document.Create(container => |
| | 0 | 296 | | { |
| | 0 | 297 | | container.Page(page => |
| | 0 | 298 | | { |
| | 0 | 299 | | page.Size(PageSizes.A4); |
| | 0 | 300 | | page.MarginHorizontal(20); |
| | 0 | 301 | | page.MarginTop(15); |
| | 0 | 302 | | page.MarginBottom(15); |
| | 0 | 303 | | page.DefaultTextStyle(x => x.FontSize(7.5f).FontFamily("Courier New")); |
| | 0 | 304 | | |
| | 0 | 305 | | page.Content().Column(col => |
| | 0 | 306 | | { |
| | 0 | 307 | | // ── ENCABEZADO ──────────────────────────────────────── |
| | 0 | 308 | | col.Item().PaddingBottom(4).Row(row => |
| | 0 | 309 | | { |
| | 0 | 310 | | row.RelativeItem().Row(r => |
| | 0 | 311 | | { |
| | 0 | 312 | | if (_logoBytes is not null) |
| | 0 | 313 | | r.ConstantItem(90).Image(_logoBytes).FitArea(); |
| | 0 | 314 | | r.RelativeItem().PaddingLeft(_logoBytes is not null ? 6 : 0) |
| | 0 | 315 | | .Column(c => |
| | 0 | 316 | | { |
| | 0 | 317 | | c.Item().Text("FUERZA AÉREA").Bold().FontSize(13).FontFamily("Arial"); |
| | 0 | 318 | | c.Item().Text("URUGUAYA").Bold().FontSize(13).FontFamily("Arial"); |
| | 0 | 319 | | }); |
| | 0 | 320 | | }); |
| | 0 | 321 | | row.ConstantItem(165).Column(c => |
| | 0 | 322 | | { |
| | 0 | 323 | | c.Item().Border(1).Padding(6).Column(inner => |
| | 0 | 324 | | { |
| | 0 | 325 | | inner.Item().Text($" {tituloPeriodo}"); |
| | 0 | 326 | | inner.Item().Text(" "); |
| | 0 | 327 | | }); |
| | 0 | 328 | | }); |
| | 0 | 329 | | }); |
| | 0 | 330 | | |
| | 0 | 331 | | // ── CABECERA FUNCIONARIO ────────────────────────────── |
| | 0 | 332 | | col.Item().Border(1).Row(row => |
| | 0 | 333 | | { |
| | 0 | 334 | | row.ConstantItem(85).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 335 | | .Text("CEDULA").Bold(); |
| | 0 | 336 | | row.ConstantItem(80).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 337 | | .AlignCenter().Text("GDO").Bold(); |
| | 0 | 338 | | row.ConstantItem(32).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 339 | | .AlignCenter().Text("ESC").Bold(); |
| | 0 | 340 | | row.RelativeItem().BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 341 | | .Text("APELLIDO Y NOMBRE").Bold(); |
| | 0 | 342 | | row.ConstantItem(22).BorderRight(1).PaddingHorizontal(4).PaddingVertical(3) |
| | 0 | 343 | | .AlignCenter().Text("UN").Bold(); |
| | 0 | 344 | | row.ConstantItem(138).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 345 | | .AlignCenter().Text("FECHAS").Bold(); |
| | 0 | 346 | | }); |
| | 0 | 347 | | |
| | 0 | 348 | | // ── DATOS FUNCIONARIO ───────────────────────────────── |
| | 0 | 349 | | col.Item().BorderLeft(1).BorderRight(1).BorderBottom(1).Row(row => |
| | 0 | 350 | | { |
| | 0 | 351 | | row.ConstantItem(85).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 352 | | .Text(cedulaMostrar); |
| | 0 | 353 | | row.ConstantItem(80).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 354 | | .Text(gradoCodigo); |
| | 0 | 355 | | row.ConstantItem(32).BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 356 | | .Text(escalafonCodigo); |
| | 0 | 357 | | row.RelativeItem().BorderRight(1).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 358 | | .Text(apellidoNombre); |
| | 0 | 359 | | row.ConstantItem(22).BorderRight(1).PaddingHorizontal(4).PaddingVertical(3) |
| | 0 | 360 | | .AlignCenter().Text(unidadCodigo); |
| | 0 | 361 | | row.ConstantItem(138).PaddingHorizontal(5).PaddingVertical(3) |
| | 0 | 362 | | .Column(c => |
| | 0 | 363 | | { |
| | 0 | 364 | | if (!string.IsNullOrEmpty(fechaIngresoStr)) |
| | 0 | 365 | | c.Item().Text(t => |
| | 0 | 366 | | { |
| | 0 | 367 | | t.Span("Fecha Ingreso: ").Bold(); |
| | 0 | 368 | | t.Span(fechaIngresoStr); |
| | 0 | 369 | | }); |
| | 0 | 370 | | else |
| | 0 | 371 | | c.Item().Text(" "); |
| | 0 | 372 | | }); |
| | 0 | 373 | | }); |
| | 0 | 374 | | |
| | 0 | 375 | | // ── CUERPO DE 3 COLUMNAS ────────────────────────────── |
| | 0 | 376 | | col.Item().Extend() |
| | 0 | 377 | | .BorderLeft(1).BorderRight(1).BorderTop(1) |
| | 0 | 378 | | .Row(row => |
| | 0 | 379 | | { |
| | 0 | 380 | | // Columna 1: Haberes |
| | 0 | 381 | | row.RelativeItem(40).BorderRight(1).Column(c => |
| | 0 | 382 | | { |
| | 0 | 383 | | foreach (var item in haberes) |
| | 0 | 384 | | FilaItem(c, item.Desc, item.Monto); |
| | 0 | 385 | | |
| | 0 | 386 | | FilaSeparador(c); |
| | 0 | 387 | | FilaTotalBold(c, "TOTAL DE HABERES", totalHaberes); |
| | 0 | 388 | | }); |
| | 0 | 389 | | |
| | 0 | 390 | | // Columna 2: Descuentos |
| | 0 | 391 | | row.RelativeItem(35).BorderRight(1).Column(c => |
| | 0 | 392 | | { |
| | 0 | 393 | | foreach (var item in descuentos.Where(d => d.Monto != 0)) |
| | 0 | 394 | | FilaItem(c, item.Desc, item.Monto); |
| | 0 | 395 | | |
| | 0 | 396 | | FilaSeparador(c); |
| | 0 | 397 | | FilaTotalBold(c, "TOTAL DESC.", totalDescuentos); |
| | 0 | 398 | | }); |
| | 0 | 399 | | |
| | 0 | 400 | | // Columna 3: Ajuste (redondeo) |
| | 0 | 401 | | row.RelativeItem(25).Column(c => |
| | 0 | 402 | | { |
| | 0 | 403 | | if (redondeo != 0m) |
| | 0 | 404 | | { |
| | 0 | 405 | | c.Item().Row(r => |
| | 0 | 406 | | { |
| | 0 | 407 | | r.RelativeItem().PaddingHorizontal(5).Text("AJUSTE"); |
| | 0 | 408 | | r.ConstantItem(60).AlignRight().PaddingHorizontal(5) |
| | 0 | 409 | | .Text(Monto(redondeo)); |
| | 0 | 410 | | }); |
| | 0 | 411 | | } |
| | 0 | 412 | | }); |
| | 0 | 413 | | }); |
| | 0 | 414 | | }); |
| | 0 | 415 | | |
| | 0 | 416 | | // ── PIE: NOMINAL | DESCUENTOS | A COBRAR ───────────────── |
| | 0 | 417 | | page.Footer().Border(1).Row(row => |
| | 0 | 418 | | { |
| | 0 | 419 | | row.RelativeItem().BorderRight(1).Padding(5).Row(r => |
| | 0 | 420 | | { |
| | 0 | 421 | | r.RelativeItem().Text(t => t.Span("NOMINAL....: ").Bold()); |
| | 0 | 422 | | r.ConstantItem(75).AlignRight().Text(Monto(totalHaberes)); |
| | 0 | 423 | | }); |
| | 0 | 424 | | row.RelativeItem().BorderRight(1).Padding(5).Row(r => |
| | 0 | 425 | | { |
| | 0 | 426 | | r.RelativeItem().Text(t => t.Span("DESCUENTOS.: ").Bold()); |
| | 0 | 427 | | r.ConstantItem(75).AlignRight().Text(Monto(totalDescuentos)); |
| | 0 | 428 | | }); |
| | 0 | 429 | | row.RelativeItem().Padding(5).Row(r => |
| | 0 | 430 | | { |
| | 0 | 431 | | r.RelativeItem().Text(t => t.Span("A COBRAR...: ").Bold()); |
| | 0 | 432 | | r.ConstantItem(75).AlignRight().Text(Monto(aCobrar)); |
| | 0 | 433 | | }); |
| | 0 | 434 | | }); |
| | 0 | 435 | | }); |
| | 0 | 436 | | }).GeneratePdf(); |
| | | 437 | | } |
| | | 438 | | |
| | | 439 | | private static string Monto(decimal valor) => |
| | 0 | 440 | | valor.ToString("N2", CultureInfo.InvariantCulture); |
| | | 441 | | |
| | | 442 | | private static void FilaItem(ColumnDescriptor col, string descripcion, decimal monto) |
| | | 443 | | { |
| | 0 | 444 | | col.Item().Row(r => |
| | 0 | 445 | | { |
| | 0 | 446 | | r.RelativeItem().PaddingHorizontal(5).Text(descripcion); |
| | 0 | 447 | | r.ConstantItem(62).AlignRight().PaddingHorizontal(5).Text(Monto(monto)); |
| | 0 | 448 | | }); |
| | 0 | 449 | | } |
| | | 450 | | |
| | | 451 | | private static void FilaSeparador(ColumnDescriptor col) |
| | | 452 | | { |
| | 0 | 453 | | col.Item().PaddingHorizontal(5).PaddingVertical(2).LineHorizontal(0.5f); |
| | 0 | 454 | | } |
| | | 455 | | |
| | | 456 | | private static void FilaTotalBold(ColumnDescriptor col, string label, decimal total) |
| | | 457 | | { |
| | 0 | 458 | | col.Item().Row(r => |
| | 0 | 459 | | { |
| | 0 | 460 | | r.RelativeItem().PaddingHorizontal(5).Text(label).Bold(); |
| | 0 | 461 | | r.ConstantItem(62).AlignRight().PaddingHorizontal(5).Text(Monto(total)).Bold(); |
| | 0 | 462 | | }); |
| | 0 | 463 | | } |
| | | 464 | | } |