public void Edit_order_multi_address()
        {
            var address1 = new Address("тест1");
            var address2 = new Address("тест2");

            InitAddress(address1, address2);
            Activate(batch, address1, address2);

            var offer = new Offer(new Price("тест"), 50);
            var line  = address2.Order(offer, 5);

            batch.BuildLineViews(new List <BatchLine> {
                new BatchLine {
                    Address = address1
                }, new BatchLine(line)
            });

            batch.CurrentReportLine.Value = batch.Lines.Value[1];
            batch.UpdateOffers(new List <Offer> {
                offer
            });
            scheduler.AdvanceByMs(1000);

            Assert.AreEqual(5, batch.CurrentOffer.Value.OrderCount);
            Order(0);
            Order(10);

            Assert.AreEqual(0, address1.Orders.Count);
            Assert.AreEqual(1, address2.Orders.Count);
            Assert.AreEqual(500, address2.Orders[0].Sum);
        }
        public void Upload_file()
        {
            var address = new Address("тест")
            {
                Id = 100,
            };

            Activate(batch, address);
            shell.Settings.Value.LastUpdate = DateTime.Now;
            var           stub = new StubRemoteCommand(UpdateResult.OK);
            UpdateCommand cmd  = null;

            shell.CommandExecuting += c => {
                cmd = (UpdateCommand)c;
                return(stub);
            };
            var actions = batch.Upload().GetEnumerator();
            var file    = Next <OpenFileResult>(actions);

            file.Dialog.FileName = "data.txt";

            Next(actions);
            Assert.AreEqual("data.txt", cmd.BatchFile);
            Assert.AreEqual(100, cmd.AddressId);
            Assert.IsInstanceOf <Batch>(shell.ActiveItem);
        }
        public void Update_order_stat()
        {
            var address = new Address("тест");

            InitAddress(address);
            var order = new Order(address, new Offer(new Price("тест"), 100));

            order.Lines[0].ExportId = 203;
            address.Orders.Add(order);

            Stat lastStat = null;

            bus.Listen <Stat>().Subscribe(s => lastStat = s);
            Activate(batch, address);
            batch.BuildLineViews(new List <BatchLine> {
                new BatchLine(order.Lines[0])
            });

            batch.SelectedReportLines.Add(batch.Lines.Value[0]);
            batch.CurrentReportLine.Value = batch.Lines.Value[0];
            batch.Delete();
            scheduler.AdvanceByMs(1000);
            Assert.IsNotNull(lastStat);
            Assert.AreEqual(0, lastStat.OrdersCount);
        }
        private OrderLine MakeOrderLine()
        {
            var address = new Address("тест");

            InitAddress(address);
            offer = new Offer(new Price("тест"), 100)
            {
                ProductSynonym  = "Тестовый товар",
                ProducerSynonym = "Тестовый производитель",
                ProductId       = 105,
            };
            return(address.Order(offer, 1));
        }
        public void Filter_lines()
        {
            var address = new Address("тест");

            InitAddress(address);
            var offer = new Offer(new Price("тест"), 50);
            var line  = address.Order(offer, 5);

            line.ExportId = 562;
            Activate(batch, address);
            batch.BuildLineViews(new List <BatchLine> {
                new BatchLine(line), new BatchLine(new Catalog("тест"), address)
            });

            //заказано
            batch.CurrentFilter.Value = batch.Filter[1];
            Assert.AreEqual(1, batch.ReportLines.Value.Count);
            Assert.IsNotNull(batch.ReportLines.Value[0].OrderLine);
        }
        public void Load_order_lines()
        {
            var address1 = new Address("тест1");
            var address2 = new Address("тест2");

            InitAddress(address1, address2);

            var offer = new Offer(new Price("тест"), 50);
            var line  = address2.Order(offer, 5);

            line.ExportId = 562;
            Activate(batch, address1, address2);
            batch.BuildLineViews(new List <BatchLine> {
                new BatchLine(line)
            });

            Assert.IsTrue(batch.CanReload);
            Assert.IsTrue(batch.CanClear);
            Assert.AreEqual(line, batch.ReportLines.Value[0].OrderLine);
        }
        public void Delete_batch_line_on_delete_order_line()
        {
            var address = new Address("тест");

            InitAddress(address);
            var offer = new Offer(new Price("тест"), 50);
            var line  = address.Order(offer, 5);

            line.ExportId = 562;
            Activate(batch, address);
            batch.BuildLineViews(new List <BatchLine> {
                new BatchLine(line)
            });

            batch.CurrentReportLine.Value = batch.Lines.Value[0];
            batch.UpdateOffers(new List <Offer> {
                offer,
            });
            Assert.AreEqual(5, batch.CurrentOffer.Value.OrderCount);
            Order(0);
            Assert.AreEqual(0, batch.ReportLines.Value.Count);
            Assert.AreEqual(0, batch.Lines.Value.Count);
        }
