Exemplo n.º 1
0
        public LoadVendedorViewModel()
        {
            if (!IsInDesignMode)
            {
                _proxy = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICommonServiceAsync>();
            }

            this.PropertyChanged += LoadVendedorViewModel_PropertyChanged;

            this.FindVendedorCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                if (!this.VendedorSearch.HasValue)
                {
                    this.AcceptCommand.Execute(null);
                }
                else
                {
                    this.IsBusy = true;
                    await this.FindVendedor();
                    this.IsBusy = false;
                }
            });

            if (this.IsInDesignMode)
            {
                this.VendedorSearch = 123456;
                this.Vendedor       = new Empleado {
                    Id              = 1,
                    Clave           = "a",
                    Usuario         = "user",
                    Nombre          = "nombre",
                    ApellidoPaterno = "appaterno",
                    ApellidoMaterno = "apmaterno"
                };
            }
        }
Exemplo n.º 2
0
        public LoginViewModel()
        {
            try
            {
                if (!IsInDesignMode)
                {
                    _proxy = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICommonServiceAsync>();
                }

                this.LoginCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
                {
                    this.IsBusy = true;
                    var pass    = this.PasswordHandler();
                    var item    = await _proxy.LoginAsync(
                        sucursal: Properties.Settings.Default.Sucursal,
                        user: this.UserName,
                        pass: pass);
                    GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(
                        new Messages.LoginResponse {
                        Success = item != null, Empleado = item
                    });
                    this.Password = null;
                    this.UserName = null;
                    this.IsBusy   = false;
                }, () =>
                {
                    return(!string.IsNullOrEmpty(this.UserName) &&
                           !string.IsNullOrEmpty(this.Password));
                });

                this.PropertyChanged += Login_PropertyChanged;

                this.ScanCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
                {
                    this.Scanning = true;
                    var fh        = new Helpers.FingerPrintHelper();
                    if (fh.Connect())
                    {
                        var finger = await fh.Scan();
                        fh.Close();
                        if (finger != null)
                        {
                            var item = _proxy.CheckFingerLogin(Properties.Settings.Default.Sucursal, finger);
                            GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(
                                new Messages.LoginResponse {
                                Success = item != null, Empleado = item
                            });
                            this.Password = null;
                            this.UserName = null;
                        }
                    }
                    this.Scanning = false;
                }, () => !this.Scanning);
            }
            catch (Exception ex)
            {
                MessageBox.Show("A handled exception just occurred: " + ex.Message, "Exception Sample");
            }
        }
