예제 #1
0
        //////////////////////////////////////
        /////////////////VENTA////////////////
        //////////////////////////////////////
        private void Btn_Generar_venta_Click(object sender, RoutedEventArgs e)
        {
            BoletaVenta    rpt     = new BoletaVenta();
            VentaHDR       dataset = new VentaHDR();
            ReportDocument doc     = new ReportDocument();


            string cabecera = "";

            txt_Id_venta.Text = "";
            bool             restar       = false;
            Producto_Negocio producto_Neg = new Producto_Negocio();
            Venta_Negocio    Venta_Neg    = new Venta_Negocio();
            Deuda_Negocio    deudaN       = new Deuda_Negocio();

            if (cmb_Cliente_Vta.Text == "" || cmb_Documento_Vta.Text == "")
            {
                if (cmb_Cliente_Vta.Text == "" && cmb_Documento_Vta.Text == "")
                {
                    MessageBox.Show("Debe seleccionar un cliente y tipo de documento");
                }
                else
                {
                    if (cmb_Cliente_Vta.Text == "")
                    {
                        MessageBox.Show("Debe seleccionar un cliente");
                    }
                    if (cmb_Documento_Vta.Text == "")
                    {
                        MessageBox.Show("Debe seleccionar un tipo de documento");
                    }
                }
            }
            else
            {
                if (Application.Current.Properties["ListadoVenta"] == null || Application.Current.Properties["ListadoVenta"].ToString() == "[]")
                {
                    MessageBox.Show("Debe ingresar al menos un Producto o Servicio");
                }
                else
                {
                    cabecera = Venta_Neg.CrearVentaHDR(txt_Fecha_V.Text, txt_iva.Text, txt_total.Text, cmb_Cliente_Vta.SelectedValue.ToString(), cmb_Documento_Vta.SelectedValue.ToString(), cmb_taller_Vta.SelectedValue.ToString());
                    if (cmb_Documento_Vta.Text == "Pagare")
                    {
                        string estadodeduda = "1";
                        deudaN.CrearDeuda(txt_Fecha_V.Text, estadodeduda, txt_total.Text, cabecera, cmb_Cliente_Vta.SelectedValue.ToString());
                    }

                    try
                    {
                        var row = dataset.Tables["VentaHdr"].NewRow();
                        row["Numero_Doc"]     = "N° Documento: " + cabecera;
                        row["Fecha"]          = "Fecha: " + txt_Fecha_V.Text;
                        row["Tipo_Doc"]       = "Tipo Documento: " + cmb_Documento_Vta.Text;
                        row["Nombre_Cliente"] = "Nombre Cliente: " + cmb_Cliente_Vta.Text;
                        row["SubTotal"]       = "SUBTOTAL $ " + txt_Sub.Text;
                        row["IVA"]            = "IVA $ " + txt_iva.Text;
                        row["Empresa_Nombre"] = cmb_taller_Vta.Text;
                        row["Total"]          = "TOTAL $ " + txt_total.Text;

                        ///campos en duro para pdf//////

                        row["rut"]       = "RUT: 78.598.553 - 9";
                        row["giro"]      = "GIRO: Venta Mantenimiento y Reparación de Vehiculos Y sus Partes Piezas Y Accesorios";
                        row["fono"]      = "FONO: 98758789";
                        row["direccion"] = "DIRECCIÓN: Alonso de Ovale 1586 , Santiago Centro";

                        row["idp_hdr"]      = "ID";
                        row["nombrep_hdr"]  = "Descripción";
                        row["tipo_hdr"]     = "Tipo";
                        row["cantidad_hdr"] = "Cantidad";
                        row["precio_hdr"]   = "Precio";
                        row["total_hdr"]    = "Total";
                        ///////////////////////////////////////////
                        ///
                        dataset.Tables["VentaHdr"].Rows.Add(row);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    if (Application.Current.Properties["ListadoVenta"] != null)
                    {
                        // trae lo que esta en la variable de sesion77k
                        var jsonValueToGet = JsonConvert.DeserializeObject(Application.Current.Properties["ListadoVenta"].ToString());

                        // lo convierte en un array
                        JArray jsonPreservar = JArray.Parse(jsonValueToGet.ToString());

                        //lo recorre para añadir al listado que luego se mostrará en la grilla
                        foreach (JObject item in jsonPreservar.Children <JObject>())
                        {
                            var precio = Math.Round(decimal.Parse(item["Precio"].ToString()), 0).ToString().Replace(".", "");
                            var total  = Math.Round(decimal.Parse(item["Total"].ToString()), 0).ToString().Replace(".", "");


                            // estos datos vienen de la grilla, creamosla entidad para añadir al listado
                            var respuesta = Venta_Neg.CrearVentaDet(item["Cantidad"].ToString(), precio, cabecera, total, item["T"].ToString(), item["ID"].ToString());
                            if (item["T"].ToString() == "P")
                            {
                                restar = producto_Neg.Restar_cant_prod(item["ID"].ToString(),
                                                                       item["Cantidad"].ToString());
                            }

                            var rowlist = dataset.Tables["Venta_DT"].NewRow();

                            rowlist["Descripcion"]  = item["Descripción"].ToString();
                            rowlist["Id_Prod_Serv"] = item["ID"].ToString();
                            // rowlist["SKU"] = ;
                            rowlist["Tipo"]            = item["T"].ToString();
                            rowlist["Cantidad"]        = item["Cantidad"].ToString();
                            rowlist["Precio"]          = item["Precio"].ToString();
                            rowlist["Total_Prod_Serv"] = item["Total"].ToString();

                            dataset.Tables["Venta_DT"].Rows.Add(rowlist);
                        }

                        txt_Id_venta.Text = cabecera;
                        MessageBox.Show("Venta generado con el Numero: " + txt_Id_venta.Text);
                    }

                    string reporte   = "BoletaVenta.rpt";
                    string ruta      = @"C:\Users\Diaz-Olivares\Documents\Proyectos\TallerMecanico\Taller_Escritorio_wpf\RPT\";
                    string rutaFinal = ruta + reporte;
                    doc.Load(rutaFinal);
                    doc.SetDataSource(dataset);
                    try
                    {
                        string nombreDoc   = "Documento_Venta" + cabecera + DateTime.Now.Millisecond + ".pdf";
                        string rutaGuardar = @"C:\RPT\" + nombreDoc;
                        doc.ExportToDisk(ExportFormatType.PortableDocFormat, rutaGuardar);
                        Process.Start(rutaGuardar);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }