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