Exemplo n.º 3
0
        public CajaViewModel()
        {
            _skipPromociones = false;
            _common          = new Helpers.CommonHelper();
            this.Productos   = new ObservableCollection <Models.Producto>();
            this.Productos.CollectionChanged += Productos_CollectionChanged;
            this.Cupones            = new ObservableCollection <Cupon>();
            this.PromocionesCupones = new ObservableCollection <Promocion>();
            this.PromocionesCupones.CollectionChanged += PromocionesCupones_CollectionChanged;
            _promocionesCuponesUsadas = new CollectionViewSource {
                Source = this.PromocionesCupones
            };
            this.PromocionesCuponesUsadas.Filter = i => {
                var item = (Promocion)i;
                return(item.Used);
            };
            this.Pagos.CollectionChanged += Pagos_CollectionChanged;
            this.PropertyChanged         += CajaViewModel_PropertyChanged;

            if (!IsInDesignMode)
            {
                _reports = new Helpers.ReportsHelper();
                _proxy   = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _pproxy  = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICommonServiceAsync>();
                _mapper  = CommonServiceLocator.ServiceLocator.Current.GetInstance <AutoMapper.IMapper>();
                _client  = new Helpers.ServiceClient();
            }

            this.RemovePagoCommand = new RelayCommand(/*async */ () => {
                //_ls.RemovePago(this.SelectedPago.Id);
                this.Pagos.Remove(this.SelectedPago);
                //await this.UpdatePromociones();
            }, () => this.SelectedPago != null);

            this.RemoveCuponCommand = new RelayCommand(() => {
                var cupon = this.SelectedCupon;
                //_ls.RemoveCupon(cupon.Folio);
                var q = this.PromocionesCupones.OfType <PromocionCupon>().Where(i => i.Cupon == cupon.Folio).ToArray();
                foreach (var item in q)
                {
                    this.PromocionesCupones.Remove(item);
                }
                this.Cupones.Remove(this.SelectedCupon);
            }, () => this.SelectedCupon != null);

            this.SaleCommand = new RelayCommand(this.Sale, () => {
                if (this.SaleResponse == null &&
                    this.Total > 0 && this.Remaining == 0)
                {
                    if (this.IsValid())
                    {
                        var pagado = this.Productos.All(i => i.Pagado);
                        if (pagado)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            });

            this.RemoveCommand = new RelayCommand(async() =>
            {
                await this.RemoveItem(this.SelectedItem);
            }, () => this.SelectedItem != null);
            this.AddCommand = new RelayCommand(async() => {
                //this.IsBusy = true;
                await Add();
                this.IsBusy = false;
            }, () => !string.IsNullOrWhiteSpace(this.SerieSearch));

            this.AddCuponCommand = new RelayCommand(() => {
                this.IsBusy = true;
                this.AddCuponHelper();
                this.IsBusy = false;
            }, () => !string.IsNullOrWhiteSpace(this.CuponSearch));

            this.LoadClienteCommand = new RelayCommand(() => {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModal
                {
                    Name = Utilities.Constants.Modals.cliente,
                    GID  = this.GID
                });
            });
            this.LoadVendedorCommand = new RelayCommand(() => {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModal
                {
                    Name = Utilities.Constants.Modals.vendedor,
                    GID  = this.GID
                });
            }, () => this.HasCalzado);
            this.RemoveVendedorCommand = new RelayCommand(() =>
            {
                this.Vendedor = null;
            }, () => this.Vendedor != null);
            this.AddDescuentoAdicional = new RelayCommand(() => {
                if (this.SelectedItem.DescuentoAdicional != null)
                {
                    this.SelectedItem.DescuentoAdicional = null;
                }
                else
                {
                    Messenger.Default.Send(
                        new Utilities.Messages.OpenModal
                    {
                        Name = Utilities.Constants.Modals.descuento,
                        GID  = this.GID
                    });
                }
            }, () => this.SelectedItem != null);
            this.AddNotaCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModalItem
                {
                    Name = Utilities.Constants.Modals.nota,
                    GID  = this.GID,
                    Item = this.SelectedItem
                });
            }, () => this.SelectedItem != null);
            this.ClearClienteCommand = new RelayCommand(async() => {
                this.Cliente      = null;
                this.NuevoCliente = null;
                _ls.ClearCliente();
                _skipPromociones = true;
                foreach (var item in this.PromocionesCupones.OfType <Common.Entities.PromocionCupon>().ToArray())
                {
                    if (item.Cliente.HasValue)
                    {
                        this.PromocionesCupones.Remove(item);
                        _ls.RemoveCupon(item.Cupon);
                    }
                }
                foreach (var item in this.Pagos.Where(i => i.ClientId.HasValue).ToArray())
                {
                    this.Pagos.Remove(item);
                    //_ls.RemovePago(item.Id);
                }
                this.ClientConfirmed = false;
                this.FormasPago.Refresh();
                _skipPromociones = false;
                await this.RefreshPromociones();
                this.SaleCommand.RaiseCanExecuteChanged();
            });

            MoveProductoCommand = new RelayCommand <Models.MoveDirection>(async dir => {
                this.Move(this.SelectedItem, this.Productos, dir, o => this.SelectedItem = o);
                await this.RefreshPromociones();
            }, dir => this.CanMove(this.SelectedItem, this.Productos, dir));

            MovePagoCommand = new RelayCommand <Models.MoveDirection>(async dir => {
                this.Move(this.SelectedPago, this.Pagos, dir, o => this.SelectedPago = (Models.Pagos.Pago)o);
                await this.RefreshPromociones();
            }, dir => this.CanMove(this.SelectedPago, this.Pagos, dir));

            MoveCuponCommand = new RelayCommand <Models.MoveDirection>(async dir => {
                this.Move(this.SelectedPromocion, this.PromocionesCupones, dir, o => this.SelectedPromocion = o);
                await this.RefreshPromociones();
            }, dir => this.CanMove(this.SelectedPromocion, this.PromocionesCupones, dir));

            this.PagarCommand = new RelayCommand(() => {
                this.ShowPagos = true;
            }, () => this.Total > 0 && this.Remaining > 0);


            this.ConfirmClienteCommand = new RelayCommand(() => {
            });

            if (!this.IsInDesignMode)
            {
                _scanner = CommonServiceLocator.ServiceLocator.Current.GetInstance <Utilities.Interfaces.IScanner>();
                if (_scanner != null)
                {
                    _scanner.DataReceived += Scaner_DataReceived;
                }
            }

            this.PrintCommand = new RelayCommand(() => {
                _reports.Compra(this.Sucursal.Clave, this.SaleResponse.Folio);
            }, () => this.IsComplete);

            this.TestCommand = new RelayCommand <string>(p => {
                if (p == "start")
                {
                    _scanner?.Start();
                }
                if (p == "stop")
                {
                    _scanner?.Stop();
                }
            });
        }
