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