public override void ImportDocument(DocumentReceiveLog log, string filename)
 {
     using (var transaction = new TransactionScope(OnDispose.Rollback)) {
         log.Save();
         transaction.VoteCommit();
     }
 }
        public override void ImportDocument(DocumentReceiveLog log, string filename)
        {
            var dsDocument = new DataSet();

            dsDocument.ReadXml(filename);
            var providerDocumentId = dsDocument.Tables["Header"].Rows[0][HeaderTable.colInvNum].ToString();

            using (new SessionScope()) {
                var doc = Document.Queryable.FirstOrDefault(d => d.FirmCode == log.Supplier.Id &&
                                                            d.ClientCode == log.ClientCode &&
                                                            d.ProviderDocumentId == providerDocumentId &&
                                                            d.DocumentType == log.DocumentType);
                if (doc != null)
                {
                    throw new Exception(String.Format(
                                            "Дублирующийся документ с аттрибутами: FirmCode = {0}, ClientCode = {1}, DocumentType = {2}, ProviderDocumentId = {3}",
                                            log.Supplier.Id,
                                            log.ClientCode,
                                            log.DocumentType,
                                            providerDocumentId));
                }
                doc = new Document(log)
                {
                    ProviderDocumentId = providerDocumentId
                };
                using (var transaction = new TransactionScope(OnDispose.Rollback)) {
                    log.Save();
                    doc.Save();
                    transaction.VoteCommit();
                }
            }
        }
Exemplo n.º 3
0
        public void ComparisonWithOrdersIfEmptyTest()
        {
            var log = new DocumentReceiveLog {
                Supplier     = appSupplier,
                ClientCode   = client.Id,
                Address      = address,
                MessageUid   = 123,
                DocumentSize = 100
            };
            var document = new Document(log);

            log.Save();
            document.Save();
            WaybillOrderMatcher.ComparisonWithOrders(document, null);
        }
        public void Document_invoice_test()
        {
            var settings = TestDrugstoreSettings.FindFirst();
            var order    = TestOrder.FindFirst();

            var log = new DocumentReceiveLog {
                Supplier     = appSupplier,
                ClientCode   = settings.Id,
                Address      = address,
                MessageUid   = 123,
                DocumentSize = 100
            };

            var doc = new Document(log)
            {
                OrderId      = order.Id,
                DocumentDate = DateTime.Now
            };
            var inv = doc.SetInvoice();

            inv.BuyerName = "Тестовый покупатель";

            log.Save();
            doc.Save();

            var doc2 = Document.Find(doc.Id);

            Assert.That(doc2, Is.Not.Null);
            Assert.That(doc2.Invoice, Is.Not.Null);
            Assert.That(doc2.Invoice.Id, Is.EqualTo(doc.Id));
            Assert.That(doc2.Invoice.BuyerName, Is.EqualTo("Тестовый покупатель"));

            var inv2 = Invoice.Find(doc.Id);

            Assert.That(inv2, Is.Not.Null);
            Assert.That(inv2.Id, Is.EqualTo(doc.Id));
            Assert.That(inv2.Document, Is.Not.Null);
            Assert.That(inv2.Document.Id, Is.EqualTo(doc.Id));
            Assert.That(inv2.Document.Address.Id, Is.EqualTo(doc.Address.Id));
            Assert.That(inv2.BuyerName, Is.EqualTo("Тестовый покупатель"));
        }
Exemplo n.º 5
0
        public void ComparisonWithOrdersIfOrderIdInOrderHeadTest()
        {
            order1 = BuildOrder();
            session.Save(order1);
            var item = new OrderItem {
                Code = "Code1", Order = order1, Quantity = 20
            };

            session.Save(item);
            order1.Items.Add(item);

            item = new OrderItem {
                Code = "Code2", Order = order1, Quantity = 25
            };
            session.Save(item);
            order1.Items.Add(item);

            item = new OrderItem {
                Code = "Code3", Order = order1, Quantity = 50
            };
            session.Save(item);
            order1.Items.Add(item);

            item = new OrderItem {
                Code = "Code4", Order = order1, Quantity = 100
            };
            session.Save(item);
            order1.Items.Add(item);

            order2 = BuildOrder();
            session.Save(order2);
            item = new OrderItem {
                Code = "Code3", Order = order2, Quantity = 15
            };
            session.Save(item);
            order2.Items.Add(item);

            item = new OrderItem {
                Code = "Code3", Order = order2, Quantity = 10
            };
            session.Save(item);
            order2.Items.Add(item);

            item = new OrderItem {
                Code = "Code5", Order = order2, Quantity = 15
            };
            session.Save(item);
            order2.Items.Add(item);

            var log = new DocumentReceiveLog(appSupplier, address)
            {
                MessageUid = 123, DocumentSize = 100
            };
            var document = new Document(log)
            {
                OrderId = order1.Id, DocumentDate = DateTime.Now
            };

            var docline = new DocumentLine {
                Document = document, Code = "Code1", Quantity = 20
            };

            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code2", Quantity = 15
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code2", Quantity = 5
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code3", Quantity = 75
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = null, Quantity = 75
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code5", Quantity = 10
            };
            document.NewLine(docline);
            log.Save();
            document.Save();

            orders.Add(order1);
            orders.Add(order2);

            Match(document);
            document.SaveAndFlush();

            var line = document.Lines[0];

            Assert.That(document.Lines[0].OrderItems, Is.EquivalentTo(new[] { order1.Items[0] }));

            line = document.Lines[1];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order1.Items[1] }));

            line = document.Lines[2];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order1.Items[1] }));

            line = document.Lines[3];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order1.Items[2], order2.Items[0], order2.Items[1] }));

            line = document.Lines[4];
            Assert.That(line.OrderItems, Is.Empty);

            line = document.Lines[5];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order2.Items[2] }));
        }