public ProductoMovimientosViewModel(IWindowManager windowmanager)
        {
            _windowManager = windowmanager;
            CmbZonas = (new TipoZonaSQL()).BuscarZona();
            Usuario u = new Usuario();
            u = DataObjects.Seguridad.UsuarioSQL.buscarUsuarioPorIdUsuario(Int32.Parse(Thread.CurrentPrincipal.Identity.Name));
            idTienda = u.IdTienda;
            idResponsable = u.IdUsuario;

            aSQL = new AlmacenSQL();
            Almacenes deposito = aSQL.BuscarAlmacen(-1, idTienda, 1);
            Almacenes anaquel = aSQL.BuscarAlmacen(-1, idTienda, 2);
            idDeposito = deposito.IdAlmacen;
            idAnaquel = anaquel.IdAlmacen;

            NumColumnAnq = anaquel.NroColumnas;
            NumRowsAnq = anaquel.NroFilas;
            AlturaAnq = anaquel.Altura;

            NumColumns = deposito.NroColumnas;
            NumRows = deposito.NroFilas;
            Altura = deposito.Altura;

            tzSQL = new TipoZonaSQL();
            LstZonas = tzSQL.ObtenerZonasxAlmacen(idDeposito);
            LstZonasAnq = tzSQL.ObtenerZonasxAlmacen(idAnaquel, 2);

            Accion2 = 2;
            Accion1 = 2;

            LstProductos = new List<ProductoCant>();
            Atendido = false;
        }
        public MantenerNotaDeIngresoViewModel(IWindowManager windowmanager)
        {
            _windowManager = windowmanager;
            pxaSQL = new ProductoSQL();
            this.cmbMotivo = DataObjects.Almacen.MotivoSQL.BuscarMotivos(1);
            AlmacenSQL aGW = new AlmacenSQL();
            u = DataObjects.Seguridad.UsuarioSQL.buscarUsuarioPorIdUsuario(Int32.Parse(Thread.CurrentPrincipal.Identity.Name));
            idTienda = u.IdTienda;
            Models.Almacen.Almacenes a;
            if (idTienda != 0)
            {
                //1 deposito
                //2 anaquel
                //3 central va al else
                a = aGW.BuscarAlmacen(-1, idTienda, 1);
            }
            else
            {
                a = aGW.BuscarAlmacen(-1, -1, 3);
            }

            List<Usuario> ul = new List<Usuario>();
            ul.Add(u);
            this.responsable = new List<Usuario>(ul);

            List<Models.Almacen.Almacenes> al = new List<Models.Almacen.Almacenes>();
            al.Add(a);
            this.almacen = al;
            Estado = true;
            EstadoMot = true;
            EstadoPro = true;
        }
