private CatalogOfferViewModel(OfferComposedId initOfferId = null)
            : base(initOfferId)
        {
            InitFields();
            NeedToCalculateDiff = true;
            DisplayName         = "Сводный прайс-лист";
            Filters             = new[] { "Все", "Основные", "Неосновные" };

            CurrentFilter.Value = Filters[0];
            CurrentRegion.Value = Consts.AllRegionLabel;

            GroupByProduct.Value = Settings.Value.GroupByProduct;
            GroupByProduct.Subscribe(_ => Offers.Value = Sort(Offers.Value));

            RetailMarkup = new NotifyValue <decimal>(true,
                                                     () => MarkupConfig.Calculate(Settings.Value.Markups, CurrentOffer.Value, User, Address),
                                                     Settings);

            RetailCost = CurrentOffer.CombineLatest(RetailMarkup, Rounding,
                                                    (o, m, r) => Round(NullableHelper.Round(o?.ResultCost * (1 + m / 100), 2), r))
                         .ToValue();

            CurrentOffer.Subscribe(_ => RetailMarkup.Recalculate());

            Persist(HideJunk, "HideJunk");
            Persist(GroupByProduct, "GroupByProduct");
            SessionValue(CurrentRegion, "CurrentRegion");
            SessionValue(CurrentFilter, "CurrentFilter");

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
        }
Exemplo n.º 2
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;
        }