Ejemplo n.º 1
0
        //todo init orderline
        public override void Update()
        {
            //Update - может быть вызван повторно если
            //мы вернулись на текущую форму с другой формы где были отредактированы данные
            if (Order.Value != null)
            {
                Session.Evict(Order.Value);
            }
            Order.Value = (IOrder)Session.Get(type, orderId);
            //если заказ был удален
            if (Order.Value == null)
            {
                IsSuccessfulActivated = false;
                return;
            }
            if (Order.Value is Order)
            {
                ((Order)Order.Value).Lines.Each(x => {
                    x.Settings = Settings;
                    x.CalculateRetailCost(Settings.Value.Markups, Shell?.SpecialMarkupProducts.Value, User);
                });
            }
            if (Settings.Value.HighlightUnmatchedOrderLines && !IsCurrentOrder)
            {
                var sentLines = (IList <SentOrderLine>)Order.Value.Lines;
                sentLines.Each(l => l.Configure(User));
                Env.RxQuery(s => MatchedWaybills.GetLookUp(s, sentLines))
                .Subscribe(x => sentLines.Each(y => y.Configure(x)));
            }
            // Текущие заказы
            else
            {
                Order.Value.Lines.Each(l => l.Configure(User));
                Order.Value.Lines
                .Cast <OrderLine>()
                .Where(x => frozenProducts.Contains(x.ProductId))
                .Each(x => x.InFrozenOrders = true);
            }

            if (CurrentLine.Value != null)
            {
                CurrentLine.Value = Order.Value.Lines.FirstOrDefault(x => x.Id == CurrentLine.Value.Id);
            }

            Source = new ObservableCollection <IOrderLine>(Order.Value.Lines.OrderBy(l => l.ProductSynonym));
            Source.ObservableForProperty(c => c.Count)
            .Where(e => e.Value == 0)
            .Subscribe(_ => TryClose());

            Lines.Recalculate();
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            OnlyWarningVisible = IsCurrentSelected.Select(v => v && User.IsPreprocessOrders).ToValue();
            ProductInfo        = new ProductInfo(this, CurrentLine);
            ProductInfo2       = new ProductInfo(this, SelectedSentLine);
            AddressSelector.Init();
            AddressSelector.FilterChanged
            .Merge(Prices.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler))
            .Merge(DbReloadToken)
            .Merge(OrdersReloadToken)
            .Merge(FilterItems.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler))
            .Where(_ => IsCurrentSelected && Session != null)
            .Select(_ =>
            {
                var orders = AddressSelector.GetActiveFilter().SelectMany(o => o.Orders)
                             .Where(x => Prices.Where(y => y.IsSelected).Select(y => y.Item.Id).Contains(x.Price.Id)).ToList();
                var activeOrders = orders.Where(x => !x.Frozen).ToList();

                var lines = activeOrders.SelectMany(o => o.Lines)
                            .OrderBy(l => l.Id)
                            .ToObservableCollection();
                lines.Each(l => {
                    l.Settings = Settings;
                    l.Order.CalculateStyle(Address);
                    if (l.Order.IsAddressExists())
                    {
                        l.CalculateRetailCost(Settings.Value.Markups, Shell?.SpecialMarkupProducts.Value, User);
                    }
                });

                // #48323 Присутствует в замороженных заказах
                var productInFrozenOrders = orders.Where(x => x.Frozen).SelectMany(x => x.Lines)
                                            .Select(x => x.ProductId).Distinct().ToList();
                lines.Where(x => productInFrozenOrders.Contains(x.ProductId))
                .Each(x => x.InFrozenOrders = true);

                var selected = FilterItems.Where(p => p.IsSelected).Select(p => p.Item.Item1).ToArray();
                if (selected.Count() != FilterItems.Count())
                {
                    var ids = new List <uint>();
                    if (selected.Contains("InFrozenOrders"))
                    {
                        ids.AddRange(lines.Where(x => x.InFrozenOrders).Select(x => x.Id));
                    }
                    if (selected.Contains("IsMinCost"))
                    {
                        ids.AddRange(lines.Where(x => x.IsMinCost).Select(x => x.Id));
                    }
                    if (selected.Contains("IsNotMinCost"))
                    {
                        ids.AddRange(lines.Where(x => !x.IsMinCost).Select(x => x.Id));
                    }
                    if (selected.Contains("OnlyWarning"))
                    {
                        ids.AddRange(lines.Where(x => x.SendResult != LineResultStatus.OK).Select(x => x.Id));
                    }
                    return(lines.Where(x => ids.Contains(x.Id)).ToObservableCollection());
                }
                return(lines);
            })
            .Subscribe(Lines, CloseCancellation.Token);

            IsSentSelected.Where(v => v)
            .Select(v => (object)v)
            .Merge(Begin.Select(d => (object)d))
            .Merge(End.Select(d => (object)d))
            .Merge(Prices.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler))
            .Merge(AddressSelector.FilterChanged)
            .Merge(DbReloadToken)
            .Do(_ => { IsLoading.Value = true; })
            //защита от множества запросов
            .Throttle(TimeSpan.FromMilliseconds(30), Scheduler)
            .Where(_ => IsSentSelected)
            .Select(_ => RxQuery(s => {
                var begin      = Begin.Value;
                var end        = End.Value.AddDays(1);
                var addressIds = AddressSelector.GetActiveFilter().Select(a => a.Id).ToArray();
                var query      = s.Query <SentOrderLine>()
                                 .Fetch(l => l.Order)
                                 .ThenFetch(o => o.Address)
                                 .Fetch(o => o.Order)
                                 .ThenFetch(o => o.Price)
                                 .Where(l => l.Order.SentOn > begin && l.Order.SentOn < end)
                                 .Where(l => addressIds.Contains(l.Order.Address.Id));

                query = Util.Filter(query, l => l.Order.Price.Id, Prices);

                var lines = query.OrderBy(l => l.ProductSynonym)
                            .ThenBy(l => l.ProductSynonym)
                            .Take(1000)
                            .ToList();
                if (Settings.Value.HighlightUnmatchedOrderLines)
                {
                    var lookup = MatchedWaybills.GetLookUp(s, lines);
                    lines.Each(l => l.Order.CalculateStyle(Address));
                    lines.Each(l => l.Configure(User, lookup));
                }
                else
                {
                    lines.Each(l => l.Order.CalculateStyle(Address));
                    lines.Each(l => l.Configure(User));
                }
                return(lines);
            }))
            .Switch()
            .Do(_ => IsLoading.Value = false)
            .Subscribe(SentLines, CloseCancellation.Token);

            CurrentLine
            .Throttle(Consts.ScrollLoadTimeout, UiScheduler)
            .Merge(DbReloadToken)
            .Subscribe(_ => UpdateAsync(), CloseCancellation.Token);
            CurrentLine
            .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler)
            .SelectMany(x => Env.RxQuery(s => LoadOrderHistory(s, Cache, Settings.Value, x, ActualAddress)))
            .Subscribe(HistoryOrders, CloseCancellation.Token);
        }
