This commit is contained in:
@@ -54,7 +54,13 @@ namespace AyaNova.Biz
|
||||
newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.PurchaseOrder.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();//needs to exist so inventory adjustment accepts it as source id (biz rule checks)
|
||||
await BizActionsAsync(AyaEvent.Created, newObject, null, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
@@ -221,6 +227,11 @@ namespace AyaNova.Biz
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
await BizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
@@ -264,12 +275,17 @@ namespace AyaNova.Biz
|
||||
return false;
|
||||
ct.PurchaseOrder.Remove(dbObject);
|
||||
await BizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return false;
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Serial.ToString(), ct);
|
||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
||||
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
||||
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
|
||||
await transaction.CommitAsync();
|
||||
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
||||
}
|
||||
catch
|
||||
@@ -393,10 +409,14 @@ namespace AyaNova.Biz
|
||||
i.PartId = poItem.PartId;
|
||||
i.PartWarehouseId = poItem.PartWarehouseId;
|
||||
i.Quantity = poItem.QuantityReceived *= -1;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = oldObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventDeleted");
|
||||
await pib.CreateAsync(i);
|
||||
i.SourceType = null;//null because the po no longer exists so this is technically a manual adjustment
|
||||
i.SourceId = null;//''
|
||||
i.Description = await Translate("PurchaseOrder") + $" {oldObj.Serial} " + await Translate("EventDeleted");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
|
||||
//MIGRATE_OUTSTANDING - update workorderitempart here if applicable
|
||||
}
|
||||
@@ -422,8 +442,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = poItem.QuantityReceived;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = newObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventCreated");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {newObj.Serial} " + await Translate("EventCreated");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
|
||||
//MIGRATE_OUTSTANDING - update workorderitempart here if applicable
|
||||
}
|
||||
@@ -442,6 +466,8 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//get the matching new item
|
||||
var newItem = newObj.Items.FirstOrDefault(z => z.Id == oldItem.Id);
|
||||
|
||||
//OLD ITEM DELETED
|
||||
if (newItem == null)
|
||||
{
|
||||
//an old item with received stock was deleted, fixup inventory
|
||||
@@ -454,8 +480,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = oldItem.QuantityReceived *= -1;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = oldObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventDeleted");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {oldObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventDeleted");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,8 +507,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = newItem.QuantityReceived;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = newObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventCreated");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {newObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventCreated");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId);
|
||||
@@ -500,8 +534,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = oldItem.QuantityReceived *= -1;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = oldObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventModified") + ":" + await Translate("Part") + "/" + await Translate("PartWarehouse");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {oldObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventModified") + " " + await Translate("Part") + "/" + await Translate("PartWarehouse");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (newItem.QuantityReceived > 0)
|
||||
@@ -513,8 +551,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = newItem.QuantityReceived;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = newObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventModified") + ":" + await Translate("Part") + "/" + await Translate("PartWarehouse");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {newObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventModified") + " " + await Translate("Part") + "/" + await Translate("PartWarehouse");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Update part values into poitem if the part or vendor has changed
|
||||
@@ -540,8 +582,12 @@ namespace AyaNova.Biz
|
||||
i.Quantity = netChange;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = newObj.Id;
|
||||
i.Description = await Translate("PurchaseOrderEdit") + ":" + await Translate("EventModified");
|
||||
await pib.CreateAsync(i);
|
||||
i.Description = await Translate("PurchaseOrder") + $" {newObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventModified") + " " + await Translate("PurchaseOrderItemQuantityReceived");
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
}
|
||||
|
||||
//MIGRATE_OUTSTANDING - update workorderitempart here if applicable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user