Ejemplo n.º 1
0
 private void btnCorte_Click(object sender, EventArgs e)
 {
     try
     {
         List <string[]> lista = Corte("SELECT venta.id_venta,clientes.id_cliente, clientes.nombres,clientes.apellido_paterno,clientes.apellido_materno, venta.fecha_de_venta," +
                                       "SUM(productos_de_venta.cantidad_comprada*productos_de_venta.precio_al_momento)-(SUM(productos_de_venta.cantidad_comprada*productos_de_venta.precio_al_momento*(productos_de_venta.descuento/100)))," +
                                       " venta.cancelada FROM venta,clientes,productos_de_venta" +
                                       " WHERE (venta.cancelada=0 AND venta.fecha_de_venta LIKE '%" + dtpFecha.Value.ToString("yyyy-MM-dd") + "%') AND venta.pagada=1" +
                                       " AND (clientes.id_cliente=venta.id_cliente) AND (productos_de_venta.id_venta=venta.id_venta) " +
                                       "GROUP BY venta.id_venta ");
         List <string[]> pendientes = Pendientes("SELECT venta.id_venta,clientes.id_cliente, clientes.nombres,clientes.apellido_paterno,clientes.apellido_materno, venta.fecha_de_venta," +
                                                 "SUM(productos_de_venta.cantidad_comprada*productos_de_venta.precio_al_momento)-(SUM(productos_de_venta.cantidad_comprada*productos_de_venta.precio_al_momento*(productos_de_venta.descuento/100)))," +
                                                 " venta.cancelada FROM venta,clientes,productos_de_venta" +
                                                 " WHERE (venta.cancelada=0 AND venta.fecha_de_venta LIKE '%" + dtpFecha.Value.ToString("yyyy-MM-dd") + "%') AND venta.pagada=0" +
                                                 " AND (clientes.id_cliente=venta.id_cliente) AND (productos_de_venta.id_venta=venta.id_venta) " +
                                                 "GROUP BY venta.id_venta ");
         List <string[]> abonos = Abonos("SELECT abonos.id_venta, abonos.fecha_abono, abonos.cantidad_abonada FROM abonos " +
                                         "WHERE abonos.fecha_abono LIKE '%" + dtpFecha.Value.ToString("yyyy-MM-dd") + "%'");
         InfoReporte rep = GuardarInfoReporte.Leer();
         string[,] data = { { "Corte", "Fecha: ",              "RFC: ",         "Direccion: ",         "Telefono: "         },
                            { " ",     lista[0][2].ToString(), rep.Reporte.rfc, rep.Reporte.direccion, rep.Reporte.telefono } };
         PDFFile pdf   = new PDFFile("corte", "corte-");
         float   total = 0;
         for (int i = 0; i < lista.Count; i++)
         {
             total += float.Parse(lista[i][6].ToString());
         }
         pdf.CrearPDF();
         pdf.CrearCabecera(data);
         pdf.AgregarCorte(lista, pendientes, abonos);
         pdf.Cerrar();
         PDFFile.Ver(pdf.Ruta);
     }
     catch (Exception) { }
 }
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrWhiteSpace(txtRFC.Text))
     {
         MessageBox.Show("El RFC no puede estar en blanco", "Operacion cancelada",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else if (String.IsNullOrWhiteSpace(txtTelefono.Text))
     {
         MessageBox.Show("El telefono no puede estar en blanco", "Operacion cancelada",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else if (String.IsNullOrWhiteSpace(txtDireccion.Text))
     {
         MessageBox.Show("La direccion no puede estar en blanco", "Operacion cancelada",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         GuardarInfoReporte.Guardar(new InfoReporte(new Reporte(txtRFC.Text, txtDireccion.Text, txtTelefono.Text, txtLeyenda.Text, txtDatosBancarios.Text)));
         MessageBox.Show("Se guardaron cambios con exito", "Operacion concretadas",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
     }
 }
        public dialogInfoReporte()
        {
            InitializeComponent();
            InfoReporte info = GuardarInfoReporte.Leer();

            txtRFC.Text            = info.Reporte.rfc;
            txtDireccion.Text      = info.Reporte.direccion;
            txtTelefono.Text       = info.Reporte.telefono;
            txtLeyenda.Text        = info.Reporte.leyenda;
            txtDatosBancarios.Text = info.Reporte.banco;
        }
Ejemplo n.º 4
0
        public static MemoryStream CreatePDF(TipoInvoice t, string folio, string fecha, List <ProductoCompleto> productos, ClienteCompleto cliente, float impuesto)
        {
            // Create a Document object
            string tv;

            if (t == TipoInvoice.Cotizacions)
            {
                tv = "Cotizacion";
            }
            else
            {
                tv = "Venta";
            }

            Document document = new Document(PageSize.LETTER, 30, 30, 30, 30);

            //MemoryStream
            MemoryStream PDFData = new MemoryStream();
            PdfWriter    writer  = PdfWriter.GetInstance(document, new FileStream(Application.StartupPath + "\\Invoice.pdf", FileMode.Create));

            // First, create our fonts
            var       titleFont      = FontFactory.GetFont("Arial", 14, Font.BOLD);
            var       titleFontNegro = FontFactory.GetFont("Arial", 14, Font.BOLD, BaseColor.WHITE);
            var       boldTableFont  = FontFactory.GetFont("Arial", 10, Font.BOLD);
            var       bodyFont       = FontFactory.GetFont("Arial", 10, Font.NORMAL);
            Rectangle pageSize       = writer.PageSize;

            // Open the Document for writing
            document.Open();
            //Add elements to the document here

            PdfPTable sp = new PdfPTable(1);

            sp.HorizontalAlignment = 2;
            sp.WidthPercentage     = 200;
            sp.SetWidths(new float[] { 20 });  // then set the column's __relative__ widths
            sp.DefaultCell.Border = Rectangle.NO_BORDER;
            sp.SpacingAfter       = 20;
            PdfPCell space = new PdfPCell(new Phrase(" ", titleFontNegro));

            space.HorizontalAlignment = 1;
            space.Border          = Rectangle.NO_BORDER;
            space.BackgroundColor = BaseColor.WHITE;
            sp.AddCell(space);
            document.Add(sp);

            // Create the header table

            iTextSharp.text.Image logo;
            //Agregando la imagen
            if (File.Exists(Application.StartupPath + "\\Recursos\\ticket.png"))
            {
                logo = iTextSharp.text.Image.GetInstance(Application.StartupPath + "\\Recursos\\ticket.png");
            }
            else
            {
                logo = iTextSharp.text.Image.GetInstance(Application.StartupPath + "\\ticket.png");
            }

            logo.SetAbsolutePosition(0, 0);
            logo.SetAbsolutePosition(80, document.PageSize.Height - 100);
            logo.ScaleToFit(logo.Width / 2, 200);
            document.Add(logo);

            PdfPTable title = new PdfPTable(2);

            title.HorizontalAlignment = 2;
            title.WidthPercentage     = 40;
            title.SetWidths(new float[] { 20, 20 });  // then set the column's __relative__ widths
            title.DefaultCell.Border = Rectangle.NO_BORDER;
            title.SpacingAfter       = 20;
            PdfPCell tileName = new PdfPCell(new Phrase(tv, titleFontNegro));

            tileName.HorizontalAlignment = 1;
            tileName.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;;
            tileName.BackgroundColor = BaseColor.BLACK;
            title.AddCell(tileName);
            tileName = new PdfPCell(new Phrase("Fecha", titleFontNegro));
            tileName.HorizontalAlignment = 1;
            tileName.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;
            tileName.BackgroundColor = BaseColor.BLACK;
            title.AddCell(tileName);
            //Adicion del numero de venta y/o cotizacion
            tileName = new PdfPCell(new Phrase(folio, bodyFont));
            tileName.HorizontalAlignment = 1;
            tileName.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;
            title.AddCell(tileName);
            tileName = new PdfPCell(new Phrase(fecha, bodyFont));
            tileName.HorizontalAlignment = 1;
            tileName.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;
            title.AddCell(tileName);
            document.Add(title);
            //Añadimos a quien va dirigida la nota e la informacion de la empresa
            PdfPTable clienteYEmpresa = new PdfPTable(2);

            clienteYEmpresa.HorizontalAlignment = 0;
            clienteYEmpresa.WidthPercentage     = 100;
            clienteYEmpresa.SetWidths(new float[] { 50, 50 });  // then set the column's __relative__ widths
            clienteYEmpresa.DefaultCell.Border = Rectangle.NO_BORDER;
            clienteYEmpresa.SpacingAfter       = 10;

            string clientData = cliente.nombre + " " + cliente.paterno + " " + cliente.materno + "\n" +
                                "Domicilio: " + cliente.domicilio + "\n" +
                                "Colonia: " + cliente.colonia + "\n" +
                                "CP: " + cliente.cp + "\n" +
                                "Telefono: " + cliente.telefono + "\n" +
                                "R.F.C.: " + cliente.rfc + "\n" +
                                "Correo: " + cliente.correo;
            PdfPCell client = new PdfPCell(new Phrase("Cliente", titleFontNegro));

            client.HorizontalAlignment = 1;
            client.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;;
            client.BackgroundColor = BaseColor.BLACK;
            clienteYEmpresa.AddCell(client);

            PdfPCell empresa = new PdfPCell(new Phrase("Datos empresa", titleFontNegro));

            empresa.HorizontalAlignment = 1;
            empresa.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;
            empresa.BackgroundColor = BaseColor.BLACK;
            clienteYEmpresa.AddCell(empresa);

            client = new PdfPCell(new Phrase(clientData, bodyFont));
            client.HorizontalAlignment = 1;
            client.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;;
            client.BackgroundColor = BaseColor.WHITE;
            clienteYEmpresa.AddCell(client);


            InfoReporte rep         = GuardarInfoReporte.Leer();
            string      empresaData = "Tienda: Tostatronic\n" +
                                      "R.F.C.: " + rep.Reporte.rfc + "\n" +
                                      "Direccion: " + rep.Reporte.direccion + "\n" +
                                      "Telefono: " + rep.Reporte.telefono + "\n";

            empresa = new PdfPCell(new Phrase(empresaData, bodyFont));
            empresa.HorizontalAlignment = 1;
            empresa.Border          = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;;
            empresa.BackgroundColor = BaseColor.WHITE;
            clienteYEmpresa.AddCell(empresa);
            document.Add(clienteYEmpresa);

            /*
             * sp = new PdfPCell(new Phrase("", titleFont));
             * sp.HorizontalAlignment = 2;
             * sp.Border = Rectangle.NO_BORDER;
             * headertable.AddCell(sp);
             *
             * PdfPCell billCell = new PdfPCell(new Phrase("Para: ", bodyFont));
             * billCell.HorizontalAlignment = 2;
             * billCell.Border = Rectangle.NO_BORDER;
             * headertable.AddCell(billCell);
             * headertable.AddCell(new Phrase(nombre + "\t" + patenro, bodyFont));
             *
             * sp = new PdfPCell(new Phrase("", titleFont));
             * sp.HorizontalAlignment = 2;
             * sp.Border = Rectangle.NO_BORDER;
             * headertable.AddCell(sp);
             *
             * PdfPCell dateCell = new PdfPCell(new Phrase("Fecha :", bodyFont));
             * dateCell.HorizontalAlignment = 2;
             * dateCell.Border = Rectangle.NO_BORDER;
             * headertable.AddCell(dateCell);
             * headertable.AddCell(new Phrase(fecha, bodyFont));
             *
             *
             *
             *
             * document.Add(headertable);*/
            //Create body table
            PdfPTable itemTable = new PdfPTable(5);

            itemTable.HorizontalAlignment = 0;
            itemTable.WidthPercentage     = 100;
            itemTable.SetWidths(new float[] { 40, 80, 20, 40, 40 });  // then set the column's __relative__ widths
            itemTable.SpacingAfter       = 40;
            itemTable.DefaultCell.Border = Rectangle.BOX;
            PdfPCell cell1 = new PdfPCell(new Phrase("Codigo", boldTableFont));

            cell1.HorizontalAlignment = 1;
            itemTable.AddCell(cell1);
            PdfPCell cell2 = new PdfPCell(new Phrase("Nombre", boldTableFont));

            cell2.HorizontalAlignment = 1;
            itemTable.AddCell(cell2);
            PdfPCell cell3 = new PdfPCell(new Phrase("Cantidad", boldTableFont));

            cell3.HorizontalAlignment = 1;
            itemTable.AddCell(cell3);
            PdfPCell cell4 = new PdfPCell(new Phrase("Precio Unitario", boldTableFont));

            cell4.HorizontalAlignment = 1;
            itemTable.AddCell(cell4);
            PdfPCell cell5 = new PdfPCell(new Phrase("Sub Total", boldTableFont));

            cell5.HorizontalAlignment = 1;
            itemTable.AddCell(cell5);

            float total = 0;
            int   cont  = 1;

            foreach (ProductoCompleto producto in productos)
            {
                PdfPCell numberCell = new PdfPCell(new Phrase(producto.Codigo, bodyFont));
                numberCell.HorizontalAlignment = 0;
                numberCell.PaddingLeft         = 10f;
                numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                if (cont % 2 == 0)
                {
                    numberCell.BackgroundColor = BaseColor.LIGHT_GRAY;
                }
                itemTable.AddCell(numberCell);

                PdfPCell descCell = new PdfPCell(new Phrase(producto.Descripcion, bodyFont));
                descCell.HorizontalAlignment = 0;
                descCell.PaddingLeft         = 10f;
                descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                if (cont % 2 == 0)
                {
                    descCell.BackgroundColor = BaseColor.LIGHT_GRAY;
                }
                itemTable.AddCell(descCell);

                PdfPCell qtyCell = new PdfPCell(new Phrase(producto.Cantidad.ToString(), bodyFont));
                qtyCell.HorizontalAlignment = 1;
                qtyCell.PaddingLeft         = 10f;
                qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                if (cont % 2 == 0)
                {
                    qtyCell.BackgroundColor = BaseColor.LIGHT_GRAY;
                }
                itemTable.AddCell(qtyCell);

                PdfPCell puCell = new PdfPCell(new Phrase(producto.Precio.ToString("$0.00"), bodyFont));
                puCell.HorizontalAlignment = 1;
                puCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                if (cont % 2 == 0)
                {
                    puCell.BackgroundColor = BaseColor.LIGHT_GRAY;
                }
                itemTable.AddCell(puCell);

                PdfPCell amtCell = new PdfPCell(new Phrase(producto.Subtotal.ToString("$0.00"), bodyFont));
                amtCell.HorizontalAlignment = 1;
                amtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                if (cont % 2 == 0)
                {
                    amtCell.BackgroundColor = BaseColor.LIGHT_GRAY;
                }
                itemTable.AddCell(amtCell);
                total += producto.Subtotal;
                cont++;
            }
            // Table footer
            PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));

            totalAmtCell1.Border = Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell1);
            PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));

            totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell2);
            PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));

            totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell3);
            PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Sub Total", boldTableFont));

            totalAmtStrCell.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            totalAmtStrCell.HorizontalAlignment = 1;
            itemTable.AddCell(totalAmtStrCell);
            PdfPCell totalAmtCell = new PdfPCell(new Phrase(total.ToString("$0.00"), boldTableFont));

            totalAmtStrCell.Border           = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            totalAmtCell.HorizontalAlignment = 1;
            itemTable.AddCell(totalAmtCell);
            PdfPCell espace = new PdfPCell(new Phrase(""));

            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            espace        = new PdfPCell(new Phrase(""));
            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            espace        = new PdfPCell(new Phrase(""));
            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            PdfPCell iva = new PdfPCell(new Phrase("IVA", boldTableFont));

            iva.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            iva.HorizontalAlignment = 1;
            itemTable.AddCell(iva);
            PdfPCell ivaV = new PdfPCell(new Phrase((total * (impuesto - 1)).ToString("$0.00"), boldTableFont));

            ivaV.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            ivaV.HorizontalAlignment = 1;
            itemTable.AddCell(ivaV);
            espace        = new PdfPCell(new Phrase(""));
            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            espace        = new PdfPCell(new Phrase(""));
            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            espace        = new PdfPCell(new Phrase(""));
            espace.Border = Rectangle.NO_BORDER;
            itemTable.AddCell(espace);
            PdfPCell totalV = new PdfPCell(new Phrase("Total", boldTableFont));

            totalV.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            totalV.HorizontalAlignment = 1;
            itemTable.AddCell(totalV);
            PdfPCell totalVV = new PdfPCell(new Phrase((total * impuesto).ToString("$0.00"), boldTableFont));

            totalVV.Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER;
            totalVV.HorizontalAlignment = 1;
            itemTable.AddCell(totalVV);

            PdfPCell cell = new PdfPCell(new Phrase("***Garantia d 1 mes despues de efectuada la venta***", bodyFont));

            cell.Colspan             = 4;
            cell.HorizontalAlignment = 1;
            itemTable.AddCell(cell);
            document.Add(itemTable);



            //Approved by
            PdfContentByte cb = new PdfContentByte(writer);
            BaseFont       bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);

            cb = new PdfContentByte(writer);
            bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);
            cb = writer.DirectContent;
            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.SetTextMatrix(pageSize.GetLeft(70), 80);
            cb.ShowText("Tejedores #680, Col. La paz, Guadalajara, Jalisco");
            cb.EndText();
            document.Close();
            return(PDFData);
        }
        private string Reporte(string folio)
        {
            try
            {
                List <ProductoCompleto> listaProductos = new List <ProductoCompleto>();
                string[] pedido, usuario, cliente;

                try
                {
                    pedido = Sql.BuscarDatos("SELECT * FROM venta WHERE id_venta = '" + folio + "'")[0];
                }
                catch (Exception)
                {
                    pedido = new string[] { " ", " ", " ", " ", " ", " ", " ", " ", " " };
                }

                try
                {
                    usuario = Sql.BuscarDatos("SELECT usuario, nombre, apellido_paterno, apellido_materno" +
                                              " FROM usuarios WHERE id_usuario = '" + pedido[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 = '" + pedido[2] + "'")[0];
                }
                catch (Exception)
                {
                    cliente = new string[] { " ", " ", " ", " ", " ", " ", " " };
                }

                foreach (string datos in pedido[5].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] temp = datos.Split(new char[] { ':' });
                    if (Sql.Existe("SELECT codigo, nombre FROM productos WHERE codigo = '" + temp[0] + "' "))
                    {
                        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])));
                    }
                    else
                    {
                        listaProductos.Add(new ProductoCompleto("Codigo elim.", "Productos elim.", float.Parse(temp[1]), int.Parse(temp[3]), float.Parse(temp[2])));
                    }
                }

                Venta venta = new Venta(int.Parse(pedido[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]),
                                        bool.Parse(pedido[3]), pedido[4], listaProductos, float.Parse(pedido[6]),
                                        float.Parse(pedido[7]), float.Parse(pedido[8]));

                InfoReporte rep = GuardarInfoReporte.Leer();
                string[,] data = { { "Cotización Tienda", "Fecha: ",   "RFC: ",         "Dirección: ",         "Telefono: ",         "Atendido por: "             },
                                   { folio,               venta.Fecha, rep.Reporte.rfc, rep.Reporte.direccion, rep.Reporte.telefono, venta.Usuario.NombreCompleto } };

                PDFFile pdf = new PDFFile("reportes", "reporte-");
                pdf.CrearPDF();

                for (int i = 0; i < 2; i++)
                {
                    if (i == 1)
                    {
                        data[0, 0] = "Cotización cliente";
                        pdf.NuevoRenglon();
                        pdf.CrearCabecera(data);
                    }
                    else
                    {
                        pdf.NuevoRenglon();
                        pdf.CrearCabecera(data);
                    }

                    pdf.AgregarInfoCliente(venta.Cliente);
                    pdf.AgregarProductos(venta, false);
                    pdf.AgregarAnotaciones(" ");
                    pdf.NuevaPagina();
                }
                data[0, 0] = "Almacen";
                pdf.CrearCabecera(data);
                pdf.AgregarInfoCliente(venta.Cliente);
                pdf.AgregarProductos(venta, true);
                pdf.AgregarAnotaciones(" ");
                pdf.Cerrar();

                return(pdf.Ruta);
            }
            catch (Exception) { }
            return(null);
        }
        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();
        }
        public void AgregarProductos(Venta venta, bool almacen)
        {
            pdf.Add(new Paragraph("\n"));
            float[] relativeWidths;
            if (!almacen)
            {
                relativeWidths = new float[] { 80, 250, 80, 80, 90, 100 }
            }
            ;
            else
            {
                relativeWidths = new float[] { 110, 250, 100, 250 }
            };
            PdfPTable tabla = new PdfPTable(relativeWidths);

            tabla.DefaultCell.Border = Rectangle.NO_BORDER;
            tabla.TotalWidth         = pdf.PageSize.Width - 80f;
            tabla.LockedWidth        = true;

            //PdfPCell cell = new PdfPCell(new Phrase("LISTADO DE PRODUCTOS", bold));
            //cell.Colspan = 5;
            //cell.Border = Rectangle.NO_BORDER;
            //cell.HorizontalAlignment = Element.ALIGN_CENTER;
            ////cell.BackgroundColor = BaseColor.GRAY;
            //tabla.AddCell(cell);
            tabla.AddCell(Celda("CODIGO", Element.ALIGN_LEFT));
            tabla.AddCell(Celda("DESCRIPCION", Element.ALIGN_LEFT));
            tabla.AddCell(Celda("UNIDAD ML", Element.ALIGN_RIGHT));
            if (!almacen)
            {
                tabla.AddCell(Celda("PRECIO", Element.ALIGN_RIGHT));
                tabla.AddCell(Celda("DESCUENTO", Element.ALIGN_RIGHT));
                tabla.AddCell(Celda("IMPORTE", Element.ALIGN_RIGHT));
            }
            else
            {
                tabla.AddCell(Celda(" "));
            }

            if (venta.Productos != null)
            {
                int k = 0;
                for (k = 0; k < venta.Productos.Count; k++)
                {
                    tabla.AddCell(new Phrase(venta.Productos[k].Codigo.ToUpper(), normal));
                    tabla.AddCell(new Phrase(venta.Productos[k].Descripcion.ToUpper(), normal));
                    tabla.AddCell(Celda(venta.Productos[k].Cantidad.ToString("0.00")));
                    if (almacen)
                    {
                        tabla.AddCell(Celda(" "));
                    }
                    if (!almacen)
                    {
                        tabla.AddCell(Celda(venta.Productos[k].Precio.ToString("$0.00")));
                        tabla.AddCell(Celda(venta.Productos[k].Descuento.ToString() + "%"));
                        tabla.AddCell(Celda(venta.Productos[k].Subtotal.ToString("$0.00")));
                    }
                }
                if (!String.IsNullOrWhiteSpace(clientes.telefono))
                {
                    k += 2;
                }
                if (!venta.Pagado)
                {
                    k += 4;
                }
                for (int i = 0; i < (26 - k); i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        tabla.AddCell(new Phrase(" ", normal));
                    }
                    if (!almacen)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            tabla.AddCell(new Phrase(" ", normal));
                        }
                    }
                }
            }

            float subtotal = venta.Total + venta.Descuento;

            subtotal /= 1.16f;
            if (!almacen)
            {
                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) && String.IsNullOrWhiteSpace(clientes.domicilio))
                {
                    vecesNuevoRenglon(2);
                }
                else
                {
                    vecesNuevoRenglon(1);
                }

                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));
                if (venta.Descuento > 0)
                {
                    PdfPCell desc = new PdfPCell(new Phrase("DESCUENTO", bold));
                    desc.Colspan             = 5;
                    desc.HorizontalAlignment = Element.ALIGN_RIGHT;
                    desc.Border = Rectangle.NO_BORDER;
                    tabla3.AddCell(desc);
                    tabla3.AddCell(new Phrase(venta.Descuento.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);
                //NuevoRenglon();
                if (!venta.Pagado)
                {
                    sub                     = new PdfPCell(new Phrase("PAGO", bold));
                    sub.Colspan             = 5;
                    sub.HorizontalAlignment = Element.ALIGN_RIGHT;
                    sub.Border              = Rectangle.NO_BORDER;
                    tabla3.Rows.Clear();
                    tabla3.AddCell(sub);
                    tabla3.AddCell(new Phrase(venta.Abono.ToString("$0.00"), normal));
                    sub                     = new PdfPCell(new Phrase("RESTANTE", bold));
                    sub.Colspan             = 5;
                    sub.HorizontalAlignment = Element.ALIGN_RIGHT;
                    sub.Border              = Rectangle.NO_BORDER;
                    tabla3.AddCell(sub);
                    tabla3.AddCell(new Phrase((venta.Total - venta.Abono).ToString("$0.00"), normal));

                    pdf.Add(tabla3);
                }
            }
            if (almacen)
            {
                pdf.Add(tabla);
                tabla.Rows.Clear();
            }
        }