Ejemplo n.º 1
0
        public NotaRevisionViewModel()
        {
            this.Items   = new ObservableCollection <Common.Entities.NoteHeader>();
            this.Details = new ObservableCollection <Common.Entities.NoteDetalle>();
            this.Details.CollectionChanged += Details_CollectionChanged;
            this.LoadCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                this.Loaded = this.Selected;
                var items   = _data.GetNoteDetails(this.Loaded.Id);
                this.Details.Clear();
                foreach (var item in items)
                {
                    this.Details.Add(item);
                }
            }, () => this.Selected != null);
            this.SaveCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                var item = await _process.RegisterNoteAsync(this.Loaded.Id);
                this.Items.Remove(this.Loaded);
                this.Details.Clear();
                this.Loaded = null;
                MessageBox.Show($"id: {item}");
            }, () => this.Loaded != null);
            this.PropertyChanged += NotaRevisionViewModel_PropertyChanged;
            if (this.IsInDesignMode)
            {
                this.Items.Add(new Common.Entities.NoteHeader {
                    Id = 1, Date = DateTime.Now, Sucursal = "08", CajeroId = 10, Total = 100
                });
                this.Items.Add(new Common.Entities.NoteHeader {
                    Id = 1, Date = DateTime.Now, Sucursal = "08", CajeroId = 10, Total = 100
                });
                this.Items.Add(new Common.Entities.NoteHeader {
                    Id = 1, Date = DateTime.Now, Sucursal = "08", CajeroId = 10, Total = 100
                });
                this.Selected = this.Items[0];
                this.Loaded   = this.Items[1];

                this.Details.Add(new Common.Entities.NoteDetalle {
                    Serie = "s1", Amount = 100, Comments = "commnets"
                });
                this.Details.Add(new Common.Entities.NoteDetalle {
                    Serie = "s1", Amount = 100, Comments = "commnets"
                });
            }
            else
            {
                _data    = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _process = CommonServiceLocator.ServiceLocator.Current.GetInstance <Helpers.ServiceClient>();

                var items = _data.GetNotes();
                foreach (var item in items)
                {
                    this.Items.Add(item);
                }
            }
        }
Ejemplo 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"
                };
            }
        }
Ejemplo n.º 3
0
        public CancelacionDevolucionViewModel()
        {
            if (!this.IsInDesignMode)
            {
                _data   = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _proxy  = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _client = new Helpers.ServiceClient();
            }
            _common            = new Helpers.CommonHelper();
            this.Productos     = new ObservableCollection <Models.CancelProducto>();
            this.CancelCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                this.IsBusy = true;

                var request = new Common.Entities.CancelSaleRequest
                {
                    Sucursal = this.Devolucion.Sucursal,
                    Folio    = this.Devolucion.Folio
                };
                await _client.CancelReturnAsync(request.Sucursal, request.Folio);

                this.Complete();
                MessageBox.Show("ready");
                this.CloseCommand.Execute(null);
                this.IsBusy = false;
            }, () => this.Productos.Any() && !this.Productos.Where(i => !i.Scanned).Any());
            this.SearchCommand = new RelayCommand(() =>
            {
                var ser  = _common.PrepareSerie(this.Search);
                var item = _data.ScanProductoFromDevolucion(ser);
                if (!this.Productos.Any())
                {
                    if (item != null && item.Success)
                    {
                        this.Search = null;
                        var dev     = _data.FindDevolucionView(item.Producto.Sucursal, item.Producto.Folio, this.Cajero.Id);

                        if (this.Sucursal.Clave != dev.Sucursal)
                        {
                            MessageBox.Show($"La devolución pertenece a otra sucursal ({dev.Sucursal})");
                            return;
                        }

                        this.Devolucion = new Models.SucursalFolio
                        {
                            Sucursal = dev.Sucursal,
                            Folio    = dev.Folio
                        };
                        foreach (var ditem in dev.Productos)
                        {
                            var can = new Models.CancelProducto
                            {
                                Producto = new Producto
                                {
                                    Id     = ditem.ArticuloId,
                                    Modelo = ditem.Modelo,
                                    Marca  = ditem.Marca,
                                    Precio = ditem.Precio,
                                    Serie  = ditem.Serie,
                                    Talla  = ditem.Medida
                                }
                            };
                            this.Productos.Add(can);
                            can.PropertyChanged += (s, e) => { this.CancelCommand.RaiseCanExecuteChanged(); };
                            if (can.Producto.Serie == ser)
                            {
                                can.Scanned = true;
                            }
                        }
                    }
                }
                else
                {
                    var pitem = this.Productos.Where(i => i.Producto.Serie == ser).SingleOrDefault();
                    if (pitem != null)
                    {
                        this.Search   = null;
                        pitem.Scanned = true;
                    }
                    else
                    {
                        this.ErrorMessage = Resources.Resource.Cancelacion_NoEncontrado;
                    }
                }
            }, () => !string.IsNullOrEmpty(this.Search));
            if (this.IsInDesignMode)
            {
                this.Search     = "0000003678429";
                this.Devolucion = new Models.SucursalFolio
                {
                    Sucursal = "00",
                    Folio    = "000123"
                };
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 1, Serie = "001", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 100, HasImage = true
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 2, Serie = "002", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1000, HasImage = true
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = false, Producto = new Producto {
                        Id = 3, Serie = "003", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1234.25m
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 4, Serie = "004", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 12456
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = false, Producto = new Producto {
                        Id = 5, Serie = "005", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 9.99m
                    }
                });
            }
        }
Ejemplo n.º 4
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"
                };
            }
        }
