diff --git a/.vscode/launch.json b/.vscode/launch.json index 0e2049e9..8fd97968 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", - "AYANOVA_SERVER_TEST_MODE": "false", + "AYANOVA_SERVER_TEST_MODE": "true", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/server/AyaNova/models/WorkOrder.cs b/server/AyaNova/models/WorkOrder.cs index 01b27178..405c009b 100644 --- a/server/AyaNova/models/WorkOrder.cs +++ b/server/AyaNova/models/WorkOrder.cs @@ -22,7 +22,7 @@ namespace AyaNova.Models [Required] public long Serial { get; set; } - public bool Active { get; set; } + public string Notes { get; set; }//WAS "SUMMARY" public string Wiki { get; set; } public string CustomFields { get; set; } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index c0629a8a..0a341a3c 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -22,7 +22,7 @@ namespace AyaNova.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 1; - internal const long EXPECTED_COLUMN_COUNT = 930; + internal const long EXPECTED_COLUMN_COUNT = 929; internal const long EXPECTED_INDEX_COUNT = 141; internal const long EXPECTED_CHECK_CONSTRAINTS = 431; internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 115; @@ -757,7 +757,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); + "color VARCHAR(12) NOT NULL default '#000000')"); //WORKORDER - await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, " + await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, " + "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, customerid BIGINT NOT NULL REFERENCES acustomer (id), " + "projectid BIGINT NOT NULL REFERENCES aproject (id), internalreferencenumber text, customerreferencenumber text, customercontactname text, " + "servicedate TIMESTAMP, completebydate TIMESTAMP, invoicenumber TEXT, customersignature TEXT, customersignaturename TEXT, customersignaturecaptured TIMESTAMP, " diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index a20c322c..1fe47d35 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -2188,8 +2188,104 @@ namespace AyaNova.Util } + private int TotalSeededWorkOrders = 0; + ////////////////////////////////////////////////////// + //PURCHASE ORDER + // + public async Task SeedWorkOrderAsync(ILogger log, int count) + { + DateTime seedStartWindow = DateTime.Now.AddYears(-1); + DateTime seedEndWindow = DateTime.Now.AddDays(-5); + for (int x = 0; x < count; x++) + { + WorkOrder o = new WorkOrder(); + o.Notes = Fake.Lorem.Sentence(); + o.Tags = RandomTags(); + o.InternalReferenceNumber = "irf-" + Fake.Finance.Account(4); + o.Active + var woDate = Fake.Date.Between(seedStartWindow, seedEndWindow); + o. = woDate.ToUniversalTime(); + o.ExpectedReceiveDate = woDate.AddDays(5).ToUniversalTime(); + + + o.VendorMemo = Fake.Lorem.Sentence(); + if (Fake.Random.Number(1, 10) == 5) + o.ProjectId = Fake.Random.Long(1, TotalSeededProjects); + + o.Text1 = Fake.Lorem.Sentence(1, 3); + o.Text2 = Fake.Lorem.Sentence(1, 3); + + List partsAdded = new List(); + int partCount = Fake.Random.Int(1, 5); + + + + + //simulate some items without tax codes + bool addTaxCode = (Fake.Random.Number(1, 4) != 3); + + //simulate some items not received + bool isReceived = (Fake.Random.Number(1, 4) != 3); + + o.Status = isReceived ? WorkOrderStatus.ClosedFullReceived : WorkOrderStatus.OpenOrdered; + + for (int y = 0; y < partCount; y++) + { + long partId = 0; + do + { + partId = Fake.Random.Long(1, TotalSeededParts); + } while (partsAdded.Contains(partId)); + partsAdded.Add(partId); + var qty = Fake.Random.Int(1, 5); + var cost = Fake.Random.Decimal(1, 25); + + // 50% chance it has received serial numbers + string serials = string.Empty; + if (isReceived && Fake.Random.Number() == 1) + { + var serialStart = Fake.Finance.Account().ToString(); + for (int si = 0; si < qty; si++) + { + serials += serialStart + si.ToString() + ", "; + + } + serials = serials.TrimEnd().TrimEnd(','); + } + + o.Items.Add(new WorkOrderItem() + { + PartId = partId, + PartWarehouseId = Fake.Random.Long(1, 3), + QuantityOrdered = qty, + QuantityReceived = isReceived ? qty : 0, + WorkOrderCost = cost, + ReceivedCost = isReceived ? cost : 0, + ReceivedDate = isReceived ? o.ExpectedReceiveDate : null, + PurchaseTaxCodeId = addTaxCode ? 3 : null,//sales and goods + Serials = serials + }); + } + + + //This seems wrong to do in a loop but is 4 times faster this way ?!? + using (AyContext ct = ServiceProviderProvider.DBContext) + { + WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct); + var NewObject = await biz.CreateAsync(o, false); + TotalSeededWorkOrders++; + if (NewObject == null) + { + var err = $"Seeder::SeedWorkOrder error creating {o.Serial}\r\n{biz.GetErrorsAsString()}"; + log.LogError(err); + throw new System.Exception(err); + } + } + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////