public static Emision getListadoEmision(DateTime periodo) { try { Emision emision = new Emision(); admEntities db = Datos.getDB(); var edificios = CatalogoEdificios.getAllEdificios(); List<EmisionEdificio> emisionesEdificios = new List<EmisionEdificio>(); double TotalGeneral = 0; var allUnidades = db.unidad.ToList(); foreach (edificio e in edificios) { EmisionEdificio emEdi = new EmisionEdificio(); emEdi.Direccion = e.direccion; var unidades = allUnidades.Where(x => x.dir_edificio == e.direccion); List<EmisionUnidad> emisionesUnidades = new List<EmisionUnidad>(); double total = 0; foreach (unidad u in unidades) { var detalle = CatalogoDeudores.getDetalleDeudaUnidad(u); double saldo = 0; foreach (CatalogoDeudores.DetalleDeuda d in detalle) { EmisionUnidad emUni = new EmisionUnidad(); emUni.Unidad = u.id_unidad; emUni.Importe = d.Importe.ToString("n2"); emUni.Periodo = d.Periodo.ToShortDateString(); emUni.Concepto = d.Tipo; //if (emUni.Periodo == periodo.ToShortDateString()) emUni.Codigo = d.NroReferencia; emUni.Recargo = d.Recargo.ToString("n2"); emUni.Deuda = (d.Importe + d.Recargo).ToString("n2"); saldo += d.Importe + d.Recargo; emUni.Saldo = saldo.ToString("n2"); total += d.Importe; emisionesUnidades.Add(emUni); } } TotalGeneral += total; emEdi.Total = total.ToString("n2"); emEdi.Unidades = emisionesUnidades; emisionesEdificios.Add(emEdi); } emision.TotalGeneral = TotalGeneral.ToString("n2"); emision.Edificios = emisionesEdificios; emision.Periodo = periodo.Month + "/" + periodo.Year; return emision; } catch (Exception e) { Logger.Log.write(e.InnerException == null ? e.Message : e.InnerException.Message); throw e; } }
private static void addUnidades(Document doc, EmisionEdificio emEdi) { PdfPTable t = new PdfPTable(8); t.WidthPercentage = 85; float[] widths = new float[] { 35f, 35f, 35f, 35f, 35f, 35f, 35f, 35f }; t.SetWidths(widths); Paragraph p; p = new Paragraph(10, "Consorcio: " + emEdi.Direccion, calibri9B); doc.Add(p); int leading = 9; PdfPCell c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Unidad", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Codigo", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Periodo", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Concepto", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Importe", calibri8B); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Recargo", calibri8B); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Deuda", calibri8B); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Saldo", calibri8B); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); foreach (EmisionUnidad u in emEdi.Unidades) { string cod; float ancho; var a = emEdi.Unidades.Where(x => x.Unidad == u.Unidad); //.Max(x => x.Periodo);+ DateTime max = DateTime.Parse(a.First().Periodo); foreach (var asd in a) { var b = DateTime.Parse(asd.Periodo); if (b > max) max = b; } if (u.Periodo == max.ToShortDateString()) { cod = u.Codigo; ancho = 0.1f; } else { cod = " "; ancho = 0f; } leading = 6; c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Unidad, calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, cod, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Periodo.Remove(0, u.Periodo.IndexOf("/") + 1), calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Concepto, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Importe, calibri8N); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Recargo, calibri8N); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Deuda, calibri8N); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = ancho; p = new Paragraph(leading, u.Saldo, calibri8N); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); } leading = 6; c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Total", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, emEdi.Total, calibri8N); p.Alignment = Element.ALIGN_RIGHT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, " ", calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); doc.Add(t); }