protected override void OnInitialize()
        {
            base.OnInitialize();

            if (Shell.LeaderCalculationWasStart)
            {
                Shell.PropertyChanged += (sender, e) => {
                    if (e.PropertyName == nameof(Shell.LeaderCalculationWasStart))
                    {
                        OnActivate();
                    }
                };
                MessageResult.Warn("Идет расчет прайс-лидеров. Прайс-лидеры и минимальные цены отобразятся после окончания расчета, это может занять какое-то время.")
                .Execute(new ActionExecutionContext());
            }

            Price.Value = Env.Query(s => s.Get <Price>(priceId)).Result;
            Promotions.FilterBySupplierId         = Price?.Value?.SupplierId;
            ProducerPromotions.FilterByProducerId = CurrentProducer.Value.Id;

            DbReloadToken
            .Do(_ => IsLoading.Value = true)
            .SelectMany(_ => RxQuery(s => s.Query <Offer>().Where(o => o.Price.Id == priceId)
                                     .Fetch(o => o.Price)
                                     .Fetch(o => o.LeaderPrice)
                                     .ToList()))
            .CatchSubscribe(BindOffers, CloseCancellation);
        }
示例#2
0
        public override void Update()
        {
            if (Session == null)
            {
                return;
            }
            var prices = Session.Query <Price>().OrderBy(c => c.Name).ToList();

            if (Address != null)
            {
                Price.LoadOrderStat(Env, prices, Address).LogResult();
                prices.Each(p => p.Order       = Address.Orders.Where(o => !o.Frozen).FirstOrDefault(o => o.Price == p));
                prices.Each(p => p.MinOrderSum = Address.Rules.FirstOrDefault(r => r.Price == p));
            }

            prices.Select(p => p.ObservableForProperty(x => x.Active))
            .Merge()
            .Throttle(TimeSpan.FromMilliseconds(1000), UiScheduler)
            .Subscribe(_ => ResultsSink.OnNext(MessageResult.Warn("Изменение настроек прайс-листов будет применено при следующем обновлении.")), CloseCancellation.Token);

            Prices.Value = prices;
            if (CurrentPrice.Value != null)
            {
                CurrentPrice.Value = Prices.Value.Where(p => p.Id == CurrentPrice.Value.Id)
                                     .DefaultIfEmpty(Prices.Value.FirstOrDefault())
                                     .First();
            }
        }
        public IEnumerable <IResult> ShowOrderHistory()
        {
            if (CurrentCatalog == null || Address == null)
            {
                yield break;
            }

            var addressId = Address.Id;
            var catalogId = CurrentCatalog.Id;
            var lines     = Env.Query(s => s.Query <SentOrderLine>()
                                      .Where(o => o.CatalogId == catalogId)
                                      .Where(o => o.Order.Address.Id == addressId)
                                      .OrderByDescending(o => o.Order.SentOn)
                                      .Fetch(l => l.Order)
                                      .ThenFetch(o => o.Price)
                                      .Take(20)
                                      .ToList()).Result;

            if (lines.Count > 0)
            {
                Shell.Navigate(new HistoryOrdersViewModel(CurrentCatalog, null, lines));
            }
            else
            {
                yield return(MessageResult.Warn("Нет истории заказов"));
            }
        }
 public void BindOffers(List <Offer> offers)
 {
     Calculate(offers);
     LoadOrderItems(offers);
     PriceOffers = offers;
     FillProducerFilter(PriceOffers);
     Filter(false);
     SelectOffer();
     Price.Value = PriceOffers.Select(o => o.Price).FirstOrDefault()
                   ?? Price.Value;
     IsLoading.Value = false;
     if (PriceOffers.Count == 0)
     {
         ResultsSink.OnNext(MessageResult.Warn("Выбранный прайс-лист отсутствует"));
         TryClose();
     }
 }
