This commit is contained in:
2021-01-22 00:11:08 +00:00
parent 0281105114
commit 0baff224c2
4 changed files with 67 additions and 41 deletions

2
.vscode/launch.json vendored
View File

@@ -53,7 +53,7 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", "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_SEEDLEVEL": "small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"

View File

@@ -45,40 +45,48 @@ namespace AyaNova.Biz
{ {
using (var transaction = await ct.Database.BeginTransactionAsync()) using (var transaction = await ct.Database.BeginTransactionAsync())
{ {
//get the last record if exists (will not if opening balance) try
var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
PartInventory newObject = new PartInventory();
newObject.Description = newDtObject.Description;
newObject.EntryDate = DateTime.UtcNow;
newObject.PartId = newDtObject.PartId;
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
newObject.SourceId = 0;
newObject.SourceType = AyaType.NoType;
newObject.Quantity = newDtObject.Quantity;
if (LastEntry != null)
{ {
newObject.LastEntryDate = LastEntry.EntryDate; //get the last record if exists (will not if opening balance)
newObject.LastBalance = LastEntry.Balance; var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
newObject.Balance = LastEntry.Balance + newObject.Quantity; PartInventory newObject = new PartInventory();
newObject.Description = newDtObject.Description;
newObject.EntryDate = DateTime.UtcNow;
newObject.PartId = newDtObject.PartId;
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
newObject.SourceId = 0;
newObject.SourceType = AyaType.NoType;
newObject.Quantity = newDtObject.Quantity;
if (LastEntry != null)
{
newObject.LastEntryDate = LastEntry.EntryDate;
newObject.LastBalance = LastEntry.Balance;
newObject.Balance = LastEntry.Balance + newObject.Quantity;
}
else
{
newObject.Balance = newObject.Quantity;
}
await ValidateAsync(newObject);
if (HasErrors)
return null;
else
{
await ct.PartInventory.AddAsync(newObject);
await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await SearchIndexAsync(newObject, true);
await transaction.CommitAsync();
return newObject;
}
} }
else catch
{ {
newObject.Balance = newObject.Quantity; //Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
} throw;
await ValidateAsync(newObject);
if (HasErrors)
return null;
else
{
await ct.PartInventory.AddAsync(newObject);
await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await SearchIndexAsync(newObject, true);
return newObject;
} }
} }
} }
@@ -190,7 +198,7 @@ namespace AyaNova.Biz
} }
//values must add up //values must add up
if (proposedObj.Balance != (proposedObj.LastBalance ?? 0 + proposedObj.Quantity)) if (proposedObj.Balance != (proposedObj.Quantity + (proposedObj.LastBalance ?? 0)))
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Balance", "Balance incorrect (LastBalance + Quantity not equal to Balance"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Balance", "Balance incorrect (LastBalance + Quantity not equal to Balance");
return; return;

View File

@@ -203,17 +203,17 @@ namespace AyaNova.Biz
} }
//values must add up //values must add up
if (proposedObj.IncidentsBalance != (proposedObj.LastIncidentsBalance ?? 0 + proposedObj.Incidents)) if (proposedObj.IncidentsBalance != (proposedObj.Incidents + (proposedObj.LastIncidentsBalance ?? 0)))
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankIncidentsBalance"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankIncidentsBalance");
return; return;
} }
if (proposedObj.CurrencyBalance != (proposedObj.LastCurrencyBalance ?? 0 + proposedObj.Currency)) if (proposedObj.CurrencyBalance != (proposedObj.Currency + (proposedObj.LastCurrencyBalance ?? 0)))
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankCurrencyBalance"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankCurrencyBalance");
return; return;
} }
if (proposedObj.HoursBalance != (proposedObj.LastHoursBalance ?? 0 + proposedObj.Hours)) if (proposedObj.HoursBalance != (proposedObj.Hours + (proposedObj.LastHoursBalance ?? 0)))
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankHoursBalance"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankHoursBalance");
return; return;

View File

@@ -1538,6 +1538,7 @@ namespace AyaNova.Util
} }
PartInventoryBiz PartInventoryBizNess = PartInventoryBiz.GetBiz(ct); PartInventoryBiz PartInventoryBizNess = PartInventoryBiz.GetBiz(ct);
int OpeningInventoryLevel = 1;
// 50% chance it has serial numbers // 50% chance it has serial numbers
if (Fake.Random.Number() == 1) if (Fake.Random.Number() == 1)
{ {
@@ -1548,14 +1549,31 @@ namespace AyaNova.Util
} }
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//add inventory to cover serials //ensure add enough inventory to cover serials
await PartInventoryBizNess.CreateAsync(new dtPartInventory() { PartId = NewObject.Id, PartWarehouseId = 1, Quantity = serialCount }); OpeningInventoryLevel = serialCount;
} }
else
OpeningInventoryLevel += Fake.Random.Number(1, 1000);
PartInventory partInventory = null;
//add opening inventory
partInventory = await PartInventoryBizNess.CreateAsync(new dtPartInventory() { PartId = NewObject.Id, PartWarehouseId = 1, Quantity = OpeningInventoryLevel, Description = "New part opening inventory" });
//make two adjustments to have some testing data
if (partInventory != null)
partInventory = await PartInventoryBizNess.CreateAsync(new dtPartInventory() { PartId = NewObject.Id, PartWarehouseId = 1, Quantity = -1, Description = "example adjustment" });
if (partInventory != null)
partInventory = await PartInventoryBizNess.CreateAsync(new dtPartInventory() { PartId = NewObject.Id, PartWarehouseId = 1, Quantity = Fake.Random.Number(1, 100), Description = "example adjustment" });
if (partInventory == null)
{ {
//add random inventory level var err = $"Seeder::SeedPart - error creating {o.PartNumber} INVENTORY \r\n{PartInventoryBizNess.GetErrorsAsString()}";
await PartInventoryBizNess.CreateAsync(new dtPartInventory() { PartId = NewObject.Id, PartWarehouseId = 1, Quantity = Fake.Random.Number(1, 100) }); log.LogError(err);
throw new System.Exception(err);
} }
} }
} }
} }