示例#1
0
        public VentaResponse Add(VentaRequest request)
        {
            Vendedor vendedor = _unitOfWork.VendedorRepository.FindFirstOrDefault(x => x.Persona.Documento.Numero == request.DocumentoVendedor);

            if (vendedor == null)
            {
                return(new VentaResponse($"Vendedor con documento {request.DocumentoVendedor} no encontrado"));
            }
            if (ExisteFactura(request.NumeroFactura))
            {
                return(new VentaResponse($"La factura {request.NumeroFactura} ya está registrada"));
            }

            VentaBuilder ventaBuilder = new VentaBuilder(request.NumeroFactura);

            foreach (var item in request.Detalles)
            {
                ProductoBodega producto = _productoService.ProductoEnBodega(item.CodigoProducto, item.CodigoBodega);
                if (producto == null)
                {
                    return(new VentaResponse($"Producto {item.CodigoProducto} no está disponible en bodega {item.CodigoBodega}"));
                }
                if (_productoService.Disponible(item.CodigoProducto, item.CodigoBodega, item.Cantidad) == false)
                {
                    return(new VentaResponse
                           (
                               mensaje: $"El producto {item.CodigoProducto} no está disponible para esa cantidad."
                           ));
                }
                ventaBuilder = ventaBuilder.AgregarDetalle(producto, item.Cantidad, item.Precio, item.Descuento);
            }

            if (ventaBuilder.IsOk().Any())
            {
                return(new VentaResponse(string.Join(',', ventaBuilder.IsOk())));
            }

            Venta venta = ventaBuilder.Build(request.Abonado, request.Impuesto);

            vendedor.Vender(venta);

            _unitOfWork.VendedorRepository.Edit(vendedor);

            if (_unitOfWork.Commit() > 0)
            {
                return(new VentaResponse
                       (
                           mensaje: "Venta registrada correctamente",
                           entidad: venta
                       ));
            }

            return(new VentaResponse("No se pudo registrar la venta"));
        }
示例#2
0
        private void Btn_Trasladar_Click(object sender, EventArgs e)
        {
            var operaciones    = new OperacionesProductos();
            int stock          = int.Parse(txtCantidad.Text);
            int canActual      = 0;
            int idUsuarioOpero = FrmHome.IdUsuario;

            if (txtCanTraslado.Text != "")
            {
                int canTras = int.Parse(txtCanTraslado.Text);

                if (stock >= canTras)
                {
                    canActual = stock - canTras;

                    var miProdBodega = new ProductoBodega
                    {
                        Id_producto      = int.Parse(txtIdProducto.Text),
                        Id_bodega        = Convert.ToInt32(selectBodega.SelectedValue),
                        Cantidad_inicial = canTras,
                        Cantidad_actual  = canTras,
                    };

                    operaciones.TrasladarProducto(miProdBodega);
                    int idTraslado = operaciones.IdTraslado;

                    var miBitacora = new Vitacora
                    {
                        Id_usuario        = idUsuarioOpero,
                        Tipo_operacion    = "Ingreso",
                        Fecha             = DateTime.Now,
                        Id_productoBodega = idTraslado
                    };

                    operaciones.RegistroBitacora(miBitacora);

                    operaciones.ActualizarProductoTraslado(int.Parse(txtIdProducto.Text), canActual);

                    MessageBox.Show("Traslado Exitoso", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtIdProducto.Clear();
                    txtNombre.Clear();
                    txtCantidad.Clear();
                    txtCanTraslado.Clear();
                    groupBox1.Visible = false;
                }
                else
                {
                    MessageBox.Show("Estas excediendo la cantidad disponible", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
示例#3
0
        public VentaBuilder AgregarDetalle(ProductoBodega producto, int cantidad, double precio, double descuento)
        {
            VentaDetalle detalleExistente = Detalles.FirstOrDefault(x => x.ProductoBodega == producto);

            if (detalleExistente != null)
            {
                detalleExistente.Aumentar(cantidad, precio, descuento);
            }
            else
            {
                Detalles.Add(new VentaDetalle
                {
                    ProductoBodega = producto,
                    Cantidad       = cantidad,
                    Precio         = precio,
                    Descuento      = descuento
                });
            }
            return(this);
        }