コード例 #1
0
        public PuntoDeVentaViewModel()
        {
            if (!IsInDesignMode)
            {
                _proxy  = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.IDataServiceAsync>();
                _pproxy = CommonServiceLocator.ServiceLocator.Current.GetInstance <Common.ServiceContracts.ICommonServiceAsync>();
            }
            this.Productos = new ObservableCollection <Producto>();
            this.Pagos     = new ObservableCollection <Models.Pagos.Pago>();
            _formas        = new Dictionary <FormaPago, bool> {
                { FormaPago.EF, true },
                { FormaPago.TC, true },
                { FormaPago.TD, true }
            };
            this.FormasPago        = CollectionViewSource.GetDefaultView(_formas);
            this.FormasPago.Filter = i => ((KeyValuePair <FormaPago, bool>)i).Value;
            this.ShowSerie         = true;
            _common = new Helpers.CommonHelper();

            this.SaleCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                var sale = new SaleRequest {
                    VendedorId = 0,
                    Productos  = this.Productos.Select(i => new SerieFormasPago {
                        Serie = i.Serie
                    }),
                    Sucursal = "01",
                    Pagos    = this.Pagos.Where(i => (i.Importe ?? 0) > 0).Select(i => new Common.Entities.Pago {
                        FormaPago = i.FormaPago,
                        Importe   = i.Importe.Value
                    })
                };
                //var res = await _proxy.SaleAsync(sale);
                //MessageBox.Show($"ID: {res}");
            }, () => {
                var sum = this.Pagos.Sum(i => i.Importe) ?? 0;
                var rem = this.Total - sum;
                return(this.Total > 0 && rem == 0);
            });
            this.AddFormaCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() => {
                var p = new Models.Pagos.Pago {
                    FormaPago = this.SelectedFormaPago
                };
                this.Pagos.Add(p);
                p.PropertyChanged += (s, e) => RaisePropertyChanged(nameof(this.TotalPayment));
                if (this.SelectedFormaPago == FormaPago.EF)
                {
                    _formas[FormaPago.EF] = false;
                    this.FormasPago.Refresh();
                }
            });
            this.FindVendedorCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.Vendedor = await _pproxy.FindVendedorAsync(this.VendedorSearch.Value);
                if (this.Vendedor != null)
                {
                    this.VendedorSearch = null;
                }
            });
            this.FindCajeroCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.Cajero = await _pproxy.FindCajeroAsync(this.CajeroSearch);
                if (this.Cajero != null)
                {
                    this.CajeroSearch = null;
                }
            });

            this.AddCommand = new GalaSoft.MvvmLight.Command.RelayCommand(async() =>
            {
                this.IsBusy = true;
                var ser     = _common.PrepareSerie(this.Serie);

                var q = this.Productos.Where(i => i.Serie == ser).SingleOrDefault();
                if (q != null)
                {
                    MessageBox.Show($"Already Added: {ser}");
                    return;
                }

                var item = await _proxy.ScanProductoAsync(ser, "01");
                if (item != null)
                {
                    if (item.Status == Status.AC || item.Status == Status.IF ||
                        item.Status == Status.CA)
                    {
                        //if(await _proxy.RequestProductoAsync(item.Producto.Serie))
                        //    this.Productos.Add(item.Producto);
                    }
                    else
                    {
                        MessageBox.Show($"{item.Producto.Serie} - {item.Status}");
                    }
                    this.Serie = null;
                }
                else
                {
                    MessageBox.Show($"Not Found: {ser}");
                }
                this.IsBusy = false;
            }, () =>
            {
                return(!string.IsNullOrWhiteSpace(this.Serie));
            });
            this.RemoveCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                //await _proxy.ReleaseProductoAsync(this.SelectedItem.Serie);
                //this.Productos.Remove(this.SelectedItem);
            }, () =>
            {
                return(this.SelectedItem != null);
            });

            this.PropertyChanged             += PuntoDeVenta_PropertyChanged;
            this.Productos.CollectionChanged += Productos_CollectionChanged;
            this.Pagos.CollectionChanged     += Pagos_CollectionChanged;

            if (this.IsInDesignMode)
            {
                this.Serie = "123";
                this.Productos.Add(new Producto {
                    Id = 1, Serie = "001", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 100, HasImage = true
                });
                this.Productos.Add(new Producto {
                    Id = 2, Serie = "002", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1000, HasImage = true
                });
                this.Productos.Add(new Producto {
                    Id = 3, Serie = "003", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 1234.25m
                });
                this.Productos.Add(new Producto {
                    Id = 4, Serie = "004", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 12456
                });
                this.Productos.Add(new Producto {
                    Id = 5, Serie = "005", Marca = "a", Modelo = "b", Talla = "c", Precio = 100, Total = 9.99m
                });

                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.EF, Importe = 100
                });
                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.TD, Importe = 30
                });
                this.Pagos.Add(new Models.Pagos.Pago {
                    FormaPago = FormaPago.TD, Importe = 20
                });
            }
        }
コード例 #2
0
        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;
            //    }
            //}
        }
コード例 #3
0
        private async Task Search()
        {
            if (!string.IsNullOrEmpty(this.Serie))
            {
                this.Item        = null;
                this.ItemStatus  = null;
                this.Promos      = null;
                this.Corridas    = null;
                this.Existencias = null;

                var ser = _common.PrepareSerie(this.Serie);
                var res = await _proxy.ScanProductoAsync(ser, this.Sucursal.Clave);

                if (res != null)
                {
                    this.Serie      = null;
                    this.Item       = res.Producto;
                    this.ItemStatus = res.Status;

                    if (res.Producto.Id.HasValue)
                    {
                        this.Corridas = await _proxy.GetPreciosAsync(res.Producto.Id.Value);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(this.Marca) && !string.IsNullOrEmpty(this.Modelo))
            {
                this.Item        = null;
                this.ItemStatus  = null;
                this.Promos      = null;
                this.Corridas    = null;
                this.Existencias = null;

                //var model = String.Format("{0,7}", this.Modelo);
                var model = _common.PrepareModelo(this.Modelo);

                var res = _proxy.FindProducto(this.Marca, model, this.Sucursal.Clave);
                if (res != null)
                {
                    this.Marca  = null;
                    this.Modelo = null;

                    this.Item = res;

                    if (res.Id.HasValue)
                    {
                        this.Corridas = await _proxy.GetPreciosAsync(res.Id.Value);
                    }
                }
            }
            else
            {
                return;
            }

            if (this.Item != null)
            {
                var request = new Common.Entities.CheckPromocionesRequest
                {
                    Sucursal  = this.Sucursal.Clave,
                    Productos = new Common.Entities.SerieFormasPago[]
                    {
                        new Common.Entities.SerieFormasPago
                        {
                            ArticuloId = this.Item.Id,
                            Serie      = this.Item.Serie,
                            //FormasPago = new Common.Constants.FormaPago[]
                            //{
                            //    Common.Constants.FormaPago.EF
                            //}
                        }
                    }
                };
                this.Promos = await _proxy.GetPromocionesAsync(request);
            }
        }