This commit is contained in:
@@ -55,14 +55,14 @@ namespace AyaNova.Biz
|
||||
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);
|
||||
var RequestsToUpdate = await BizActionsAsync(AyaEvent.Created, newObject, null, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
await PostSaveBizActionsAsync(AyaEvent.Created, newObject, null, transaction);
|
||||
await UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
@@ -250,7 +250,7 @@ namespace AyaNova.Biz
|
||||
if (HasErrors) return null;
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
await BizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||
var RequestsToUpdate = await BizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
@@ -260,7 +260,7 @@ namespace AyaNova.Biz
|
||||
try
|
||||
{
|
||||
await ct.SaveChangesAsync();
|
||||
await PostSaveBizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||
await UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -297,14 +297,14 @@ namespace AyaNova.Biz
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.PurchaseOrder.Remove(dbObject);
|
||||
await BizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
var RequestsToUpdate=await BizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return false;
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
await PostSaveBizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
await UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Serial.ToString(), ct);
|
||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
||||
@@ -398,14 +398,21 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
private class RequestUpdate
|
||||
{
|
||||
public long PartRequestId { get; set; }
|
||||
public long? POItemId { get; set; }
|
||||
public decimal ReceivedQuantity { get; set; }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//BIZ ACTIONS
|
||||
//A PO can now be edited in any way user wishes at any time so this method is to fix up
|
||||
//any changes they make in affected objects and inventory
|
||||
//
|
||||
private async Task BizActionsAsync(AyaEvent ayaEvent, PurchaseOrder newObj, PurchaseOrder oldObj, IDbContextTransaction transaction)
|
||||
private async Task<List<RequestUpdate>> BizActionsAsync(AyaEvent ayaEvent, PurchaseOrder newObj, PurchaseOrder oldObj, IDbContextTransaction transaction)
|
||||
{
|
||||
List<RequestUpdate> RequestsToUpdate = new List<RequestUpdate>();
|
||||
|
||||
//Get inventory object for updating
|
||||
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||
@@ -429,7 +436,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
//might have contributed serials so remove them here, handles empty serials so no issue calling this
|
||||
@@ -441,15 +448,10 @@ namespace AyaNova.Biz
|
||||
if (poItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//De-request it
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == poItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = null;
|
||||
w.Received = 0;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)poItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
|
||||
}
|
||||
}
|
||||
return;//done, nothing more to do here
|
||||
return RequestsToUpdate;//done, nothing more to do here
|
||||
}
|
||||
|
||||
|
||||
@@ -475,7 +477,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
await PartBiz.AppendSerialsAsync(poItem.PartId, poItem.Serials, ct, UserId);
|
||||
@@ -490,17 +492,11 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (poItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//set it on request
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == poItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = poItem.Id;
|
||||
w.Received = poItem.QuantityReceived;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)poItem.WorkOrderItemPartRequestId, POItemId = poItem.Id, ReceivedQuantity = poItem.QuantityReceived });
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
//MODIFIED
|
||||
@@ -530,7 +526,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
//might have serials so remove those as well
|
||||
await PartBiz.RemoveSerialsAsync(oldItem.PartId, oldItem.Serials, ct, UserId);
|
||||
@@ -539,13 +535,7 @@ namespace AyaNova.Biz
|
||||
//fixup woitempartrequest if any
|
||||
if (oldItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//De-request it
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == oldItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = null;
|
||||
w.Received = 0;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,7 +568,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
await PartBiz.AppendSerialsAsync(newItem.PartId, newItem.Serials, ct, UserId);
|
||||
@@ -588,13 +578,7 @@ namespace AyaNova.Biz
|
||||
|
||||
if (newItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//set it on request
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == newItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = newItem.Id;//nope, no id here fuck.....
|
||||
w.Received = newItem.QuantityReceived;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)newItem.WorkOrderItemPartRequestId, POItemId = newItem.Id, ReceivedQuantity = newItem.QuantityReceived });
|
||||
}
|
||||
continue;//on to next item no possible other changes here
|
||||
}
|
||||
@@ -616,7 +600,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
await PartBiz.RemoveSerialsAsync(oldItem.PartId, oldItem.Serials, ct, UserId);
|
||||
@@ -624,13 +608,7 @@ namespace AyaNova.Biz
|
||||
//change of serial or part invalidates the workorderitempartrequest as it has specific part and warehouse so remove it here
|
||||
if (oldItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//De-request it
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == oldItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = null;
|
||||
w.Received = 0;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -647,19 +625,13 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
await PartBiz.AppendSerialsAsync(newItem.PartId, newItem.Serials, ct, UserId);
|
||||
if (newItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//set it on request
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == newItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.PurchaseOrderItemId = newItem.Id;
|
||||
w.Received = newItem.QuantityReceived;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)newItem.WorkOrderItemPartRequestId, POItemId = newItem.Id, ReceivedQuantity = newItem.QuantityReceived });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,7 +662,7 @@ namespace AyaNova.Biz
|
||||
if (await pib.CreateAsync(i) == null)
|
||||
{
|
||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
||||
return;
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
//MIGRATE_OUTSTANDING - update workorderitempart here if applicable
|
||||
@@ -711,14 +683,9 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
//update workorderitempartrequest if applicable
|
||||
if (oldItem.WorkOrderItemPartRequestId != null)
|
||||
if (newItem.WorkOrderItemPartRequestId != null)
|
||||
{
|
||||
//set it on request
|
||||
var w = await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x => x.Id == oldItem.WorkOrderItemPartRequestId);
|
||||
if (w != null)
|
||||
{
|
||||
w.Received = newItem.QuantityReceived;
|
||||
}
|
||||
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)newItem.WorkOrderItemPartRequestId, POItemId = newItem.Id, ReceivedQuantity = newItem.QuantityReceived });
|
||||
}
|
||||
continue;//on to next
|
||||
}
|
||||
@@ -735,8 +702,28 @@ namespace AyaNova.Biz
|
||||
|
||||
}
|
||||
}//modified block
|
||||
return RequestsToUpdate;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//BIZ ACTIONS
|
||||
//A PO can now be edited in any way user wishes at any time so this method is to fix up
|
||||
//any changes they make in affected objects and inventory
|
||||
//
|
||||
private async Task UpdateWorkOrderItemPartRequestsAsync(List<RequestUpdate> requestsToUpdate)
|
||||
{
|
||||
foreach(var r in requestsToUpdate){
|
||||
var w=await ct.WorkOrderItemPartRequest.FirstOrDefaultAsync(x=>x.Id==r.PartRequestId);
|
||||
if(w!=null){
|
||||
w.PurchaseOrderItemId=r.POItemId;
|
||||
w.Received=r.ReceivedQuantity;
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Called to update Part values into poitem like VendorNumber and costs etc
|
||||
private void SetPoItemDefaultPartValues(PurchaseOrderItem poItem, List<Part> poParts, long vendorId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user