Example #1
0
        public void extraerFactura(FacturaTO facturaTO)
        {
            Boolean error = true;

            using (context = new EmpresaEntities())
            {
                var query = from facturas in context.Facturas
                            where facturaTO.Consecutivo == facturas.Consecutivo
                            select facturas;

                if (query != null)
                {
                    foreach (Factura c in query)
                    {
                        error = false;
                        facturaTO.Consecutivo = c.Consecutivo;
                        facturaTO.Cliente     = c.Cliente;
                        facturaTO.FechaHora   = c.Fecha_Hora;
                        facturaTO.Total       = c.Total;
                    }
                }
                if (error)
                {
                    throw new DbUpdateException();
                }
            }
        }
Example #2
0
        public void extraerProducto(ProductoTO productoTO)
        {
            Boolean error = true;

            using (context = new EmpresaEntities())
            {
                var query = from producto in context.Productoes
                            where productoTO.Codigo == producto.ID_Producto
                            select producto;


                if (query != null)
                {
                    foreach (Producto c in query)
                    {
                        error = false;
                        productoTO.CantidadInventario = c.Cantidad_Disponible;
                        productoTO.Descripcion        = c.Descripcion;
                        productoTO.PrecioVenta        = c.Precio_Unidad;
                    }
                }
                if (error)
                {
                    throw new DbUpdateException();
                }
            }
        }
Example #3
0
        public List <Detalles_FacturaTO> obtenerDetalles(Detalles_FacturaTO detallesTO)
        {
            List <Detalles_FacturaTO> lista = new List <Detalles_FacturaTO>();

            using (context = new EmpresaEntities())
            {
                var query = from detalle in context.Detalle_Factura
                            where detallesTO.Consecutivo_Factura == detalle.Factura
                            select detalle;


                Detalles_FacturaTO dTO;

                if (query != null)
                {
                    foreach (Detalle_Factura df in query)
                    {
                        dTO = new Detalles_FacturaTO();
                        dTO.Consecutivo_Factura = df.Factura;
                        dTO.Cantidad            = df.Cantidad;
                        dTO.Codigo_Producto     = df.Producto;
                        lista.Add(dTO);
                    }
                }
                else
                {
                    throw new Exception("No hay productos para mostrar de la factura");
                }
            }
            return(lista);
        }
Example #4
0
        public List <FacturaTO> reporte(ReporteFacturacionTO reporteTO)
        {
            List <FacturaTO> listaFacturas = new List <FacturaTO>();
            DateTime         fechaInicio   = DateTime.Parse(reporteTO.FechaInicio);
            DateTime         fechaFin      = DateTime.Parse(reporteTO.FechaFin);

            using (context = new EmpresaEntities())
            {
                /*saca todas las facturas de un cliente*/
                var query = from reporte in context.Facturas
                            where (reporteTO.Cliente == reporte.Cliente) &&
                            (reporte.Fecha_Hora >= fechaInicio &&
                             reporte.Fecha_Hora <= fechaFin)
                            select reporte;

                FacturaTO facturaTO;
                foreach (Factura fac in query)
                {
                    facturaTO             = new FacturaTO();
                    facturaTO.Cliente     = fac.Cliente;
                    facturaTO.Consecutivo = fac.Consecutivo;
                    facturaTO.FechaHora   = fac.Fecha_Hora;
                    facturaTO.Total       = fac.Total;
                    listaFacturas.Add(facturaTO);
                }
            }

            return(listaFacturas);
        }
Example #5
0
        public void insertarFactura(FacturaTO facturaTo)
        {
            using (context = new EmpresaEntities())
            {
                var      dateQuery  = context.Database.SqlQuery <DateTime>("SELECT getdate()");
                DateTime serverDate = dateQuery.AsEnumerable().First();

                Factura facturaDAO = new Factura
                {
                    Cliente    = facturaTo.Cliente,
                    Fecha_Hora = serverDate,
                    Total      = 0
                };
                context.Facturas.Add(facturaDAO);
                context.SaveChanges();

                var query = from factura in context.Facturas
                            select factura;

                List <FacturaTO> list = new List <FacturaTO>();

                foreach (Factura factura in query)
                {
                    facturaTo.Consecutivo = factura.Consecutivo;
                }
            }
        }
