Exemplo n.º 1
0
        public void Group_by_code_and_product()
        {
            var code     = new string(Guid.NewGuid().ToString().Take(20).ToArray());
            var supplier = TestSupplier.CreateNaked(session);
            var client   = TestClient.CreateNaked(session);
            var price    = supplier.Prices[0];
            var order    = new TestOrder(client.Users[0], price)
            {
                WriteTime = DateTime.Now.AddDays(-5)
            };
            var productSynonym = price.AddProductSynonym(TestProduct.Random(session).First());

            session.Save(productSynonym);
            var item = order.AddItem(TestProduct.RandomProducts(session).First(), 10, 456);

            item.SynonymCode = productSynonym.Id;
            item.Code        = code;
            session.Save(order);
            Property("ReportInterval", 5);
            Property("SupplierProductCodePosition", 0);
            Property("SupplierProductNamePosition", 1);
            Property("FirmCodeEqual", new List <ulong> {
                supplier.Id
            });
            var sheet = ReadReport <RatingReport>();

            Assert.AreEqual("Оригинальный код товара", sheet.GetRow(2).GetCell(0).StringCellValue);
            Assert.AreEqual(code, sheet.GetRow(3).GetCell(0).StringCellValue);
            Assert.AreEqual("Оригинальное наименование товара", sheet.GetRow(2).GetCell(1).StringCellValue);
            Assert.AreEqual(productSynonym.Name, sheet.GetRow(3).GetCell(1).StringCellValue);
        }
        public void Do_now_showcr_code()
        {
            DefaultConf();

            order = new TestOrder(client.Users[0], supplier.Prices[0]);
            var product = session.Query <TestProduct>().First(p => p.CatalogProduct.CatalogName.Mnn != null);

            order.WriteTime = order.WriteTime.AddDays(-1);
            order.AddItem(product, 15, 901.25f);
            session.Save(order);

            Property("ShowCode", true);
            Property("ShowCodeCr", false);
            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);

            Assert.That(text, Is.Not.Contains("Код изготовителя"));
            var item = order.Items[0];
            var sum  = session.Query <TestOrderItem>()
                       .Where(x => x.Product == item.Product && x.CodeFirmCr == item.CodeFirmCr &&
                              x.Order.WriteTime > DateTime.Today.AddDays(-1))
                       .ToArray()
                       .Sum(x => x.Quantity * (decimal)x.Cost);
            var row = FindRowByProduct(sheet, item.Product);

            //Сумма по всем
            Assert.AreEqual(sum, row.GetCell(19).NumericCellValue);
        }
        public void Filter_by_mnn()
        {
            DefaultConf();

            var product  = order.Items[0].Product;
            var mnn      = product.CatalogProduct.CatalogName.Mnn;
            var product1 = session.Query <TestProduct>().First(p => p.CatalogProduct.CatalogName.Mnn != mnn);
            var mnn1     = product1.CatalogProduct.CatalogName.Mnn;

            Property("MnnNonEqual", new List <long> {
                mnn1.Id
            });
            order.AddItem(product1, 34, 123.34f);

            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);

            Assert.IsTrue(HaveMnn(sheet, String.Format("Следующие МНН исключены из отчета: {0}", mnn1.Mnn), 0));
            Assert.IsTrue(HaveMnn(sheet, product));
            var tableText = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                            .Skip(5)
                            .Implode(Environment.NewLine);

            Assert.That(tableText, Is.Not.StringContaining(mnn1.Mnn));
            Assert.That(text, Does.Contain("Сумма по поставщику"));
        }
