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" }; } }
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(); } }); }