Example #6
0
        public void extraerCliente(ClienteTO clienteTO)
        {
            Boolean error = true;

            using (context = new EmpresaEntities())
            {
                var query = from clientes in context.Clientes
                            where clienteTO.Cedula == clientes.Cedula
                            select clientes;

                if (query != null)
                {
                    foreach (Cliente c in query)
                    {
                        error              = false;
                        clienteTO.Nombre   = c.Nombre;
                        clienteTO.Apellido = c.Apellido;
                        clienteTO.Correo   = c.Correo;
                        clienteTO.Telefono = c.Telefono;
                    }
                }
                if (error)
                {
                    throw new DbUpdateException();
                }
            }
        }
Example #7
0
        public void eliminarProducto(ProductoTO productoTO)
        {
            Boolean error = true;

            context = new EmpresaEntities();

            var productoEliminar =
                from producto in context.Productoes
                where producto.ID_Producto == productoTO.Codigo
                select producto;

            foreach (var productDelete in productoEliminar)
            {
                error = false;
                context.Productoes.Remove(productDelete);
            }

            if (error)
            {
                throw new DbUpdateException();
            }
            try
            {
                context.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                throw new Exception();
            }
        }
Example #8
0
        public void eliminarCliente(ClienteTO clienteTO)
        {
            context = new EmpresaEntities();
            Boolean error           = true;
            var     clienteEliminar =
                from cliente in context.Clientes
                where cliente.Cedula == clienteTO.Cedula
                select cliente;

            foreach (var clientDelete in clienteEliminar)
            {
                error = false;
                context.Clientes.Remove(clientDelete);
            }
            if (error)
            {
                throw new DbUpdateException();
            }

            try
            {
                context.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                throw new Exception();
            }
        }
Example #9
0
        public void extraerProductoCantidad(int codigo, int cantidad)
        {
            Boolean error = true;

            using (context = new EmpresaEntities())
            {
                var query = from producto in context.Productoes
                            where codigo == producto.ID_Producto
                            select producto;


                if (query != null)
                {
                    foreach (Producto c in query)
                    {
                        if (c.Cantidad_Disponible >= cantidad)
                        {
                            actualizarCantidadProducto(codigo, c.Cantidad_Disponible - cantidad);
                            error = false;
                        }
                    }
                }
                if (error)
                {
                    throw new DbUpdateException();
                }
            }
        }
Example #10
0
        public void actualizarCantidadProducto(int codigo, int cantidad)
        {
            context = new EmpresaEntities();
            Producto productoDAO = (from producto in context.Productoes
                                    where producto.ID_Producto == codigo
                                    select producto).First();

            productoDAO.Cantidad_Disponible = cantidad;
            context.SaveChanges();
        }
Example #11
0
        public void actualizarTotalFactura(FacturaTO facturaTO)
        {
            context = new EmpresaEntities();

            Factura factura = (from facturas in context.Facturas
                               where facturas.Consecutivo == facturaTO.Consecutivo
                               select facturas).First();

            factura.Total = facturaTO.Total;
            context.SaveChanges();
        }
Example #12
0
        public void actualizarProducto(ProductoTO productoTO)
        {
            context = new EmpresaEntities();

            Producto productoDAO = (from producto in context.Productoes
                                    where producto.ID_Producto == productoTO.Codigo
                                    select producto).First();

            productoDAO.Cantidad_Disponible = productoTO.CantidadInventario;
            productoDAO.Descripcion         = productoTO.Descripcion;
            productoDAO.Precio_Unidad       = productoTO.PrecioVenta;
            context.SaveChanges();
        }
Example #13
0
        public void actualizarCliente(ClienteTO clienteTO)
        {
            context = new EmpresaEntities();

            Cliente cliente = (from clientes in context.Clientes
                               where clientes.Cedula == clienteTO.Cedula
                               select clientes).First();

            cliente.Nombre   = clienteTO.Nombre;
            cliente.Apellido = clienteTO.Apellido;
            cliente.Correo   = clienteTO.Correo;
            cliente.Telefono = clienteTO.Telefono;

            context.SaveChanges();
        }