Exemplo n.º 4
0
        public void Load_history()
        {
            var priceId      = localSession.Query <Offer>().First().Price.Id.PriceId;
            var user         = ServerUser();
            var activePrices = user.GetActivePricesNaked(session);
            var price        = activePrices.Where(p => p.Id.PriceId == priceId)
                               .Concat(activePrices)
                               .First()
                               .Price;
            var order = new TestOrder(user, price)
            {
                Submited  = true,
                Processed = true
            };
            var offer = session.Query <TestCore>().First(c => c.Price == price);

            order.AddItem(offer, 1);
            session.Save(order);
            localSession.DeleteEach <SentOrder>();

            var cmd = new UpdateCommand {
                SyncData = "OrderHistory"
            };

            Run(cmd);

            Assert.AreEqual("Загрузка истории заказов завершена успешно.", cmd.SuccessMessage);
            Assert.That(localSession.Query <SentOrder>().Count(), Is.GreaterThan(0));
            var localOrder = localSession.Query <SentOrder>().First(o => o.ServerId == order.Id);

            Assert.AreEqual(1, localOrder.Lines.Count);
            Assert.AreEqual(1, localOrder.LinesCount);
            Assert.That(localOrder.Lines[0].ResultCost, Is.GreaterThan(0));
        }
Exemplo n.º 5
0
        public void FreeOrdersTest()
        {
            var supplier = TestSupplier.CreateNaked(session);
            var client   = TestClient.CreateNaked(session);
            var product  = new TestProduct("Тестовый продукт");

            session.Save(product);

            var order = new TestOrder(client.Users.First(), supplier.Prices[0]);

            order.AddItem(product, 1, 100);
            session.Save(order);

            var result = ExecuteReport();
            var sum1   = result.AsEnumerable().Where(r => r["OrdersSum"] != DBNull.Value).Sum(r => (decimal)r["OrdersSum"]);

            var freeOrdersQuery = session.CreateSQLQuery(
                String.Format("INSERT INTO billing.freeorders VALUES({0}, {1});",
                              order.Address.Payer.Id,
                              supplier.Payer.Id));

            freeOrdersQuery.ExecuteUpdate();

            result = ExecuteReport();
            var sum2 = result.AsEnumerable().Where(r => r["OrdersSum"] != DBNull.Value).Sum(r => (decimal)r["OrdersSum"]);

            Assert.That(sum2, Is.EqualTo(sum1 - 100));
        }
        public void Generate_report()
        {
            var code     = new string(Guid.NewGuid().ToString().Take(20).ToArray());
            var supplier = TestSupplier.CreateNaked(session);
            var client   = TestClient.CreateNaked(session);
            var price    = supplier.Prices[0];
            var order    = new TestOrder(client.Users[0], price)
            {
                WriteTime = DateTime.Now.AddDays(-5)
            };
            var productSynonym = price.AddProductSynonym(TestProduct.Random(session).First());

            session.Save(productSynonym);
            var item = order.AddItem(TestProduct.RandomProducts(session).First(), 10, 456);

            item.SynonymCode = productSynonym.Id;
            item.Code        = code;
            session.Save(order);

            Property("ReportInterval", 5);
            Property("SupplierId", supplier.Id);
            Property("Regions", new List <ulong> {
                client.RegionCode
            });

            var AFCode = $"{item.Product.Id}_{item.CodeFirmCr ?? 0}";
            var sheet  = ReadReport <PulsOrderReport>();
            var text   = ToText(sheet);

            Assert.That(text, Does.Contain(AFCode));
        }
