Esempio n. 1
0
        public ConsultaDevolucionViewModel()
        {
            if (!this.IsInDesignMode)
            {
                _common  = new Helpers.CommonHelper();
                _proxy   = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _reports = new Helpers.ReportsHelper();
            }
            this.PropertyChanged += ConsultaDevolucionViewModel_PropertyChanged;
            this.SearchCommand    = new RelayCommand(() => {
                var settings    = CommonServiceLocator.ServiceLocator.Current.GetInstance <Utilities.Models.Settings>();
                var folio       = _common.PrepareVentaDevolucion(this.Search);
                this.Devolucion = _proxy.FindDevolucionView(settings.Sucursal.Clave, folio, this.Cajero.Id);
                if (this.Devolucion != null)
                {
                    this.Search = null;
                }
            });

            if (this.IsInDesignMode)
            {
                this.Search     = "devolucion";
                this.Devolucion = new Common.Entities.DevolucionView
                {
                    Folio     = "folio",
                    Sucursal  = "sucursal",
                    Productos = new Common.Entities.ProductoView[] {
                        new Common.Entities.ProductoView {
                            Serie = "1", Precio = 100
                        },
                        new Common.Entities.ProductoView {
                            Serie = "2", Precio = 99.9m
                        },
                        new Common.Entities.ProductoView {
                            Serie = "3", Precio = 1999.89m
                        }
                    }
                };
            }
        }
Esempio n. 2
0
        public DevolucionViewModel()
        {
            _common = new Helpers.CommonHelper();
            this.PropertyChanged             += DevolucionViewModel_PropertyChanged;
            this.Productos                    = new ObservableCollection <Models.ProductoDevolucion>();
            this.Productos.CollectionChanged += Productos_CollectionChanged;
            if (!IsInDesignMode)
            {
                _reports = new Helpers.ReportsHelper();
                _client  = new Helpers.ServiceClient();
                _proxy   = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
            }
            this.LoadCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                this.IsBusy = true;
                var ser     = _common.PrepareSerie(this.SerieSearch);

                var item = await _proxy.ScanProductoDevolucionAsync(ser, cancelacion: false);
                if (item != null && item.Success)
                {
                    if (!this.Productos.Any())
                    {
                        AddItem(item.Producto);
                        this.SerieSearch = null;
                        this.Venta       = new Models.SucursalFolio {
                            Sucursal = item.Producto.Sucursal, Folio = item.Producto.Folio
                        };

                        //var ven = _proxy.FindVentaView(this.Venta.Sucursal, this.Venta.Folio, 0);

                        var sale          = _proxy.FindSale(this.Venta.Sucursal, this.Venta.Folio);
                        this.CanSetClient = !sale.ClienteId.HasValue;
                        if (sale.ClienteId.HasValue)
                        {
                            this.Cliente = _proxy.FindCliente(sale.ClienteId.Value);
                            if (this.Cliente != null)
                            {
                                this.NuevoCliente = new Models.NuevoCliente
                                {
                                    Id        = this.Cliente.Id,
                                    Nombre    = this.Cliente.Nombre,
                                    ApPaterno = this.Cliente.ApPaterno,
                                    ApMaterno = this.Cliente.ApMaterno
                                };
                            }
                        }
                    }
                    else
                    {
                        if (this.Venta.Sucursal == item.Producto.Sucursal &&
                            this.Venta.Folio == item.Producto.Folio)
                        {
                            var current = this.Productos.Where(i => i.Item.Serie == item.Producto.Serie).SingleOrDefault();
                            if (current == null)
                            {
                                AddItem(item.Producto);
                            }
                            else
                            {
                                this.Productos.Remove(current);
                            }
                            this.SerieSearch = null;
                        }
                        else
                        {
                            MessageBox.Show($"El producto {item.Producto.Serie}, no pertenece a la misma venta.");
                        }
                    }
                }
                else
                {
                    if (item == null)
                    {
                        this.ErrorMessage = "Artículo no encontrado";
                    }
                    else
                    {
                        if (item.Status == Common.Constants.Status.BA)
                        {
                            this.ErrorMessage = "El articulo ha excedido el tiempo valido para su devolución o cambio";
                        }
                        else
                        {
                            this.ErrorMessage = "Artículo no valido";
                        }
                    }
                }
                this.IsBusy = false;
            }, () => !string.IsNullOrWhiteSpace(this.SerieSearch));
            this.ReturnCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                //Messenger.Default.Send(new Messages.RequestApproval { GID = this.GID });

                this.IsBusy = true;
                var request = new Common.Entities.ReturnRequest
                {
                    Sucursal = this.Venta.Sucursal,
                    Folio    = this.Venta.Folio,
                    Comments = "",
                    Items    = this.Productos.Select(i => i.Item.Serie),
                    Razones  = this.Productos.ToDictionary(i => i.Item.Serie,
                                                           i => new Common.Entities.RazonItem {
                        TipoRazon = i.RazonId.Value,
                        Notas     = i.Razon
                    })
                };
                request.Cliente = Helpers.Parsers.PaseCliente(this.NuevoCliente, this.Cliente, this.Sucursal);
                this.Folio      = await _client.ReturnAsync(request);
                this.IsBusy     = false;
            }, () => this.Total > 0);

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

            this.LoadClienteCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModal
                {
                    Name = Utilities.Constants.Modals.cliente,
                    GID  = this.GID
                });
            }, () => this.CanSetClient);
            this.ClearClienteCommand = new RelayCommand(() =>
            {
                this.Cliente      = null;
                this.NuevoCliente = null;
            }, () => this.CanSetClient);
            if (this.IsInDesignMode)
            {
                this.ClienteId   = 90;
                this.Folio       = "123";
                this.SerieSearch = "0000003342601";
                this.Venta       = new Models.SucursalFolio {
                    Folio = "folio", Sucursal = "sucursal"
                };
                this.Productos.Add(new Models.ProductoDevolucion {
                    Item = new ProductoDevolucion {
                        Sucursal = "01", Folio = "123", Serie = "0000003413693", Marca = "FFF", Modelo = "2608", Talla = "27.5", Precio = 799
                    }
                });
                this.Productos.Add(new Models.ProductoDevolucion {
                    Item = new ProductoDevolucion {
                        Sucursal = "01", Folio = "124", Serie = "0000003420542", Marca = "AAA", Modelo = "1234", Talla = "28", Precio = 123.45m
                    }
                });

                this.NuevoCliente = new Client.Models.NuevoCliente {
                    Nombre = "nom", ApPaterno = "ap pa", ApMaterno = "ap ma"
                };
            }
        }
