Ejemplo n.º 1
0
        public int getUltimoIngresadoenVentas()
        {
            MySqlDataReader rdr   = null;
            int             total = 0;

            string consulta = "SELECT idVenta FROM venta ";

            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());

            rdr = cmd.ExecuteReader();
            int          mayor = 0;
            ventasFacade vt    = new ventasFacade();

            if (vt.getVentastotales() == 1)
            {
                total = 1;
            }

            else if (vt.getVentastotales() > 1)
            {
                while (rdr.Read())
                {
                    if (rdr.GetInt64(0) > mayor)
                    {
                        mayor = rdr.GetInt32(0);
                    }
                }
            }
            total = mayor;


            getconexion.CerrarConexion();

            return(total);
        }
Ejemplo n.º 2
0
        //############################################################
        //################           REPORTES      ##################
        //############################################################
        private void calendarReportes_SelectedDatesChanged(object sender,
        SelectionChangedEventArgs e)
        {

            var calendar = sender as Calendar;
            if (calendarReportes.SelectedDate.HasValue)
            {
                DateTime date = calendar.SelectedDate.Value;
                lfechareporte.Content = date.ToString("d");
                //Buscar ventas por fecha
                ventasFacade vfac = new ventasFacade();
                List<MVentas> listVentasDia = vfac.getVentasByFechaDia(date);
                //MessageBox.Show(date.Month.ToString() + "/" + date.Year.ToString());
                List<MVentas> listVentasMes = vfac.getVentasByFechaMes(date);
                List<MVentas> listVentasAño = vfac.getVentasByFechaAño(date);
                //MessageBox.Show(listVentasDia.Count.ToString());
                int totalVentasDia = 0;
                double totalgananciaDia = 0;
                foreach (var item in listVentasDia)
                {
                    totalVentasDia = totalVentasDia + 1;
                    totalgananciaDia = totalgananciaDia + item.total;

                }

                lventasDia.Content = totalVentasDia.ToString();
                lgananciaDia.Content = "$" + totalgananciaDia.ToString();

                int totalVentasMes = 0;
                double totalgananciaMes = 0;
                foreach (var item in listVentasMes)
                {
                    totalVentasMes = totalVentasMes + 1;
                    totalgananciaMes = totalgananciaMes + item.total;

                }

                lventasMes.Content = totalVentasMes.ToString();
                lgananciaMes.Content = "$" + totalgananciaMes.ToString();

                int totalVentasAño = 0;
                double totalgananciaAño = 0;
                foreach (var item in listVentasAño)
                {
                    totalVentasAño = totalVentasAño + 1;
                    totalgananciaAño = totalgananciaAño + item.total;

                }

                lventasAño.Content = totalVentasAño.ToString();
                lgananciaAño.Content = "$" + totalgananciaAño.ToString();

            }
        }
Ejemplo n.º 3
0
        public int getUltimoIngresadoenVentas()
        {
            MySqlDataReader rdr = null;
            int total = 0;

            string consulta = "SELECT idVenta FROM venta ";

            MySqlCommand cmd = new MySqlCommand(consulta, getconexion.getConexion());
            rdr = cmd.ExecuteReader();
            int mayor = 0;
            ventasFacade vt = new ventasFacade();
            if (vt.getVentastotales() == 1)
            {
                total = 1;
            }

            else if (vt.getVentastotales() > 1)
            {
                while (rdr.Read())
                {
                    if (rdr.GetInt64(0) > mayor)
                    {
                        mayor = rdr.GetInt32(0);
                    }
                }

            }
            total = mayor;


            getconexion.CerrarConexion();

            return total;

        }
Ejemplo n.º 4
0
        public string GuardarVentas(List<MVentas> listVentas)
        {
            //Boolean guardar = false;
            string i = "";

            try
            {
                /*string c="Select*from venta";
                MySqlCommand comm1 = new MySqlCommand(c, getconexion.getConexion());
                long id = comm1.LastInsertedId;
                id = id + 1;*/

                //verificar si es primera venta para luego agregar un id igual para venta en temp
                ventasFacade v = new ventasFacade();
                if (v.getVentastotales() == 0)
                {//primer venta 

                    foreach (var vts in listVentas)
                    {
                        string consultinsert = "INSERT INTO venta(idVenta,idProducto, rutCliente, rutVendedor,cantidad, total,fecha,tipoVenta) VALUES (@idVenta,@idProducto, @rutCliente, @rutVendedor,@cantidad, @total,@fecha,@tipoVenta)";
                        MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                        comm.Parameters.AddWithValue("@idVenta", 0);
                        comm.Parameters.AddWithValue("@idProducto", vts.idProducto);
                        comm.Parameters.AddWithValue("@rutCliente", vts.rutCliente);
                        comm.Parameters.AddWithValue("@rutVendedor", vts.rutVendedor);
                        comm.Parameters.AddWithValue("@cantidad", vts.cantidad);
                        comm.Parameters.AddWithValue("@total", vts.total);
                        comm.Parameters.AddWithValue("@fecha", vts.fecha);
                        comm.Parameters.AddWithValue("@tipoVenta", vts.tipoVenta);
                        comm.ExecuteNonQuery();


                    }
                }
                else
                {//+1 en ventas obtener el ultimo id y sumar +1 para un unico id de ventas en temp
                    ventasFacade vt = new ventasFacade();
                    int idultimo = vt.getUltimoIngresadoenVentas();
                    idultimo = idultimo + 1;
                    foreach (var vts in listVentas)
                    {
                        string consultinsert = "INSERT INTO venta(idVenta,idProducto, rutCliente, rutVendedor,cantidad, total,fecha,tipoVenta) VALUES (@idVenta,@idProducto, @rutCliente, @rutVendedor,@cantidad, @total,@fecha,@tipoVenta)";
                        MySqlCommand comm = new MySqlCommand(consultinsert, getconexion.getConexion());
                        //long id = comm.LastInsertedId;
                        //id = id + 1;
                        comm.Parameters.AddWithValue("@idVenta", idultimo);
                        comm.Parameters.AddWithValue("@idProducto", vts.idProducto);
                        comm.Parameters.AddWithValue("@rutCliente", vts.rutCliente);
                        comm.Parameters.AddWithValue("@rutVendedor", vts.rutVendedor);
                        comm.Parameters.AddWithValue("@cantidad", vts.cantidad);
                        comm.Parameters.AddWithValue("@total", vts.total);
                        comm.Parameters.AddWithValue("@fecha", vts.fecha);
                        comm.Parameters.AddWithValue("@tipoVenta", vts.tipoVenta);
                        comm.ExecuteNonQuery();


                    }
                }





                getconexion.CerrarConexion();

                //guardar = true;
            }
            catch (Exception e)
            {
                //guardar = false;
                i = e.ToString();

            }
            finally
            {
                getconexion.CerrarConexion();

            }
            return i;

        }