Ejemplo n.º 5
0
        public VerificarValeViewModel()
        {
            this.PropertyChanged += VerificarValeViewModel_PropertyChanged;
            if (!IsInDesignMode)
            {
                _client   = new Helpers.ServiceClient();
                _proxy    = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _pcredito = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICreditoValeServiceAsync>();
            }
            this.FindValeCommand = new RelayCommand(async() => {
                this.IsBusy = true;
                this.Vale   = await _proxy.FindValeAsync(this.ValeSearch);
                if (this.Vale != null)
                {
                    this.TotalVale    = null;
                    this.Cliente      = null;
                    this.NuevoCliente = null;
                    if (this.Vale.WithLimite)
                    {
                        this.TotalVale = this.Vale.Limite;
                        this.Cliente   = new Cliente
                        {
                            Id = this.Vale.ClienteId
                        };
                    }
                }
                this.IsBusy = false;
            }, () => !String.IsNullOrEmpty(this.ValeSearch));
            this.RegistrarValeCommand = new RelayCommand(async() =>
            {
                this.IsBusy = true;
                var request = new Common.Entities.RegisterValeRequest
                {
                    Vale        = this.Vale.Vale,
                    Cantidad    = this.TotalVale,
                    Electronica = false,
                    Cliente     = Helpers.Parsers.PaseCliente(this.NuevoCliente, this.Cliente, this.Sucursal)
                };
                var res     = await _client.RegisterValeAsync(request);
                this.IsBusy = false;
            }, () => this.Vale != null && this.TotalVale.HasValue &&
                                                         (this.Cliente != null || this.NuevoCliente != null) &&
                                                         !this.Vale.WithLimite);
            this.SolicitarCreditoCommand = new RelayCommand(async() =>
            {
                this.IsBusy = true;
                var request = new Common.Entities.SolicitudCreditoRequest
                {
                    Electronica = this.SolicitudElectronica,
                    Vale        = this.Vale.Vale,
                    idusuario   = this.Cajero.Id,
                    Monto       = this.Solicitud.Value,
                    Sucursal    = this.Sucursal.Clave
                };
                var res = await _pcredito.RequestAsync(request);
                if (res.Processing.HasValue)
                {
                    MessageBox.Show($"Result: {res.Processing}");
                }
                this.IsBusy = false;
            }, () => this.Vale != null && this.Solicitud.HasValue);
            this.CreditoCommand = new RelayCommand(() =>
            {
                this.Credito = true;
            }, () => !this.Credito);
            this.LoadClienteCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send(
                    new Utilities.Messages.OpenModal
                {
                    Name = Utilities.Constants.Modals.cliente,
                    GID  = this.GID
                });
            }, () => {
                if (this.Vale != null)
                {
                    return(!this.Vale.WithLimite);
                }
                return(false);
            });
            this.ClearClienteCommand = new RelayCommand(() =>
            {
                this.NuevoCliente = null;
                this.Cliente      = null;
            }, () => {
                if (this.Vale != null)
                {
                    return(!this.Vale.WithLimite);
                }
                return(false);
            });

            if (this.IsInDesignMode)
            {
                this.NuevoCliente = new Models.NuevoCliente
                {
                    Nombre    = "nom",
                    ApMaterno = "mat",
                    ApPaterno = "pat",
                    Id        = 999
                };
                this.ValeSearch = "search";
                this.Vale       = new ValeResponse
                {
                    Cancelado       = true,
                    CanceladoMotivo = "motivo",
                    Disponible      = 100,
                    Vale            = "123",
                    Distribuidor    = new Distribuidor
                    {
                        Id          = 1,
                        Nombre      = "nombre",
                        ApMaterno   = "materno",
                        ApPaterno   = "paterno",
                        Status      = Common.Constants.StatusDistribuidor.SOBREGIRADO,
                        Electronica = true,
                        Firmas      = new short[] { 1, 2, 3 }
                    }
                };

                this.Solicitud = 30000m;
                this.TotalVale = 10000m;
            }
        }
Ejemplo n.º 6
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();
                }
            });
        }
Ejemplo n.º 7
0
        public CancelacionViewModel()
        {
            if (!IsInDesignMode)
            {
                _proxy  = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _client = new Helpers.ServiceClient();
            }
            _common = new Helpers.CommonHelper();
            this.PropertyChanged             += CancelacionViewModel_PropertyChanged;
            this.Productos                    = new ObservableCollection <Models.CancelProducto>();
            this.Productos.CollectionChanged += Productos_CollectionChanged;

            this.ScanCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                this.IsBusy = true;
                await Scan();
                this.IsBusy = false;
            }, () => !string.IsNullOrWhiteSpace(this.SerieSearch));

            this.CancelCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() => {
                this.IsBusy = true;

                var request = new Common.Entities.CancelSaleRequest
                {
                    Sucursal = this.Venta.Sucursal,
                    Folio    = this.Venta.Folio
                };
                await _client.CancelSaleAsync(request);

                this.Complete();

                this.IsBusy = false;
            }, () => this.Productos.Any() && !this.Productos.Where(i => !i.Scanned).Any());

            if (this.IsInDesignMode)
            {
                this.ErrorMessage = "error";
                this.Venta        = new Models.SucursalFolio {
                    Sucursal = "01", Folio = "414628"
                };
                this.SerieSearch = "0000003343805";
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 1, Serie = "001", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 100, HasImage = true
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 2, Serie = "002", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1000, HasImage = true
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = false, Producto = new Producto {
                        Id = 3, Serie = "003", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1234.25m
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = true, Producto = new Producto {
                        Id = 4, Serie = "004", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 12456
                    }
                });
                this.Productos.Add(new Models.CancelProducto {
                    Scanned = false, Producto = new Producto {
                        Id = 5, Serie = "005", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 9.99m
                    }
                });
            }
        }