public override void Execute(ISession session) { var random = new Random(); var user = User(session); var order = session.Query <TestOrder>().Where(o => o.User == user) .OrderByDescending(o => o.WriteTime) .FirstOrDefault(); if (order == null) { throw new Exception("Не заказов для формирования накладной"); } var log = new TestDocumentLog(order.Price.Supplier, order.Address); Waybill = new TestWaybill(log); session.Save(Waybill); session.Save(new TestDocumentSendLog(user, log)); foreach (var orderline in order.Items) { var line = new TestWaybillLine(Waybill); line.Product = orderline.Product.FullName; line.Quantity = orderline.Quantity; line.SupplierCost = (decimal?)orderline.Cost; line.Period = DateTime.Today.AddDays(random.Next(5 * 365)).ToShortDateString(); Waybill.Lines.Add(line); session.Save(line); session.CreateSQLQuery("insert into Documents.WaybillOrders(DocumentLineId, OrderLineId) values (:documentLineId, :orderLineId)") .SetParameter("documentLineId", line.Id) .SetParameter("orderLineId", orderline.Id) .ExecuteUpdate(); } }
public void check_parse_waybill_if_file_is_not_local() { var file = "9229370.dbf"; var log = new TestDocumentLog(supplier, testAddress, file); session.Save(log); var service = new WaybillService(); // файл накладной в нужной директории отсутствует var ids = service.ParseWaybill(new[] { log.Id }); using (new SessionScope()) { var logs = DocumentReceiveLog.Queryable.Where(l => l.Supplier.Id == supplier.Id && l.ClientCode == client.Id).ToList(); Assert.That(logs.Count(), Is.EqualTo(1)); Assert.That(ids.Length, Is.EqualTo(0)); // Проверяем наличие записей в documentheaders Assert.That(Document.Queryable.Count(doc => doc.Log.Id == logs[0].Id), Is.EqualTo(0)); } var thread = new Thread(() => { Thread.Sleep(3000); File.Copy(@"..\..\Data\Waybills\9229370.dbf", Path.Combine(waybillsPath, string.Format("{0}_{1}({2}){3}", log.Id, supplier.Name, Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)))); }); thread.Start(); // подкладываем файл в процессе разбора накладной ids = service.ParseWaybill(new[] { log.Id }); using (new SessionScope()) { var logs = DocumentReceiveLog.Queryable.Where(l => l.Supplier.Id == supplier.Id && l.ClientCode == client.Id).ToList(); Assert.That(logs.Count(), Is.EqualTo(1)); Assert.That(ids.Length, Is.EqualTo(1)); Assert.That(Document.Queryable.Where(doc => doc.Log.Id == logs[0].Id).Count(), Is.EqualTo(1), "не нашли документа для {0}", logs[0].Id); } }
private TestWaybillLine CreateBodyLine(string serialNumber = null, TestProduct product = null) { var user = TestUser.Queryable.First(u => u.AvaliableAddresses.Count > 0); if (product == null) { product = TestProduct.Queryable.First(); } var documentLog = new TestDocumentLog(testSupplier, user.Client) { FileName = Path.GetRandomFileName() + ".txt" }; var document = new TestWaybill(documentLog); var documentLine = new TestWaybillLine { Waybill = document, SerialNumber = serialNumber, CatalogProduct = product }; document.Lines = new List <TestWaybillLine>(); document.Lines.Add(documentLine); document.Save(); Assert.That(document.Lines.Count, Is.EqualTo(1)); Assert.That(document.Lines[0].Id, Is.GreaterThan(0)); return(documentLine); }
public override void Execute(ISession session) { var user = User(session); Waybill = Service.Test.TestHelpers.DataMother.CreateWaybill(session, user); var products = session.Query <TestProduct>().Where(x => !x.Hidden && x.CatalogProduct.Pharmacie).Take(1).ToArray(); Waybill.Lines.Clear(); Waybill.Lines.Add(new TestWaybillLine(Waybill) { Product = products[0].FullName, CatalogProduct = products[0], Certificates = "РОСС BE.ФМ11.Д06711", CertificatesDate = "01.16.2013", Period = "30.09.2014", Producer = "Алкон-Куврер н.в. с.а.", Country = "БЕЛЬГИЯ", RetailCost = 600, RetailCostMarkup = 5, SupplierCostWithoutNDS = 536.17m, SupplierCost = 589.79m, Quantity = 1, SerialNumber = "A 565", Amount = 589.79m, NDS = 10, NDSAmount = 53.62m, }); Document = Waybill.Log; session.Save(Waybill); SendLog = new TestDocumentSendLog(user, Document); session.Save(SendLog); }
public static List <DocumentReceiveLog> GetFilesForParsing(ISession session, params string[] filePaths) { var client = TestClient.Create(session); var supplier = TestSupplier.Create(session); var resultList = new List <uint>(); foreach (var filePath in filePaths) { var file = filePath; if (!File.Exists(file)) { file = Path.Combine(@"..\..\Data\Waybills\multifile", filePath); } var log = new TestDocumentLog(supplier, client, Path.GetFileName(filePath)); session.Save(log); resultList.Add(log.Id); var clientDir = Path.Combine(Settings.Default.DocumentPath, log.Address.Id.ToString().PadLeft(3, '0')); var documentDir = Path.Combine(clientDir, DocumentType.Waybill + "s"); var name = String.Format("{0}_{1}({2}){3}", log.Id, supplier.Name, Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)); Common.Tools.FileHelper.CreateDirectoryRecursive(documentDir); File.Copy(file, Path.Combine(documentDir, name)); } return(DocumentReceiveLog.LoadByIds(resultList.ToArray())); }
private TestWaybillLine CreateBodyLine() { var documentLog = new TestDocumentLog { Supplier = testSupplier, Client = testUser.Client, DocumentType = DocumentType.Waybill, LogTime = DateTime.Now, FileName = Path.GetRandomFileName() + ".txt" }; var document = new TestWaybill(documentLog); var documentLine = new TestWaybillLine(); documentLine.Waybill = document; document.Lines.Add(documentLine); using (new TransactionScope()) { document.Save(); } Assert.That(document.Lines.Count, Is.EqualTo(1)); Assert.That(document.Lines[0].Id, Is.GreaterThan(0)); return(documentLine); }
public override void Execute(ISession session) { var user = User(session); var supplier = user.GetActivePricesNaked(session).First().Price.Supplier; Document = new TestDocumentLog(supplier, user.AvaliableAddresses[0], ""); Document.DocumentType = DocumentType.Reject; session.Save(Document); session.Save(new TestDocumentSendLog(user, Document)); Document.CreateFile(Config.DocsPath, "test reject"); }
public override void Execute(ISession session) { var user = User(session); Waybill = Service.Test.TestHelpers.DataMother.CreateWaybill(session, user); Waybill.DocumentDate = DateTime.Now.AddYears(-1); Document = Waybill.Log; session.Save(Waybill); SendLog = new TestDocumentSendLog(user, Document); session.Save(SendLog); }
public override void Execute(ISession session) { var user = User(session); Waybill = Service.Test.TestHelpers.DataMother.CreateWaybill(session, user); Document = Waybill.Log; session.Save(Waybill); SendLog = new TestDocumentSendLog(user, Document); session.Save(SendLog); if (createFile) { Filename = Waybill.Log.CreateFile(Config.DocsPath, "waybill content"); } }
private TestWaybill SetupWaybill(TestSupplier supplier, TestClient client, out TestDocumentSendLog sendLog) { var log = new TestDocumentLog(supplier, client); session.Save(log); var doc = new TestWaybill(log); var product = session.Query <TestProduct>().First(x => !x.Hidden); doc.AddLine(product); doc.ProviderDocumentId = "G1"; session.Save(doc); sendLog = new TestDocumentSendLog(client.Users[0], log); session.Save(sendLog); return(doc); }
public void Get_waybill() { var supplier = TestSupplier.CreateNaked(session); var log = new TestDocumentLog(supplier, client); session.Save(log); log.CreateFile(ConfigurationManager.AppSettings["DocPath"], "test"); session.Transaction.Commit(); var data = service.GetWaybills(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1)).Tables[0]; Assert.That(data.Rows.Count, Is.GreaterThan(0)); var result = service.GetWaybill(Convert.ToUInt32(data.Rows[0]["Id"])); Assert.That(result.Length, Is.GreaterThan(0)); }
public void Export_waybills() { var supplier = TestSupplier.CreateNaked(session); var client = TestClient.CreateNaked(session); var log = new TestDocumentLog(supplier, client); session.Save(log); var doc = new TestWaybill(log); var product = session.Query<TestProduct>().First(x => !x.Hidden); doc.AddLine(product); doc.ProviderDocumentId = "G1"; session.Save(doc); var sendLog = new TestDocumentSendLog(client.Users[0], log); session.Save(sendLog); FlushAndCommit(); Program.ProcessUser(config, client.Users[0].Id, ProtocolType.DbfAsna); Assert.IsTrue(File.Exists($"tmp/{client.Users[0].Id}/waybills/{doc.Id}.dbf")); }
public void DeleteTempFolderTest() { var rostaSource = new RostaCertificateSource(); var product = session.Query <Product>().First(p => p.CatalogProduct != null); var documentLog = new TestDocumentLog { Supplier = _testSupplier, Client = _testUser.Client, DocumentType = DocumentType.Waybill, LogTime = DateTime.Now, FileName = Path.GetRandomFileName() + ".txt" }; var document = new TestWaybill(documentLog); session.Save(document); var realDocument = session.Load <Document>(document.Id); var task = new CertificateTask { SerialNumber = "123", CatalogProduct = product.CatalogProduct, }; task.CertificateSource = _source; task.DocumentLine = new DocumentLine { Code = "000002", SerialNumber = "C392764", Document = realDocument, ProductEntity = product }; Save(task.DocumentLine); Save(task); var certificsteCatalog = new CertificateSourceCatalog { CertificateSource = _source, SerialNumber = task.DocumentLine.SerialNumber, SupplierCode = task.DocumentLine.Code, OriginFilePath = "005/0052602p-0.gif", CatalogProduct = product.CatalogProduct }; Save(certificsteCatalog); Reopen(); rostaSource.GetCertificateFiles(task, session); // Проверяем, что временная папка удалена Assert.That(Directory.Exists(rostaSource.TMPDownloadDir), Is.False); }
public static void InnerCreateOrderReject(ISession session, params Tuple <string, uint, uint>[] linesMap) { var user = ServerFixture.User(session); var supplier = user.GetActivePricesNaked(session).First().Price.Supplier; var log = new TestDocumentLog(supplier, user.AvaliableAddresses[0], ""); log.DocumentType = global::Test.Support.DocumentType.Reject; session.Save(log); session.Save(new TestDocumentSendLog(user, log)); var orderReject = new TestOrderReject(log); foreach (var map in linesMap) { var product = session.Get <TestProduct>(map.Item2); orderReject.CreateLine(map.Item1, product, map.Item3); } session.Save(orderReject); }
public TestDocumentLog CreateTestLog(string file) { var log = new TestDocumentLog(supplier, testAddress, file); session.Save(log); if (!File.Exists(file)) { file = @"..\..\Data\Waybills\" + file; } File.Copy(file, Path.Combine(waybillsPath, String.Format("{0}_{1}({2}){3}", log.Id, supplier.Name, Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)))); return(log); }
public void Export_prices() { FileHelper.InitDir("ftp"); var log = new TestDocumentLog(supplier, client); session.Save(log); var doc = new TestWaybill(log); var product = session.Query <TestProduct>().First(x => !x.Hidden); doc.AddLine(product); doc.ProviderDocumentId = "G1"; session.Save(doc); var sendLog = new TestDocumentSendLog(user, log); session.Save(sendLog); session.Save(new FtpConfig(session.Load <User>(user.Id), session.Load <Supplier>(supplier.Id)) { PriceUrl = $"ftp://localhost:{port}/тестовый поставщик/common/PRICE.DBF", WaybillUrl = $"ftp://localhost:{port}/тестовый поставщик/in", OrderUrl = $"ftp://localhost:{port}/тестовый поставщик/out", }); FlushAndCommit(); var job = new FtpExportJob(); job.Execute(null); var prices = Directory.GetFiles("ftp/тестовый поставщик/common").Implode(Path.GetFileName); Assert.AreEqual("PRICE.DBF", prices); var waybills = Directory.GetFiles("ftp/тестовый поставщик/in").Implode(Path.GetFileName); Assert.AreEqual($"{log.Id}.dbf", waybills); }
public static TestWaybill CreateWaybill(ISession session, TestUser user) { var supplier = user.GetActivePricesNaked(session).First().Price.Supplier; var log = new TestDocumentLog(supplier, user.AvaliableAddresses[0], ""); var waybill = new TestWaybill(log); var products = session.Query <TestProduct>().Where(x => !x.Hidden).Take(32).ToArray(); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = products[0].FullName, CatalogProduct = products[0], Certificates = "РОСС BE.ФМ11.Д06711", CertificatesDate = "01.16.2013", Period = "30.09.2014", Producer = "Алкон-Куврер н.в. с.а.", Country = "БЕЛЬГИЯ", SupplierCostWithoutNDS = 536.17m, SupplierCost = 589.79m, Quantity = 1, SerialNumber = "A 565", Amount = 589.79m, NDS = 10, NDSAmount = 53.62m, }); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = products[1].FullName, CatalogProduct = products[1], Certificates = "РОСС RU.ФМ08.Д38737", Period = "01.05.2017", Producer = "Нью-Фарм Инк./Вектор-Медика ЗАО, РОССИЯ", ProducerCost = 213.18m, RegistryCost = 382.89m, SupplierPriceMarkup = -5.746m, SupplierCostWithoutNDS = 200.93m, SupplierCost = 221.03m, Quantity = 2, VitallyImportant = true, NDS = 10, SerialNumber = "21012", Amount = 442.05m, NDSAmount = 40.19m, BillOfEntryNumber = "10609010/101209/0004305/1", EAN13 = "4605635002748", }); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = products[1].FullName, CatalogProduct = products[1], Certificates = "РОСС RU.ФМ08.Д38737", Period = "01.05.2017", Producer = "Нью-Фарм Инк./Вектор-Медика ЗАО, РОССИЯ", ProducerCost = 213.18m, RegistryCost = 382.89m, SupplierPriceMarkup = -5.746m, SupplierCostWithoutNDS = 200.93m, SupplierCost = 221.03m, Quantity = 2, VitallyImportant = true, NDS = 10, SerialNumber = "21012", Amount = 442.05m, NDSAmount = 40.19m, BillOfEntryNumber = "10609010/101209/0004305/1", //для отчета по жизененно важным EAN13 = "4606915000379", }); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = "Лопедиум капсулы 2 мг", CatalogProduct = products[1], Period = "01.05.2018", Producer = "Салютас Фарма", SupplierCostWithoutNDS = 23.5m, SupplierCost = 25.86m, Quantity = 2, SerialNumber = "DR5963", EAN13 = "4030855000890", }); for (var i = 0; i < 29; i++) { waybill.Lines.Add(new TestWaybillLine(waybill) { Product = products[i + 1].FullName, CatalogProduct = products[i + 1], Certificates = "РОСС RU.ФМ08.Д38737", Period = "01.05.2017", Producer = "Нью-Фарм Инк./Вектор-Медика ЗАО, РОССИЯ", SupplierCostWithoutNDS = 23.5m, SupplierCost = 25.86m, Quantity = 2, }); } return(waybill); }