コード例 #1
0
        private double GetSaldoChequexCodVenta(Int32 CodVenta)
        {
            int ban = 0;

            Clases.cCheque cheque  = new Clases.cCheque();
            DataTable      tcheque = cheque.GetChequexCodVenta(CodVenta);

            if (tcheque.Rows.Count > 0)
            {
                for (int i = 0; i < tcheque.Rows.Count; i++)
                {
                    if (tcheque.Rows[i]["FechaPago"].ToString() == "")
                    {
                        ban = 1;
                    }
                }
            }
            if (ban == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #2
0
        private void CargarGrilla()
        {
            Clases.cFunciones fun     = new Clases.cFunciones();
            string            Patente = txtPatente.Text;

            Clases.cCheque cheque = new Clases.cCheque();
            DataTable      trdo   = cheque.GetChequesxPatente(Patente);

            trdo = fun.TablaaMiles(trdo, "Importe");
            Grilla.DataSource = trdo;
            if (trdo.Rows.Count > 0)
            {
                txtNombre.Text      = trdo.Rows[0]["Nombre"].ToString();
                txtApellido.Text    = trdo.Rows[0]["Apellido"].ToString();
                txtDescripcion.Text = trdo.Rows[0]["Descripcion"].ToString();
            }
            Grilla.Columns[1].HeaderText = "Nro Cheque";
            Grilla.Columns[3].HeaderText = "Fecha Pago";
            Grilla.Columns[4].HeaderText = "Fecha Vto";

            Grilla.Columns[1].Width   = 150;
            Grilla.Columns[2].Width   = 150;
            Grilla.Columns[3].Width   = 120;
            Grilla.Columns[4].Width   = 120;
            Grilla.Columns[0].Visible = false;
            Grilla.Columns[5].Visible = false;
            Grilla.Columns[6].Visible = false;
            Grilla.Columns[7].Visible = false;
        }
コード例 #3
0
        private void BuscarCheques(Int32 CodPrenda)
        {
            Clases.cCheque cheque = new Clases.cCheque();
            DataTable      trdo   = cheque.GetChequexCodPrenda(CodPrenda);

            Clases.cFunciones fun = new Clases.cFunciones();
            trdo = fun.TablaaMiles(trdo, "Importe");
            GrillaCheques.DataSource            = trdo;
            GrillaCheques.Columns[0].HeaderText = "Cheque";
            GrillaCheques.Columns[2].HeaderText = "Vencimiento";
            GrillaCheques.Columns[3].Visible    = false;
            GrillaCheques.Columns[4].Width      = 310;
            GrillaCheques.Columns[1].Width      = 100;
            txtImporteCheque.Text    = "";
            txtCheque.Text           = "";
            txtFechaVencimiento.Text = "";
            double TotalCheques = 0;

            for (int i = 0; i < trdo.Rows.Count; i++)
            {
                TotalCheques = TotalCheques + Convert.ToDouble(trdo.Rows[i][1].ToString());
            }
            txtTotalCheque.Text = TotalCheques.ToString();
            //Clases.cFunciones fun = new Clases.cFunciones();
            txtTotalCheque.Text = fun.ParteEntera(txtTotalCheque.Text);
            txtTotalCheque.Text = fun.FormatoEnteroMiles(txtTotalCheque.Text);
            CalcularDiferencias();
        }
コード例 #4
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            Clases.cFunciones fun = new Clases.cFunciones();
            if (fun.ValidarFecha(txtFechaDesde.Text) == false)
            {
                MessageBox.Show("Fecha desde incorrecta", Clases.cMensaje.Mensaje());
                return;
            }

            if (fun.ValidarFecha(txtFechaHasta.Text) == false)
            {
                MessageBox.Show("Fecha hasta incorrecta", Clases.cMensaje.Mensaje());
                return;
            }

            if (Convert.ToDateTime(txtFechaDesde.Text) > Convert.ToDateTime(txtFechaHasta.Text))
            {
                MessageBox.Show("La fecha desde debe ser inferior a la fecha hasta", Clases.cMensaje.Mensaje());
                return;
            }

            DateTime FechaDesde = Convert.ToDateTime(txtFechaDesde.Text);
            DateTime FechaHasta = Convert.ToDateTime(txtFechaHasta.Text);
            int      Impagos    = 0;
            Int32?   CodBanco   = null;
            string   NroCheque  = "";

            if (cmbBanco.SelectedIndex > 0)
            {
                CodBanco = Convert.ToInt32(cmbBanco.SelectedValue);
            }
            NroCheque = txtNumeroCheque.Text;
            if (chkImpagos.Checked == true)
            {
                Impagos = 1;
            }
            Clases.cCheque cheque = new Clases.cCheque();
            DataTable      trdo   = cheque.GetChequesxFecha(FechaDesde, FechaHasta, Impagos, CodBanco, NroCheque);

            trdo          = fun.TablaaMiles(trdo, "Importe");
            txtTotal.Text = fun.TotalizarColumna(trdo, "Importe").ToString();
            if (txtTotal.Text != "")
            {
                txtTotal.Text = fun.SepararDecimales(txtTotal.Text);
                txtTotal.Text = fun.FormatoEnteroMiles(txtTotal.Text);
            }
            Grilla.DataSource            = trdo;
            Grilla.Columns[1].Width      = 100;
            Grilla.Columns[1].HeaderText = "Fec. Cobro";
            Grilla.Columns[2].Width      = 100;
            Grilla.Columns[2].HeaderText = "Fecha Vto.";
            Grilla.Columns[3].Width      = 140;
            Grilla.Columns[3].HeaderText = "Nro. Cheque";
            Grilla.Columns[5].Width      = 220;
            Grilla.Columns[6].Visible    = false;
        }
コード例 #5
0
        private void btnAnular_Click(object sender, EventArgs e)
        {
            Clases.cFunciones fun = new Clases.cFunciones();

            /*
             * if (Grilla.Rows.Count < 2)
             * {
             *  MessageBox.Show("Debe Seleccionar una prenda para continuar ", Clases.cMensaje.Mensaje());
             *  return;
             * }
             *
             * if (Grilla.CurrentRow == null)
             * {
             *  MessageBox.Show("Seleccione una fila para continuar.", Clases.cMensaje.Mensaje());
             *  return;
             * }
             *
             * if (Grilla.CurrentRow.Cells[6].Value.ToString() == "")
             * {
             *  MessageBox.Show("La prenda no se puede anular debido a que no ha sido cobrada.", Clases.cMensaje.Mensaje());
             *  return;
             * }
             */
            string Descripcion = "ANULACION DE COBRO DE PRENDA:  Patente " + txtPatente.Text;

            Descripcion = Descripcion + ", Cliente " + txtNombre.Text;
            string CodPrenda = Principal.CodigoPrincipalAbm;
            Double Importe   = fun.ToDouble(txtImporte.Text);
            Int32  CodVenta  = Convert.ToInt32(txtCodVenta.Text);

            Clases.cPrenda prenda = new Clases.cPrenda();
            prenda.AnularPagoPrenda(Convert.ToInt32(CodPrenda));
            Clases.cMovimiento mov = new Clases.cMovimiento();
            if (txtDiferencia.Text != "0")
            {
                double Diferencia = fun.ToDouble(txtDiferencia.Text);
                string TEXTO      = "ANULACION DIFERENCIA PRENDA, PATENTE " + txtPatente.Text;
                // mov.RegistrarMovimientoDescripcion(CodVenta, Principal.CodUsuarioLogueado, (-1) * Diferencia, 0, 0, 0, 0, DateTime.Now, TEXTO);
            }
            DateTime Fecha = Convert.ToDateTime(txtFecha.Text);

            Clases.cCheque cheque = new Clases.cCheque();
            cheque.BorrarChequexCodPrenda(Convert.ToInt32(CodPrenda));
            Importe = fun.ToDouble(txtTotalCheque.Text);
            mov.RegistrarMovimientoDescripcion(CodVenta, Principal.CodUsuarioLogueado, (-1) * Importe, 0, 0, 0, 0, Fecha, Descripcion);
            MessageBox.Show("Datos grabados correctamente", Clases.cMensaje.Mensaje());
            GetPrendaxCod(Convert.ToInt32(CodPrenda));
        }
コード例 #6
0
        private void BtnVerGanancia_Click(object sender, EventArgs e)
        {
            if (txtEntregado.Text == "")
            {
                MessageBox.Show("Debe ingresar un Nombre destinatario a entregar el cheque ");
                return;
            }
            if (Grilla.CurrentRow == null)
            {
                MessageBox.Show("Debe Seleccionar un cheque para continuar ", Clases.cMensaje.Mensaje());
                return;
            }
            Clases.cCheque cheque    = new Clases.cCheque();
            string         NroCheque = Grilla.CurrentRow.Cells[1].Value.ToString();

            cheque.GrabarEntrega(NroCheque, txtEntregado.Text);
            MessageBox.Show("Datos Grabados Correctamente");
        }
コード例 #7
0
        private void btnGrabar_Click(object sender, EventArgs e)
        {
            Clases.cFunciones fun = new Clases.cFunciones();

            if (Grilla.CurrentRow == null)
            {
                MessageBox.Show("Debe Seleccionar un cheque para continuar ", Clases.cMensaje.Mensaje());
                return;
            }

            if (Grilla.Rows.Count < 2)
            {
                MessageBox.Show("Debe Seleccionar una prenda para continuar ", Clases.cMensaje.Mensaje());
                return;
            }

            if (txtFecha.Text == "")
            {
                MessageBox.Show("Debe ingresar una fecha para continuar.", Clases.cMensaje.Mensaje());
                return;
            }

            if (fun.ValidarFecha(txtFecha.Text) == false)
            {
                MessageBox.Show("La fecha ingresada es incorrecta.", Clases.cMensaje.Mensaje());
                return;
            }

            DateTime Fecha       = Convert.ToDateTime(txtFecha.Text);
            Int32    CodVenta    = Convert.ToInt32(Grilla.CurrentRow.Cells[0].Value.ToString());
            string   NroCheque   = Grilla.CurrentRow.Cells[1].Value.ToString();
            string   Descripcion = "COBRO CHEQUE " + txtPatente.Text + " , " + NroCheque.ToString();

            Descripcion = Descripcion + ", " + txtEntregado.Text;
            Double Importe = fun.ToDouble(Grilla.CurrentRow.Cells[2].Value.ToString());

            Clases.cCheque cheque = new Clases.cCheque();
            cheque.RegistrarCobroCheque(txtFecha.Text, Convert.ToInt32(CodVenta), NroCheque);
            Clases.cMovimiento mov = new Clases.cMovimiento();
            mov.RegistrarMovimientoDescripcion(CodVenta, Principal.CodUsuarioLogueado, Importe, 0, 0, 0, 0, Fecha, Descripcion);
            CargarGrilla();
            MessageBox.Show("Datos grabados correctamente", Clases.cMensaje.Mensaje());
        }
コード例 #8
0
        private void ArmarDataTableDeudores()
        {
            string Apellido = null;

            if (txtApellido.Text != "")
            {
                Apellido = txtApellido.Text;
            }
            Clases.cVenta objVenta   = new Clases.cVenta();
            DateTime      FechaDesde = Convert.ToDateTime(txtFechaDesde.Text);
            DateTime      FechaHasta = Convert.ToDateTime(txtFechaHasta.Text);
            Int32         CodVenta   = 0;
            Double        Cobranza   = 0;

            Clases.cFunciones fun         = new Clases.cFunciones();
            cCobranza         objCobranza = new cCobranza();
            string            Col         = "CodVenta;Patente;Descripcion;Apellido;ImporteVenta;Cuotas;Cheque;Cobranza;Prenda;Telefono;Tipo";

            //Tipo se usa para saber a donde tiene que abrir
            Clases.cCuota  cuota        = new Clases.cCuota();
            Clases.cCheque objCheque    = new Clases.cCheque();
            cPrenda        objPrenda    = new cPrenda();
            string         telefono     = "";
            int            TieneDeuda   = 0;
            Double         Cuotas       = 0;
            Double         Prenda       = 0;
            Double         Cheque       = 0;
            string         val          = "";
            int            TipoPantalla = 1;
            DataTable      tb           = new DataTable();

            tb = fun.CrearTabla(Col);
            DataTable trdo = objVenta.GetVentasxFecha(FechaDesde, FechaHasta, txtPatente.Text.Trim(), Apellido);

            for (int i = 0; i < trdo.Rows.Count; i++)
            {
                CodVenta   = Convert.ToInt32(trdo.Rows[i]["CodVenta"].ToString());
                TieneDeuda = objVenta.TieneDeuda(CodVenta);
                if (TieneDeuda == 1)
                {
                    Cuotas   = cuota.GetSaldoDeudaCuotas(CodVenta);
                    Cheque   = objCheque.GetSaldoCheque(CodVenta);
                    Cobranza = objCobranza.GetSaldoCobranza(CodVenta);
                    Prenda   = objPrenda.ImporteAdeudado(CodVenta);
                    telefono = BuscarTelefonoCliente(CodVenta);
                    val      = CodVenta.ToString();
                    val      = val + ";" + trdo.Rows[i]["Patente"].ToString();
                    val      = val + ";" + trdo.Rows[i]["Descripcion"].ToString();
                    val      = val + ";" + trdo.Rows[i]["Apellido"].ToString();
                    val      = val + ";" + trdo.Rows[i]["ImporteVenta"].ToString();
                    val      = val + ";" + Cuotas.ToString();
                    val      = val + ";" + Cheque.ToString();
                    val      = val + ";" + Cobranza.ToString();
                    val      = val + ";" + Prenda.ToString();
                    val      = val + ";" + telefono.ToString();
                    val      = val + ";" + TipoPantalla.ToString();
                    tb       = fun.AgregarFilas(tb, val);
                }
            }
            TipoPantalla = 2;
            //agrego las cuotas anteriores
            cCuotasAnteriores cuotasAnt  = new cCuotasAnteriores();
            DataTable         tcuotasAnt = cuotasAnt.GetCuotasAnterioresAdeudadesxFecha(txtPatente.Text, txtApellido.Text, FechaDesde, FechaHasta);

            for (int i = 0; i < tcuotasAnt.Rows.Count; i++)
            {
                val = tcuotasAnt.Rows[i]["CodGrupo"].ToString();
                val = val + ";" + tcuotasAnt.Rows[i]["Patente"].ToString();
                val = val + ";" + tcuotasAnt.Rows[i]["Descripcion"].ToString();
                val = val + ";" + tcuotasAnt.Rows[i]["Apellido"].ToString();
                val = val + ";" + tcuotasAnt.Rows[i]["Importe"].ToString();
                val = val + ";";
                val = val + ";";
                val = val + ";";
                val = val + ";";
                val = val + ";" + tcuotasAnt.Rows[i]["Telefono"].ToString();
                val = val + ";" + TipoPantalla.ToString();
                tb  = fun.AgregarFilas(tb, val);
            }
            TipoPantalla = 3;
            //Cobranza general
            cCobranzaGeneral cobGen   = new cCobranzaGeneral();
            DataTable        tbCobGen = cobGen.GetDedudaCobranzaGeneralxFecha(Apellido, txtPatente.Text, FechaDesde, FechaHasta);

            for (int i = 0; i < tbCobGen.Rows.Count; i++)
            {
                val = tbCobGen.Rows[i]["CodCobranza"].ToString();
                val = val + ";" + tbCobGen.Rows[i]["Patente"].ToString();
                val = val + ";" + tbCobGen.Rows[i]["Descripcion"].ToString();
                val = val + ";" + tbCobGen.Rows[i]["Cliente"].ToString();
                val = val + ";" + tbCobGen.Rows[i]["Importe"].ToString();
                val = val + ";" + tbCobGen.Rows[i]["Importe"].ToString();
                val = val + ";";
                val = val + ";" + tbCobGen.Rows[i]["Importe"].ToString();
                val = val + ";";
                val = val + ";" + tbCobGen.Rows[i]["Telefono"].ToString();
                val = val + ";" + TipoPantalla.ToString();
                tb  = fun.AgregarFilas(tb, val);
            }
            //

            Double TotalVenta    = fun.TotalizarColumna(tb, "ImporteVenta");
            Double TotalCuotas   = fun.TotalizarColumna(tb, "Cuotas");
            Double TotalPrenda   = fun.TotalizarColumna(tb, "Prenda");
            Double TotalCobranza = fun.TotalizarColumna(tb, "Cobranza");
            Double TotalCheque   = fun.TotalizarColumna(tb, "Cheque");

            val = "";
            val = val + ";";
            val = val + ";";
            val = val + ";";
            val = val + ";" + TotalVenta.ToString();
            val = val + ";" + TotalCuotas.ToString();
            val = val + ";" + TotalCheque.ToString();
            val = val + ";" + TotalCobranza.ToString();
            val = val + ";" + TotalPrenda.ToString();
            val = val + ";" + telefono.ToString();
            tb  = fun.AgregarFilas(tb, val);

            tb = fun.TablaaMiles(tb, "ImporteVenta");
            tb = fun.TablaaMiles(tb, "Cuotas");
            tb = fun.TablaaMiles(tb, "Cheque");
            tb = fun.TablaaMiles(tb, "Cobranza");
            tb = fun.TablaaMiles(tb, "Prenda");
            Grilla.DataSource            = tb;
            Grilla.Columns[0].Visible    = false;
            Grilla.Columns[10].Visible   = false;
            Grilla.Columns[4].HeaderText = "Total";
            Grilla.Columns[5].HeaderText = "Documentos";
            for (int i = 0; i < Grilla.Rows.Count - 1; i++)
            {
                if (i == (Grilla.Rows.Count - 2))
                {
                    Grilla.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
                }
            }
        }
コード例 #9
0
        private void Actualizar()
        {
            //obtengo el importe de documentos a cobrar
            GetDeudasxPrestamo();
            GetEfectivosaPagar();
            GetCobranzaGeneral();
            GetChequesPagar();
            Clases.cFunciones        fun       = new Clases.cFunciones();
            Clases.cCuota            cuota     = new Clases.cCuota();
            Clases.cCuotasAnteriores cuotasAnt = new Clases.cCuotasAnteriores();
            Clases.cCheque           cheque    = new Clases.cCheque();
            Double ImporteCheque = cheque.GetTotalChequesaCobrar();

            Clases.cChequeCobrar chequeCob = new Clases.cChequeCobrar();
            ImporteCheque = ImporteCheque + chequeCob.GetTotalChequesaCobrar();
            Double Importe = cuota.GetMontoCuotasImpagas();
            Double ImporteCuotasAnteriores = cuotasAnt.GetMontoCuotasImpagas();

            Importe = Importe + ImporteCuotasAnteriores;
            Double ImporteSinInteres          = cuota.GetMontoCuotasImpagasSinInteres();
            double ImporteSinInteresCuotasAnt = cuotasAnt.GetMontoCuotasImpagasSinInteres();

            ImporteSinInteres            = ImporteSinInteres + ImporteSinInteresCuotasAnt;
            txtDocumentos.Text           = fun.TransformarEntero(Importe.ToString().Replace(",", "."));
            txtDocumentos.Text           = fun.FormatoEnteroMiles(txtDocumentos.Text);
            txtDocumentosSinInteres.Text = ImporteSinInteres.ToString();
            txtDocumentosSinInteres.Text = fun.TransformarEntero(ImporteSinInteres.ToString());
            txtDocumentosSinInteres.Text = fun.FormatoEnteroMiles(txtDocumentosSinInteres.Text);
            txtTotalCheque.Text          = fun.FormatoEnteroMiles(ImporteCheque.ToString());
            Clases.cResumenCuentas res = new Clases.cResumenCuentas();
            DataTable trdo             = res.GetResumenCuentas();

            if (trdo.Rows.Count > 0)
            {
                double ImporteEfectivo = Convert.ToDouble(trdo.Rows[0]["ImporteEfectivo"]);
                txtEfectivo.Text = fun.TransformarEntero(ImporteEfectivo.ToString().Replace(",", "."));
                txtEfectivo.Text = fun.FormatoEnteroMiles(txtEfectivo.Text);

                double ImporteAuto = Convert.ToDouble(trdo.Rows[0]["ImporteAuto"]);
                txtVehículo.Text = fun.TransformarEntero(ImporteAuto.ToString().Replace(",", "."));
                txtVehículo.Text = fun.FormatoEnteroMiles(txtVehículo.Text);

                double ImportePrenda = Convert.ToDouble(trdo.Rows[0]["ImportePrenda"]);
                txtPrenda.Text = fun.TransformarEntero(ImportePrenda.ToString().Replace(",", "."));
                txtPrenda.Text = fun.FormatoEnteroMiles(txtPrenda.Text);

                double ImporteCobranza = Convert.ToDouble(trdo.Rows[0]["ImporteCobranza"]);
                txtCobranzas.Text = fun.TransformarEntero(ImporteCobranza.ToString().Replace(",", "."));
                txtCobranzas.Text = fun.FormatoEnteroMiles(txtCobranzas.Text);

                double ImporteBanco = Convert.ToDouble(trdo.Rows[0]["ImporteBanco"]);
                txtBanco.Text = fun.TransformarEntero(ImporteBanco.ToString().Replace(",", "."));
                txtBanco.Text = fun.FormatoEnteroMiles(txtBanco.Text);

                Clases.cComisionVendedor com = new Clases.cComisionVendedor();
                txtComisiones.Text = com.GetComisionesPendientes().ToString();
                if (txtComisiones.Text != "")
                {
                    txtComisiones.Text = fun.FormatoEnteroMiles(txtComisiones.Text);
                }

                Clases.cGastosPagar gasto = new Clases.cGastosPagar();
                txtGastosPendientes.Text = gasto.GetGastosaPagar().ToString();

                if (txtGastosPendientes.Text != "")
                {
                    txtGastosPendientes.Text = fun.FormatoEnteroMiles(txtGastosPendientes.Text);
                }

                Clases.cCobranza cob = new Clases.cCobranza();
                txtCobranzas.Text = cob.GetTotalDeudaCobranzas().ToString();
                txtCobranzas.Text = fun.FormatoEnteroMiles(txtCobranzas.Text);
                GetPrendas();
                GetTotalVehiculo();
                GetTarjeta();
            }
        }
コード例 #10
0
        private void btnAnular_Click(object sender, EventArgs e)
        {
            if (Grilla.CurrentRow == null)
            {
                MessageBox.Show("Debe seleccionar un registro para continuar ", Clases.cMensaje.Mensaje());
                return;
            }

            string msj    = "Confirma anular la venta ";
            var    result = MessageBox.Show(msj, "Información",
                                            MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question);

            // If the no button was pressed ...
            if (result == DialogResult.No)
            {
                return;
            }

            string Patente  = Grilla.CurrentRow.Cells[4].Value.ToString();
            string CodVenta = Grilla.CurrentRow.Cells[0].Value.ToString();

            //
            Int32  CodAutoPartePago1     = 0;
            Int32  CodAutoPartePago2     = 0;
            double ImportePagadoCobranza = 0;
            double ImportePagadoCuotas   = 0;
            double ImportePagadoPrenda   = 0;
            double ImportePagadoCheque   = 0;

            Clases.cVenta    objVenta2 = new Clases.cVenta();
            Clases.cCobranza cobranza  = new Clases.cCobranza();
            Clases.cPrenda   prenda    = new Clases.cPrenda();
            ImportePagadoCobranza = cobranza.GetImportePagado(Convert.ToInt32(CodVenta));
            Clases.cCuota  cuota  = new Clases.cCuota();
            Clases.cCheque cheque = new Clases.cCheque();
            ImportePagadoCuotas = cuota.ImportePagado(Convert.ToInt32(CodVenta));
            ImportePagadoPrenda = prenda.ImportePagado(Convert.ToInt32(CodVenta));
            ImportePagadoCheque = cheque.ImportePagado(Convert.ToInt32(CodVenta));
            DataTable tresult2 = objVenta2.GetAutosPartePago(Convert.ToInt32(CodVenta));

            for (int z = 0; z < tresult2.Rows.Count; z++)
            {
                if (z == 0)
                {
                    if (tresult2.Rows[0]["CodAuto"].ToString() != "")
                    {
                        CodAutoPartePago1 = Convert.ToInt32(tresult2.Rows[0]["CodAuto"].ToString());
                    }
                }

                if (z == 1)
                {
                    if (tresult2.Rows[0]["CodAuto"].ToString() != "")
                    {
                        CodAutoPartePago2 = Convert.ToInt32(tresult2.Rows[0]["CodAuto"].ToString());
                    }
                }
            }

            double ImporteAutoPartePago = 0;
            double ImporteCredito       = 0;
            double ImporteEfectivo      = 0;
            double ImportePrenda        = 0;
            double ImporteCobranza      = 0;
            double ImporteBanco         = 0;
            double CodAutoVendido       = -1;
            double CodAutoPartePago     = -1;
            double ImporteAutoNegativo  = 0;
            double ImporteSenia         = 0;

            Clases.cVenta objVenta = new Clases.cVenta();

            if (CodVenta != "")
            {
                Clases.cMovimiento objMov = new Clases.cMovimiento();
                ImporteAutoNegativo = objMov.GetImporteAutoNegativoxCodVenta(Convert.ToInt32(CodVenta));
                ImporteAutoNegativo = -1 * ImporteAutoNegativo;

                DataTable trdo = objVenta.GetVentaxCodigo(Convert.ToInt32(CodVenta));
                if (trdo.Rows.Count > 0)
                {
                    ImporteCredito  = Convert.ToDouble(trdo.Rows[0]["ImporteCredito"].ToString());
                    ImporteEfectivo = Convert.ToDouble(trdo.Rows[0]["ImporteEfectivo"].ToString());
                    ImportePrenda   = Convert.ToDouble(trdo.Rows[0]["ImportePrenda"].ToString());
                    ImporteCobranza = Convert.ToDouble(trdo.Rows[0]["ImporteCobranza"].ToString());
                    if (trdo.Rows[0]["PrecioSenia"].ToString() != "")
                    {
                        ImporteSenia = Convert.ToDouble(trdo.Rows[0]["PrecioSenia"].ToString());
                    }
                    ImporteEfectivo = ImporteEfectivo + ImporteSenia;
                    if (trdo.Rows[0]["CodAutoVendido"].ToString() != "")
                    {
                        CodAutoVendido = Convert.ToInt32(trdo.Rows[0]["CodAutoVendido"].ToString());
                    }

                    if (trdo.Rows[0]["CodAutoPartePago"].ToString() != "")
                    {
                        CodAutoPartePago = Convert.ToInt32(trdo.Rows[0]["CodAutoPartePago"].ToString());
                    }

                    if (trdo.Rows[0]["ImporteAutoPartePago"].ToString() != "")
                    {
                        ImporteAutoPartePago = Convert.ToDouble(trdo.Rows[0]["ImporteAutoPartePago"].ToString());
                    }

                    if (trdo.Rows[0]["ImporteBanco"].ToString() != "")
                    {
                        ImporteBanco = Convert.ToDouble(trdo.Rows[0]["ImporteBanco"].ToString());
                    }
                }

                //importe total del credito en documentos usado mas abajo
                double        ImporteTotalDocumento = 0;
                Clases.cCuota objCuotas             = new Clases.cCuota();
                ImporteTotalDocumento = objCuotas.GetSaldoDeudaCuotas(Convert.ToInt32(CodVenta));
                SqlConnection con = new SqlConnection();
                con.ConnectionString = Clases.cConexion.Cadenacon();
                con.Open();
                SqlTransaction Transaccion;
                Transaccion = con.BeginTransaction();
                SqlCommand Comand = new SqlCommand();
                Comand.Connection  = con;
                Comand.Transaction = Transaccion;
                try
                {
                    //vuelvo el auto al stock
                    //string sql = "insert into StockAuto(CodAuto,FechaAlta,CodUsuario)";
                    //sql = sql + " values(" + CodAutoVendido.ToString();
                    //sql = sql + "," + "'" + DateTime.Now.ToShortDateString() + "'";
                    //sql = sql + "," + Principal.CodUsuarioLogueado;
                    //sql = sql + ")";
                    string sql = "update StockAuto  set FechaBaja = null";
                    sql = sql + " where CodStock=";
                    sql = sql + " (select max(CodStock) from StockAuto sa ";
                    sql = sql + " where sa.CodAuto =" + CodAutoVendido.ToString();
                    sql = sql + ")";
                    Comand.CommandText = sql;
                    Comand.ExecuteNonQuery();
                    //si pago con un auto le doy de baja
                    if (CodAutoPartePago > 0)
                    {
                        SqlCommand Comand2 = new SqlCommand();
                        Comand2.Connection  = con;
                        Comand2.Transaction = Transaccion;
                        string sqlStock = "update StockAuto";
                        sqlStock            = sqlStock + " set FechaBaja =" + "'" + DateTime.Now.ToShortDateString() + "'";
                        sqlStock            = sqlStock + " where CodAuto =" + CodAutoPartePago;
                        Comand2.CommandText = sqlStock;
                        Comand2.ExecuteNonQuery();
                    }
                    //borro la venta
                    string     sql3    = "delete from venta where CodVenta=" + CodVenta.ToString();
                    SqlCommand Comand3 = new SqlCommand();
                    Comand3.Connection  = con;
                    Comand3.Transaction = Transaccion;
                    Comand3.CommandText = sql3;
                    Comand3.ExecuteNonQuery();

                    //borro las cuotas

                    string     sql4    = "delete from cuotas where CodVenta=" + CodVenta.ToString();
                    SqlCommand Comand4 = new SqlCommand();
                    Comand4.Connection  = con;
                    Comand4.Transaction = Transaccion;
                    Comand4.CommandText = sql4;
                    Comand4.ExecuteNonQuery();

                    //borro la prenda

                    string     sqlPrenda    = "delete from Prenda where CodVenta=" + CodVenta.ToString();
                    SqlCommand ComandPrenda = new SqlCommand();
                    ComandPrenda.Connection  = con;
                    ComandPrenda.Transaction = Transaccion;
                    ComandPrenda.CommandText = sqlPrenda;
                    ComandPrenda.ExecuteNonQuery();

                    //borro los cheques

                    string     sqlCheque    = "delete from Cheque where CodVenta=" + CodVenta.ToString();
                    SqlCommand ComandCheque = new SqlCommand();
                    ComandCheque.Connection  = con;
                    ComandCheque.Transaction = Transaccion;
                    ComandCheque.CommandText = sqlCheque;
                    ComandCheque.ExecuteNonQuery();

                    //si hubo un saldo de cobranza tb lo anulo
                    //ya que significa que habia pagado una cobranza
                    //y debo volver a sacar el efectivo cobrado

                    //borro las cobranzas

                    string     sqlCobranza    = "delete from Cobranza where CodVenta=" + CodVenta.ToString();
                    SqlCommand ComandCobranza = new SqlCommand();
                    ComandCobranza.Connection  = con;
                    ComandCobranza.Transaction = Transaccion;
                    ComandCobranza.CommandText = sqlCobranza;
                    ComandCobranza.ExecuteNonQuery();



                    //borro las comisiones
                    if (ImportePagadoCobranza > 0)
                    {
                        //vuelvo el efectivo atraz
                        ImporteEfectivo = ImporteEfectivo + ImportePagadoCobranza;
                        //
                    }

                    if (ImportePagadoCuotas > 0)
                    {
                        ImporteEfectivo = ImporteEfectivo + ImportePagadoCuotas;
                    }

                    if (ImportePagadoPrenda > 0)
                    {
                        ImporteEfectivo = ImporteEfectivo + ImportePagadoPrenda;
                    }

                    if (ImportePagadoCheque > 0)
                    {
                        ImporteEfectivo = ImporteEfectivo + ImportePagadoCheque;
                    }

                    string     sqlComision    = "delete from ComisionVendedor where CodVenta=" + CodVenta.ToString();
                    SqlCommand ComandComision = new SqlCommand();
                    ComandComision.Connection  = con;
                    ComandComision.Transaction = Transaccion;
                    ComandComision.CommandText = sqlComision;
                    ComandComision.ExecuteNonQuery();

                    //Inserto el movimiento con los valores opuesto
                    ImporteCredito        = ImporteCredito * (-1);
                    ImporteTotalDocumento = ImporteTotalDocumento * (-1);
                    ImporteEfectivo       = ImporteEfectivo * (-1);
                    ImportePrenda         = ImportePrenda * (-1);
                    ImporteCobranza       = ImporteCobranza * (-1);
                    ImporteBanco          = ImporteBanco * (-1);
                    ImporteAutoPartePago  = (-1) * ImporteAutoPartePago;


                    string Descrip = "ANULACION VENTA " + Patente.ToString();
                    string sql5    = "Insert into Movimiento(ImporteDocumento,ImporteEfectivo";
                    sql5 = sql5 + ",ImportePrenda,ImporteCobranza,CodUsuario,Fecha,ImporteAuto,ImporteBanco,Descripcion)";
                    sql5 = sql5 + "Values(" + ImporteTotalDocumento.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + ImporteEfectivo.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + ImportePrenda.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + ImporteCobranza.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + Principal.CodUsuarioLogueado.ToString();
                    sql5 = sql5 + "," + "'" + DateTime.Now.ToShortDateString() + "'";
                    sql5 = sql5 + "," + ImporteAutoPartePago.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + ImporteBanco.ToString().Replace(",", ".");
                    sql5 = sql5 + "," + "'" + Descrip + "'";
                    sql5 = sql5 + ")";
                    //finalmente inserto el movimiento opuesto
                    //para que vuelva el valor de la cuenta vehiculo
                    SqlCommand Comand5 = new SqlCommand();
                    Comand5.Connection  = con;
                    Comand5.Transaction = Transaccion;
                    Comand5.CommandText = sql5;
                    Comand5.ExecuteNonQuery();

                    string sql5b = "Insert into Movimiento(ImporteDocumento,ImporteEfectivo";
                    sql5b = sql5b + ",ImportePrenda,ImporteCobranza,CodUsuario,Fecha,ImporteAuto,ImporteBanco)";
                    sql5b = sql5b + "Values(" + ImporteTotalDocumento.ToString().Replace(",", ".");
                    sql5b = sql5b + ",0";
                    sql5b = sql5b + ",0";
                    sql5b = sql5b + ",0";
                    sql5b = sql5b + "," + Principal.CodUsuarioLogueado.ToString();
                    sql5b = sql5b + "," + "'" + DateTime.Now.ToShortDateString() + "'";
                    sql5b = sql5b + "," + ImporteAutoNegativo.ToString().Replace(",", ".");
                    sql5b = sql5b + ",0";
                    sql5b = sql5b + ")";
                    //finalmente inserto el movimiento opuesto del auto
                    //para que vuelva el valor de la cuenta vehiculo
                    SqlCommand Comand5b = new SqlCommand();
                    Comand5b.Connection  = con;
                    Comand5b.Transaction = Transaccion;
                    Comand5b.CommandText = sql5b;
                    Comand5b.ExecuteNonQuery();

                    string     sql6    = "delete from VentasxAuto where CodVenta =" + CodVenta.ToString();
                    SqlCommand Comand6 = new SqlCommand();
                    Comand6.Connection  = con;
                    Comand6.Transaction = Transaccion;
                    Comand6.CommandText = sql6;
                    Comand6.ExecuteNonQuery();

                    string     sql7    = "delete from GastosPagar where CodVenta =" + CodVenta.ToString();
                    SqlCommand Comand7 = new SqlCommand();
                    Comand7.Connection  = con;
                    Comand7.Transaction = Transaccion;
                    Comand7.CommandText = sql7;
                    Comand7.ExecuteNonQuery();

                    // doy de baja los autos del stock que ingresaron
                    // como parte de pago
                    if (CodAutoPartePago1 > 0)
                    {
                        string sql8 = "update StockAuto set FechaBaja=" + "'" + DateTime.Now.ToShortDateString() + "'";
                        sql8 = sql8 + " where CodAuto=" + CodAutoPartePago1.ToString();
                        SqlCommand Comand8 = new SqlCommand();
                        Comand8.Connection  = con;
                        Comand8.Transaction = Transaccion;
                        Comand8.CommandText = sql8;
                        Comand8.ExecuteNonQuery();
                    }

                    Transaccion.Commit();
                    con.Close();
                    GetVentas();
                    MessageBox.Show("Venta anulada correctamente", Clases.cMensaje.Mensaje());
                }
                catch (Exception ex)
                {
                    Transaccion.Rollback();
                    MessageBox.Show("Hubo un error en el proceso de anulación de venta", Clases.cMensaje.Mensaje());
                }
            }
        }