Exemplo n.º 7
0
        public void CreateOrder()
        {
            var testUser  = session.Load <TestUser>(user.Id);
            var testUser2 = client.CreateUser(session);

            testUser2.AvaliableAddresses.AddEach(client.Addresses);
            testUser.AllowDownloadUnconfirmedOrders = true;
            session.CreateSQLQuery("insert into Customers.UserPrices(PriceId, RegionId, UserId) " +
                                   "select PriceId, RegionId, :target " +
                                   "from Customers.UserPrices " +
                                   "where UserId = :source")
            .SetParameter("source", testUser.Id)
            .SetParameter("target", testUser2.Id)
            .ExecuteUpdate();
            session.Flush();
            var activePrices = testUser2.GetActivePricesNaked(session);
            var price        = activePrices.First()
                               .Price;
            var order = new TestOrder(testUser2, price)
            {
                Submited  = false,
                Processed = false
            };
            var offer = session.Query <TestCore>().First(c => c.Price == price && !c.Junk);

            order.AddItem(offer, 1);
            session.Save(order);
        }
        public void Show_junk()
        {
            supplier = TestSupplier.CreateNaked(session);
            supplier.CreateSampleCore(session);
            client          = TestClient.CreateNaked(session);
            order           = new TestOrder(client.Users[0], supplier.Prices[0]);
            order.WriteTime = order.WriteTime.AddDays(-1);
            var offer = supplier.Prices[0].Core[0];

            offer.Junk = true;
            order.AddItem(offer, 10);
            session.Save(order);

            Property("ProductNamePosition", 0);
            Property("MnnPosition", 1);

            Property("ShowCode", true);
            Property("ByPreviousMonth", false);
            Property("ReportInterval", 1);
            Property("SourceFirmCode", (int)supplier.Id);

            Property("HideJunk", false);

            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);

            Assert.That(text, Does.Contain(offer.Code));
            Assert.That(text, Is.Not.StringContaining("Из отчета исключены уцененные товары и товары с ограниченным сроком годност"));
        }
        public void Remove_duplicate_codes()
        {
            supplier = TestSupplier.CreateNaked(session);
            supplier.CreateSampleCore(session);
            client          = TestClient.CreateNaked(session);
            order           = new TestOrder(client.Users[0], supplier.Prices[0]);
            order.WriteTime = order.WriteTime.AddDays(-1);
            var offer = supplier.Prices[0].Core[0];

            order.AddItem(offer, 10);
            session.Save(order);

            Property("ProductNamePosition", 0);
            Property("MnnPosition", 1);

            Property("ByPreviousMonth", false);
            Property("ShowCode", true);
            Property("ReportInterval", 1);
            Property("SourceFirmCode", (int)supplier.Id);

            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);
            var row   = FindRowByProduct(sheet, offer.Product);

            Assert.AreEqual(offer.Code, row.GetCell(0).StringCellValue, text);
        }
Exemplo n.º 10
0
        public override void Execute(ISession session)
        {
            var testUser = User(session);
            var price    = testUser.GetActivePrices(session)[0];
            var order    = new TestOrder(testUser, price);

            order.WriteTime = DateTime.Now.AddDays(-1);
            order.AddItem(price.Core[0], 1);
            session.Save(order);
        }
Exemplo n.º 11
0
        protected TestOrder CreateOrder(TestClient client = null, TestSupplier supplier = null)
        {
            supplier = supplier ?? TestSupplier.CreateNaked(session);
            client   = client ?? TestClient.CreateNaked(session);
            var order   = new TestOrder(client.Users[0], supplier.Prices[0]);
            var product = session.Query <TestProduct>().First();

            order.WriteTime = order.WriteTime.AddDays(-1);
            order.AddItem(product, 10, 897.23f);
            return(order);
        }
        public void Group_by_code()
        {
            supplier = TestSupplier.CreateNaked(session);
            supplier.CreateSampleCore(session);
            client          = TestClient.CreateNaked(session);
            order           = new TestOrder(client.Users[0], supplier.Prices[0]);
            order.WriteTime = order.WriteTime.AddDays(-1);
            var offer = supplier.Prices[0].Core[0];

            offer.Code   = "code-1";
            offer.CodeCr = "code-cr-1";
            var item = order.AddItem(offer, 10);

            Assert.IsNotNull(item.CodeFirmCr);

            item            = order.AddItem(offer, 5);
            item.CodeFirmCr = null;

            session.Save(order);

            Property("ShowCode", true);
            Property("ShowCodeCr", true);
            Property("ProductNamePosition", 0);
            Property("FirmCrPosition", 1);

            Property("ByPreviousMonth", false);
            Property("ReportInterval", 1);
            Property("SourceFirmCode", (int)supplier.Id);

            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);

            Assert.That(text, Does.Contain("|code-1|code-cr-1|"));
            var rowCount = sheet.Rows().Count(x => x.Cells[0].StringCellValue == "code-1" &&
                                              x.Cells[1].StringCellValue == "code-cr-1");

            Assert.AreEqual(1, rowCount, text, "строки должны быть сгруппированы по Code, CodeCr");
        }
        private void SimpleConf()
        {
            rival    = TestSupplier.CreateNaked(session);
            supplier = TestSupplier.CreateNaked(session);
            client   = TestClient.CreateNaked(session);
            order    = new TestOrder(client.Users[0], supplier.Prices[0]);
            var product = session.Query <TestProduct>().First(p => p.CatalogProduct.CatalogName.Mnn != null);

            order.WriteTime = order.WriteTime.AddDays(-1);
            order.AddItem(product, 10, 897.23f);
            session.Save(order);

            Property("ByPreviousMonth", false);
            Property("ReportInterval", 1);

            Property("SourceFirmCode", (int)supplier.Id);
        }