Ejemplo n.º 3
0
        public BuscarZonaViewModel(IWindowManager windowmanager)
        {
            _windowManager = windowmanager;
            Usuario u = new Usuario();
            u = DataObjects.Seguridad.UsuarioSQL.buscarUsuarioPorIdUsuario(Int32.Parse(Thread.CurrentPrincipal.Identity.Name));
            idTienda = u.IdTienda;
            idResponsable = u.IdUsuario;

            TiendaSQL tSQL = new TiendaSQL();
            CmbTiendas = tSQL.BuscarTienda();
            Index = this.CmbTiendas.FindIndex(x => x.IdTienda == idTienda);

            AlmacenSQL aSQL = new AlmacenSQL();
            Almacenes anaquel = aSQL.BuscarAlmacen(-1, idTienda, 2);

            idAnaquel = anaquel.IdAlmacen;

            NumColumns = anaquel.NroColumnas;
            NumRows = anaquel.NroFilas;
            Altura = anaquel.Altura;

            TipoZonaSQL tzSQL = new TipoZonaSQL();
            LstZonasAnq = tzSQL.ObtenerZonasxAlmacen(idAnaquel, 2);
            CmbZonas = lstZonasAnq;
            ProductoSQL pSQL = new ProductoSQL();
            LstProductos = pSQL.BuscarProductoxTienda(idTienda);
        }
 public reporteStockViewModel()
 {
     uSQL = new AlmacenSQL();
     CmbDpto = uSQL.BuscarAlmacen();
     deft= new Almacenes();
     deft.Nombre="TODOS";
     CmbDpto.Insert(0, deft);
     Index1 = 0;
 }
        public MantenerAlmacenViewModel(IWindowManager windowmanager)
        {
            _windowManager = windowmanager;
            uSQL = new UbigeoSQL();
            tSQL = new TiendaSQL();
            pxaSQL = new ProductoSQL();
            aSQL = new AlmacenSQL();
            tzSQL = new TipoZonaSQL();
            int existe = aSQL.existeCentral();
            Editar = true;

            if (existe > 0)
            {
                Almacenes central = aSQL.BuscarAlmacen(-1, -1, 3);
                accion = 2;
                Editar = false;
                /* idTienda = t.IdTienda;  */
                /*carga de la informacion general*/
                TxtNombre = central.Nombre;
                TxtTelefono = central.Telefono;
                TxtDir = central.Direccion;
                List<Ubigeo> u = uSQL.buscarUbigeo2(central.IdUbigeo);

                /*carga de los combobox*/
                CmbDpto = uSQL.BuscarDpto();
                Index1 = CmbDpto.FindIndex(x => x.CodDpto == u[0].CodDpto);
                SelectedDpto = u[0].CodDpto;
                Index2 = CmbProv.FindIndex(x => x.CodProv == u[0].CodProv);
                SelectedProv = u[0].CodProv;
                Index3 = CmbDist.FindIndex(x => x.CodDist == u[0].CodDist);

                Content = "Ver distribución";
                TxtNumColumns = central.NroColumnas.ToString();
                TxtNumRows = central.NroFilas.ToString();
                TxtAltura = central.Altura.ToString();

                lstZonas = tzSQL.ObtenerZonasxAlmacen(central.IdAlmacen, 3);
                _windowManager.ShowDialog(new AlertViewModel(_windowManager, "El almacen central ya existe"));
            }
            else if (existe == 0)
            {
                CmbZonas = (new TipoZonaSQL()).BuscarZona();
                CmbDpto = uSQL.BuscarDpto();
                Content = "Generar distribución";
            }
            else
            {
                _windowManager.ShowDialog(new AlertViewModel(_windowManager, "Ocurrió un problema"));
            }
        }