Esempio n. 3
0
        public CambioViewModel()
        {
            this.PropertyChanged += CambioViewModel_PropertyChanged;
            _common        = new Helpers.CommonHelper();
            this.Productos = new ObservableCollection <Models.ProductoCambio>();
            this.Productos.CollectionChanged += Productos_CollectionChanged;
            this.Pagos.CollectionChanged     += Pagos_CollectionChanged;
            if (!this.IsInDesignMode)
            {
                _reports = new Helpers.ReportsHelper();
                _client  = new Helpers.ServiceClient();
                _proxy   = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _mapper  = CommonServiceLocator.ServiceLocator.Current.GetInstance <AutoMapper.IMapper>();
            }

            //this.PagarCommand = new RelayCommand(() => {

            //    this.ShowPagos = true;

            //}, () => this.Total > 0 && this.Remaining > 0);
            //this.AddFormaCommand = new RelayCommand<FormaPago>(fp => {
            //    this.ShowPagos = false;
            //    Messenger.Default.Send(
            //        new Messages.OpenPago
            //        {
            //            GID = this.GID,
            //            FormaPago = fp,
            //            Total = this.Remaining,
            //            Caja = this,
            //            ClientId = this.Cliente?.Id,
            //            ProductosPlazos = this.Productos.Where(i => i.MaxPlazos.HasValue && i.MaxPlazos > 0)
            //        });
            //}, p => {
            //    var q = this._formas.Where(i => i.Key == p);
            //    return q.Any() && this.Total > 0 && this.Remaining > 0 && q.Single().Value.Enabled;
            //});
            this.AddPagoCommand = new RelayCommand(() => {
                this.ShowPagos = true;
            }, () => this.Remaining > 0);

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

                await this.Scan(ser);
                this.AddPagoCommand.RaiseCanExecuteChanged();
                this.SaveCommand.RaiseCanExecuteChanged();

                this.IsBusy = false;
            }, () => !string.IsNullOrEmpty(this.SerieSearch));

            this.SaveCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                this.IsBusy = true;
                var request = new Common.Entities.ChangeRequest
                {
                    Sucursal = this.Venta.Sucursal,
                    Folio    = this.Venta.Folio,
                    Items    = this.Productos.Select(i => new Common.Entities.ChangeItem
                    {
                        OldItem = i.OldItem.Serie,
                        NewItem = i.NewItem.Serie
                    }),
                    Pagos   = this.PreparePagos(),
                    Razones = this.Productos.ToDictionary(i => i.OldItem.Serie,
                                                          i => new Common.Entities.RazonItem
                    {
                        TipoRazon = i.RazonId.Value,
                        Notas     = i.Razon
                    })
                };
                request.Cliente = Helpers.Parsers.PaseCliente(this.NuevoCliente, this.Cliente, this.Sucursal);
                this.Result     = await _client.ChangeAsync(request);
                this.IsBusy     = false;
            }, () => this.Productos.Any() &&
                                                                           !this.Productos.Where(i => !i.Complete).Any() &&
                                                                           this.Remaining <= 0);

            this.RemovePagoCommand = new RelayCommand(() => {
                //if (!_formas[this.SelectedPago.FormaPago].Duplicate)
                //{
                //    _formas[this.SelectedPago.FormaPago].Enabled = true;
                //    this.FormasPago.Refresh();
                //}
                //_ls.RemovePago(this.SelectedPago.Id);
                this.Pagos.Remove(this.SelectedPago);
            }, () => this.SelectedPago != null);

            this.LoadClienteCommand = new RelayCommand(() => {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModal
                {
                    Name = Utilities.Constants.Modals.cliente,
                    GID  = this.GID
                });
            });
            this.ClearClienteCommand = new RelayCommand(() => {
                this.Cliente      = null;
                this.NuevoCliente = null;
                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();
            });

            this.PrintCommand = new RelayCommand <string>(rpt => {
                if (rpt == "venta")
                {
                    _reports.Compra(this.Sucursal.Clave, this.Result.Venta);
                }
                if (rpt == "devolucion")
                {
                    _reports.Devolucion(this.Sucursal.Clave, this.Result.Devolucion);
                }
            }, rpt => this.IsComplete);

            if (this.IsInDesignMode)
            {
                this.Result = new ChangeResponse {
                    Devolucion = "111",
                    Venta      = "222",
                    Cliente    = 333
                };
                this.SerieSearch = "0000003342601";
                this.Venta       = new Models.SucursalFolio {
                    Sucursal = "01", Folio = "000123"
                };
                this.Productos.Add(new Models.ProductoCambio {
                    OldItem = new ProductoDevolucion {
                        Sucursal = "01", Folio = "123", Serie = "0000003413693", Marca = "FFF", Modelo = "2608", Talla = "27.5", Precio = 799
                    },
                    NewItem = new Models.Producto {
                        Serie = "0000003420542", Marca = "AAA", Modelo = "1234", Talla = "28", Precio = 123.45m
                    }
                });
                this.Productos.Add(new Models.ProductoCambio
                {
                    OldItem = null,
                    NewItem = new Models.Producto {
                        Serie = "0000003420542", Marca = "AAA", Modelo = "1234", Talla = "28", Precio = 123.45m
                    }
                });
                this.Productos.Add(new Models.ProductoCambio
                {
                    OldItem = new ProductoDevolucion {
                        Sucursal = "01", Folio = "123", Serie = "0000003413693", Marca = "FFF", Modelo = "2608", Talla = "27.5", Precio = 799
                    },
                    NewItem = null
                });
                this.NuevoCliente = new Models.NuevoCliente {
                    Nombre = "nom", ApPaterno = "ap pa", ApMaterno = "ap ma"
                };
            }
        }
Esempio n. 4
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();
                }
            });
        }