| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Globalization; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Text; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using FAU.DataAccess.Repositories; |
| | | 8 | | using FAU.Entidades; |
| | | 9 | | using FAU.Logica.DTOs; |
| | | 10 | | |
| | | 11 | | namespace FAU.Logica.Services; |
| | | 12 | | |
| | | 13 | | public class ReporteDeficitService : IReporteDeficitService |
| | | 14 | | { |
| | | 15 | | private const int AnchoLinea = 80; |
| | | 16 | | private const char SaltoPagina = '\f'; |
| | | 17 | | private const char ControlImpresora = '\u0012'; |
| | | 18 | | private const char LineaLegacy = '─'; |
| | | 19 | | private const string NuevaLinea = "\r\n"; |
| | | 20 | | |
| | 1 | 21 | | private static readonly CultureInfo CulturaMontos = CultureInfo.GetCultureInfo("en-US"); |
| | | 22 | | |
| | | 23 | | private readonly IReporteDeficitRepository _repo; |
| | | 24 | | |
| | 7 | 25 | | public ReporteDeficitService(IReporteDeficitRepository repo) |
| | | 26 | | { |
| | 7 | 27 | | _repo = repo; |
| | 7 | 28 | | } |
| | | 29 | | |
| | | 30 | | public async Task<ReporteDeficitPorPersonaDto> ObtenerDeficitPorPersonaAsync( |
| | | 31 | | long periodoId, CancellationToken ct = default) |
| | | 32 | | { |
| | 2 | 33 | | var filas = (await _repo.ObtenerPlanillaAjusteConRelacionAsync(periodoId, ct)).ToList(); |
| | | 34 | | |
| | 2 | 35 | | var situaciones = filas |
| | 3 | 36 | | .GroupBy(f => f.SituacionNombre) |
| | 1 | 37 | | .OrderBy(g => g.Key) |
| | 1 | 38 | | .Select(gSit => BuildGrupoSituacion(gSit.Key, gSit)) |
| | 2 | 39 | | .ToList(); |
| | | 40 | | |
| | 2 | 41 | | return new ReporteDeficitPorPersonaDto |
| | 2 | 42 | | { |
| | 2 | 43 | | Situaciones = situaciones, |
| | 1 | 44 | | TotalSolicitado = situaciones.Sum(s => s.TotalSolicitado), |
| | 1 | 45 | | TotalAplicado = situaciones.Sum(s => s.TotalAplicado), |
| | 1 | 46 | | TotalDeficit = situaciones.Sum(s => s.TotalDeficit) |
| | 2 | 47 | | }; |
| | 2 | 48 | | } |
| | | 49 | | |
| | | 50 | | private static DeficitGrupoSituacionDto BuildGrupoSituacion( |
| | | 51 | | string situacion, IEnumerable<PlanillaAjusteConRelacionRow> filas) |
| | | 52 | | { |
| | 1 | 53 | | var unidades = filas |
| | 3 | 54 | | .GroupBy(f => f.UnidadNombre) |
| | 1 | 55 | | .OrderBy(g => g.Key) |
| | 1 | 56 | | .Select(gUni => BuildGrupoUnidad(gUni.Key, gUni)) |
| | 1 | 57 | | .ToList(); |
| | | 58 | | |
| | 1 | 59 | | return new DeficitGrupoSituacionDto |
| | 1 | 60 | | { |
| | 1 | 61 | | Situacion = situacion, |
| | 1 | 62 | | Unidades = unidades, |
| | 1 | 63 | | TotalSolicitado = unidades.Sum(u => u.TotalSolicitado), |
| | 1 | 64 | | TotalAplicado = unidades.Sum(u => u.TotalAplicado), |
| | 1 | 65 | | TotalDeficit = unidades.Sum(u => u.TotalDeficit) |
| | 1 | 66 | | }; |
| | | 67 | | } |
| | | 68 | | |
| | | 69 | | private static DeficitGrupoUnidadDto BuildGrupoUnidad( |
| | | 70 | | string unidad, IEnumerable<PlanillaAjusteConRelacionRow> filas) |
| | | 71 | | { |
| | 1 | 72 | | var companias = filas |
| | 3 | 73 | | .GroupBy(f => f.CompaniaNombre) |
| | 1 | 74 | | .OrderBy(g => g.Key) |
| | 1 | 75 | | .Select(gCia => BuildGrupoCompania(gCia.Key, gCia)) |
| | 1 | 76 | | .ToList(); |
| | | 77 | | |
| | 1 | 78 | | return new DeficitGrupoUnidadDto |
| | 1 | 79 | | { |
| | 1 | 80 | | Unidad = unidad, |
| | 1 | 81 | | Companias = companias, |
| | 1 | 82 | | TotalSolicitado = companias.Sum(c => c.TotalSolicitado), |
| | 1 | 83 | | TotalAplicado = companias.Sum(c => c.TotalAplicado), |
| | 1 | 84 | | TotalDeficit = companias.Sum(c => c.TotalDeficit) |
| | 1 | 85 | | }; |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | private static DeficitGrupoCompaniaDto BuildGrupoCompania( |
| | | 89 | | string compania, IEnumerable<PlanillaAjusteConRelacionRow> filas) |
| | | 90 | | { |
| | 1 | 91 | | var personas = filas |
| | 3 | 92 | | .GroupBy(f => new { f.PersonaId, f.Cedula, f.PersonaNombre }) |
| | 2 | 93 | | .OrderBy(g => g.Key.PersonaNombre) |
| | 2 | 94 | | .Select(gPer => BuildPersona(gPer.Key.PersonaId, gPer.Key.Cedula, gPer.Key.PersonaNombre, gPer)) |
| | 1 | 95 | | .ToList(); |
| | | 96 | | |
| | 1 | 97 | | return new DeficitGrupoCompaniaDto |
| | 1 | 98 | | { |
| | 1 | 99 | | Compania = compania, |
| | 1 | 100 | | Personas = personas, |
| | 2 | 101 | | TotalSolicitado = personas.Sum(p => p.TotalSolicitado), |
| | 2 | 102 | | TotalAplicado = personas.Sum(p => p.TotalAplicado), |
| | 2 | 103 | | TotalDeficit = personas.Sum(p => p.TotalDeficit) |
| | 1 | 104 | | }; |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | private static DeficitPersonaDto BuildPersona( |
| | | 108 | | long personaId, string cedula, string nombre, IEnumerable<PlanillaAjusteConRelacionRow> filas) |
| | | 109 | | { |
| | 2 | 110 | | var acreedores = filas |
| | 3 | 111 | | .OrderBy(f => f.AcreedorNombre) |
| | 3 | 112 | | .Select(f => new DeficitAcreedorFilaDto |
| | 3 | 113 | | { |
| | 3 | 114 | | AcreedorId = f.AcreedorId, |
| | 3 | 115 | | AcreedorCodigo = f.AcreedorCodigo, |
| | 3 | 116 | | AcreedorNombre = f.AcreedorNombre, |
| | 3 | 117 | | MontoSolicitado = f.MontoSolicitado, |
| | 3 | 118 | | MontoAplicado = f.MontoAplicado, |
| | 3 | 119 | | MontoDeficit = f.MontoNoAplicado |
| | 3 | 120 | | }) |
| | 2 | 121 | | .ToList(); |
| | | 122 | | |
| | 2 | 123 | | return new DeficitPersonaDto |
| | 2 | 124 | | { |
| | 2 | 125 | | PersonaId = personaId, |
| | 2 | 126 | | Cedula = cedula, |
| | 2 | 127 | | Nombre = nombre, |
| | 2 | 128 | | Acreedores = acreedores, |
| | 3 | 129 | | TotalSolicitado = acreedores.Sum(a => a.MontoSolicitado), |
| | 3 | 130 | | TotalAplicado = acreedores.Sum(a => a.MontoAplicado), |
| | 3 | 131 | | TotalDeficit = acreedores.Sum(a => a.MontoDeficit) |
| | 2 | 132 | | }; |
| | | 133 | | } |
| | | 134 | | |
| | | 135 | | public async Task<byte[]> GenerarTxtDeficitPorPersonaAsync( |
| | | 136 | | long periodoId, int anio, int mes, CancellationToken ct = default) |
| | | 137 | | { |
| | 2 | 138 | | var filas = (await _repo.ObtenerPlanillaAjusteConRelacionAsync(periodoId, ct)).ToList(); |
| | 2 | 139 | | var sb = new StringBuilder(); |
| | 2 | 140 | | var hoja = 1; |
| | 2 | 141 | | var primeraPagina = true; |
| | | 142 | | |
| | 2 | 143 | | var grupos = filas |
| | 1 | 144 | | .GroupBy(f => new |
| | 1 | 145 | | { |
| | 1 | 146 | | f.SituacionCodigo, |
| | 1 | 147 | | f.UnidadCodigo, |
| | 1 | 148 | | f.CompaniaCodigo, |
| | 1 | 149 | | f.SituacionNombre, |
| | 1 | 150 | | f.UnidadNombre, |
| | 1 | 151 | | f.CompaniaNombre |
| | 1 | 152 | | }) |
| | 1 | 153 | | .OrderBy(g => g.Key.SituacionCodigo) |
| | 1 | 154 | | .ThenBy(g => g.Key.UnidadCodigo) |
| | 1 | 155 | | .ThenBy(g => g.Key.CompaniaCodigo) |
| | 1 | 156 | | .ThenBy(g => g.Key.SituacionNombre) |
| | 1 | 157 | | .ThenBy(g => g.Key.UnidadNombre) |
| | 1 | 158 | | .ThenBy(g => g.Key.CompaniaNombre) |
| | 2 | 159 | | .ToList(); |
| | | 160 | | |
| | 2 | 161 | | if (grupos.Count == 0) |
| | | 162 | | { |
| | 1 | 163 | | AgregarEncabezadoPersona(sb, hoja, anio, mes); |
| | 1 | 164 | | return CodificarLegacy(sb.ToString()); |
| | | 165 | | } |
| | | 166 | | |
| | 4 | 167 | | foreach (var grupo in grupos) |
| | | 168 | | { |
| | 1 | 169 | | if (!primeraPagina) |
| | 0 | 170 | | sb.Append(SaltoPagina); |
| | | 171 | | |
| | 1 | 172 | | AgregarEncabezadoPersona(sb, hoja++, anio, mes); |
| | 1 | 173 | | primeraPagina = false; |
| | | 174 | | |
| | 1 | 175 | | AgregarLinea(sb); |
| | 1 | 176 | | AgregarLinea(sb); |
| | 1 | 177 | | AgregarLinea(sb, $" Sit./Uni./Comp.{CodigoGrupo(grupo.Key.SituacionCodigo, 2)}/{CodigoGrupo(grupo.Key.Un |
| | | 178 | | |
| | 1 | 179 | | var personas = grupo |
| | 1 | 180 | | .GroupBy(f => new { f.PersonaId, f.Cedula, f.PersonaNombre, f.GradoNombre }) |
| | 2 | 181 | | .OrderBy(g => g.Key.PersonaNombre); |
| | | 182 | | |
| | 4 | 183 | | foreach (var persona in personas) |
| | | 184 | | { |
| | 1 | 185 | | AgregarLinea(sb); |
| | 1 | 186 | | AgregarLinea(sb, $" {Fijo(persona.Key.GradoNombre, 12)} {Fijo(persona.Key.PersonaNombre, 60)}"); |
| | 1 | 187 | | AgregarLinea(sb, $" {new string(' ',12)} {Fijo(persona.Key.PersonaNombre, 30)} {persona.Key.Cedula}"); |
| | | 188 | | |
| | 1 | 189 | | var filasPersona = persona |
| | 1 | 190 | | .OrderBy(f => CodigoNumerico(f.CodigoConcepto)) |
| | 1 | 191 | | .ThenBy(f => f.NombreConcepto) |
| | 1 | 192 | | .ToList(); |
| | | 193 | | |
| | 4 | 194 | | for (var i = 0; i < filasPersona.Count; i++) |
| | | 195 | | { |
| | 1 | 196 | | var fila = filasPersona[i]; |
| | 1 | 197 | | var marca = i == 0 ? " ®" : ""; |
| | 1 | 198 | | AgregarLinea(sb, |
| | 1 | 199 | | $" {Fijo(fila.CodigoConcepto, 15, derecha: true)} {Fijo(fila.NombreConcepto, 49)} {Monto(fila.Mo |
| | | 200 | | } |
| | | 201 | | |
| | 1 | 202 | | AgregarLinea(sb, |
| | 2 | 203 | | $"{new string(' ',47)}Total Deficit {Monto(filasPersona.Sum(f => f.MontoNoAplicado), 14)}"); |
| | | 204 | | } |
| | | 205 | | } |
| | | 206 | | |
| | 1 | 207 | | return CodificarLegacy(sb.ToString()); |
| | 2 | 208 | | } |
| | | 209 | | |
| | | 210 | | public async Task<ReporteDeficitPorAcreedorDto> ObtenerDeficitPorAcreedorAsync( |
| | | 211 | | long periodoId, CancellationToken ct = default) |
| | | 212 | | { |
| | 2 | 213 | | var filas = (await _repo.ObtenerPlanillaAjusteConRelacionAsync(periodoId, ct)).ToList(); |
| | | 214 | | |
| | 2 | 215 | | var acreedores = filas |
| | 2 | 216 | | .GroupBy(f => new { f.AcreedorId, f.AcreedorCodigo, f.AcreedorNombre }) |
| | 2 | 217 | | .OrderBy(g => g.Key.AcreedorNombre) |
| | 2 | 218 | | .Select(gAcr => |
| | 2 | 219 | | { |
| | 2 | 220 | | var personas = gAcr |
| | 2 | 221 | | .OrderBy(f => f.PersonaNombre) |
| | 2 | 222 | | .Select(f => new DeficitPersonaAcreedorFilaDto |
| | 2 | 223 | | { |
| | 2 | 224 | | Cedula = f.Cedula, |
| | 2 | 225 | | Nombre = f.PersonaNombre, |
| | 2 | 226 | | Estado = f.Estado, |
| | 2 | 227 | | Solicitado = f.MontoSolicitado, |
| | 2 | 228 | | Descontado = f.MontoAplicado, |
| | 2 | 229 | | Deficit = f.MontoNoAplicado, |
| | 2 | 230 | | Diferencia = DiferenciaLegacy(f), |
| | 2 | 231 | | Observaciones = f.Observaciones |
| | 2 | 232 | | }) |
| | 2 | 233 | | .ToList(); |
| | 2 | 234 | | |
| | 2 | 235 | | return new DeficitGrupoAcreedorDto |
| | 2 | 236 | | { |
| | 2 | 237 | | AcreedorId = gAcr.Key.AcreedorId, |
| | 2 | 238 | | AcreedorCodigo = gAcr.Key.AcreedorCodigo, |
| | 2 | 239 | | AcreedorNombre = gAcr.Key.AcreedorNombre, |
| | 2 | 240 | | Personas = personas, |
| | 2 | 241 | | TotalSolicitado = personas.Sum(p => p.Solicitado), |
| | 2 | 242 | | TotalDescontado = personas.Sum(p => p.Descontado), |
| | 2 | 243 | | TotalDeficit = personas.Sum(p => p.Deficit), |
| | 2 | 244 | | TotalDiferencia = personas.Sum(p => p.Diferencia) |
| | 2 | 245 | | }; |
| | 2 | 246 | | }) |
| | 2 | 247 | | .ToList(); |
| | | 248 | | |
| | 2 | 249 | | return new ReporteDeficitPorAcreedorDto |
| | 2 | 250 | | { |
| | 2 | 251 | | Acreedores = acreedores, |
| | 2 | 252 | | TotalSolicitado = acreedores.Sum(a => a.TotalSolicitado), |
| | 2 | 253 | | TotalDescontado = acreedores.Sum(a => a.TotalDescontado), |
| | 2 | 254 | | TotalDeficit = acreedores.Sum(a => a.TotalDeficit), |
| | 2 | 255 | | TotalDiferencia = acreedores.Sum(a => a.TotalDiferencia) |
| | 2 | 256 | | }; |
| | 2 | 257 | | } |
| | | 258 | | |
| | | 259 | | public async Task<byte[]> GenerarTxtDeficitPorAcreedorAsync( |
| | | 260 | | long periodoId, int anio, int mes, CancellationToken ct = default) |
| | | 261 | | { |
| | 1 | 262 | | var filas = (await _repo.ObtenerPlanillaAjusteConRelacionAsync(periodoId, ct)).ToList(); |
| | 1 | 263 | | var sb = new StringBuilder(); |
| | 1 | 264 | | var hoja = 1; |
| | | 265 | | |
| | 1 | 266 | | var acreedores = filas |
| | 0 | 267 | | .GroupBy(f => new { f.AcreedorId, f.AcreedorCodigo, f.AcreedorNombre }) |
| | 0 | 268 | | .OrderBy(g => g.Key.AcreedorNombre) |
| | 1 | 269 | | .ToList(); |
| | | 270 | | |
| | 1 | 271 | | if (acreedores.Count == 0) |
| | | 272 | | { |
| | 1 | 273 | | AgregarEncabezadoAcreedor(sb, hoja, "", "", anio, mes); |
| | 1 | 274 | | return CodificarLegacy(sb.ToString()); |
| | | 275 | | } |
| | | 276 | | |
| | 0 | 277 | | foreach (var acreedor in acreedores) |
| | | 278 | | { |
| | 0 | 279 | | var codigoReporte = CodigoAcreedorLegacy(acreedor); |
| | 0 | 280 | | AgregarEncabezadoAcreedor(sb, hoja++, codigoReporte, acreedor.Key.AcreedorNombre, anio, mes); |
| | | 281 | | |
| | 0 | 282 | | var filasNormales = acreedor |
| | 0 | 283 | | .Where(f => !EsNoRevista(f.Estado)) |
| | 0 | 284 | | .OrderBy(f => f.PersonaNombre) |
| | 0 | 285 | | .ToList(); |
| | | 286 | | |
| | 0 | 287 | | var filasNoRevista = acreedor |
| | 0 | 288 | | .Where(f => EsNoRevista(f.Estado)) |
| | 0 | 289 | | .OrderBy(f => f.PersonaNombre) |
| | 0 | 290 | | .ToList(); |
| | | 291 | | |
| | 0 | 292 | | foreach (var fila in filasNormales) |
| | 0 | 293 | | AgregarLinea(sb, FormatearFilaAcreedor(fila)); |
| | | 294 | | |
| | 0 | 295 | | AgregarTotalesAcreedor(sb, filasNormales, " Totales:"); |
| | | 296 | | |
| | 0 | 297 | | if (filasNoRevista.Count > 0) |
| | | 298 | | { |
| | 0 | 299 | | AgregarLinea(sb); |
| | | 300 | | |
| | 0 | 301 | | foreach (var fila in filasNoRevista) |
| | | 302 | | { |
| | 0 | 303 | | AgregarLinea(sb, FormatearFilaNoRevista(fila)); |
| | 0 | 304 | | AgregarLinea(sb); |
| | | 305 | | } |
| | | 306 | | |
| | 0 | 307 | | AgregarTotalesNoRevista(sb, filasNoRevista); |
| | | 308 | | } |
| | | 309 | | |
| | 0 | 310 | | var totalSolicitado = acreedor.Sum(f => f.MontoSolicitado); |
| | 0 | 311 | | AgregarLinea(sb); |
| | 0 | 312 | | AgregarLinea(sb, $" Total solicitado {Monto(totalSolicitado, 17)}"); |
| | 0 | 313 | | AgregarLinea(sb, $" {new string(LineaLegacy, 17)}"); |
| | | 314 | | } |
| | | 315 | | |
| | 0 | 316 | | return CodificarLegacy(sb.ToString()); |
| | 1 | 317 | | } |
| | | 318 | | |
| | | 319 | | private static void AgregarEncabezadoPersona(StringBuilder sb, int hoja, int anio, int mes) |
| | | 320 | | { |
| | 2 | 321 | | AgregarLinea(sb); |
| | 2 | 322 | | AgregarLinea(sb, ControlImpresora.ToString()); |
| | 2 | 323 | | AgregarLinea(sb, $" Inc.:03 Prog.:004 Sect.:34 U.Ej.:023 C.G.F.A. Fecha:{DateTime.Today:dd/MM/yyyy |
| | 2 | 324 | | AgregarLinea(sb, $" DEPARTAMENTO DE RETRIBUCIONES PERSONALES Prog: SUM38232 Hoja :{hoja,8}"); |
| | 2 | 325 | | AgregarLinea(sb, Separador()); |
| | 2 | 326 | | AgregarLinea(sb, Centrar($"Listado de Déficit por Funcionario * Presupuesto de {NombreMes(mes)} de {anio}")); |
| | 2 | 327 | | AgregarLinea(sb, Centrar("(Por Situacion, Unidad, Compañia)")); |
| | 2 | 328 | | AgregarLinea(sb, Separador()); |
| | 2 | 329 | | } |
| | | 330 | | |
| | | 331 | | private static void AgregarEncabezadoAcreedor(StringBuilder sb, int hoja, string codigo, string acreedor, int anio, |
| | | 332 | | { |
| | 1 | 333 | | sb.Append(SaltoPagina); |
| | 1 | 334 | | AgregarLinea(sb); |
| | 1 | 335 | | AgregarLinea(sb); |
| | 1 | 336 | | AgregarLinea(sb, ControlImpresora.ToString()); |
| | 1 | 337 | | AgregarLinea(sb, $" FUERZA AEREA.- Fecha:{DateTime.Today:dd/MM/yyyy |
| | 1 | 338 | | AgregarLinea(sb, $" COMANDO GENERAL.- Hoja :{hoja,10}"); |
| | 1 | 339 | | AgregarLinea(sb, " DIRECCION DE ECONOMIA Y FINANZAS.- Prog: SUM45037"); |
| | 1 | 340 | | AgregarLinea(sb, Separador()); |
| | 1 | 341 | | AgregarLinea(sb, Centrar($"Planilla de Ajuste de : {codigo} {acreedor}".TrimEnd())); |
| | 1 | 342 | | AgregarLinea(sb, Centrar("INSUFICIENCIAS DE LIQUIDO PRESUPUESTAL")); |
| | 1 | 343 | | AgregarLinea(sb, Separador()); |
| | 1 | 344 | | AgregarLinea(sb); |
| | 1 | 345 | | AgregarLinea(sb, "Cédula Ape. y Nomb. Solicit. Déficit Diferencia Descont. Obs."); |
| | 1 | 346 | | AgregarLinea(sb, Separador()); |
| | 1 | 347 | | } |
| | | 348 | | |
| | | 349 | | private static string FormatearFilaAcreedor(PlanillaAjusteConRelacionRow fila) |
| | | 350 | | { |
| | 0 | 351 | | var diferencia = DiferenciaLegacy(fila); |
| | 0 | 352 | | var obs = diferencia - fila.MontoAplicado; |
| | | 353 | | |
| | 0 | 354 | | return string.Concat( |
| | 0 | 355 | | Fijo(fila.Cedula, 8), |
| | 0 | 356 | | " ", |
| | 0 | 357 | | Fijo(fila.PersonaNombre, 18), |
| | 0 | 358 | | Monto(fila.MontoSolicitado, 12), |
| | 0 | 359 | | Monto(fila.MontoNoAplicado, 12), |
| | 0 | 360 | | Monto(diferencia, 13), |
| | 0 | 361 | | Monto(fila.MontoAplicado, 11), |
| | 0 | 362 | | Monto(obs, 10)); |
| | | 363 | | } |
| | | 364 | | |
| | | 365 | | private static string FormatearFilaNoRevista(PlanillaAjusteConRelacionRow fila) |
| | | 366 | | { |
| | 0 | 367 | | return string.Concat( |
| | 0 | 368 | | Fijo(fila.Cedula, 8), |
| | 0 | 369 | | " ", |
| | 0 | 370 | | Fijo(fila.PersonaNombre, 18), |
| | 0 | 371 | | Monto(fila.MontoSolicitado, 12), |
| | 0 | 372 | | " ", |
| | 0 | 373 | | new string(LineaLegacy, 10), |
| | 0 | 374 | | ">", |
| | 0 | 375 | | Monto(fila.MontoSolicitado, 13), |
| | 0 | 376 | | new string(' ', 13), |
| | 0 | 377 | | Fijo("BAJA", 8, derecha: true)); |
| | | 378 | | } |
| | | 379 | | |
| | | 380 | | private static void AgregarTotalesAcreedor(StringBuilder sb, IReadOnlyCollection<PlanillaAjusteConRelacionRow> filas |
| | | 381 | | { |
| | 0 | 382 | | if (filas.Count == 0) |
| | 0 | 383 | | return; |
| | | 384 | | |
| | 0 | 385 | | var totalSolicitado = filas.Sum(f => f.MontoSolicitado); |
| | 0 | 386 | | var totalDeficit = filas.Sum(f => f.MontoNoAplicado); |
| | 0 | 387 | | var totalDiferencia = filas.Sum(DiferenciaLegacy); |
| | 0 | 388 | | var totalDescontado = filas.Sum(f => f.MontoAplicado); |
| | | 389 | | |
| | 0 | 390 | | AgregarLinea(sb, $" {new string(' ',24)}{new string(LineaLegacy, 10)} {new string(LineaLegacy, 10)} {new strin |
| | 0 | 391 | | AgregarLinea(sb, $"{etiqueta}{Monto(totalSolicitado, 24)}{Monto(totalDeficit, 14)} {new string(LineaLegacy, 7)}{ |
| | 0 | 392 | | AgregarLinea(sb, $"{new string(' ',61)}{Monto(totalDiferencia, 13)}"); |
| | 0 | 393 | | } |
| | | 394 | | |
| | | 395 | | private static void AgregarTotalesNoRevista(StringBuilder sb, IReadOnlyCollection<PlanillaAjusteConRelacionRow> fila |
| | | 396 | | { |
| | 0 | 397 | | var total = filas.Sum(f => f.MontoSolicitado); |
| | | 398 | | |
| | 0 | 399 | | AgregarLinea(sb, $" {new string(' ',24)}{new string(LineaLegacy, 10)} {new string(LineaLegacy, 10)} {new string( |
| | 0 | 400 | | AgregarLinea(sb, $" Totales (NO REVISTAN):{Monto(total, 12)}{new string(LineaLegacy, 9)}>{Monto(total, 14)}"); |
| | 0 | 401 | | } |
| | | 402 | | |
| | | 403 | | private static decimal DiferenciaLegacy(PlanillaAjusteConRelacionRow fila) => |
| | 2 | 404 | | fila.MontoSolicitado - fila.MontoNoAplicado; |
| | | 405 | | |
| | | 406 | | private static string CodigoAcreedorLegacy(IEnumerable<PlanillaAjusteConRelacionRow> filas) |
| | | 407 | | { |
| | 0 | 408 | | var codigoConcepto = filas |
| | 0 | 409 | | .Select(f => f.CodigoConcepto) |
| | 0 | 410 | | .FirstOrDefault(c => !string.IsNullOrWhiteSpace(c)); |
| | | 411 | | |
| | 0 | 412 | | if (!string.IsNullOrWhiteSpace(codigoConcepto)) |
| | 0 | 413 | | return codigoConcepto.Trim(); |
| | | 414 | | |
| | 0 | 415 | | return filas.Select(f => f.AcreedorCodigo).FirstOrDefault(c => !string.IsNullOrWhiteSpace(c))?.Trim() ?? ""; |
| | | 416 | | } |
| | | 417 | | |
| | | 418 | | private static bool EsNoRevista(string estado) => |
| | 0 | 419 | | string.Equals(estado, "no_revista", StringComparison.OrdinalIgnoreCase); |
| | | 420 | | |
| | | 421 | | private static int CodigoNumerico(string codigo) => |
| | 1 | 422 | | int.TryParse(codigo, NumberStyles.Integer, CultureInfo.InvariantCulture, out var valor) |
| | 1 | 423 | | ? valor |
| | 1 | 424 | | : int.MaxValue; |
| | | 425 | | |
| | | 426 | | private static string CodigoGrupo(string codigo, int ancho) |
| | | 427 | | { |
| | 3 | 428 | | var texto = string.IsNullOrWhiteSpace(codigo) ? "0" : codigo.Trim(); |
| | 3 | 429 | | return Fijo(texto, ancho, derecha: true); |
| | | 430 | | } |
| | | 431 | | |
| | | 432 | | private static string Monto(decimal monto, int ancho) => |
| | 2 | 433 | | monto.ToString("#,##0.00", CulturaMontos).PadLeft(ancho); |
| | | 434 | | |
| | | 435 | | private static string Fijo(string? valor, int ancho, bool derecha = false) |
| | | 436 | | { |
| | 8 | 437 | | var texto = string.IsNullOrWhiteSpace(valor) ? "" : valor.Trim(); |
| | 8 | 438 | | if (texto.Length > ancho) |
| | 0 | 439 | | texto = texto[..ancho]; |
| | | 440 | | |
| | 8 | 441 | | return derecha ? texto.PadLeft(ancho) : texto.PadRight(ancho); |
| | | 442 | | } |
| | | 443 | | |
| | | 444 | | private static string Centrar(string texto) |
| | | 445 | | { |
| | 6 | 446 | | if (texto.Length >= AnchoLinea) |
| | 0 | 447 | | return texto; |
| | | 448 | | |
| | 6 | 449 | | var margen = (AnchoLinea - texto.Length) / 2; |
| | 6 | 450 | | return new string(' ', margen) + texto; |
| | | 451 | | } |
| | | 452 | | |
| | | 453 | | private static string Separador() => |
| | 7 | 454 | | $" {new string(LineaLegacy, AnchoLinea - 2)}"; |
| | | 455 | | |
| | | 456 | | private static string NombreMes(int mes) |
| | | 457 | | { |
| | 2 | 458 | | string[] meses = |
| | 2 | 459 | | { |
| | 2 | 460 | | "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", |
| | 2 | 461 | | "Julio", "Agosto", "Setiembre", "Octubre", "Noviembre", "Diciembre" |
| | 2 | 462 | | }; |
| | | 463 | | |
| | 2 | 464 | | return mes is >= 1 and <= 12 ? meses[mes - 1] : mes.ToString(CultureInfo.InvariantCulture); |
| | | 465 | | } |
| | | 466 | | |
| | | 467 | | private static void AgregarLinea(StringBuilder sb, string linea = "") |
| | | 468 | | { |
| | 37 | 469 | | sb.Append(linea); |
| | 37 | 470 | | sb.Append(NuevaLinea); |
| | 37 | 471 | | } |
| | | 472 | | |
| | | 473 | | private static byte[] CodificarLegacy(string texto) |
| | | 474 | | { |
| | 3 | 475 | | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); |
| | 3 | 476 | | return Encoding.GetEncoding(850).GetBytes(texto); |
| | | 477 | | } |
| | | 478 | | } |