Beispiel #1
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            ProductInfo  = new ProductInfo(this, CurrentLine.OfType <BaseOffer>());
            OrderWarning = new InlineEditWarning(UiScheduler, Manager);

            //если это отправленный заказ редактор не должен работать
            var currentOrderLine = new NotifyValue <OrderLine>();

            if (IsCurrentOrder)
            {
                currentOrderLine = CurrentLine.Select(v => (OrderLine)v).ToValue();
                currentOrderLine.Subscribe(v => CurrentLine.Value = v);
            }
            editor             = new Editor(OrderWarning, Manager, currentOrderLine, Lines.Cast <IList>().ToValue());
            OnlyWarningVisible = new NotifyValue <bool>(User.IsPreprocessOrders && IsCurrentOrder);
            CurrentLine.OfType <BaseOffer>()
            .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler)
            .Select(x => RxQuery(s => BaseOfferViewModel.LoadOrderHistory(s, Cache, Settings.Value, x, Address)))
            .Switch()
            .Subscribe(HistoryOrders, CloseCancellation.Token);

            FilterItems.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler)
            .Select(_ => Filter())
            .Subscribe(Lines, CloseCancellation.Token);
        }
        public IEnumerable <IResult> AddFromCatalog()
        {
            if (!User.IsStockEnabled || !CanAddFromCatalog)
            {
                yield break;
            }
            var dlg = new AddWaybillLineFromCatalog();

            yield return(new DialogResult(dlg));

            if (dlg.WasCancelled)
            {
                yield break;
            }
            var line = new WaybillLine(Waybill)
            {
                CatalogId    = dlg.CurrentCatalog.Value.Id,
                ProductId    = Session.Query <Product>().FirstOrDefault(r => r.CatalogId == dlg.CurrentCatalog.Value.Id)?.Id,
                Product      = dlg.CurrentCatalog.Value.FullName,
                ProducerId   = dlg.CurrentProducer.Value.Id,
                Producer     = dlg.CurrentProducer.Value.Name,
                SupplierCost = dlg.SupplierCost.Value,
                Quantity     = dlg.Quantity.Value
            };

            CurrentLine.Value  = Lines.Value.AddNewItem(line);
            CurrentWaybillLine = CurrentLine.OfType <WaybillLine>().ToValue();
        }