Exemplo n.º 14
0
        public override void Execute(ISession session)
        {
            var user   = User(session);
            var client = user.Client;
            var user2  = client.CreateUser(session);

            user2.AvaliableAddresses.AddEach(client.Addresses);
            user.AllowDownloadUnconfirmedOrders = true;
            if (Clean)
            {
                session.CreateSQLQuery("delete from Orders.OrdersHead where Submited = 0 and ClientCode = :clientId")
                .SetParameter("clientId", user.Client.Id)
                .ExecuteUpdate();
            }
            session.CreateSQLQuery("insert into Customers.UserPrices(PriceId, RegionId, UserId) " +
                                   "select PriceId, RegionId, :target " +
                                   "from Customers.UserPrices " +
                                   "where UserId = :source")
            .SetParameter("source", user.Id)
            .SetParameter("target", user2.Id)
            .ExecuteUpdate();
            session.Flush();
            var activePrices = user2.GetActivePricesNaked(session);
            var price        = activePrices.Where(p => p.Id.PriceId == priceId)
                               .Concat(activePrices)
                               .First()
                               .Price;

            Order = new TestOrder(user2, price)
            {
                Submited  = false,
                Processed = false
            };
            if (Address != null)
            {
                Order.Address = Address;
            }
            //уцененные препараты не восстанавливаются
            var offer = session.Query <TestCore>().First(c => c.Price == price && !c.Junk);

            Order.AddItem(offer, 1);
            session.Save(Order);
        }
