Exemple #1
0
        public CotizaCab ConsultarCab(int cotiid)
        {
            BD            bd     = new BD();
            string        cadena = bd.Cadena;
            SqlConnection cn     = new SqlConnection(cadena);

            string sql = "SELECT * FROM SWVMCCAB_COTI06 "
                         + "WHERE SWVM06COTI_ID=@SWVM06COTI_ID";
            SqlCommand cmd = new SqlCommand(sql, cn);

            // Añadimos el valor del parámetro de la consulta
            cmd.Parameters.AddWithValue("@SWVM06COTI_ID", cotiid);
            /* Instanciamos el proveedor para devolver datos*/
            CotizaCab ccab = new CotizaCab();

            cn.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ccab.Fecha = reader.GetDateTime(1);
                ccab.Cliid = reader.GetInt32(2);
                ccab.Total = reader.GetDecimal(3);
            }
            reader.Close();
            cn.Close();
            return(ccab);
        }
Exemple #2
0
    private void Calculo()
    {
        //coizacion id (cid)
        int cid = loadParametros();
        //obtenemos cabecera de cotizacion, para usar total y formar el calculo
        CotizaBD  ctzaBD   = new CotizaBD();
        CotizaCab cabecera = ctzaBD.ConsultarCab(cid);

        //llenamos resultados
        lblTotal.Text = Convert.ToString(Math.Round(cabecera.Total, 2));
        lblSt.Text    = Convert.ToString(Math.Round(cabecera.Total / Convert.ToDecimal(1.12), 2));
        lblIva.Text   = Convert.ToString(Math.Round(decimal.Parse(lblSt.Text) * Convert.ToDecimal(0.12), 2));
    }
Exemple #3
0
    private void loadCliente()
    {
        //coizacion id (cid)
        int cid = loadParametros();
        //obtenemos cabecera de cotizacion, para usar clienteid
        CotizaBD  ctzaBD   = new CotizaBD();
        CotizaCab cabecera = ctzaBD.ConsultarCab(cid);
        //consultamos cliente
        ClienteBD cBD     = new ClienteBD();
        Cliente   cliente = cBD.ConsultarC(cabecera.Cliid);

        lblCliente.Text = cliente.Nombre;
        lblFecha.Text   = cabecera.Fecha.ToShortDateString().ToString();
        lblCiruc.Text   = cliente.Ciruc;
        lblFono.Text    = cliente.Fono1;
        lblDir.Text     = cliente.Dir;
    }
Exemple #4
0
        public void InsertCab(CotizaCab cabecera)
        {
            BD            bd     = new BD();
            string        cadena = bd.Cadena;
            SqlConnection cn     = new SqlConnection(cadena);
            SqlCommand    cmd    = new SqlCommand("SP_INSERT_CABCOTI", cn);

            cmd.CommandType = CommandType.StoredProcedure;
            //insertamos según parametros
            cmd.Parameters.AddWithValue("@SWVM06COTI_ID", cabecera.Cotiid);
            cmd.Parameters.AddWithValue("@SWVM06FECHA", DateTime.Now);
            cmd.Parameters.AddWithValue("@SWVM06CLI_ID", cabecera.Cliid);
            cmd.Parameters.AddWithValue("@SWVM06TOTAL", cabecera.Total);
            cmd.Parameters.AddWithValue("@SWVM06ESTADO", cabecera.Estado);
            cmd.Parameters.AddWithValue("@SWVM06FECHA_UPDATE", DateTime.Now);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
        }
    private void Grabar()
    {
        int       cliid  = int.Parse(Session["cliid"].ToString());
        CotizaBD  cBD    = new CotizaBD();
        int       cotiid = cBD.LastCotiza() + 1;
        CotizaCab cCab   = new CotizaCab();
        CotizaDet cDet   = new CotizaDet();

        //llenamos cabecera con datos de formulario
        cCab.Cotiid = cotiid;
        cCab.Cliid  = cliid;
        cCab.Total  = decimal.Parse(lblTotal.Text);
        cCab.Estado = "A";
        //insertamos cabecera en tabla
        cBD.InsertCab(cCab);
        //foreach para recorrer el grid por filas para posterior insercion del detalle
        foreach (GridViewRow gvd in gvDetalle.Rows)
        {
            //vector codigo que toma el productoid y codigoid combinado
            //funcion split para posteriormente guardar en variables int
            string[] codigo = gvd.Cells[0].Text.ToString().Split('C');
            string[] codigo2 = codigo[1].Split('V');
            int      gpid, gcid, gprov;
            //variable para evaluar el arreglo carrito
            gpid          = Convert.ToInt32(codigo[0].Substring(1));
            gcid          = Convert.ToInt32(codigo2[0]);
            gprov         = Convert.ToInt32(codigo2[1]);
            cDet.Cotiid   = cotiid;
            cDet.Prodid   = gpid;
            cDet.Cateid   = gcid;
            cDet.Cantidad = int.Parse(gvd.Cells[2].Text.ToString());
            cDet.Precio   = decimal.Parse(gvd.Cells[3].Text.ToString());
            cDet.Subtotal = cDet.Precio * cDet.Cantidad;
            cDet.Iva      = cDet.Subtotal * Convert.ToDecimal(0.12);
            cDet.Prov     = gprov;
            //insertar detalle en tabla
            cBD.InsertDet(cDet);
        }
    }
