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 LoadClienteViewModel() { if (!this.IsInDesignMode) { _proxy = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>(); } _common = new Helpers.CommonHelper(); this.Screen = "search"; this.ChangeViewCommand = new RelayCommand <string>(v => { this.Screen = v; }); this.PropertyChanged += LoadClienteViewModel_PropertyChanged; this.SearchCommand = new RelayCommand(() => { if (!this.ClienteSearch.HasValue && string.IsNullOrWhiteSpace(this.ClienteTelefonoSearch)) { if (this.Cliente != null) { Messenger.Default.Send(new Messages.ClienteMessage { Cliente = this.Cliente }, this.GID); } } else { var phone = _common.PreparePhone(this.ClienteTelefonoSearch); this.Cliente = _proxy.FindCliente(this.ClienteSearch, phone); if (this.Cliente != null) { this.ClienteSearch = null; this.ClienteTelefonoSearch = null; } else { MessageBox.Show("Cliente no encontrado.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }); if (this.IsInDesignMode) { this.ClienteSearch = 123; this.ClienteTelefonoSearch = "1234567890"; this.NuevoCliente = new Models.NuevoCliente { Nombre = "nombre", ApPaterno = "ap paterno", ApMaterno = "ap materno", Calle = "calle", Celular = "1234567890", CodigoPostal = "cp", Colonia = null, Email = "email", Referencia = "entre calles", Numero = 123, }; this.Colonias = new Common.Entities.Colonia[] { new Common.Entities.Colonia { Id = 1, Nombre = "colonia", CodigoPostal = "cp", CiudadId = 2, CiudadNombre = "ciudad", EstadoId = 3, EstadoNombre = "estado" } }; this.NuevoCliente.Colonia = this.Colonias.First(); } }
private async Task Scan(string ser) { if (this.Productos.Any()) { var current = this.Productos.Where(i => i.OldItem != null && i.OldItem.Serie == ser).SingleOrDefault(); if (current != null) { if (current.NewItem == null) { var res = MessageBox.Show($"La serie '{ser}' ya está registrada en el cambio\nDesea removerla?", "Confirmar", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { this.Productos.Remove(current); } } else { var res = MessageBox.Show($"La serie '{ser}' ya está registrada en el cambio\nDesea removerla?", "Confirmar", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { current.OldItem = null; } } this.SerieSearch = null; return; } var curnew = this.Productos.Where(i => i.NewItem != null && i.NewItem.Serie == ser).SingleOrDefault(); if (curnew != null) { this.SerieSearch = null; if (curnew.OldItem == null) { var res = MessageBox.Show($"La serie '{ser}' ya está registrada en el cambio\nDesea removerla?", "Confirmar", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { await _client.ReleaseProductoAsync(curnew.NewItem.Serie); this.Productos.Remove(curnew); } } else { var res = MessageBox.Show($"La serie '{ser}' ya está registrada en el cambio\nDeseas removerla?", "Confirmar", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { await _client.ReleaseProductoAsync(curnew.NewItem.Serie); curnew.NewItem = null; } } return; } var add = _sale.Productos.Where(i => i.Serie == ser).SingleOrDefault(); if (add != null) { var cur = this.Productos.Where(i => i.OldItem == null && i.NewItem.Corrida == add.Corrida && i.NewItem.Marca == add.Marca && i.NewItem.Modelo == add.Modelo).SingleOrDefault(); var old = new Common.Entities.ProductoDevolucion { Id = add.Id.Value, Sucursal = _sale.Sucursal, Folio = _sale.Folio, Serie = add.Serie, Marca = add.Marca, Modelo = add.Modelo, Talla = add.Talla, Corrida = add.Corrida, Precio = add.Precio, Pago = add.precdesc }; if (cur != null) { cur.OldItem = old; } else { this.AddItem(old); } this.SerieSearch = null; return; } var scan = await _proxy.ScanProductoAsync(ser, this.Sucursal.Clave); if (scan != null) { var svalid = new Common.Constants.Status[] { Common.Constants.Status.AC, Common.Constants.Status.IF, Common.Constants.Status.AB }; if (!svalid.Contains(scan.Status) && !(scan.Status == Status.CA && scan.UsuarioCajaId == this.Cajero.Id)) { MessageBox.Show($"{scan.Producto.Serie} - {scan.Status}"); return; } var cur = this.Productos.Where(i => i.OldItem != null && i.OldItem.Corrida == scan.Producto.Corrida && i.OldItem.Marca == scan.Producto.Marca && i.OldItem.Modelo == scan.Producto.Modelo && i.NewItem == null).FirstOrDefault(); if (cur == null) { cur = this.Productos.Where(i => i.OldItem != null && i.OldItem.Marca == scan.Producto.Marca && i.OldItem.Modelo == scan.Producto.Modelo && i.OldItem.Precio == scan.Producto.Precio && i.NewItem == null).FirstOrDefault(); } if (cur == null) { cur = this.Productos.Where(i => i.OldItem != null && i.OldItem.Marca == scan.Producto.Marca && i.OldItem.Modelo == scan.Producto.Modelo && i.NewItem == null).FirstOrDefault(); } if (cur == null) { cur = this.Productos.Where(i => i.OldItem != null && i.OldItem.Precio == i.OldItem.Pago && i.OldItem.Precio == scan.Producto.Precio && i.NewItem == null).FirstOrDefault(); } if (cur != null) { await _client.RequestProductoAsync(scan.Producto.Serie); cur.NewItem = _mapper.Map <Models.Producto>(scan.Producto); this.SerieSearch = null; } else { var series = this.Productos.Where(i => i.OldItem != null).Select(i => i.OldItem.Serie).ToArray(); //var valid = _sale.Productos.Where(i => //i.Corrida == scan.Producto.Corrida && // i.Marca == scan.Producto.Marca // && i.Modelo == scan.Producto.Modelo // && !series.Contains(i.Serie)).Any(); //if (valid) //{ // await _client.RequestProductoAsync(scan.Producto.Serie); // this.Productos.Add(new Models.ProductoCambio { NewItem = scan.Producto }); // this.SerieSearch = null; //} //else { var empty = this.Productos.Where(i => i.OldItem != null && i.NewItem == null).FirstOrDefault(); if (empty != null) { await _client.RequestProductoAsync(scan.Producto.Serie); empty.NewItem = _mapper.Map <Models.Producto>(scan.Producto); this.SerieSearch = null; } else { MessageBox.Show($"Producto {ser} no valido"); } } } return; } //var current = _sale.Productos.Where(i => i.Serie == ser).SingleOrDefault(); } else { var item = await _proxy.ScanProductoDevolucionAsync(ser, cancelacion : false); if (item != null && item.Success) { this.Venta = new Models.SucursalFolio { Sucursal = item.Producto.Sucursal, Folio = item.Producto.Folio }; _sale = _proxy.FindSale(item.Producto.Sucursal, item.Producto.Folio); if (_sale.ClienteId != null) { 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 }; } } this.AddItem(item.Producto); this.SerieSearch = null; } else { if (item == null) { MessageBox.Show("Artículo no encontrado", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Artículo no valido", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } //scans siguientes ya no van al server //var ditem = await _proxy.ScanProductoDevolucionAsync(ser); //if (ditem != null) //{ // if (!this.Productos.Any()) // { // this.Venta = new Models.SucursalFolio { Sucursal = ditem.Producto.Sucursal, Folio = ditem.Producto.Folio }; // var res = _proxy.FindSale(ditem.Producto.Sucursal, ditem.Producto.Folio); // this.Productos.Add(new Models.ProductoCambio { OldItem = ditem.Producto }); // } // else // { // var current = this.Productos.Where(i => i.NewItem.Serie == ditem.Producto.Serie).SingleOrDefault(); // if (current != null) // { // current.OldItem = ditem.Producto; // } // else // { // //checar en venta existente // this.Productos.Add(new Models.ProductoCambio { OldItem = ditem.Producto }); // } // } // this.SerieSearch = null; //} //else { // var sitem = await _proxy.ScanProductoAsync(serie: ser, sucursal: this.Sucursal.Clave); // if (sitem != null) // { // if (!this.Productos.Any()) // { // this.Productos.Add(new Models.ProductoCambio { NewItem = sitem.Producto }); // } // else // { // var current = this.Productos.Where(i => i.OldItem.Serie == sitem.Producto.Serie).SingleOrDefault(); // if (current != null) // { // current.NewItem = sitem.Producto; // } // else // { // //checar si es corrida de la venta existente // this.Productos.Add(new Models.ProductoCambio { NewItem = sitem.Producto }); // } // } // this.SerieSearch = null; // } //} }
protected async Task <Models.Pagos.Pago> ParsePago(Utilities.Messages.Pago o, Guid?id = null) { Models.Pagos.Pago p = null; switch (o.FormaPago) { case FormaPago.EF: p = new Models.Pagos.Pago { FormaPago = o.FormaPago, Importe = o.Importe }; break; case FormaPago.MD: p = new Models.Pagos.Pago { FormaPago = o.FormaPago, Importe = o.Importe, ClientId = o.Cliente }; break; case FormaPago.DV: p = new Models.Pagos.PagoDevolucion { FormaPago = o.FormaPago, Importe = o.Importe, Sucursal = o.Sucursal, Folio = o.Folio }; break; case FormaPago.TC: case FormaPago.TD: p = new Models.Pagos.PagoTarjeta { FormaPago = o.FormaPago, Importe = o.Importe, Terminacion = o.Terminacion, Referencia = o.Referencia }; break; case FormaPago.VA: { var pv = new Models.Pagos.PagoVale { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ContraVale = o.ContraVale, Limite = o.Limite, ClientId = o.Cliente, ProductosPlazos = o.PlazosProductos }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; pv.Promociones = promos.Promociones; var vale = await _proxy.FindValeAsync(o.Vale); pv.Info = new Models.Pagos.PagoValeInfo { Distribuidor = vale.Distribuidor.Nombre, Promocion = vale.Distribuidor.Promocion, Electronica = vale.Distribuidor.Electronica }; if (o.Cliente.HasValue) { var cli = _proxy.FindCliente(o.Cliente.Value); Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); } } p = pv; } break; case FormaPago.VD: { var pv = new Models.Pagos.PagoVale { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ClientId = o.Cliente }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; pv.Promociones = promos.Promociones; var vale = await _proxy.FindValeDigitalAsync(o.Vale); pv.Info = new Models.Pagos.PagoValeInfo { Distribuidor = vale.Distribuidor.Nombre, Promocion = vale.Distribuidor.Promocion, Electronica = vale.Distribuidor.Electronica }; if (o.Cliente.HasValue) { var cli = _proxy.FindCliente(o.Cliente.Value); Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); } } p = pv; } break; case FormaPago.VE: { var pv = new Models.Pagos.PagoVale { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Negocio = o.Negocio, NoCuenta = o.NoCuenta, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ClientId = o.Cliente }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; pv.Promociones = promos.Promociones; //var vale = await _proxy.FindValeDigitalAsync(o.Vale); //pv.Info = new Models.Pagos.PagoValeInfo //{ // Distribuidor = vale.Distribuidor.Nombre, // Promocion = vale.Distribuidor.Promocion, // SoloCalzado = vale.Distribuidor.SoloCalzado //}; //if (o.Cliente.HasValue) //{ // var cli = _proxy.FindCliente(o.Cliente.Value); // Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); //} } p = pv; } break; case FormaPago.CP: { var cp = new Models.Pagos.PagoCredito { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ContraVale = o.ContraVale, Limite = o.Limite, ClientId = o.Cliente }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; cp.Promociones = promos.Promociones; var vale = await _proxy.FindTarjetahabienteAsync(o.Vale); cp.Info = new Models.Pagos.PagoValeInfo { Distribuidor = vale.Distribuidor.Nombre, Promocion = vale.Distribuidor.Promocion, Electronica = vale.Distribuidor.Electronica }; if (o.Cliente.HasValue) { var cli = _proxy.FindCliente(o.Cliente.Value); Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); } else { this.Cliente = new Cliente { DistribuidorId = o.DistribuidorId }; } } p = cp; } break; case FormaPago.CD: { var cp = new Models.Pagos.PagoCredito { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ContraVale = o.ContraVale, Limite = o.Limite, ClientId = o.Cliente }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; cp.Promociones = promos.Promociones; var vale = await _proxy.FindDistribuidorAsync(o.Vale); cp.Info = new Models.Pagos.PagoValeInfo { Distribuidor = vale.Distribuidor.Nombre, Promocion = vale.Distribuidor.Promocion, Electronica = vale.Distribuidor.Electronica }; if (o.Cliente.HasValue) { var cli = _proxy.FindCliente(o.Cliente.Value); Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); } else { this.Cliente = new Cliente { DistribuidorId = o.DistribuidorId }; } } p = cp; } break; case FormaPago.CV: var cv = new Models.Pagos.PagoContraVale { FormaPago = o.FormaPago, Importe = o.Importe, Vale = o.Vale, Plazos = o.Plazos, Promociones = o.Promociones, SelectedPlazo = o.SelectedPlazo, SelectedPromocion = o.SelectedPromocion, ContraVale = o.ContraVale, Limite = o.Limite, Sucursal = o.Sucursal, ClientId = o.Cliente }; if (!this.IsInDesignMode) { var promos = await _proxy.FindPromocionesValeAsync(this.Sucursal.Clave); //pv.Plazos = promos.Plazos; cv.Promociones = promos.Promociones; var vale = await _proxy.FindContraValeAsync(o.Sucursal, o.Vale); cv.Info = new Models.Pagos.PagoValeInfo { Distribuidor = vale.Distribuidor.Nombre, Promocion = vale.Distribuidor.Promocion, Electronica = vale.Distribuidor.Electronica }; if (o.Cliente.HasValue) { var cli = _proxy.FindCliente(o.Cliente.Value); Messenger.Default.Send(new Messages.ClienteMessage { Cliente = cli }, this.GID); } } p = cv; break; default: throw new NotSupportedException(); } p.Id = id ?? Guid.NewGuid(); return(p); }