Beispiel #3
0
        public OrderDetailsViewModel(IOrder order, List <uint> fProducts = null)
        {
            InitFields();
            orderId = order.Id;
            type    = NHibernateUtil.GetClass(order);
            if (IsCurrentOrder)
            {
                DisplayName = "Текущий заказ";
            }
            else
            {
                DisplayName = "Архивный заказ";
            }
            Lines           = new NotifyValue <IList <IOrderLine> >(new List <IOrderLine>(), Filter);
            MatchedWaybills = new MatchedWaybills(this,
                                                  CurrentLine.OfType <SentOrderLine>().ToValue(),
                                                  new NotifyValue <bool>(!IsCurrentOrder));
            if (User.CanExport(this, type.Name))
            {
                ExcelExporter.Properties = new[] { "Lines" }
            }
            ;
            else
            {
                ExcelExporter.Properties = new string[0];
            }
            ExcelExporter.ActiveProperty.Refresh();
            frozenProducts = fProducts ?? new List <uint>();

            FilterItems = new List <Selectable <Tuple <string, string> > >();
            FilterItems.Add(
                new Selectable <Tuple <string, string> >(Tuple.Create("InFrozenOrders", "Позиции присутствуют в замороженных заказах")));
            FilterItems.Add(new Selectable <Tuple <string, string> >(Tuple.Create("IsMinCost", "Позиции по мин.ценам")));
            FilterItems.Add(new Selectable <Tuple <string, string> >(Tuple.Create("IsNotMinCost", "Позиции не по мин.ценам")));
            FilterItems.Add(new Selectable <Tuple <string, string> >(Tuple.Create("OnlyWarning", "Только позиции с корректировкой")));

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
        }
        public IEnumerable <IResult> BarcodeScanned(string barcode)
        {
            if (!User.IsStockEnabled || !CanAddFromCatalog)
            {
                yield break;
            }

            BarcodeProducts BarcodeProduct = Session.Query <BarcodeProducts>()
                                             .Where(x => x.Barcode == barcode).FirstOrDefault();

            if (BarcodeProduct != null)
            {
                var dlg = new AddWaybillLineFromCatalog(BarcodeProduct);
                yield return(new DialogResult(dlg));

                if (dlg.WasCancelled)
                {
                    yield break;
                }
                var line = new WaybillLine(Waybill)
                {
                    CatalogId    = dlg.CurrentCatalog.Value.Id,
                    ProductId    = Session.Query <Product>().FirstOrDefault(r => r.CatalogId == dlg.CurrentCatalog.Value.Id)?.Id,
                    Product      = dlg.CurrentCatalog.Value.FullName,
                    ProducerId   = dlg.CurrentProducer.Value.Id,
                    Producer     = dlg.CurrentProducer.Value.Name,
                    SupplierCost = dlg.SupplierCost.Value,
                    Quantity     = dlg.Quantity.Value
                };
                CurrentLine.Value  = Lines.Value.AddNewItem(line);
                CurrentWaybillLine = CurrentLine.OfType <WaybillLine>().ToValue();
            }
            else
            {
                Manager.Notify("Товар по штрихкоду не найден");
            }
        }
        public WaybillDetails(uint id)
        {
            DisplayName = "Детализация накладной";
            this.id     = id;
            InitFields();
            CurrentWaybillLine = CurrentLine.OfType <WaybillLine>().ToValue();

            Settings.Subscribe(_ => Calculate());
            CurrentTax.Subscribe(v => {
                if (Lines.Value == null)
                {
                    return;
                }
                if (v == null || v.Value == -1)
                {
                    Lines.Value.Filter = null;
                }
                else
                {
                    Lines.Value.Filter = o => ((WaybillLine)o).Nds == v.Value;
                }
            });
            Lines.Select(v => v == null
                                ? Observable.Empty <EventPattern <NotifyCollectionChangedEventArgs> >()
                                : v.ToCollectionChanged())
            .Switch()
            .Subscribe(e => {
                if (e.EventArgs.Action == NotifyCollectionChangedAction.Remove)
                {
                    e.EventArgs.OldItems.OfType <WaybillLine>().Each(l => Waybill.RemoveLine(l));
                }
                else if (e.EventArgs.Action == NotifyCollectionChangedAction.Add)
                {
                    e.EventArgs.NewItems.OfType <WaybillLine>().Each(l => Waybill.AddLine(l));
                }
            });
            OrderLines = CurrentWaybillLine
                         .Throttle(Consts.ScrollLoadTimeout, UiScheduler)
                         .Select(v => {
                if (v == null)
                {
                    return(new List <SentOrderLine>());
                }
                var lineId       = v.Id;
                var orderLineIds = Session.Query <WaybillOrder>().Where(l => l.DocumentLineId == lineId)
                                   .Select(l => (uint?)l.OrderLineId)
                                   .ToArray();
                var line = Session.Query <SentOrderLine>().FirstOrDefault(l => orderLineIds.Contains(l.ServerId));
                if (line != null)
                {
                    CurrentOrderLine.Value = line;
                    line.Order.Lines.Each(l => l.Configure(User));
                    return(line.Order.Lines.OrderBy(l => l.ProductSynonym).ToList());
                }
                return(new List <SentOrderLine>());
            })
                         .ToValue(CloseCancellation);
            EmptyLabelVisibility = OrderLines
                                   .Select(v => v == null || v.Count == 0 ? Visibility.Visible : Visibility.Collapsed)
                                   .ToValue();
            OrderDetailsVisibility = EmptyLabelVisibility
                                     .Select(v => v == Visibility.Collapsed ? Visibility.Visible :  Visibility.Collapsed)
                                     .ToValue();
        }