Beispiel #1
0
 private void cargarDetalles(int idVenta)
 {
     dgvDetalles.SetDataSource(
         from d in VentasDetallesRepository.ObtenerDetallesDeVenta(idVenta)
         select new
     {
         EArticulosRepository.ObtenerArticulosPorId(
             Convert.ToDecimal(d.IdArticulo)).Descripcion,
         d.Precio,
         d.Cantidad,
         d.Importe
     }
         );
 }
Beispiel #2
0
        private void ImprimirVenta(EVentas p)
        {
            var    cliente       = ClientesRepository.ObtenerClientePorId(Convert.ToDecimal(p.IdCliente));
            string dirección     = cliente.Direccion;
            string razónSocial   = cliente.RazonSocial;
            string documento     = cliente.NroDocumento.ToString();
            string tipoDocumento = TiposDocumentoRepository.TiposDocumentoPorId(cliente.IdTipoDocumento).Descripcion;
            string comprobante   = "Venta";
            string número        = p.Id.ToString();
            string fecha         = String.Format("{0: dd/MM/yyyy}", p.Fecha);
            string subTotal      = p.Importe.ToString();
            string descuento     = p.Descuento.ToString();
            string total         = p.ImporteTotal.ToString();
            //string validez = p.DiasValidez.ToString();
            DataTable dt = VentasDetallesRepository.CargarDetalles(p.Id);

            //MostrarReporte(dt, dirección, razónSocial, documento,
            //    tipoDocumento, comprobante, número, fecha,
            //    subTotal, descuento, total, validez);
            MostrarReporte(dt, dirección, razónSocial, documento,
                           tipoDocumento, comprobante, número, fecha,
                           subTotal, descuento, total);
        }
Beispiel #3
0
        private void GuardarVenta()
        {
            EVentas _venta = new EVentas();
            List <EVentasDetalles> _detalleVenta = new List <EVentasDetalles>();

            try
            {
                _venta.IdCliente     = IdCliente;
                _venta.Fecha         = Fecha;
                _venta.Importe       = Subtotal;
                _venta.Descuento     = Descuento;
                _venta.DescuentoPorc = DescPorc;
                _venta.ImporteTotal  = ImporteTotal;
                _venta.PrecioLista   = PrecioLista;
                _venta.IdUsuario     = IdUsuario;
                _venta.Estado        = Estado;
                var idVentaRegistrada = VentasRepository.Insertar(_venta);
                if (idVentaRegistrada == 0)
                {
                    MessageBox.Show("Error al registrar Venta", "Registrar venta");
                    return;
                }

                for (int i = 0; i <= Convert.ToInt32(dgvDetalles.Rows.Count - 1); i++)
                {
                    EVentasDetalles detalle = new EVentasDetalles();
                    detalle.IdArticulo = Convert.ToInt32(dgvDetalles.Rows[i].Cells[0].Value);
                    detalle.Cantidad   = Convert.ToInt32(dgvDetalles.Rows[i].Cells[3].Value);
                    detalle.Precio     = Convert.ToInt32(dgvDetalles.Rows[i].Cells[4].Value);
                    detalle.Importe    = Convert.ToInt32(dgvDetalles.Rows[i].Cells[5].Value);
                    detalle.IdVenta    = idVentaRegistrada;
                    _detalleVenta.Add(detalle);
                    if (!VentasDetallesRepository.Insertar(detalle))
                    {
                        VentasRepository.EliminarVentaRegistradaIncorrectamente(idVentaRegistrada);
                        VentasDetallesRepository.EliminarDetallesVentaRegistradosIncorrectamente(idVentaRegistrada);
                        MessageBox.Show("Error al registrar Venta", "Registrar venta");
                        return;
                    }
                }
                if (Configuration.ImprimeVentas)
                {
                    ImprimirVenta(_venta.Id);
                }
                if (Configuration.VentaDescuentaStock)
                {
                    foreach (var item in _detalleVenta)
                    {
                        EArticulosRepository.DescontarStockArticulo(
                            Convert.ToDecimal(item.IdArticulo), Convert.ToDecimal(item.Cantidad));
                    }
                }
                if (Configuration.SoloCobroEfectivo)
                {
                }
                MessageBox.Show("Venta registrada correctamente", "Registrar venta");
                LimpiarVentana();
            }
            catch (Exception ex)
            {
                ShowError("Error al intentar leer los datos: \n" + ex.Message);
            }
        }