Ejemplo n.º 5
0
        private void btnReporteMes_Click(object sender, RoutedEventArgs e)
        {
            if (!lfechareporte.Content.Equals(""))
            {
                if (!lventasMes.Content.Equals("0"))
                {
                    DateTime date = Convert.ToDateTime(lfechareporte.Content);
                    //MessageBox.Show(date.Month.ToString() + "/" + date.Year.ToString());
                    ventasFacade vfac = new ventasFacade();
                    List<MVentas> listVentasMes = vfac.getVentasByFechaMes(date);

                    if (listVentasMes.Count > 0)
                    {
                        SaveFileDialog exportSaveFileDialog = new SaveFileDialog();

                        exportSaveFileDialog.Title = "Guardar reporte ventas mensuales";
                        exportSaveFileDialog.Filter = "PDF(*.pdf)|*.pdf";
                        exportSaveFileDialog.FileName = "ReporteVentasMensuales";
                        exportSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        if (exportSaveFileDialog.ShowDialog() == true)
                        {
                            // Creamos el documento con el tamaño de página tradicional
                            Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50);
                            PdfWriter writer = null;
                            // Indicamos donde vamos a guardar el documento
                            try
                            {
                                writer = PdfWriter.GetInstance(doc, new FileStream(exportSaveFileDialog.FileName, FileMode.Create));
                                doc.AddCreator("Magnolia");
                                doc.Open();
                                iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlLogo, System.Drawing.Imaging.ImageFormat.Png);
                                imagen.Alignment = Element.ALIGN_CENTER;
                                imagen.ScaleToFit(120f, 120f);
                                doc.Add(imagen);
                                doc.Add(Chunk.NEWLINE);

                                iTextSharp.text.Font _fontTitulo = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 25, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph("Reporte de ventas mensual");
                                titulo.Alignment = Element.ALIGN_CENTER;
                                titulo.Font = _fontTitulo;
                                doc.Add(titulo);
                                doc.Add(Chunk.NEWLINE);

                                iTextSharp.text.Paragraph dgeneral = new iTextSharp.text.Paragraph("Detalles general");
                                dgeneral.Alignment = Element.ALIGN_LEFT;

                                //doc.AddTitle("Reporte de MVentas");
                                iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                //////////////////////////////////////
                                ///////Tabla especificos    //////////
                                /////////////////////////////////////
                                iTextSharp.text.Paragraph despecifico = new iTextSharp.text.Paragraph("Detalles Especificos");
                                despecifico.Alignment = Element.ALIGN_LEFT;

                                // doc.Add(Chunk.NEWLINE);

                                categoriaFacade catFacEsp = new categoriaFacade();
                                ProductoFacade prodFacEsp = new ProductoFacade();
                                ventasFacade ventasFacEsp = new ventasFacade();
                                PdfPTable tblEspecifico = new PdfPTable(5);

                                string tempIdpro = "";

                                int dineroTotalbyCat = 0;
                                List<MVentas> listProductosinCatniInfoProd = new List<MVentas>();
                                List<MVentas> listProductoConCategoria = new List<MVentas>();

                                foreach (var item in listVentasMes)
                                {
                                    if (!tempIdpro.Equals(item.idProducto))
                                    {
                                        string IDCategoria = prodFacEsp.getIdCatbyidProd(item.idProducto);

                                        if (string.IsNullOrEmpty(IDCategoria))
                                        {
                                            //MessageBox.Show(item.idProducto + ":Sin categoria");
                                            //Agregar en celda distinta para obtener el total, no tienen categoria porque posiblemente se borra una categoria durante el mes o tiempo de uso.
                                            //Sin nombre de producto  ni categoria
                                            List<MVentas> listventaAgrupadabyFecha = ventasFacEsp.getVentasbyIdProdSinNombreGroupByFecha(item.idProducto, date);
                                            foreach (var i in listventaAgrupadabyFecha)
                                            {
                                                MVentas sinInfo = new MVentas(i.fecha, i.idProducto, i.nombreProducto, i.cantidad, i.total, i.idCategoria);
                                                bool exists = listProductosinCatniInfoProd.Any(x => x.fecha == sinInfo.fecha && x.idProducto == sinInfo.idProducto);
                                                if (!exists)
                                                {
                                                    listProductosinCatniInfoProd.Add(sinInfo);
                                                }

                                            }

                                            // existeSinCategoria = true;

                                        }
                                        else
                                        {
                                            //Con nombre de producto pero sin categoria
                                            string NombreCat = catFacEsp.getNombreCategoriaById(IDCategoria);
                                            if (string.IsNullOrEmpty(NombreCat))
                                            {

                                                List<MVentas> listventaAgrupadabyFecha = ventasFacEsp.getVentasbyIdProdGroupByFecha(item.idProducto, date);
                                                foreach (var i in listventaAgrupadabyFecha)
                                                {
                                                    MVentas sinInfo = new MVentas(i.fecha, i.idProducto, i.nombreProducto, i.cantidad, i.total, i.idCategoria);
                                                    listProductosinCatniInfoProd.Add(sinInfo);
                                                }

                                            }
                                            else
                                            {

                                                /*Agrupar por categoria los idproducto
                                                  Obtener todas las id categoria para obtener idprodudcto y buscar por idproducto en ventas 
                                                 * si no encuentra idproducto en ventas categoria no ha tenido ventas
                                                 * */
                                                //Obtiene el cantidadTotal , dineroTotal recaudado para producto agrupado por fecha
                                                List<MVentas> listVentaPorIdprod = ventasFacEsp.getVentasbyIdProdGroupByFecha(item.idProducto, date);
                                                foreach (var v in listVentaPorIdprod)
                                                {
                                                    //idcategoria que sera igual para distinto idproducto
                                                    MVentas ConInfo = new MVentas(v.fecha, v.idProducto, v.nombreProducto, v.cantidad, v.total, v.idCategoria);
                                                    bool exists = listProductoConCategoria.Any(x => x.fecha == ConInfo.fecha && x.idProducto == ConInfo.idProducto && x.idCategoria == ConInfo.idCategoria);
                                                    if (!exists)
                                                    {
                                                        listProductoConCategoria.Add(ConInfo);


                                                    }

                                                }

                                            }
                                        }
                                    }

                                }
                                //LLenar tabla especifico 
                                PdfPCell clFechaEsp = new PdfPCell();
                                PdfPCell clidprod = new PdfPCell();
                                PdfPCell clnombreprod = new PdfPCell();
                                PdfPCell clCant = new PdfPCell();
                                PdfPCell cltotalEsp = new PdfPCell();

                                listProductoConCategoria = listProductoConCategoria.OrderByDescending(i => i.idCategoria).ToList();

                                var q = from x in listProductoConCategoria
                                        group x.idCategoria by x.idCategoria into g
                                        let count = g.Count()
                                        /*orderby count descending*/
                                        select new { Value = g.Key, Count = count };


                                int posList = 0;
                                foreach (var x in q)
                                {
                                    tblEspecifico.WidthPercentage = 100;
                                    tblEspecifico.HorizontalAlignment = Element.ALIGN_LEFT;
                                    PdfPCell clnombreCat = new PdfPCell(new Phrase(catFacEsp.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                    clnombreCat.Colspan = 2;
                                    PdfPCell h1 = new PdfPCell(new Phrase(""));
                                    PdfPCell h2 = new PdfPCell(new Phrase(""));
                                    PdfPCell h3 = new PdfPCell(new Phrase(""));
                                    h1.Border = 0;
                                    h2.Border = 0;
                                    h3.Border = 0;
                                    tblEspecifico.AddCell(clnombreCat);
                                    tblEspecifico.AddCell(h1);
                                    tblEspecifico.AddCell(h2);
                                    tblEspecifico.AddCell(h3);

                                    clFechaEsp = new PdfPCell(new Phrase("Fecha", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("Nombre", _standardFont));
                                    clCant = new PdfPCell(new Phrase("Cantidad", _standardFont));
                                    //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase("Total", _standardFont));

                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);

                                    for (int i = 0; i < x.Count; i++)
                                    {
                                        var v = listProductoConCategoria[posList];

                                        clFechaEsp = new PdfPCell(new Phrase(v.fecha.ToString("d"), _standardFont));
                                        //clidprod = new PdfPCell(new Phrase(x.Value.ToString(), _standardFont));
                                        clidprod = new PdfPCell(new Phrase(v.idProducto.ToString(), _standardFont));

                                        //clnombreprod = new PdfPCell(new Phrase(v.idCategoria.ToString() + ":" + v.nombreProducto, _standardFont));
                                        clnombreprod = new PdfPCell(new Phrase(v.nombreProducto.ToString(), _standardFont));
                                        //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                        clCant = new PdfPCell(new Phrase(v.cantidad.ToString(), _standardFont));
                                        //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                        cltotalEsp = new PdfPCell(new Phrase(v.total.ToString(), _standardFont));

                                        tblEspecifico.AddCell(clFechaEsp);
                                        tblEspecifico.AddCell(clidprod);
                                        tblEspecifico.AddCell(clnombreprod);
                                        tblEspecifico.AddCell(clCant);
                                        //tblEspecifico.AddCell(clTipoPag);
                                        tblEspecifico.AddCell(cltotalEsp);
                                        dineroTotalbyCat = dineroTotalbyCat + Convert.ToInt32(v.total);
                                        tempIdpro = v.idProducto;
                                        posList = posList + 1;
                                    }
                                    //#################################
                                    //en cada categoria 
                                    //#################################
                                    clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                    clCant = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase(dineroTotalbyCat.ToString(), _standardFont));
                                    dineroTotalbyCat = 0;

                                    clFechaEsp.Border = 0;
                                    clidprod.Border = 0;
                                    clnombreprod.Border = 0;
                                    clCant.Border = 1;
                                    cltotalEsp.Border = 1;



                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);


                                    /////////////////////////////////////////////
                                    clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                    clCant = new PdfPCell(new Phrase("", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp = new PdfPCell(new Phrase("", _standardFont));
                                    clFechaEsp.Border = 0;
                                    clidprod.Border = 0;
                                    clnombreprod.Border = 0;
                                    clCant.Border = 0;
                                    cltotalEsp.Border = 0;

                                    cltotalEsp.FixedHeight = 30f;
                                    clFechaEsp.FixedHeight = 30f;
                                    clidprod.FixedHeight = 30f;
                                    clnombreprod.FixedHeight = 30f;
                                    clCant.FixedHeight = 30f;
                                    cltotalEsp.FixedHeight = 30f;

                                    tblEspecifico.AddCell(clFechaEsp);
                                    tblEspecifico.AddCell(clidprod);
                                    tblEspecifico.AddCell(clnombreprod);
                                    tblEspecifico.AddCell(clCant);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblEspecifico.AddCell(cltotalEsp);
                                    //}
                                    // catActual = prodFac.getIdCatbyidProd(v.idProducto);
                                    //MessageBox.Show(catActual);


                                }


                                //#######################################################
                                //###### PRODUCTOS QUE SE HALLAN ELIMINADO ############
                                //#######################################################
                                //Tabla para tabla otros que no tengan una categoria asociada pero que igualmente deben estar en reportes de ventas.
                                bool otros = false;
                                PdfPTable tblOtros = new PdfPTable(5);
                                int totalOtros = 0;
                                int subtotalCosto_otros = 0;
                                int totalCosto_otros = 0;
                                int diferenciaVenta_otros = 0;
                                int totalDiferencia_otros = 0;
                                if (listProductosinCatniInfoProd.Count > 0)
                                {
                                    otros = true;
                                    tblOtros.WidthPercentage = 100;
                                    tblOtros.HorizontalAlignment = Element.ALIGN_LEFT;
                                    PdfPCell clnombreCat_otros = new PdfPCell(new Phrase("Otros", _standardFont));
                                    clnombreCat_otros.Colspan = 2;
                                    PdfPCell h11 = new PdfPCell(new Phrase(""));
                                    PdfPCell h22 = new PdfPCell(new Phrase(""));
                                    PdfPCell h33 = new PdfPCell(new Phrase(""));
                                    h11.Border = 0;
                                    h22.Border = 0;
                                    h33.Border = 0;
                                    tblOtros.AddCell(clnombreCat_otros);
                                    tblOtros.AddCell(h11);
                                    tblOtros.AddCell(h22);
                                    tblOtros.AddCell(h33);

                                    PdfPCell clFechaEsp_otros = new PdfPCell(new Phrase("Fecha", _standardFont));
                                    PdfPCell clidprod_otros = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                    PdfPCell clnombreprod_otros = new PdfPCell(new Phrase("Nombre", _standardFont));
                                    PdfPCell clCant_otros = new PdfPCell(new Phrase("Cantidad", _standardFont));

                                    //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                    PdfPCell cltotalEsp_otros = new PdfPCell(new Phrase("Total", _standardFont));

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);


                                    foreach (var item in listProductosinCatniInfoProd)
                                    {
                                        clFechaEsp_otros = new PdfPCell(new Phrase(item.fecha.ToString("d"), _standardFont));
                                        clidprod_otros = new PdfPCell(new Phrase(item.idProducto, _standardFont));

                                        clnombreprod_otros = new PdfPCell(new Phrase(item.nombreProducto, _standardFont));
                                        //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                        clCant_otros = new PdfPCell(new Phrase(item.cantidad.ToString(), _standardFont));
                                        //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                        cltotalEsp_otros = new PdfPCell(new Phrase(item.total.ToString(), _standardFont));

                                        tblOtros.AddCell(clFechaEsp_otros);
                                        tblOtros.AddCell(clidprod_otros);
                                        tblOtros.AddCell(clnombreprod_otros);
                                        tblOtros.AddCell(clCant_otros);
                                        //tblEspecifico.AddCell(clTipoPag);
                                        tblOtros.AddCell(cltotalEsp_otros);
                                        totalOtros = totalOtros + Convert.ToInt32(item.total);

                                        if (string.IsNullOrEmpty(prodFacEsp.getPrecioCompraProducto(item.idProducto).ToString()))
                                        {
                                            subtotalCosto_otros = 0;
                                        }
                                        else
                                        {
                                            subtotalCosto_otros = item.cantidad * prodFacEsp.getPrecioCompraProducto(item.idProducto);
                                        }
                                        //MessageBox.Show("idProducto=" + item.idProducto);
                                        totalCosto_otros = totalCosto_otros + subtotalCosto_otros;
                                        diferenciaVenta_otros = totalOtros - subtotalCosto_otros; //subtotalCosto_otros - totalCosto_otros;
                                        totalDiferencia_otros = totalDiferencia_otros + diferenciaVenta_otros;


                                    }


                                    clFechaEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clCant_otros = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp_otros = new PdfPCell(new Phrase(totalOtros.ToString(), _standardFont));
                                    clFechaEsp_otros.Border = 0;
                                    clidprod_otros.Border = 0;
                                    clnombreprod_otros.Border = 0;
                                    clCant_otros.Border = 1;
                                    cltotalEsp_otros.Border = 1;

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);
                                    clFechaEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clidprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clnombreprod_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clCant_otros = new PdfPCell(new Phrase("", _standardFont));
                                    //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                    cltotalEsp_otros = new PdfPCell(new Phrase("", _standardFont));
                                    clFechaEsp_otros.Border = 0;
                                    clidprod_otros.Border = 0;
                                    clnombreprod_otros.Border = 0;
                                    clCant_otros.Border = 0;
                                    cltotalEsp_otros.Border = 0;

                                    cltotalEsp_otros.FixedHeight = 50f;
                                    clFechaEsp_otros.FixedHeight = 50f;
                                    clidprod_otros.FixedHeight = 50f;
                                    clnombreprod_otros.FixedHeight = 50f;
                                    clCant_otros.FixedHeight = 50f;
                                    cltotalEsp_otros.FixedHeight = 50f;

                                    tblOtros.AddCell(clFechaEsp_otros);
                                    tblOtros.AddCell(clidprod_otros);
                                    tblOtros.AddCell(clnombreprod_otros);
                                    tblOtros.AddCell(clCant_otros);
                                    //tblEspecifico.AddCell(clTipoPag);
                                    tblOtros.AddCell(cltotalEsp_otros);

                                }

                                //#######################################################
                                //######            DETALLES GENERALES       ############
                                //#######################################################

                                PdfPTable tblGenerales = new PdfPTable(5);
                                //doc.SetMargins(0f, 0f, 0f, 0f);
                                tblGenerales.HorizontalAlignment = Element.ALIGN_LEFT;
                                // Configuramos el título de las columnas de la tabla
                                PdfPCell clFecha = new PdfPCell(new Phrase("Mes", _standardFont));
                                PdfPCell clCat = new PdfPCell(new Phrase("Categoria", _standardFont));
                                PdfPCell clSubtotal = new PdfPCell(new Phrase("Subtotal ventas", _standardFont));
                                PdfPCell clSubtotalCosto = new PdfPCell(new Phrase("Subtotal costo", _standardFont));
                                PdfPCell clDiferencia = new PdfPCell(new Phrase("Diferencia", _standardFont));
                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);

                                categoriaFacade catFac = new categoriaFacade();
                                ProductoFacade prodFac = new ProductoFacade();

                                int subtotal = 0;
                                int total = 0;
                                int posListG = 0;
                                int subtotalCosto = 0;
                                int totalCosto = 0;
                                int totalCostoVenta = 0;
                                int diferenciaVenta = 0;
                                int totalDiferencia = 0;

                                //Agrupar por categoria los idproducto
                                List<MVentas> ListcatGeneral = new List<MVentas>();
                                foreach (var x in q)
                                {
                                    for (int i = 0; i < x.Count; i++)
                                    {
                                        var v = listProductoConCategoria[posListG];


                                        subtotal = subtotal + Convert.ToInt32(v.total);
                                        subtotalCosto = v.cantidad * prodFac.getPrecioCompraProducto(v.idProducto);
                                        posListG = posListG + 1;
                                        totalCosto = totalCosto + subtotalCosto;
                                        diferenciaVenta = subtotal - totalCosto;
                                        totalDiferencia = totalDiferencia + diferenciaVenta;
                                        //gananciaReal = gananciaReal + totalDiferencia;

                                    }
                                    total = total + subtotal;
                                    clFecha = new PdfPCell(new Phrase(date.ToString("y"), _standardFont));
                                    clCat = new PdfPCell(new Phrase(catFac.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                    clSubtotal = new PdfPCell(new Phrase(subtotal.ToString(), _standardFont));
                                    clSubtotalCosto = new PdfPCell(new Phrase(subtotalCosto.ToString(), _standardFont));
                                    clDiferencia = new PdfPCell(new Phrase(diferenciaVenta.ToString(), _standardFont));
                                    tblGenerales.AddCell(clFecha);
                                    tblGenerales.AddCell(clCat);
                                    tblGenerales.AddCell(clSubtotal);
                                    tblGenerales.AddCell(clSubtotalCosto);
                                    tblGenerales.AddCell(clDiferencia);
                                    subtotal = 0;
                                    subtotalCosto = 0;
                                    diferenciaVenta = 0;
                                    totalCostoVenta = totalCostoVenta + totalCosto;
                                    totalCosto = 0;

                                }
                                if (otros)
                                {
                                    clFecha = new PdfPCell(new Phrase(date.ToString("y"), _standardFont));
                                    clCat = new PdfPCell(new Phrase("Otros", _standardFont));
                                    clSubtotal = new PdfPCell(new Phrase(totalOtros.ToString(), _standardFont));
                                    clSubtotalCosto = new PdfPCell(new Phrase(subtotalCosto_otros.ToString(), _standardFont));
                                    clDiferencia = new PdfPCell(new Phrase(diferenciaVenta_otros.ToString(), _standardFont));
                                    tblGenerales.AddCell(clFecha);
                                    tblGenerales.AddCell(clCat);
                                    tblGenerales.AddCell(clSubtotal);
                                    tblGenerales.AddCell(clSubtotalCosto);
                                    tblGenerales.AddCell(clDiferencia);
                                    total = total + totalOtros;

                                    subtotalCosto = subtotalCosto + totalCosto_otros;
                                    totalCosto = totalCosto + subtotalCosto;
                                    totalDiferencia = totalDiferencia + diferenciaVenta_otros;
                                    totalCostoVenta = totalCostoVenta + totalCosto_otros;
                                    //diferenciaVenta_otros = diferenciaVenta + diferenciaVenta_otros;
                                    //totalDiferencia_otros = totalDiferencia + diferenciaVenta_otros;
                                }

                                clFecha = new PdfPCell(new Phrase("", _standardFont));
                                clCat = new PdfPCell(new Phrase("Total ", _standardFont));
                                clSubtotal = new PdfPCell(new Phrase(total.ToString(), _standardFont));
                                clSubtotalCosto = new PdfPCell(new Phrase(totalCostoVenta.ToString(), _standardFont));
                                clDiferencia = new PdfPCell(new Phrase("", _standardFont));

                                clFecha.Border = 0;
                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);

                                //Ganancia Real

                                clFecha = new PdfPCell(new Phrase("", _standardFont));
                                clCat = new PdfPCell(new Phrase("", _standardFont));
                                clSubtotal = new PdfPCell(new Phrase("", _standardFont));
                                clSubtotalCosto = new PdfPCell(new Phrase("Ganancia Real", _standardFont));
                                clDiferencia = new PdfPCell(new Phrase(totalDiferencia.ToString(), _standardFont));

                                clFecha.Border = 0;
                                clCat.Border = 0;
                                clSubtotal.Border = 0;

                                tblGenerales.AddCell(clFecha);
                                tblGenerales.AddCell(clCat);
                                tblGenerales.AddCell(clSubtotal);
                                tblGenerales.AddCell(clSubtotalCosto);
                                tblGenerales.AddCell(clDiferencia);


                                int vtotales = listVentasMes.Count;
                                iTextSharp.text.Font _fontDe = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                                iTextSharp.text.Paragraph ventasTotal = new iTextSharp.text.Paragraph("Total Ventas:" + vtotales.ToString(), _fontDe);
                                int efectivo = ventasFacEsp.getVentasByFechaMesPagoEfectivo(date);
                                int cuenta = ventasFacEsp.getVentasByFechaMesPagocuenta(date);
                                int debito = ventasFacEsp.getVentasByFechaMesPagodebito(date);
                                int cheque = ventasFacEsp.getVentasByFechaMesPagoCheque(date);
                                iTextSharp.text.Paragraph pago = new iTextSharp.text.Paragraph("Pago: Efectivo:" + efectivo.ToString() + "  Cuenta:" + cuenta.ToString() + "  Debito:" + debito.ToString() + "  Cheque:" + cheque.ToString(), _fontDe);
                                ventasTotal.Alignment = Element.ALIGN_LEFT;
                                if (otros)
                                {


                                    doc.Add(dgeneral);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(tblGenerales);
                                    doc.Add(ventasTotal);
                                    doc.Add(pago);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(despecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblEspecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblOtros);

                                }
                                else
                                {

                                    doc.Add(dgeneral);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(tblGenerales);
                                    doc.Add(ventasTotal);
                                    doc.Add(pago);
                                    doc.Add(Chunk.NEWLINE);
                                    doc.Add(despecifico);
                                    doc.Add(new Chunk("\n"));
                                    doc.Add(tblEspecifico);
                                    doc.Add(new Chunk("\n"));
                                }

                                int page = writer.PageNumber;
                                //iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(page.ToString(), _standardFont);
                                //doc.Add(p);

                                doc.Close();
                                writer.Close();

                                //MessageBox.Show("Pdf Creado!");
                            }
                            // }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                doc.Close();
                                writer.Close();
                            }
                            System.Diagnostics.Process.Start(exportSaveFileDialog.FileName);
                        }


                    }
                    else
                    {
                        MessageBox.Show("Mes no ha tenido ventas", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }


                }
                else
                {
                    MessageBox.Show("Mes no ha tenido ventas", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Seleccionar fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }
Ejemplo n.º 6
0
        private void btnproductosXrubro_Click(object sender, RoutedEventArgs e)
        {

            categoriaFacade catFac1 = new categoriaFacade();

            int hay = catFac1.getTotalCategoriabyMes(MesRubroProd);
            if (!string.IsNullOrEmpty(month))
            {
                if (hay > 0)
                {

                    //buscar productos que fueron ingresados o modificados dentro de la fecha indicada
                    ProductoFacade prodFac = new ProductoFacade();
                    List<Producto> listProductoMes = prodFac.getALLProductosbyFechaMes(Convert.ToDateTime(month));
                    //MessageBox.Show(listProductoMes.Count.ToString());
                    //categorizar productos y obtener total de costo de compra en reporte

                    if (listProductoMes.Count > 0)
                    {
                        SaveFileDialog exportSaveFileDialog = new SaveFileDialog();
                        exportSaveFileDialog.Title = "Guardar reporte de costo para productos adquiridos";
                        exportSaveFileDialog.Filter = "PDF(*.pdf)|*.pdf";
                        exportSaveFileDialog.FileName = "ReporteCostoProdAdquiridos";
                        exportSaveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        if (exportSaveFileDialog.ShowDialog() == true)
                        {

                            string tempIdpro = "";

                            int dineroTotalbyCat = 0;
                            List<Producto> listProductoConCategoria = listProductoMes;

                            foreach (var item in listProductoMes)
                            {
                                if (!tempIdpro.Equals(item.idProducto))
                                {

                                    Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50);
                                    PdfWriter writer = null;
                                    // Indicamos donde vamos a guardar el documento
                                    try
                                    {
                                        writer = PdfWriter.GetInstance(doc, new FileStream(exportSaveFileDialog.FileName, FileMode.Create));
                                        doc.AddCreator("Magnolia");
                                        doc.Open();
                                        iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(urlLogo, System.Drawing.Imaging.ImageFormat.Png);
                                        imagen.Alignment = Element.ALIGN_CENTER;
                                        imagen.ScaleToFit(120f, 120f);
                                        doc.Add(imagen);
                                        doc.Add(Chunk.NEWLINE);

                                        iTextSharp.text.Font _fontTitulo = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 25, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                        iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph("Reporte de costo ventas mensuales");
                                        titulo.Alignment = Element.ALIGN_CENTER;
                                        titulo.Font = _fontTitulo;
                                        doc.Add(titulo);
                                        doc.Add(Chunk.NEWLINE);

                                        iTextSharp.text.Paragraph dgeneral = new iTextSharp.text.Paragraph("Detalles general");
                                        dgeneral.Alignment = Element.ALIGN_LEFT;

                                        //doc.AddTitle("Reporte de MVentas");
                                        iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);


                                        //////////////////////////////////////
                                        ///////Tabla especificos    //////////
                                        /////////////////////////////////////

                                        categoriaFacade catFacEsp = new categoriaFacade();
                                        ProductoFacade prodFacEsp = new ProductoFacade();
                                        ventasFacade ventasFacEsp = new ventasFacade();
                                        PdfPTable tblEspecifico = new PdfPTable(5);

                                        iTextSharp.text.Paragraph despecifico = new iTextSharp.text.Paragraph("Detalles Especificos");
                                        despecifico.Alignment = Element.ALIGN_LEFT;
                                        //LLenar tabla especifico 
                                        PdfPCell clFechaEsp = new PdfPCell();
                                        //PdfPCell clidprod = new PdfPCell();
                                        PdfPCell clnombreprod = new PdfPCell();
                                        PdfPCell clPrecioReal = new PdfPCell();
                                        PdfPCell clCant = new PdfPCell();
                                        PdfPCell cltotalEsp = new PdfPCell();

                                        listProductoConCategoria = listProductoConCategoria.OrderByDescending(i => i.idCategoria).ToList();
                                        //MessageBox.Show("TotalProductos:" + listProductoConCategoria.Count().ToString());
                                        var q = from x in listProductoConCategoria
                                                group x.idCategoria by x.idCategoria into g
                                                let count = g.Count()
                                                /*orderby count descending*/
                                                select new { Value = g.Key, Count = count };


                                        int posList = 0;
                                        foreach (var x in q)
                                        {
                                            tblEspecifico.WidthPercentage = 100;
                                            tblEspecifico.HorizontalAlignment = Element.ALIGN_LEFT;
                                            PdfPCell clnombreCat = new PdfPCell(new Phrase(catFacEsp.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                            clnombreCat.Colspan = 2;
                                            PdfPCell h1 = new PdfPCell(new Phrase(""));
                                            PdfPCell h2 = new PdfPCell(new Phrase(""));
                                            PdfPCell h3 = new PdfPCell(new Phrase(""));
                                            h1.Border = 0;
                                            h2.Border = 0;
                                            h3.Border = 0;
                                            tblEspecifico.AddCell(clnombreCat);
                                            tblEspecifico.AddCell(h1);
                                            tblEspecifico.AddCell(h2);
                                            tblEspecifico.AddCell(h3);

                                            clFechaEsp = new PdfPCell(new Phrase("Fecha", _standardFont));
                                            //clidprod = new PdfPCell(new Phrase("IDProducto", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("Nombre", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("Precio Compra", _standardFont));
                                            clCant = new PdfPCell(new Phrase("Stock", _standardFont));
                                            //PdfPCell clTipoPag = new PdfPCell(new Phrase("Tipo Pago", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase("Total", _standardFont));

                                            tblEspecifico.AddCell(clFechaEsp);
                                            // tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);

                                            for (int i = 0; i < x.Count; i++)
                                            {
                                                var v = listProductoConCategoria[posList];

                                                clFechaEsp = new PdfPCell(new Phrase(v.fecha.ToString("y"), _standardFont));
                                                //clidprod = new PdfPCell(new Phrase(x.Value.ToString(), _standardFont));
                                                // clidprod = new PdfPCell(new Phrase(v.idProducto.ToString(), _standardFont));

                                                //clnombreprod = new PdfPCell(new Phrase(v.idCategoria.ToString() + ":" + v.nombreProducto, _standardFont));
                                                clnombreprod = new PdfPCell(new Phrase(v.nombre.ToString(), _standardFont));
                                                //clnombreprod= new PdfPCell(new Phrase(prodFacEsp.getnombreProdbyidProd(v.idProducto), _standardFont));
                                                clPrecioReal = new PdfPCell(new Phrase(v.precioReal.ToString(), _standardFont));
                                                clCant = new PdfPCell(new Phrase(v.stock.ToString(), _standardFont));
                                                //clTipoPag = new PdfPCell(new Phrase("", _standardFont));
                                                cltotalEsp = new PdfPCell(new Phrase(v.total.ToString(), _standardFont));

                                                tblEspecifico.AddCell(clFechaEsp);
                                                //tblEspecifico.AddCell(clidprod);
                                                tblEspecifico.AddCell(clnombreprod);
                                                tblEspecifico.AddCell(clPrecioReal);
                                                tblEspecifico.AddCell(clCant);
                                                //tblEspecifico.AddCell(clTipoPag);
                                                tblEspecifico.AddCell(cltotalEsp);
                                                dineroTotalbyCat = dineroTotalbyCat + v.total;
                                                tempIdpro = v.idProducto;
                                                posList = posList + 1;
                                            }
                                            //#################################
                                            //en cada categoria 
                                            //#################################
                                            clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                            ////clidprod = new PdfPCell(new Phrase("", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("", _standardFont));
                                            clCant = new PdfPCell(new Phrase("Subtotal($)", _standardFont));
                                            //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase(dineroTotalbyCat.ToString(), _standardFont));
                                            dineroTotalbyCat = 0;

                                            clFechaEsp.Border = 0;
                                            // clidprod.Border = 0;
                                            clnombreprod.Border = 0;
                                            clPrecioReal.Border = 0;
                                            clCant.Border = 1;
                                            cltotalEsp.Border = 1;



                                            tblEspecifico.AddCell(clFechaEsp);
                                            //tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);


                                            /////////////////////////////////////////////
                                            clFechaEsp = new PdfPCell(new Phrase("", _standardFont));
                                            //clidprod = new PdfPCell(new Phrase("", _standardFont));
                                            clnombreprod = new PdfPCell(new Phrase("", _standardFont));
                                            clCant = new PdfPCell(new Phrase("", _standardFont));
                                            clPrecioReal = new PdfPCell(new Phrase("", _standardFont));
                                            //clTipoPag = new PdfPCell(new Phrase("-----------", _standardFont));
                                            cltotalEsp = new PdfPCell(new Phrase("", _standardFont));
                                            clFechaEsp.Border = 0;
                                            //clidprod.Border = 0;
                                            clnombreprod.Border = 0;
                                            clPrecioReal.Border = 0;
                                            clCant.Border = 0;
                                            cltotalEsp.Border = 0;

                                            cltotalEsp.FixedHeight = 30f;
                                            clFechaEsp.FixedHeight = 30f;
                                            // clidprod.FixedHeight = 30f;
                                            clnombreprod.FixedHeight = 30f;
                                            clPrecioReal.FixedHeight = 30f;
                                            clCant.FixedHeight = 30f;
                                            cltotalEsp.FixedHeight = 30f;

                                            tblEspecifico.AddCell(clFechaEsp);
                                            // tblEspecifico.AddCell(clidprod);
                                            tblEspecifico.AddCell(clnombreprod);
                                            tblEspecifico.AddCell(clPrecioReal);
                                            tblEspecifico.AddCell(clCant);
                                            //tblEspecifico.AddCell(clTipoPag);
                                            tblEspecifico.AddCell(cltotalEsp);

                                        }
                                        //#######################################################
                                        //######            DETALLES GENERALES       ############
                                        //#######################################################

                                        PdfPTable tblGenerales = new PdfPTable(3);
                                        //doc.SetMargins(0f, 0f, 0f, 0f);
                                        tblGenerales.HorizontalAlignment = Element.ALIGN_LEFT;
                                        // Configuramos el título de las columnas de la tabla
                                        PdfPCell clFecha = new PdfPCell(new Phrase("Mes", _standardFont));
                                        PdfPCell clCat = new PdfPCell(new Phrase("Categoria", _standardFont));
                                        PdfPCell clSubtotal = new PdfPCell(new Phrase("Subtotal", _standardFont));
                                        tblGenerales.AddCell(clFecha);
                                        tblGenerales.AddCell(clCat);
                                        tblGenerales.AddCell(clSubtotal);

                                        categoriaFacade catFac = new categoriaFacade();


                                        int subtotal = 0;
                                        int total = 0;
                                        int posListG = 0;
                                        //Agrupar por categoria los idproducto

                                        foreach (var x in q)
                                        {
                                            for (int i = 0; i < x.Count; i++)
                                            {
                                                var v = listProductoConCategoria[posListG];


                                                subtotal = subtotal + v.total;
                                                posListG = posListG + 1;
                                            }
                                            total = total + subtotal;
                                            clFecha = new PdfPCell(new Phrase(Convert.ToDateTime(month).ToString("y"), _standardFont));
                                            clCat = new PdfPCell(new Phrase(catFac.getNombreCategoriaById(x.Value.ToString()), _standardFont));
                                            clSubtotal = new PdfPCell(new Phrase(subtotal.ToString(), _standardFont));
                                            tblGenerales.AddCell(clFecha);
                                            tblGenerales.AddCell(clCat);
                                            tblGenerales.AddCell(clSubtotal);
                                            subtotal = 0;
                                        }


                                        clFecha = new PdfPCell(new Phrase("", _standardFont));
                                        clCat = new PdfPCell(new Phrase("Total Costo  Producto Adquiridos", _standardFont));
                                        clSubtotal = new PdfPCell(new Phrase(total.ToString(), _standardFont));

                                        clFecha.Border = 0;
                                        tblGenerales.AddCell(clFecha);
                                        tblGenerales.AddCell(clCat);
                                        tblGenerales.AddCell(clSubtotal);



                                        doc.Add(dgeneral);
                                        doc.Add(Chunk.NEWLINE);
                                        doc.Add(tblGenerales);
                                        doc.Add(Chunk.NEWLINE);
                                        doc.Add(despecifico);
                                        doc.Add(new Chunk("\n"));
                                        doc.Add(tblEspecifico);
                                        doc.Add(new Chunk("\n"));






                                        doc.Close();
                                        writer.Close();




                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.ToString());
                                    }
                                    finally
                                    {
                                        doc.Close();
                                        writer.Close();
                                    }

                                }

                            }
                            System.Diagnostics.Process.Start(exportSaveFileDialog.FileName);
                        }




                    }
                    else
                    {
                        MessageBox.Show("No hay Productos ingresados", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Seleccionar mes para generar reporte", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 7
0
        private void btnDevolver_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (datagridVentas.Items.Count > 0)
                {
                    if (datagridVentas.SelectedItem != null)
                    {
                        var row = GetDataGridRows(datagridVentas);
                        if (row != null)
                        {
                            VentaTemporal rv=new VentaTemporal();
                            foreach (DataGridRow r in row)
                            {
                                 rv = (VentaTemporal)r.Item;
                            }
                                int difDevo = Convert.ToInt32(rv.cantidad) - Convert.ToInt32(rv.devolver);
                                //MessageBox.Show("dif:" + difDevo.ToString());
                                if (difDevo == 0)
                                {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                    int sumStock = Convert.ToInt32(rv.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(rv.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(borrar))
                                    {
                                        MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion ingresada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        txtidventa.Text = "";
                                        txtidProducto.Text = "";
                                        fechaventa.Text = "";
                                        venta.Clear();
                                        datagridVentas.ItemsSource = venta;
                                        ltotal.Content = "0";
                                        Valor = 1;
                                        this.Close();
                                    }
                                }
                                else
                                {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                    int sumStock = Convert.ToInt32(rv.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(rv.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text), difDevo, difDevo * Convert.ToInt32(rv.precio));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(actVenta))
                                    {
                                        MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion ingresada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        txtidventa.Text = "";
                                        txtidProducto.Text = "";
                                        fechaventa.Text = "";
                                        venta.Clear();
                                        datagridVentas.ItemsSource = venta;
                                        ltotal.Content = "0";
                                        Valor = 1;
                                        this.Close();
                                    }

                                }
                            

                        }
                    }



                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
Ejemplo n.º 8
0
        private void btnBuscarVenta_Click(object sender, RoutedEventArgs e)
        {

            if (txtidventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idventa", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (txtidProducto.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idProducto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (fechaventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar Fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {


                ventasFacade ventFac = new ventasFacade();
                List<MVentas> listaVentaDevolucion = ventFac.getVentasForDevolucion(Convert.ToDouble(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));
                var rows = GetDataGridRows(datagridVentas);
                if (listaVentaDevolucion.Count != 0)
                {
                    venta.Clear();
                    datagridVentas.ItemsSource = venta;
                    //llenar datagridVenta para devoulcion
                    foreach (var item in listaVentaDevolucion)
                    {
                        ProductoFacade prodFobtener = new ProductoFacade();
                        Producto Prod = new Producto();
                        Prod = prodFobtener.getProductosByID(item.idProducto);
                        vtemp = new VentaTemporal(item.idVenta, item.idProducto, Prod.nombre, Prod.precio, item.cantidad.ToString(), "1", item.total.ToString());
                        venta.Add(vtemp);
                        cantidad = cantidad + 1;
                        total = total + Convert.ToInt32(item.total);

                        //ltotal.Content = Prod.precio;
                        ltotal.Content = item.total;
                        TextBoxValue.Text = item.cantidad.ToString();
                    }
                    datagridVentas.ItemsSource = venta;
                }
                else
                {
                    MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }

        }
Ejemplo n.º 9
0
        private void btnPagar_Click(object sender, RoutedEventArgs e)
        {


            int value = cbTipoPago.SelectedIndex;
            List<VentaTemporal> listVentatemporal = new List<VentaTemporal>();
            List<MVentas> listVentas = new List<MVentas>();
            List<Producto> listProducto = new List<Producto>();
            MVentas v = new MVentas();
            string tipopago = "";

            //string rutVendedor = "";

            DateTime fechaactual = DateTime.Now.Date;
            //string fechaactual = f.ToShortDateString();

            if (datagridVentas.Items.Count != 0)
            {
                switch (value)
                {
                    case 0:
                        //MessageBox.Show("efectivo");
                        tipopago = "efectivo";
                        rutcliente = "";
                        break;
                    case 1:
                        //MessageBox.Show("cuenta");
                        tipopago = "cuenta";
                        rutcliente = "";
                        break;
                    case 2:
                        //MessageBox.Show("debito");
                        tipopago = "debito";
                        rutcliente = "";
                        break;
                    case 3:
                        //MessageBox.Show("cheque");
                        /*PagoconCheque pc = new PagoconCheque();
                        pc.ShowDialog();*/

                        //Guardar cheque
                        tipopago = "cheque";

                        //Cheque chequeSave = new Cheque(getCheque.rut, getCheque.nombre, getCheque.nombreBanco, getCheque.fechaemision, getCheque.fechaexpiracion, getCheque.monto);



                        //MessageBox.Show(getCheque.rut);
                        break;
                }
                //Obtener datos de datagrid para guardar
                rutcliente = getCheque.rut;
                var rows = GetDataGridRows(datagridVentas);
                foreach (DataGridRow r in rows)
                {
                    VentaTemporal rv = (VentaTemporal)r.Item;
                    listVentatemporal.Add(rv);
                }
                foreach (var item in listVentatemporal)
                {
                    int p = ToEntero(txttotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                    MVentas vts = new MVentas(item.idVenta, item.idProducto, rutcliente, rutLogin, Convert.ToInt32(item.cantidad), Convert.ToDouble(p), fechaactual, tipopago
                        );
                    listVentas.Add(vts);

                }
                //Guardas lista de ventas

                if (rbtnSi.IsChecked == true)
                {
                    if (!string.IsNullOrEmpty(rutcliente))
                    {
                        //guardar detalles de deuda a cliente  y detalles de venta

                        //actualizar deuda y total de compras 
                        //MessageBox.Show("guardar usuario a fiar");
                        //Agregar registo a cliente de ventas 
                        //actualizar deuda y total de compras
                        clienteFacade clienteFac = new clienteFacade();
                        //MessageBox.Show("rut cliente a fiar:"+rutcliente);
                        int p = ToEntero(txttotal.Text, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));


                        string rActu = clienteFac.actualizar_DFT_Cliente(rutcliente, Convert.ToDouble(p), fechaactual);
                        if (rActu.Equals(""))
                        {
                            MessageBox.Show("Deuda ingresada a usuario:" + nombreCliente + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                            ventasFacade vtfac = new ventasFacade();
                            string resp = vtfac.GuardarVentas(listVentas);

                            if (resp.Equals(""))
                            {
                                int idventaGen = vtfac.getUltimoIngresadoenVentas();
                                MessageBox.Show("Anotar el siguiente idventa para posible devolucion:" + idventaGen.ToString() + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                vendedorFacade vendFac = new vendedorFacade();
                                vendFac.actualizarVentasVend(rutLogin);
                                //Descontar stock en (lista) de producto
                                ProductoFacade prd = new ProductoFacade();
                                foreach (var item in listVentas)
                                {
                                    string res = prd.actualizarStockProducto(item.idProducto.ToString(), item.cantidad.ToString());
                                    if (resp.Equals(""))
                                    {
                                        //MessageBox.Show("stock actualizado:" + item.idProducto);
                                    }
                                }
                                if (!string.IsNullOrEmpty(getCheque.nombre))
                                {
                                    chequeFacade chFac = new chequeFacade();
                                    getCheque = pc.getformCheque();
                                    string rep = chFac.GuardarCheque(getCheque);
                                    if (rep.Equals(""))
                                    {
                                        MessageBox.Show("Detalles cheque guardado", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Error al guardar detalles cheque:" + rep + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                }
                                if (!string.IsNullOrEmpty(ventaTemp.idProducto))
                                {
                                    int difDevo = Convert.ToInt32(ventaTemp.cantidad) - Convert.ToInt32(ventaTemp.devolver);
                                    //MessageBox.Show("dif:" + difDevo.ToString());
                                    if (difDevo == 0)
                                    {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                        int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                        ProductoFacade prodFac = new ProductoFacade();
                                        string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                        ventasFacade ventFac = new ventasFacade();
                                        string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion));

                                        if (!string.IsNullOrEmpty(actStock))
                                        {
                                            MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                        }
                                        else if (!string.IsNullOrEmpty(borrar))
                                        {
                                            MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                            btnPagar.Content = "Pagar";
                                            ventaTemp = new VentaTemporal();
                                            ltotalDevolucion.Visibility = Visibility.Hidden;
                                            txtTotaldevolucion.Visibility = Visibility.Hidden;
                                            lDiferencia.Visibility = Visibility.Hidden;
                                            txtDiferencia.Visibility = Visibility.Hidden;
                                            dineroDevolucion = 0;

                                        }
                                    }
                                    else
                                    {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                        int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                        ProductoFacade prodFac = new ProductoFacade();
                                        string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                        ventasFacade ventFac = new ventasFacade();
                                        string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion), difDevo, difDevo * Convert.ToInt32(ventaTemp.precio));

                                        if (!string.IsNullOrEmpty(actStock))
                                        {
                                            MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                        }
                                        else if (!string.IsNullOrEmpty(actVenta))
                                        {
                                            MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);

                                            btnPagar.Content = "Pagar";
                                            ventaTemp = new VentaTemporal();
                                            ltotalDevolucion.Visibility = Visibility.Hidden;
                                            txtTotaldevolucion.Visibility = Visibility.Hidden;
                                            lDiferencia.Visibility = Visibility.Hidden;
                                            txtDiferencia.Visibility = Visibility.Hidden;
                                            dineroDevolucion = 0;
                                        }

                                    }
                                }
                                limpiarRegistroVentas();
                            }
                            else
                            {
                                MessageBox.Show("Error al guardar detalle ventas:" + resp, "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }


                        }
                        else
                        {
                            MessageBox.Show("Error al ingresar deuda a usuario:" + rActu, "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        // MessageBox.Show("Elegir usuario al que se fiara.");
                        DescuentoCliente dc = new DescuentoCliente("ds");
                        dc.Owner = Window.GetWindow(this); ;
                        dc.btnCancelar.Visibility = Visibility.Visible;
                        dc.Title = "Elegir Cliente";
                        dc.ShowDialog();

                        //txtdescuento.Text = dc.getValor();
                        getCheque.rut = dc.getrut();
                        rutcliente = dc.getrut();
                        nombreCliente = dc.getnombreCliente();
                        if (!rutcliente.Equals(""))
                        {
                            //actualizar deuda y total de compras 
                            //MessageBox.Show("Guardar usuario a fiar", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                            //Agregar registo a cliente de ventas 
                            //actualizar deuda y total de compras
                            clienteFacade clienteFac = new clienteFacade();
                            //MessageBox.Show("rut cliente a fiar:"+rutcliente);
                            string rActu = clienteFac.actualizar_DFT_Cliente(rutcliente, Convert.ToDouble(txttotal.Text), fechaactual);
                            if (rActu.Equals(""))
                            {
                                MessageBox.Show("Deuda ingresada a usuario:" + nombreCliente + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                ventasFacade vtfac = new ventasFacade();
                                string resp = vtfac.GuardarVentas(listVentas);

                                if (resp.Equals(""))
                                {
                                    int idventaGen = vtfac.getUltimoIngresadoenVentas();
                                    MessageBox.Show("Anotar el siguiente idventa para posible devolucion:" + idventaGen.ToString(), "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                                    vendedorFacade vendFac = new vendedorFacade();
                                    vendFac.actualizarVentasVend(rutLogin);
                                    //Descontar stock en (lista) de producto
                                    ProductoFacade prd = new ProductoFacade();
                                    foreach (var item in listVentas)
                                    {
                                        string res = prd.actualizarStockProducto(item.idProducto.ToString(), item.cantidad.ToString());
                                        if (resp.Equals(""))
                                        {
                                            //MessageBox.Show("stock actualizado:" + item.idProducto);
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(getCheque.nombre))
                                    {
                                        chequeFacade chFac = new chequeFacade();
                                        getCheque = pc.getformCheque();
                                        string rep = chFac.GuardarCheque(getCheque);
                                        if (rep.Equals(""))
                                        {
                                            MessageBox.Show("Detalles cheque guardado", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);

                                        }
                                        else
                                        {
                                            MessageBox.Show("Error al guardar detalles cheque:" + rep + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                        }
                                    }
                                    //Si esta en proceso de devolucion btn se llamara cambiar
                                    if (!string.IsNullOrEmpty(ventaTemp.idProducto))
                                    {
                                        int difDevo = Convert.ToInt32(ventaTemp.cantidad) - Convert.ToInt32(ventaTemp.devolver);
                                        //MessageBox.Show("dif:" + difDevo.ToString());
                                        if (difDevo == 0)
                                        {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                            int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                            ProductoFacade prodFac = new ProductoFacade();
                                            string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                            ventasFacade ventFac = new ventasFacade();
                                            string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion));

                                            if (!string.IsNullOrEmpty(actStock))
                                            {
                                                MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                            }
                                            else if (!string.IsNullOrEmpty(borrar))
                                            {
                                                MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                                btnPagar.Content = "Pagar";
                                                ventaTemp = new VentaTemporal();
                                                ltotalDevolucion.Visibility = Visibility.Hidden;
                                                txtTotaldevolucion.Visibility = Visibility.Hidden;
                                                lDiferencia.Visibility = Visibility.Hidden;
                                                txtDiferencia.Visibility = Visibility.Hidden;
                                                dineroDevolucion = 0;

                                            }
                                        }
                                        else
                                        {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                            int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                            ProductoFacade prodFac = new ProductoFacade();
                                            string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                            ventasFacade ventFac = new ventasFacade();
                                            string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion), difDevo, difDevo * Convert.ToInt32(ventaTemp.precio));

                                            if (!string.IsNullOrEmpty(actStock))
                                            {
                                                MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                            }
                                            else if (!string.IsNullOrEmpty(actVenta))
                                            {
                                                MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                                btnPagar.Content = "Pagar";
                                                ventaTemp = new VentaTemporal();
                                                ltotalDevolucion.Visibility = Visibility.Hidden;
                                                txtTotaldevolucion.Visibility = Visibility.Hidden;
                                                lDiferencia.Visibility = Visibility.Hidden;
                                                txtDiferencia.Visibility = Visibility.Hidden;
                                                dineroDevolucion = 0;
                                            }

                                        }
                                    }


                                    limpiarRegistroVentas();
                                }
                                else
                                {
                                    MessageBox.Show("Error al guardar detalle ventas:" + resp + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }


                            }
                            else
                            {
                                MessageBox.Show("Error al ingresar deuda a usuario:" + rActu + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }

                    //}
                }
                else if (rbtnNo.IsChecked == true)
                {
                    //MessageBox.Show("Guardar solo detalles venta:no fiar");

                    ventasFacade vtfac = new ventasFacade();
                    if (string.IsNullOrEmpty(rutcliente))
                    {
                        for (int i = 0; i < listVentas.Count; i++)
                        {
                            listVentas[i].rutCliente = "";

                        }
                        string resp = vtfac.GuardarVentas(listVentas);
                        if (resp.Equals(""))
                        {
                            //Descontar stock en (lista) de producto
                            ProductoFacade prd = new ProductoFacade();
                            foreach (var item in listVentas)
                            {
                                string res = prd.actualizarStockProducto(item.idProducto.ToString(), item.cantidad.ToString());
                                // MessageBox.Show("stock actualizado:" + item.idProducto);
                            }

                            int idventaGen = vtfac.getUltimoIngresadoenVentas();
                            MessageBox.Show("Anotar el siguiente idventa para posible devolucion:" + idventaGen.ToString() + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                            vendedorFacade vendFac = new vendedorFacade();
                            vendFac.actualizarVentasVend(rutLogin);
                            //MessageBox.Show("Detalles venta guardado");
                            //Agregar registo a cliente de ventas 
                            if (!string.IsNullOrEmpty(getCheque.nombre))
                            {
                                chequeFacade chFac = new chequeFacade();
                                getCheque = pc.getformCheque();
                                string rep = chFac.GuardarCheque(getCheque);
                                if (rep.Equals(""))
                                {
                                    MessageBox.Show("Detalles cheque guardado", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Error al guardar detalles cheque:" + rep + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                            if (!string.IsNullOrEmpty(ventaTemp.idProducto))
                            {
                                int difDevo = Convert.ToInt32(ventaTemp.cantidad) - Convert.ToInt32(ventaTemp.devolver);
                                //MessageBox.Show("dif:" + difDevo.ToString());
                                if (difDevo == 0)
                                {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                    int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(borrar))
                                    {
                                        MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        btnPagar.Content = "Pagar";
                                        ventaTemp = new VentaTemporal();
                                        ltotalDevolucion.Visibility = Visibility.Hidden;
                                        txtTotaldevolucion.Visibility = Visibility.Hidden;
                                        lDiferencia.Visibility = Visibility.Hidden;
                                        txtDiferencia.Visibility = Visibility.Hidden;
                                        dineroDevolucion = 0;
                                    }
                                }
                                else
                                {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                    int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion), difDevo, difDevo * Convert.ToInt32(ventaTemp.precio));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(actVenta))
                                    {
                                        MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        btnPagar.Content = "Pagar";
                                        ventaTemp = new VentaTemporal();
                                        ltotalDevolucion.Visibility = Visibility.Hidden;
                                        txtTotaldevolucion.Visibility = Visibility.Hidden;
                                        lDiferencia.Visibility = Visibility.Hidden;
                                        txtDiferencia.Visibility = Visibility.Hidden;
                                        dineroDevolucion = 0;
                                    }

                                }
                            }
                            limpiarRegistroVentas();

                        }
                        else
                        {
                            MessageBox.Show("Error al guardar detalle ventas:" + resp + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    //Si existe cliente pero no se fia de actualiza registro de venta a cliente
                    {
                        string resp = vtfac.GuardarVentas(listVentas);
                        if (resp.Equals(""))
                        {
                            //Descontar stock en (lista) de producto
                            ProductoFacade prd = new ProductoFacade();
                            foreach (var item in listVentas)
                            {
                                string res = prd.actualizarStockProducto(item.idProducto.ToString(), item.cantidad.ToString());
                                //MessageBox.Show("stock actualizado:" + item.idProducto);
                            }
                            int idventaGen = vtfac.getUltimoIngresadoenVentas();
                            MessageBox.Show("Anotar el siguiente idventa para posible devolucion:" + idventaGen.ToString() + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
                            vendedorFacade vendFac = new vendedorFacade();
                            vendFac.actualizarVentasVend(rutLogin);
                            if (!string.IsNullOrEmpty(ventaTemp.idProducto))
                            {
                                int difDevo = Convert.ToInt32(ventaTemp.cantidad) - Convert.ToInt32(ventaTemp.devolver);
                                //MessageBox.Show("dif:" + difDevo.ToString());
                                if (difDevo == 0)
                                {//si cantidad devolucion es igul a cantidad venta, actualizar stock producto y borrar registro de venta
                                    int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string borrar = ventFac.borrarventaByidVenta(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(borrar))
                                    {
                                        MessageBox.Show("Error al borrar venta:" + borrar + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        btnPagar.Content = "Pagar";
                                        ventaTemp = new VentaTemporal();
                                        ltotalDevolucion.Visibility = Visibility.Hidden;
                                        txtTotaldevolucion.Visibility = Visibility.Hidden;
                                        lDiferencia.Visibility = Visibility.Hidden;
                                        txtDiferencia.Visibility = Visibility.Hidden;
                                        dineroDevolucion = 0;
                                    }
                                }
                                else
                                {//si cantidad devolucion no es igual a cantidad en venta , actualizar venta e stock producto
                                    int sumStock = Convert.ToInt32(ventaTemp.devolver);
                                    ProductoFacade prodFac = new ProductoFacade();
                                    string actStock = prodFac.actualizarStockProductoDevolucion(ventaTemp.idProducto, sumStock);
                                    ventasFacade ventFac = new ventasFacade();
                                    string actVenta = ventFac.actualizarventaDevolucion(Convert.ToDouble(ventaTemp.idVenta), ventaTemp.idProducto, Convert.ToDateTime(fechaDevolucion), difDevo, difDevo * Convert.ToInt32(ventaTemp.precio));

                                    if (!string.IsNullOrEmpty(actStock))
                                    {
                                        MessageBox.Show("Error al actualizar stock:" + actStock + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else if (!string.IsNullOrEmpty(actVenta))
                                    {
                                        MessageBox.Show("Error al actualizar venta:" + actVenta + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Devolucion cambiada correctamente.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                        btnPagar.Content = "Pagar";
                                        ventaTemp = new VentaTemporal();
                                        ltotalDevolucion.Visibility = Visibility.Hidden;
                                        txtTotaldevolucion.Visibility = Visibility.Hidden;
                                        lDiferencia.Visibility = Visibility.Hidden;
                                        txtDiferencia.Visibility = Visibility.Hidden;
                                        dineroDevolucion = 0;
                                    }

                                }
                            }

                            //Agregar registo a cliente de ventas 
                            if (!string.IsNullOrEmpty(getCheque.nombre))
                            {
                                chequeFacade chFac = new chequeFacade();
                                getCheque = pc.getformCheque();
                                string rep = chFac.GuardarCheque(getCheque);
                                if (rep.Equals(""))
                                {
                                    MessageBox.Show("Detalles cheque guardado", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Error al guardar detalles cheque:" + rep + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                            clienteFacade clienteFac = new clienteFacade();
                            //MessageBox.Show("rut cliente a fiar:"+rutcliente);
                            string rActu = clienteFac.actualizar_DFT_Cliente(rutcliente, 0, fechaactual);
                            if (rActu.Equals(""))
                            {
                                MessageBox.Show("Registro de cliente actualizado", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Information);


                            }
                            else
                            {
                                MessageBox.Show("Error al actualizar registro cliente:" + rActu + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                            }



                            limpiarRegistroVentas();

                        }
                        else
                        {
                            MessageBox.Show("Error al guardar detalle ventas:" + resp + "", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }



                }
            }
            else
            {
                MessageBox.Show("Elegir al menos un producto para venta!", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

        }
Ejemplo n.º 10
0
        public string GuardarVentas(List <MVentas> listVentas)
        {
            //Boolean guardar = false;
            string i = "";

            try
            {
                /*string c="Select*from venta";
                 * MySqlCommand comm1 = new MySqlCommand(c, getconexion.getConexion());
                 * long id = comm1.LastInsertedId;
                 * id = id + 1;*/

                //verificar si es primera venta para luego agregar un id igual para venta en temp
                ventasFacade v = new ventasFacade();
                if (v.getVentastotales() == 0)
                {//primer venta
                    foreach (var vts in listVentas)
                    {
                        string       consultinsert = "INSERT INTO venta(idVenta,idProducto, rutCliente, rutVendedor,cantidad, total,fecha,tipoVenta) VALUES (@idVenta,@idProducto, @rutCliente, @rutVendedor,@cantidad, @total,@fecha,@tipoVenta)";
                        MySqlCommand comm          = new MySqlCommand(consultinsert, getconexion.getConexion());
                        comm.Parameters.AddWithValue("@idVenta", 0);
                        comm.Parameters.AddWithValue("@idProducto", vts.idProducto);
                        comm.Parameters.AddWithValue("@rutCliente", vts.rutCliente);
                        comm.Parameters.AddWithValue("@rutVendedor", vts.rutVendedor);
                        comm.Parameters.AddWithValue("@cantidad", vts.cantidad);
                        comm.Parameters.AddWithValue("@total", vts.total);
                        comm.Parameters.AddWithValue("@fecha", vts.fecha);
                        comm.Parameters.AddWithValue("@tipoVenta", vts.tipoVenta);
                        comm.ExecuteNonQuery();
                    }
                }
                else
                {//+1 en ventas obtener el ultimo id y sumar +1 para un unico id de ventas en temp
                    ventasFacade vt       = new ventasFacade();
                    int          idultimo = vt.getUltimoIngresadoenVentas();
                    idultimo = idultimo + 1;
                    foreach (var vts in listVentas)
                    {
                        string       consultinsert = "INSERT INTO venta(idVenta,idProducto, rutCliente, rutVendedor,cantidad, total,fecha,tipoVenta) VALUES (@idVenta,@idProducto, @rutCliente, @rutVendedor,@cantidad, @total,@fecha,@tipoVenta)";
                        MySqlCommand comm          = new MySqlCommand(consultinsert, getconexion.getConexion());
                        //long id = comm.LastInsertedId;
                        //id = id + 1;
                        comm.Parameters.AddWithValue("@idVenta", idultimo);
                        comm.Parameters.AddWithValue("@idProducto", vts.idProducto);
                        comm.Parameters.AddWithValue("@rutCliente", vts.rutCliente);
                        comm.Parameters.AddWithValue("@rutVendedor", vts.rutVendedor);
                        comm.Parameters.AddWithValue("@cantidad", vts.cantidad);
                        comm.Parameters.AddWithValue("@total", vts.total);
                        comm.Parameters.AddWithValue("@fecha", vts.fecha);
                        comm.Parameters.AddWithValue("@tipoVenta", vts.tipoVenta);
                        comm.ExecuteNonQuery();
                    }
                }



                getconexion.CerrarConexion();

                //guardar = true;
            }
            catch (Exception e)
            {
                //guardar = false;
                i = e.ToString();
            }
            finally
            {
                getconexion.CerrarConexion();
            }
            return(i);
        }
Ejemplo n.º 11
0
        private void btnBuscarVenta_Click(object sender, RoutedEventArgs e)
        {

            if (txtidventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idventa", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (txtidProducto.Text.Equals(""))
            {
                MessageBox.Show("Ingresar idProducto", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (fechaventa.Text.Equals(""))
            {
                MessageBox.Show("Ingresar Fecha", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                int n;
                bool isNumeric = int.TryParse(txtidventa.Text, out n);
                if (isNumeric)
                {

                    ventasFacade ventFac = new ventasFacade();
                    List<MVentas> listaVentaDevolucion = ventFac.getVentasForDevolucion(Convert.ToInt32(txtidventa.Text), txtidProducto.Text, Convert.ToDateTime(fechaventa.Text));
                    var rows = GetDataGridRows(datagridVentas);
                    if (listaVentaDevolucion.Count != 0)
                    {
                        venta.Clear();
                        datagridVentas.ItemsSource = venta;
                        //llenar datagridVenta para devoulcion
                        foreach (var item in listaVentaDevolucion)
                        {
                            ProductoFacade prodFobtener = new ProductoFacade();
                            Producto Prod = new Producto();
                            Prod = prodFobtener.getProductosByID(item.idProducto);
                            int p = ToEntero(Prod.precio, NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string precio = p.ToString("#,#", CultureInfo.InvariantCulture);
                            int t = ToEntero(item.total.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string total = t.ToString("#,#", CultureInfo.InvariantCulture); ;
                            vtemp = new VentaTemporal(Convert.ToInt32(item.idVenta), item.idProducto, Prod.nombre, precio, item.cantidad.ToString(), "1", total.ToString());
                            venta.Add(vtemp);
                            cantidad = cantidad + 1;
                            total = total + Convert.ToInt32(item.total);

                            //ltotal.Content = Prod.precio;
                            int st = ToEntero(item.total.ToString(), NumberStyles.Float | NumberStyles.AllowThousands, new CultureInfo("en-GB"));
                            string stp = st.ToString("#,#", CultureInfo.InvariantCulture);

                            ltotal.Content = stp;
                            TextBoxValue.Text = item.cantidad.ToString();
                        }
                        datagridVentas.ItemsSource = venta;
                    }
                    else
                    {
                        MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("No se han encontrado ventas con estos datos.", "Magnolia", MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }

        }