private string ReporteCotizacion(string id_cotizacion) { try { List <ProductoCompleto> listaProductos = new List <ProductoCompleto>(); string[] cotizacion, usuario, cliente; try { cotizacion = Sql.BuscarDatos("SELECT * FROM cotizacion WHERE id_cotizacion = '" + id_cotizacion + "'")[0]; } catch (Exception) { cotizacion = new string[] { " ", " ", " ", " ", " ", " ", " ", " ", " " }; } try { usuario = Sql.BuscarDatos("SELECT usuario, nombre, apellido_paterno, apellido_materno" + " FROM usuarios WHERE id_usuario = '" + cotizacion[1] + "'")[0]; } catch (Exception) { usuario = new string[] { " ", " ", " ", " " }; } try { cliente = Sql.BuscarDatos("SELECT nombres, apellido_paterno, apellido_materno, rfc, telefono, domicilio, correo_electronico " + " FROM clientes WHERE id_cliente = '" + cotizacion[2] + "'")[0]; } catch (Exception) { cliente = new string[] { " ", " ", " ", " ", " ", " ", " " }; } foreach (string datos in cotizacion[3].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { string[] temp = datos.Split(new char[] { ':' }); string[] producto = Sql.BuscarDatos("SELECT codigo, nombre FROM productos WHERE codigo = '" + temp[0] + "'")[0]; listaProductos.Add(new ProductoCompleto(producto[0], producto[1], float.Parse(temp[1]), int.Parse(temp[3]), float.Parse(temp[2]))); } Cotizacion cotizar = new Cotizacion(int.Parse(cotizacion[0]), new Usuarios(usuario[0], usuario[1] + " " + usuario[2] + " " + usuario[3]), new Clientes(cliente[0], cliente[1], cliente[2], cliente[3], cliente[4], cliente[5], cliente[6]), cotizacion[5], listaProductos, float.Parse(cotizacion[4])); InfoReporte rep = GuardarInfoReporte.Leer(); string[,] data = { { "Precotización", "Fecha: ", "RFC: ", "Dirección: ", "Telefono: ", "Atendido por: " }, { cotizar.Id_cotizacion.ToString(), cotizar.Fecha.ToString(), rep.Reporte.rfc, rep.Reporte.direccion, rep.Reporte.telefono, cotizar.Usuario.NombreCompleto } }; PDFFile pdf = new PDFFile("reportes", "reporte-"); pdf.CrearPDF(); pdf.CrearCabecera(data); pdf.AgregarInfoCliente(cotizar.Cliente); pdf.AgregarProductos(cotizar); pdf.AgregarAnotaciones(" "); pdf.Cerrar(); return(pdf.Ruta); } catch (Exception) { } return(null); }
public void AgregarProductos(Cotizacion cotizacion) { pdf.Add(new Paragraph("\n")); float[] relativeWidths; relativeWidths = new float[] { 80, 250, 80, 80, 90, 100 }; PdfPTable tabla = new PdfPTable(relativeWidths); tabla.DefaultCell.Border = Rectangle.NO_BORDER; tabla.TotalWidth = pdf.PageSize.Width - 80f; tabla.LockedWidth = true; tabla.AddCell(Celda("CODIGO", Element.ALIGN_LEFT)); tabla.AddCell(Celda("DESCRIPCION", Element.ALIGN_LEFT)); tabla.AddCell(Celda("UNIDAD ML", Element.ALIGN_RIGHT)); tabla.AddCell(Celda("PRECIO", Element.ALIGN_RIGHT)); tabla.AddCell(Celda("DESCUENTO", Element.ALIGN_RIGHT)); tabla.AddCell(Celda("IMPORTE", Element.ALIGN_RIGHT)); if (cotizacion.Productos != null) { int k = 0; for (k = 0; k < cotizacion.Productos.Count; k++) { tabla.AddCell(new Phrase(cotizacion.Productos[k].Codigo.ToUpper(), normal)); tabla.AddCell(new Phrase(cotizacion.Productos[k].Descripcion.ToUpper(), normal)); tabla.AddCell(Celda(cotizacion.Productos[k].Cantidad.ToString("0.00"))); tabla.AddCell(Celda(cotizacion.Productos[k].Precio.ToString("$0.00"))); tabla.AddCell(Celda(cotizacion.Productos[k].Descuento.ToString() + "%")); tabla.AddCell(Celda(cotizacion.Productos[k].Subtotal.ToString("$0.00"))); } if (!String.IsNullOrWhiteSpace(clientes.telefono)) { k += 2; } for (int i = 0; i < (26 - k); i++) { for (int j = 0; j < 6; j++) { tabla.AddCell(new Phrase(" ", normal)); } } } pdf.Add(tabla); float[] anchoRelativo; anchoRelativo = new float[] { 250, 400 }; PdfPTable comentario = new PdfPTable(anchoRelativo); comentario.DefaultCell.Border = Rectangle.BOX; comentario.TotalWidth = pdf.PageSize.Width - 80f; comentario.LockedWidth = true; InfoReporte info = GuardarInfoReporte.Leer(); PdfPCell leyenda = new PdfPCell(new Phrase(info.Reporte.leyenda)); PdfPCell banco = new PdfPCell(new Phrase(info.Reporte.banco)); leyenda.HorizontalAlignment = Element.ALIGN_CENTER; banco.HorizontalAlignment = Element.ALIGN_CENTER; comentario.AddCell(leyenda); comentario.AddCell(banco); pdf.Add(comentario); if (String.IsNullOrWhiteSpace(clientes.telefono)) { vecesNuevoRenglon(2); } float subtotal = cotizacion.Total; subtotal /= 1.16f; if (clientes.telefono != "") { vecesNuevoRenglon(2); } PdfPTable tabla3 = new PdfPTable(relativeWidths); tabla3.DefaultCell.Border = Rectangle.NO_BORDER; tabla3.TotalWidth = pdf.PageSize.Width - 80f; tabla3.LockedWidth = true; PdfPCell sub = new PdfPCell(new Phrase("SUBTOTAL", bold)); sub.Colspan = 5; sub.HorizontalAlignment = Element.ALIGN_RIGHT; sub.Border = Rectangle.NO_BORDER; tabla3.AddCell(sub); tabla3.AddCell(new Phrase(subtotal.ToString("$0.00"), normal)); PdfPCell subIva = new PdfPCell(new Phrase("16% I.V.A.", bold)); subIva.Colspan = 5; subIva.HorizontalAlignment = Element.ALIGN_RIGHT; subIva.Border = Rectangle.NO_BORDER; tabla3.AddCell(subIva); float iva = subtotal * .16f; tabla3.AddCell(new Phrase(iva.ToString("$0.00"), normal)); PdfPCell total = new PdfPCell(new Phrase("TOTAL", bold)); total.Colspan = 5; total.HorizontalAlignment = Element.ALIGN_RIGHT; total.Border = Rectangle.NO_BORDER; tabla3.AddCell(total); subtotal *= 1.16f; tabla3.AddCell(new Phrase(subtotal.ToString("$0.00"), normal)); pdf.Add(tabla3); tabla.Rows.Clear(); tabla3.Rows.Clear(); }