示例#5
0
        public IEnumerable <IResult> Add()
        {
            if (!Can2Add)
            {
                yield return(MessageResult.Warn("Движения товаров по накладным не обнаружено"));

                yield break;
            }
            var catalogList = new List <Catalog>();

            yield return(new DialogResult(new CatalogViewModel(catalogList), resizable: true));

            catalogList.AddRange(Items);
            catalogList = catalogList.Distinct().OrderBy(x => x.FullName).ToList();
            Items       = new ReactiveCollection <Catalog>(catalogList);
            if (Items.Any())
            {
                CurrentItem.Value = Items.First();
            }
            Refresh();
        }
示例#6
0
        public IEnumerable <IResult> ExportExcel()
        {
            if (!Can2ExportExcel)
            {
                yield return(MessageResult.Warn("Не выбраны товары. Используйте \"Добавить товар в список\""));

                yield break;
            }
            var settings = new GoodsMovementReportSettings()
            {
                Begin             = Begin.Value,
                End               = End.Value,
                FilterByWriteTime = false,
                CatalogIds        = Items.Select(x => x.Id).ToArray(),
                CatalogNames      = Items.Select(x => x.FullName).ToList().Implode()
            };

            if (!Addresses2.Value.All(x => x.IsSelected))
            {
                settings.AddressIds   = Addresses2.Value.Where(x => x.IsSelected).Select(x => x.Item.Id).ToArray();
                settings.AddressNames = Addresses2.Value.Where(x => x.IsSelected).Select(x => x.Item.Name).ToList().Implode();
            }
            if (!Suppliers.Value.All(x => x.IsSelected))
            {
                settings.SupplierIds   = Suppliers.Value.Where(x => x.IsSelected).Select(x => x.Item.Id).ToArray();
                settings.SupplierNames = Suppliers.Value.Where(x => x.IsSelected).Select(x => x.Item.FullName).ToList().Implode();
            }
            if (!Producers.Value.All(x => x.IsSelected))
            {
                settings.ProducerIds   = Producers.Value.Where(x => x.IsSelected).Select(x => x.Item.Id).ToArray();
                settings.ProducerNames = Producers.Value.Where(x => x.IsSelected).Select(x => x.Item.Name).ToList().Implode();
            }

            var commnand = new GoodsMovementReport(settings);

            yield return(new Models.Results.TaskResult(commnand.ToTask(Shell.Config)));

            yield return(new OpenResult(commnand.Result));
        }
        public IEnumerable <IResult> Save()
        {
            UpdateMarkups();
            UpdatePriceTags();
            var error = Settings.Value.Validate(validateMarkups: HaveAddresses);

            if (error?.Count > 0)
            {
                if (Session != null)
                {
                    Session.FlushMode = FlushMode.Never;
                }
                GoToErrorTab(error.First()[0]);
                yield return(MessageResult.Warn(error.First()[1]));

                yield break;
            }

            if (passwordUpdated)
            {
                Settings.Value.Password = password;
            }
            if (diadokPasswordUpdated)
            {
                Settings.Value.DiadokPassword = diadokPassword;
            }
            if (sbisPasswordUpdated)
            {
                Settings.Value.SbisPassword = sbisPassword;
            }

            if (App.Current != null)
            {
                StyleHelper.BuildStyles(App.Current.Resources, Styles);
            }

            if (Session != null)
            {
                IsCredentialsChanged = Session.IsChanged(Settings.Value, s => s.Password) ||
                                       Session.IsChanged(Settings.Value, s => s.UserName);
                if (Session.IsChanged(Settings.Value, s => s.GroupWaybillsBySupplier) &&
                    Settings.Value.GroupWaybillsBySupplier)
                {
                    foreach (var dirMap in DirMaps)
                    {
                        try {
                            Directory.CreateDirectory(dirMap.Dir);
                        }
                        catch (Exception e) {
                            Log.Error($"Не удалось создать директорию {dirMap.Dir}", e);
                        }
                    }
                }

                if (Session.IsChanged(Settings.Value, x => x.JunkPeriod))
                {
                    yield return(new Models.Results.TaskResult(Query(s => DbMaintain.CalcJunk(s, Settings.Value))));
                }

                Session.FlushMode = FlushMode.Auto;
                Settings.Value.ApplyChanges(Session);
                SynchronizeSpecialMarkUps();
            }
            TryClose();
        }