Esempio n. 8
0
        public CatalogChooser(string term, Address address)
        {
            BaseScreen.InitFields(this);
            DisplayName  = "Выберите товар";
            WasCancelled = true;
            var env = Config.Env.Current;

            SearchBehavior = new SearchBehavior(env);
            SearchBehavior.ActiveSearchTerm.Value = term;

            SearchBehavior.ActiveSearchTerm
            .Do(_ => IsLoading.Value = true)
            .Select(_ => env.RxQuery(s => {
                var sql = @"
drop temporary table if exists StockCatalogs;
create temporary table StockCatalogs(
	CatalogId int unsigned,
	MinRetailCost decimal(12, 2),
	primary key(CatalogId)
);
insert into StockCatalogs
select CatalogId, min(RetailCost) as MinRetailCost
from Stocks
where AddressId = @addressId and Quantity > 0
	and Status = @stockStatus
	and RetailCost > 0
group by CatalogId;

drop temporary table if exists GroupByType;
create temporary table GroupByType (
	MnnId int unsigned,
	Type int unsigned,
	MinRetailCost decimal(12, 2),
	primary key(MnnId, Type)
)
select cn.MnnId, c.Type, min(MinRetailCost) as MinRetailCost
from StockCatalogs s
	join Catalogs c on c.Id = s.CatalogId
		join CatalogNames cn on cn.Id = c.NameId
where cn.MnnId is not null
	and c.Type is not null
group by cn.MnnId, c.Type;

select c.Id as CatalogId, cn.Name, c.Form, c.HaveOffers, c.VitallyImportant,
	s.MinRetailCost as MinRetailCost,
	t.MinRetailCost as MinEquivalentCost
from Catalogs c
	join CatalogNames cn on cn.Id = c.NameId
		left join StockCatalogs s on s.CatalogId = c.Id
		left join GroupByType t on t.MnnId = cn.MnnId and t.Type = c.TYpe
where (cn.Name like @term or c.Form like @term) and (s.CatalogId is not null or t.MnnId is not null)
order by cn.Name, c.Form;

drop temporary table GroupByType;
drop temporary table StockCatalogs;
";
                return(s.Connection.Query <CatalogLine>(sql, new {
                    term = "%" + SearchBehavior.ActiveSearchTerm.Value + "%",
                    addressId = address.Id,
                    stockStatus = StockStatus.Available
                }).ToList());
            }))
            .Switch()
            .Do(_ => IsLoading.Value = false)
            .Subscribe(Items);

            Items.Subscribe(_ => {
                CurrentItem.Value = (Items.Value ?? Enumerable.Empty <CatalogDisplayItem>()).FirstOrDefault();
            });

            CurrentItem
            .SelectMany(x => Env.RxQuery(s => {
                if (x == null)
                {
                    return(null);
                }
                var catalogId = x.CatalogId;
                return(s.Query <Catalog>()
                       .Fetch(c => c.Name)
                       .ThenFetch(n => n.Mnn)
                       .FirstOrDefault(c => c.Id == catalogId));
            }))
            .Subscribe(CurrentCatalog, CloseCancellation.Token);
            CurrentCatalog.Select(x => x?.Name?.Description != null).Subscribe(CanShowDescription);
        }