private void AddItem(Common.Entities.ProductoDevolucion item) { Messenger.Default.Send( new Utilities.Messages.OpenModalDevolucionItem { GID = this.GID, Item = item }); }
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; // } //} }