Example #14
0
 public void insertarCliente(ClienteTO cliente)
 {
     using (context = new EmpresaEntities())
     {
         Cliente nuevoCliente = new Cliente
         {
             Cedula   = cliente.Cedula,
             Nombre   = cliente.Nombre,
             Apellido = cliente.Apellido,
             Correo   = cliente.Correo,
             Telefono = cliente.Telefono
         };
         context.Clientes.Add(nuevoCliente);
         context.SaveChanges();
     }
 }
Example #15
0
        public List <TO.FacturaTO> getFacturas()
        {
            using (context = new EmpresaEntities())
            {
                var query = from factura in context.Facturas
                            select factura;

                List <FacturaTO> list      = new List <FacturaTO>();
                FacturaTO        facturaTo = new FacturaTO();
                foreach (Factura factura in query)
                {
                    facturaTo             = new FacturaTO();
                    facturaTo.Cliente     = factura.Cliente;
                    facturaTo.Consecutivo = factura.Consecutivo;
                    facturaTo.FechaHora   = factura.Fecha_Hora;
                    facturaTo.Total       = factura.Total;
                    list.Add(facturaTo);
                }
                return(list);
            }
        }
Example #16
0
        public List <TO.ProductoTO> getProductos()
        {
            using (context = new EmpresaEntities())
            {
                var query = from producto in context.Productoes
                            select producto;

                List <ProductoTO> list       = new List <ProductoTO>();
                ProductoTO        productoTO = new ProductoTO();
                foreach (Producto producto in query)
                {
                    productoTO = new ProductoTO();
                    productoTO.CantidadInventario = producto.Cantidad_Disponible;
                    productoTO.Codigo             = producto.ID_Producto;
                    productoTO.Descripcion        = producto.Descripcion;
                    productoTO.PrecioVenta        = producto.Precio_Unidad;
                    list.Add(productoTO);
                }
                return(list);
            }
        }
Example #17
0
        public void insertarProducto(ProductoTO productoTO)
        {
            using (context = new EmpresaEntities())
            {
                Producto productoDAO = new Producto
                {
                    Cantidad_Disponible = productoTO.CantidadInventario,
                    Descripcion         = productoTO.Descripcion,
                    ID_Producto         = productoTO.Codigo,
                    Precio_Unidad       = productoTO.PrecioVenta
                };

                try
                {
                    context.Productoes.Add(productoDAO);
                    context.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    throw new DbUpdateException();
                }
            }
        }
Example #18
0
        public void insertarDetalle(Detalles_FacturaTO detalleTO)
        {
            try
            {
                ProductoDAO productoDAO = new ProductoDAO();
                using (context = new EmpresaEntities())
                {
                    Detalle_Factura detalleDAO = new Detalle_Factura
                    {
                        Factura  = detalleTO.Consecutivo_Factura,
                        Producto = detalleTO.Codigo_Producto,
                        Cantidad = detalleTO.Cantidad
                    };

                    ProductoTO productoTO = new ProductoTO();
                    productoTO.Codigo = detalleTO.Codigo_Producto;

                    productoDAO.extraerProducto(productoTO);

                    if (detalleTO.Cantidad == 0)
                    {
                        throw new Exception("La cantidad de un producto no puede ser 0");
                    }
                    if (productoTO.CantidadInventario < detalleTO.Cantidad)
                    {
                        throw new Exception("Error, no hay suficientes productos para satisfcaer la demanda");
                    }
                    context.Detalle_Factura.Add(detalleDAO);
                    context.SaveChanges();
                    productoDAO.extraerProductoCantidad(detalleTO.Codigo_Producto, detalleTO.Cantidad);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #19
0
        /*-----------CLIENTES-----------*/
        public List <TO.ClienteTO> getClients()
        {
            using (context = new EmpresaEntities())
            {
                var query = from clients in context.Clientes
                            select clients;

                List <ClienteTO> list      = new List <ClienteTO>();
                ClienteTO        clienteTO = new ClienteTO();
                foreach (Cliente client in query)
                {
                    clienteTO          = new ClienteTO();
                    clienteTO.Nombre   = client.Nombre;
                    clienteTO.Telefono = client.Telefono;
                    clienteTO.Correo   = client.Correo;
                    clienteTO.Cedula   = client.Cedula;
                    clienteTO.Apellido = client.Apellido;
                    list.Add(clienteTO);
                }


                return(list);
            }
        }