Ejemplo n.º 4
0
        public OrderLinesViewModel()
        {
            DisplayName = "Сводный заказ";

            InitFields();
            Lines             = new NotifyValue <ObservableCollection <OrderLine> >(new ObservableCollection <OrderLine>());
            SentLines         = new NotifyValue <List <SentOrderLine> >(new List <SentOrderLine>());
            IsCurrentSelected = new NotifyValue <bool>(true);
            Begin             = new NotifyValue <DateTime>(DateTime.Today.AddMonths(-3).FirstDayOfMonth());
            End             = new NotifyValue <DateTime>(DateTime.Today);
            AddressSelector = new AddressSelector(this);

            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", "Только позиции с корректировкой")));

            CanDelete    = CurrentLine.CombineLatest(IsCurrentSelected, (l, s) => l != null && s).ToValue();
            BeginEnabled = IsSentSelected.ToValue();
            EndEnabled   = IsSentSelected.ToValue();

            IsCurrentSelected.Subscribe(_ => NotifyOfPropertyChange(nameof(CanPrint)));
            IsCurrentSelected.Subscribe(_ => NotifyOfPropertyChange(nameof(CanExport)));

            Sum = new NotifyValue <decimal>(() => {
                if (IsCurrentSelected)
                {
                    return(Lines.Value.Sum(l => l.MixedSum));
                }
                return(SentLines.Value.Sum(l => l.MixedSum));
            }, SentLines, Lines, IsCurrentSelected);

            OrderWarning = new InlineEditWarning(UiScheduler, Manager);
            QuickSearch  = new QuickSearch <OrderLine>(UiScheduler,
                                                       s => Lines.Value.FirstOrDefault(l => l.ProductSynonym.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0),
                                                       CurrentLine);
            QuickSearch2 = new QuickSearch <SentOrderLine>(UiScheduler,
                                                           s => SentLines.Value.FirstOrDefault(l => l.ProductSynonym.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0),
                                                           SelectedSentLine);
            Editor = new Editor(OrderWarning, Manager, CurrentLine, Lines.Cast <IList>().ToValue());

            var currentLinesChanged = this.ObservableForProperty(m => m.CurrentLine.Value.Count)
                                      .Throttle(Consts.RefreshOrderStatTimeout, UiScheduler)
                                      .Select(e => new Stat(Address));

            OnCloseDisposable.Add(Bus.RegisterMessageSource(currentLinesChanged));
            OnCloseDisposable.Add(currentLinesChanged.Subscribe(_ => Sum.Recalculate()));

            Settings.Subscribe(_ => CalculateOrderLine());

            if (Session != null)
            {
                Prices = Session.Query <Price>().OrderBy(p => p.Name).ToList()
                         .Select(p => new Selectable <Price>(p))
                         .ToList();
            }
            else
            {
                Prices = new List <Selectable <Price> >();
            }

            MatchedWaybills = new MatchedWaybills(this, SelectedSentLine, IsSentSelected);
            IsCurrentSelected
            .Select(v => v ? "Lines" : "SentLines")
            .Subscribe(ExcelExporter.ActiveProperty);

            Observable.Merge(IsCurrentSelected.Select(x => (object)x), Lines, SentLines, currentLinesChanged)
            .Select(_ => {
                if (IsCurrentSelected)
                {
                    return(Lines.Value?.Count ?? 0);
                }
                return(SentLines.Value?.Count ?? 0);
            })
            .Subscribe(LinesCount);
            IsLoading = new NotifyValue <bool>();
            IsCurrentSelected.Where(v => v)
            .Select(_ => false)
            .Subscribe(IsLoading);

            SessionValue(Begin, GetType().Name + ".Begin");
            SessionValue(End, GetType().Name + ".End");
            SessionValue(IsSentSelected, GetType().Name + ".IsSentSelected");
            Persist(IsExpanded, "IsExpanded");

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
        }