Exemplo n.º 4
0
        public PuntoDeVentaViewModel()
        {
            if (!IsInDesignMode)
            {
                _proxy  = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _pproxy = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICommonServiceAsync>();
            }
            this.Productos = new ObservableCollection <Producto>();
            this.Pagos     = new ObservableCollection <Models.Pagos.Pago>();
            _formas        = new Dictionary <FormaPago, bool> {
                { FormaPago.EF, true },
                { FormaPago.TC, true },
                { FormaPago.TD, true }
            };
            this.FormasPago        = CollectionViewSource.GetDefaultView(_formas);
            this.FormasPago.Filter = i => ((KeyValuePair <FormaPago, bool>)i).Value;
            this.ShowSerie         = true;
            _common = new Helpers.CommonHelper();

            this.SaleCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                var sale = new SaleRequest {
                    VendedorId = 0,
                    Productos  = this.Productos.Select(i => new SerieFormasPago {
                        Serie = i.Serie
                    }),
                    Sucursal = "01",
                    Pagos    = this.Pagos.Where(i => (i.Importe ?? 0) > 0).Select(i => new Common.Entities.Pago {
                        FormaPago = i.FormaPago,
                        Importe   = i.Importe.Value
                    })
                };
                //var res = await _proxy.SaleAsync(sale);
                //MessageBox.Show($"ID: {res}");
            }, () => {
                var sum = this.Pagos.Sum(i => i.Importe) ?? 0;
                var rem = this.Total - sum;
                return(this.Total > 0 && rem == 0);
            });
            this.AddFormaCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() => {
                var p = new Models.Pagos.Pago {
                    FormaPago = this.SelectedFormaPago
                };
                this.Pagos.Add(p);
                p.PropertyChanged += (s, e) => RaisePropertyChanged(nameof(this.TotalPayment));
                if (this.SelectedFormaPago == FormaPago.EF)
                {
                    _formas[FormaPago.EF] = false;
                    this.FormasPago.Refresh();
                }
            });
            this.FindVendedorCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.Vendedor = await _pproxy.FindVendedorAsync(this.VendedorSearch.Value);
                if (this.Vendedor != null)
                {
                    this.VendedorSearch = null;
                }
            });
            this.FindCajeroCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.Cajero = await _pproxy.FindCajeroAsync(this.CajeroSearch);
                if (this.Cajero != null)
                {
                    this.CajeroSearch = null;
                }
            });

            this.AddCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.IsBusy = true;
                var ser     = _common.PrepareSerie(this.Serie);

                var q = this.Productos.Where(i => i.Serie == ser).SingleOrDefault();
                if (q != null)
                {
                    MessageBox.Show($"Already Added: {ser}");
                    return;
                }

                var item = await _proxy.ScanProductoAsync(ser, "01");
                if (item != null)
                {
                    if (item.Status == Status.AC || item.Status == Status.IF ||
                        item.Status == Status.CA)
                    {
                        //if(await _proxy.RequestProductoAsync(item.Producto.Serie))
                        //    this.Productos.Add(item.Producto);
                    }
                    else
                    {
                        MessageBox.Show($"{item.Producto.Serie} - {item.Status}");
                    }
                    this.Serie = null;
                }
                else
                {
                    MessageBox.Show($"Not Found: {ser}");
                }
                this.IsBusy = false;
            }, () =>
            {
                return(!string.IsNullOrWhiteSpace(this.Serie));
            });
            this.RemoveCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                //await _proxy.ReleaseProductoAsync(this.SelectedItem.Serie);
                //this.Productos.Remove(this.SelectedItem);
            }, () =>
            {
                return(this.SelectedItem != null);
            });

            this.PropertyChanged             += PuntoDeVenta_PropertyChanged;
            this.Productos.CollectionChanged += Productos_CollectionChanged;
            this.Pagos.CollectionChanged     += Pagos_CollectionChanged;

            if (this.IsInDesignMode)
            {
                this.Serie = "123";
                this.Productos.Add(new Producto {
                    Id = 1, Serie = "001", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 100, HasImage = true
                });
                this.Productos.Add(new Producto {
                    Id = 2, Serie = "002", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1000, HasImage = true
                });
                this.Productos.Add(new Producto {
                    Id = 3, Serie = "003", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1234.25m
                });
                this.Productos.Add(new Producto {
                    Id = 4, Serie = "004", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 12456
                });
                this.Productos.Add(new Producto {
                    Id = 5, Serie = "005", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 9.99m
                });

                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.EF, Importe = 100
                });
                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.TD, Importe = 30
                });
                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.TD, Importe = 20
                });
            }
        }