Ejemplo n.º 6
0
        public List<NotaIS> BuscarNotas(string a = null)
        {
            List<NotaIS> lstNotaIs = new List<NotaIS>();

            AlmacenSQL asql = new AlmacenSQL();
            if (a != null)
            {
            if (string.Compare("Entrada", a, true) == 0)
            {
                string where = " WHERE tipo=1 ORDER BY fechaReg Desc";
                db.cmd.CommandText = "SELECT * FROM NotaIS" + where;

            }
            if (string.Compare("Salida", a, true) == 0)
            {
                string where = " WHERE tipo=2 ORDER BY fechaReg Desc";
                db.cmd.CommandText = "SELECT * FROM NotaIS" + where;

            }
            if (string.Compare("MovimientoInterno", a, true) == 0)
            {
                string where = " WHERE tipo=3 ORDER BY fechaReg Desc";
                db.cmd.CommandText = "SELECT * FROM NotaIS" + where;

            }
            }
            else {
            db.cmd.CommandText = "SELECT * FROM NotaIS ORDER BY fechaReg Desc";

            }
            try
            {
                if (tipo)  db.conn.Open();
                SqlDataReader reader = db.cmd.ExecuteReader();

                while (reader.Read())
                {
                    NotaIS nota = new NotaIS();

                    nota.FechaReg = reader.IsDBNull(reader.GetOrdinal("fechaReg")) ? DateTime.MinValue : DateTime.Parse(reader["fechaReg"].ToString());
                    nota.IdAlmacen = reader.IsDBNull(reader.GetOrdinal("idAlmacen")) ? -1 : int.Parse(reader["idAlmacen"].ToString());
                    nota.IdDoc = reader.IsDBNull(reader.GetOrdinal("idDoc")) ? -1 : int.Parse(reader["idDoc"].ToString());
                    nota.IdMotivo = reader.IsDBNull(reader.GetOrdinal("idMotivo")) ? -1 : int.Parse(reader["idMotivo"].ToString());
                    nota.IdNota = reader.IsDBNull(reader.GetOrdinal("idNota")) ? -1 : int.Parse(reader["idNota"].ToString());
                    nota.IdResponsable = reader.IsDBNull(reader.GetOrdinal("responsable")) ? -1 : int.Parse(reader["responsable"].ToString());
                    nota.Observaciones = reader.IsDBNull(reader.GetOrdinal("observaciones")) ? "" : reader["observaciones"].ToString();
                    nota.Tipo = reader.IsDBNull(reader.GetOrdinal("tipo")) ? -1 : int.Parse(reader["tipo"].ToString());
                    nota.IdNotaString = "Nota00000" + nota.IdNota.ToString();
                    nota.IdAlmacenString = asql.BuscarAlmacen(nota.IdAlmacen, -1, -1).Nombre;
                    if (nota.Tipo == 1) nota.TipoString = "Entrada";
                    if (nota.Tipo == 2) nota.TipoString = "Salida";
                    if (nota.Tipo == 3) nota.TipoString = "Movimiento Interno";
                    nota.LstProducto = BuscarNotas(nota.IdNota);
                    lstNotaIs.Add(nota);

                }
                db.cmd.Parameters.Clear();
                if (tipo)  db.conn.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace.ToString());
            }

            return lstNotaIs;
        }
        public PosicionProductoViewModel(IWindowManager windowmanager, object sender, int accion)
        {
            _windowManager = windowmanager;
            this.accion = accion;
            if (accion == 1)
            {
                this.mantenerNotaDeIngresoViewModel = (sender as MantenerNotaDeIngresoViewModel);
                this.LstProductos = (sender as MantenerNotaDeIngresoViewModel).LstProductos;
                ImSource = "/Assets/add.png";
                Ejecutar = "Agregar";

            }
            else
            {
                this.mantenerNotaDeSalidaViewModel = (sender as MantenerNotaDeSalidaViewModel);
                this.LstProductos = (sender as MantenerNotaDeSalidaViewModel).LstProductos;
                ImSource = "/Assets/minus.png";
                Ejecutar = "Disminuir";

            }

            Usuario u = new Usuario();
            u = DataObjects.Seguridad.UsuarioSQL.buscarUsuarioPorIdUsuario(Int32.Parse(Thread.CurrentPrincipal.Identity.Name));

            idTienda = u.IdTienda;
            aSQL = new AlmacenSQL();
            Almacenes deposito = aSQL.BuscarAlmacen(-1, idTienda == 0 ? -1 : idTienda, idTienda == 0 ? 3 : 1);

            id = deposito.IdAlmacen;

            NumColumns = deposito.NroColumnas;
            NumRows = deposito.NroFilas;
            Altura = deposito.Altura;

            tzSQL = new TipoZonaSQL();
            LstZonas = tzSQL.ObtenerZonasxAlmacen(deposito.IdAlmacen);

            Accion2 = 2;
            Accion1 = 2;
            Enable = true;
        }
        public void GuardarVenta(string cmbTipoVenta)
        {
            int numFilas = LstVenta.Count();
            if (numFilas > 0)
            {
                Venta v = new Venta();
                v.LstDetalle = new List<DetalleVenta>();
                v.LstPagos = new List<VentaPago>();
                v.LstDetalleServicio = new List<DetalleVentaServicio>();
                //guardar datos de la venta
                //completar
                if (tipoVenta[cmbTipoVenta] == 0)
                    v.TipoDocPago = "Boleta";
                else
                {
                    v.TipoDocPago = "Factura";
                    //validar que los datos de ruc y razon social
                    if (!string.IsNullOrEmpty(TxtRuc) && !string.IsNullOrEmpty(TxtRazonSocial))
                    {
                        v.Ruc = TxtRuc;
                        v.RazonSocial = TxtRazonSocial;
                    }
                    else
                    {
                        MessageBox.Show("Falta ingresar Ruc o Razón Social", "AVISO", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }

                v.NumDocPago = null;
                v.TipoVenta = "Tienda";
                v.Estado = 1;
                v.FechaReg = System.DateTime.Now;
                v.IdUsuario = Convert.ToInt32(Thread.CurrentPrincipal.Identity.Name);
                //idCliente desde la tarjeta de este si es que hay
                if (!string.IsNullOrEmpty(TxtCliente))
                {
                    v.IdCliente = Convert.ToInt32(cliente.Id);
                    v.CodTarjeta = Convert.ToInt32(TxtCliente);
                }
                else
                {
                    v.IdCliente = -1;
                    v.CodTarjeta = -1;
                }

                //guardar detalle de la venta
                foreach (DetalleVenta dv in lstVenta)
                {
                    v.LstDetalle.Add(dv);
                }
                v.Monto = total;
                v.Descuento = desc;
                v.Igv = igv_total;

                v.PtosGanados = Convert.ToInt32(v.Monto / PUNTO);

                foreach (VentaPago vp in lstPagos)
                {
                    if (vp.Nombre.Equals("Efectivo"))
                    {
                        vp.Monto -= Double.Parse(txtVuelto);
                    }
                    v.LstPagos.Add(vp);
                }

                //guardar detalle de servicios de la venta, si es que hay
                if (LstVentaServicios.Count() > 0)
                {
                    foreach (DetalleVentaServicio dvs in LstVentaServicios)
                    {
                        v.LstDetalleServicio.Add(dvs);
                    }
                }

                //insertar en la base de datos
                DBConexion db = new DBConexion();
                db.conn.Open();
                SqlTransaction trans = db.conn.BeginTransaction(IsolationLevel.Serializable);
                db.cmd.Transaction = trans;
                VentaSQL vsql = new VentaSQL(db);
                if (v.IdCliente == -1)
                {
                    int k = vsql.AgregarSinCliente(v);
                    if (k != 0)
                    {

                        NotaISSQL ntgw = new NotaISSQL();
                        NotaIS nota = new NotaIS();
                        AlmacenSQL asql = new AlmacenSQL();
                        nota.IdAlmacen = asql.BuscarAlmacen(-1, idTienda, 2).IdAlmacen;
                        // Logica de  Referencia de documento

                        //Si existe documento de referencia colocar el ID
                        nota.IdDoc = v.IdVenta;

                        nota.IdMotivo = 9;
                        nota.IdResponsable = v.IdUsuario;
                        nota.Observaciones = "Venta en Cajero";
                        nota.Tipo = 2;
                        List<ProductoCant> LstProductos = new List<ProductoCant>();
                        List<ProductoCant> lpcan = new List<ProductoCant>();

                        for (int i = 0; i < v.LstDetalle.Count; i++)
                        {
                            Producto p = new ProductoSQL().Buscar_por_CodigoProducto(v.LstDetalle.ElementAt(i).IdProducto);
                            ProductoCant pcan = new ProductoCant();
                            pcan.IdProducto = p.IdProducto;
                            pcan.CodigoProd = p.CodigoProd;
                            pcan.Nombre = p.Nombre;
                            pcan.CanAtender = v.LstDetalle.ElementAt(i).Cantidad.ToString();
                            lpcan.Add(pcan);

                        }
                        LstProductos = new List<ProductoCant>(lpcan);

                        nota.LstProducto = LstProductos;

                        nota.IdNota = ntgw.AgregarNota(nota);

                        trans.Commit();
                        ntgw.AgregarNotaxSector(nota);
                        MessageBox.Show("Venta Realizada con Exito");
                        Limpiar();
                    }
                    else
                    {
                        trans.Rollback();
                        MessageBox.Show("Ocurrio un Error en el proceso");
                    }
                }
                else
                {
                    int k = vsql.Agregar(v);
                    if (k != 0)
                    {

                        NotaISSQL ntgw = new NotaISSQL();
                        NotaIS nota = new NotaIS();
                        AlmacenSQL asql = new AlmacenSQL();
                        nota.IdAlmacen = asql.BuscarAlmacen(-1, idTienda, 2).IdAlmacen;
                        // Logica de  Referencia de documento

                        //Si existe documento de referencia colocar el ID
                        nota.IdDoc = v.IdVenta;

                        nota.IdMotivo = 9;
                        nota.IdResponsable = v.IdUsuario;
                        nota.Observaciones = "Venta en Cajero";
                        nota.Tipo = 2;
                        List<ProductoCant> LstProductos = new List<ProductoCant>();
                        List<ProductoCant> lpcan = new List<ProductoCant>();

                        for (int i = 0; i < v.LstDetalle.Count; i++)
                        {
                            Producto p = new ProductoSQL().Buscar_por_CodigoProducto(v.LstDetalle.ElementAt(i).IdProducto);
                            ProductoCant pcan = new ProductoCant();
                            pcan.IdProducto = p.IdProducto;
                            pcan.CodigoProd = p.CodigoProd;
                            pcan.Nombre = p.Nombre;
                            pcan.CanAtender = v.LstDetalle.ElementAt(i).Cantidad.ToString();
                            lpcan.Add(pcan);

                        }
                        LstProductos = new List<ProductoCant>(lpcan);

                        nota.LstProducto = LstProductos;

                        nota.IdNota = ntgw.AgregarNota(nota);

                        trans.Commit();

                        ntgw.AgregarNotaxSector(nota);
                        MessageBox.Show("Venta Realizada con Exito");
                        Limpiar();
                    }
                    else
                    {
                        trans.Rollback();
                        MessageBox.Show("Ocurrio un Error en el proceso");
                    }
                }

                if (v.TipoDocPago.Equals("Boleta"))
                {
                    GenerarPDFBoletaProductos(v);
                    if (v.LstDetalleServicio.Count() > 0)
                        GenerarPDFBoletaServicios(v);
                }
                else
                {
                    GenerarPDFFacturaProductos(v);
                    if (v.LstDetalleServicio.Count() > 0)
                        GenerarPDFFacturaServicios(v);
                }

            }
            else
            {
                MessageBox.Show("Debe ingreasar datos de la venta");
                return;
            }
        }
Ejemplo n.º 9
0
        public List<OrdenDespacho> BuscarOrdenDespacho(int idOrdenDespacho, int idVenta, int estado)
        {
            List<OrdenDespacho> listaOrdenDespacho = new List<OrdenDespacho>();

            string select = "SELECT * ";
            string from = "FROM OrdenDespacho ";
            string where = "WHERE 1 = 1";

            if (estado > 0)
            {
                where += " AND estado = @estado ";
                db.cmd.Parameters.AddWithValue("@estado", estado);
            }
            if (idOrdenDespacho > 0)
            {
                where += " AND idOrdenDespacho = @idOrdenDespacho ";
                db.cmd.Parameters.AddWithValue("@idOrdenDespacho", idOrdenDespacho);
            }

            if (idVenta > 0)
            {
                where += " AND idVenta = @idVenta ";
                db.cmd.Parameters.AddWithValue("@idVenta", idVenta);
            }

            Usuario u = UsuarioSQL.buscarUsuarioPorIdUsuario(Int32.Parse(Thread.CurrentPrincipal.Identity.Name));

            // PARA USUARIO EN ALMACEN

            if (u.IdTienda != 0)
            {
                AlmacenSQL aSQL = new AlmacenSQL();
                int idTi = u.IdTienda;
                Almacenes alm = aSQL.BuscarAlmacen(-1, idTi, 1);

                if (alm != null)
                {
                    Trace.WriteLine("IDALMACEN: " + alm.IdAlmacen);
                    Trace.WriteLine("IDTIENDA: " + idTi);

                    where += " AND idAlmacen = @idAlmacen ";
                    db.cmd.Parameters.AddWithValue("@idAlmacen", alm.IdAlmacen);
                }
            }

            db.cmd.CommandText = select + from + where;

            try
            {
                db.conn.Open();
                SqlDataReader reader = db.cmd.ExecuteReader();

                while (reader.Read())
                {

                    OrdenDespacho p = new OrdenDespacho();

                    p.IdOrdenDespacho = Int32.Parse(reader["idOrdenDespacho"].ToString());
                    p.CodOrden = "OD-" + (1000000 + p.IdOrdenDespacho).ToString();

                    int id = Int32.Parse(reader["idVenta"].ToString());
                    p.Venta = new MantenerGuiaDeRemisionViewModel(new MyWindowManager()).getVentafromID(id);
                    p.Estado = Int32.Parse(reader["estado"].ToString());
                    p.FechaDespacho = DateTime.Parse(reader["fechaDespacho"].ToString());
                    p.Direccion = reader["direccion"].ToString();
                    p.Telefono = reader["telefono"].ToString();

                    int idTienda = u.IdTienda;

                    //Trace.WriteLine("IdTienda: "+idTienda);
                    p.AlmOrigen = BuscarTIENfromID(idTienda).Deposito;

                    if (p.Venta.IdUsuario == Int32.Parse(Thread.CurrentPrincipal.Identity.Name))
                        listaOrdenDespacho.Add(p);
                }
                db.cmd.Parameters.Clear();
                reader.Close();
                db.conn.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace.ToString());
            }

            return listaOrdenDespacho;
        }
Ejemplo n.º 10
0
        public Tienda BuscarTIENfromID(int id)
        {
            DBConexion db = new DBConexion();
            db.cmd.CommandText = "SELECT * FROM Tienda WHERE idTienda = " + id;

            try
            {
                db.conn.Open();
                SqlDataReader reader = db.cmd.ExecuteReader();
                if (reader.Read())
                {
                    Tienda t = new Tienda();
                    t.IdTienda = int.Parse(reader["idTienda"].ToString());
                    t.IdUbigeo = reader.IsDBNull(reader.GetOrdinal("idUbigeo")) ? -1 : int.Parse(reader["idUbigeo"].ToString());
                    t.Nombre = reader.IsDBNull(reader.GetOrdinal("nombre")) ? null : reader["nombre"].ToString();
                    t.Direccion = reader.IsDBNull(reader.GetOrdinal("direccion")) ? null : reader["direccion"].ToString();
                    t.Telefono = reader.IsDBNull(reader.GetOrdinal("telefono")) ? null : reader["telefono"].ToString();
                    t.Administrador = reader.IsDBNull(reader.GetOrdinal("administrador")) ? null : reader["administrador"].ToString();
                    AlmacenSQL aSQL = new AlmacenSQL();
                    t.Deposito = aSQL.BuscarAlmacen(-1, t.IdTienda, 1);

                    Trace.WriteLine("Deposito: " + t.Deposito.Nombre);
                    return t;
                }

                db.cmd.Parameters.Clear();
                db.conn.Close();
                reader.Close();

            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
                return null;
            }

            return null;
        }
Ejemplo n.º 11
0
        public void Recargar(MadeInHouse.Dictionary.DynamicGrid dg)
        {
            AlmacenSQL aSQL = new AlmacenSQL();
            Almacenes anaquel = aSQL.BuscarAlmacen(-1, idTienda, 2);

            idAnaquel = anaquel.IdAlmacen;

            NumColumns = anaquel.NroColumnas;
            NumRows = anaquel.NroFilas;
            Altura = anaquel.Altura;
            dg.RecreateGridCells();

            TipoZonaSQL tzSQL = new TipoZonaSQL();
            LstZonasAnq = tzSQL.ObtenerZonasxAlmacen(idAnaquel, 2);
            CmbZonas = lstZonasAnq;
            ProductoSQL pSQL = new ProductoSQL();
            LstProductos = pSQL.BuscarProductoxTienda(idTienda);
            TxtStockActual = "";
            TxtCapacidad = "";
        }