Exemplo n.º 15
0
        public void Cost_optimization_for_global_rule()
        {
            var product         = session.Query <TestProduct>().First();
            var producer        = session.Query <TestProducer>().First();
            var supplier        = TestSupplier.CreateNaked(session);
            var productSynonym  = supplier.Prices[0].AddProductSynonym(product);
            var producerSynonym = supplier.Prices[0].AddProducerSynonym(producer);
            var client          = TestClient.CreateNaked(session);

            var order = new TestOrder(client.Users[0], supplier.Prices[0]);
            var item  = order.AddItem(product, 10, 150);

            item.CodeFirmCr        = producer.Id;
            item.SynonymCode       = productSynonym.Id;
            item.SynonymFirmCrCode = producerSynonym.Id;
            order.WriteTime        = order.WriteTime.AddDays(-2);
            session.Save(order);

            session.CreateSQLQuery(@"insert into logs.CostOptimizationLogs(LoggedOn, ClientId, ProductId, ProducerId, SelfCost, ResultCost, SupplierId, UserId)
values (:loggedOn, :clientId, :productId, :producerId, :selfCost, :resultCost, :supplierId, :userId);")
            .SetParameter("clientId", client.Id)
            .SetParameter("productId", product.Id)
            .SetParameter("producerId", producer.Id)
            .SetParameter("selfCost", 100)
            .SetParameter("resultCost", 150)
            .SetParameter("supplierId", supplier.Id)
            .SetParameter("userId", client.Users[0].Id)
            .SetParameter("loggedOn", order.WriteTime.AddHours(-2))
            .ExecuteUpdate();

            Property("ByPreviousMonth", false);
            Property("ReportInterval", 5);
            Property("FirmCode", supplier.Id);
            var sheet = ReadReport <OptimizationEfficiency>();
            var row   = sheet.GetRow(9);

            //количество
            Assert.AreEqual(10, row.GetCell(9).NumericCellValue);
            //начальная цена
            Assert.AreEqual(100, row.GetCell(10).NumericCellValue);
            //конечная цена
            Assert.AreEqual(150, row.GetCell(11).NumericCellValue);
        }
Exemplo n.º 16
0
        public void Partial_order_reject()
        {
            var supplier = TestSupplier.CreateNaked(session);
            var price    = supplier.Prices[0];

            supplier.CreateSampleCore(session);
            price.Costs[0].PriceItem.PriceDate = DateTime.Now.AddDays(-10);
            session.Save(supplier);
            supplier.Maintain(session);
            //нужно что бы сохранить синонимы
            session.Flush();

            var order = new TestOrder(client.Users[0], price);

            order.AddItem(price.Core[0], 1);
            order.ClientOrderId = 1;
            session.Save(order);
            session.Flush();

            var request     = ToClientOrder(price.Core[0], price.Core[1]);
            var results     = PostOrder(request);
            var orderResult = results[0];

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(orderResult.ClientOrderId, request.Orders[0].ClientOrderId);
            Assert.AreEqual(orderResult.Result, OrderResultStatus.OK);
            //Должны сформировать новый заказ
            Assert.AreNotEqual(orderResult.ServerOrderId, order.Id);
            Assert.AreEqual(2, orderResult.Lines.Count, "В ответе должны присутствовать все строки заявки");

            var orders = session.Query <TestOrder>()
                         .Where(x => x.User.Id == user.Id)
                         .ToArray();

            Assert.AreEqual(2, orders.Length);
            Assert.AreEqual(1, orders[0].Items.Count, $"userid = {user.Id}");
            Assert.AreEqual(1, orders[1].Items.Count, $"userid = {user.Id}");
        }
        public void Setup()
        {
            supplier = TestSupplier.CreateNaked(session);
            supplier.CreateSampleCore(session);
            supplier.Prices[0].Core.Where(c => c.Producer != null)
            .Each(c => TestAssortment.CheckAndCreate(session, c.Product, c.Producer));
            var client = TestClient.CreateNaked(session);
            var order  = new TestOrder(client.Users[0], supplier.Prices[0]);

            order.Processed = false;
            order.WriteTime = DateTime.Today.AddDays(-1);
            order.AddItem(supplier.Prices[0].Core[0], 1);
            session.Save(order);
            supplier.Maintain(session);
            session.Transaction.Commit();

            calculator = new CostCalculator();

            ratings = RatingCalculator
                      .Caclucated(DateTime.Today.AddDays(-10), DateTime.Today)
                      .Take(3)
                      .ToArray();
        }
        public void Build_order_without_rivals_and_suppliers()
        {
            supplier = TestSupplier.CreateNaked(session);
            client   = TestClient.CreateNaked(session);
            order    = new TestOrder(client.Users[0], supplier.Prices[0]);
            var product = session.Query <TestProduct>().First(p => p.CatalogProduct.CatalogName.Mnn != null);

            order.WriteTime = order.WriteTime.AddDays(-1);
            order.AddItem(product, 10, 897.23f);
            session.Save(order);

            Property("ProductNamePosition", 0);
            Property("MnnPosition", 1);

            Property("ByPreviousMonth", false);
            Property("ReportInterval", 1);
            Property("HideSupplierStat", true);
            Property("SourceFirmCode", (int)supplier.Id);

            var sheet = ReadReport <MixedReport>();
            var text  = ToText(sheet);

            Assert.That(text, Is.Not.StringContaining("Сумма по поставщику"));
        }