Exemple #6
0
        public void Makepdf(int cotiid, string ruta)
        {
            //funciones
            Funciones f = new Funciones();
            //traemos datos de la tabla cotizaciones para llenar documento pdf
            CotizaBD         ctzBD    = new CotizaBD();
            CotizaCab        cCab     = ctzBD.ConsultarCab(cotiid);
            List <CotizaDet> listcDet = ctzBD.ConsultarDet(cotiid);

            //creacion de documento
            Document       document = new Document();
            PdfWriter      pdfw     = default(PdfWriter);
            PdfContentByte cb       = default(PdfContentByte);

            iTextSharp.text.pdf.BaseFont fuente = default(iTextSharp.text.pdf.BaseFont);
            //para que el pdf se cree en la carpeta debe asegurarse que se tienen todos los pemisos en el servidor
            pdfw = PdfWriter.GetInstance(document, new FileStream(ruta + cotiid.ToString() + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None));
            //apertura para iniciar incercion de datos
            document.Open();
            cb = pdfw.DirectContent;
            //Nueva pagina
            document.NewPage();
            cb.BeginText();
            fuente = FontFactory.GetFont(FontFactory.TIMES_ROMAN, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL).BaseFont;
            cb.SetFontAndSize(fuente, 20);
            cb.SetColorFill(iTextSharp.text.Color.BLACK);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Cotización # " + cotiid.ToString(), 300, PageSize.LEDGER.Height - 75, 0);
            cb.EndText();
            pdfw.Flush();

            //creacion de la tabla detalle
            Table oTblDet = new Table(5, listcDet.Count - 1);

            oTblDet.DefaultHorizontalAlignment = 1;

            //Instancia de clienteBD para accder medoto consultarC para obetener datos del Cliente
            ClienteBD cliBD = new ClienteBD();
            Cliente   cli   = cliBD.ConsultarC(cCab.Cliid);

            //Incersion del logo al documento
            try
            {
                Image png = Image.GetInstance(new Uri("http://viveromarket.com/images/logo.png"));
                png.SetAbsolutePosition(350, 753);
                png.ScalePercent(85);
                document.Add(png);
            }
            catch
            {
            }

            //parrafos cabecera de documento datos de ViveroMarket
            Paragraph p0  = new Paragraph(new Chunk("ViveroMarket.com / Vivero Cia. Ltd. ", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p01 = new Paragraph(new Chunk("Acuerelas del Rio Mz. 225 V. 1 - Fono: 042236212", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p02 = new Paragraph(new Chunk("email: [email protected]", FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            //parrafos cabecera de Cotizacion
            Paragraph p1 = new Paragraph(new Chunk("Cliente:       " + f.Mayus(cli.Nombre.ToLower())
                                                   + tabulador1(cli.Nombre.Length) +
                                                   "Fecha:       " + cCab.Fecha.ToShortDateString().ToString(),
                                                   FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p2 = new Paragraph(new Chunk("Ci/Ruc:       " + cli.Ciruc
                                                   + tabulador2(cli.Nombre.Length, cli.Ciruc.Length) +
                                                   "Teléfono:   " + cli.Fono1, FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p3 = new Paragraph(new Chunk("Dirección:   " + f.Mayus(cli.Dir.ToLower()), FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p4 = new Paragraph(new Chunk("Detalle:", FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            //espacios entre parrafos 1 y parrafo4
            p1.SpacingBefore = 50;
            p4.SpacingBefore = 15;

            //incersion parrafos de cabecera al documento
            document.Add(p0);
            document.Add(p01);
            document.Add(p02);
            document.Add(p1);
            document.Add(p2);
            document.Add(p3);
            document.Add(p4);

            //header del detalle
            Cell cell1 = new Cell("Codigo");
            Cell cell2 = new Cell("Producto");
            Cell cell3 = new Cell("Cantidad");
            Cell cell4 = new Cell("P. Unitario");
            Cell cell5 = new Cell("Total");

            //sombras en los headers
            cell1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            cell2.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            cell3.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            cell4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            cell5.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            //add  header a la taabla detalle
            oTblDet.AddCell(cell1);
            oTblDet.AddCell(cell2);
            oTblDet.AddCell(cell3);
            oTblDet.AddCell(cell4);
            oTblDet.AddCell(cell5);

            //instaciamos productoBD para acceder a metodo consultar producto para obtener nombre
            ProductoBD pBD = new ProductoBD();

            //rrecorremos la lista detalle y llenamos tabla del pdf
            for (int i = 0; i <= listcDet.Count - 1; i++)
            {
                Producto p = pBD.Consultar(listcDet[i].Prodid, listcDet[i].Cateid, listcDet[i].Prov);

                oTblDet.AddCell("P" + listcDet[i].Prodid.ToString() + "C" + listcDet[i].Cateid.ToString() + "V" + listcDet[i].Prov.ToString());
                oTblDet.AddCell(p.Nombre);
                oTblDet.AddCell(listcDet[i].Cantidad.ToString());
                oTblDet.AddCell(Math.Round(listcDet[i].Precio, 2).ToString());
                oTblDet.AddCell(Math.Round(listcDet[i].Subtotal, 2).ToString());
            }


            //separador
            Cell cell6 = new Cell("");

            cell6.Leading = 30;
            //cell6.Rowspan = 3;
            cell6.Colspan         = 5;
            cell6.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
            oTblDet.AddCell(cell6);

            //separador colspan 3
            Cell cell60 = new Cell("");

            cell60.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell60.Rowspan             = 3;
            cell60.Colspan             = 3;
            oTblDet.AddCell(cell60);

            //subtotal etiqueta
            Cell cell61 = new Cell("SubTotal:");

            cell61.HorizontalAlignment = Element.ALIGN_RIGHT;
            oTblDet.AddCell(cell61);
            //subtotal valor
            decimal st     = cCab.Total / decimal.Parse("1,12");
            Cell    cell62 = new Cell(Math.Round(st, 2).ToString());

            oTblDet.AddCell(cell62);

            //iva etiqueta
            Cell cell71 = new Cell("Iva:");

            cell71.HorizontalAlignment = Element.ALIGN_RIGHT;
            oTblDet.AddCell(cell71);
            //iva valor
            decimal iva    = st * decimal.Parse("0,12");
            Cell    cell72 = new Cell(Math.Round(iva, 2).ToString());

            oTblDet.AddCell(cell72);

            //total etiqueta
            Cell cell81 = new Cell("Total:");

            cell81.HorizontalAlignment = Element.ALIGN_RIGHT;
            oTblDet.AddCell(cell81);
            //total valor
            Cell cell82 = new Cell(Math.Round(cCab.Total, 2).ToString());

            oTblDet.AddCell(cell82);
            //incersion de tabla detalle al documento
            oTblDet.Cellpadding = 1;
            oTblDet.Offset      = 15;
            document.Add(oTblDet);

            //parrafo final
            string    msgfinal = "ViveroMarket.com                                 Tiempo de Valides 15 días desde su emisión";
            Paragraph pfinal   = new Paragraph(new Chunk(msgfinal, FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            pfinal.SpacingBefore = 20;
            //insercion parrafo final
            document.Add(pfinal);

            document.Close();
        }