This commit is contained in:
2021-08-26 19:41:55 +00:00
parent eaea990999
commit 01262376fd
3 changed files with 51 additions and 40 deletions

View File

@@ -250,16 +250,19 @@ namespace AyaNova.Biz
if (HasErrors) return null;
using (var transaction = await ct.Database.BeginTransactionAsync())
{
var RequestsToUpdate = await BizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
if (HasErrors)
{
await transaction.RollbackAsync();
return null;
}
ct.Replace(dbObject, putObject);
try
{
await ct.SaveChangesAsync();
ct.Replace(dbObject, putObject);
await ct.SaveChangesAsync();//needs to exist so woitempartrequest can be set with poitemid
var RequestsToUpdate = await BizActionsAsync(AyaEvent.Modified, putObject, dbObject, transaction);
if (HasErrors)
{
await transaction.RollbackAsync();
return null;
}
//ct.Replace(dbObject, putObject);
//await ct.SaveChangesAsync();//this is the save that sets the item id
await UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
await transaction.CommitAsync();
}
@@ -297,14 +300,14 @@ namespace AyaNova.Biz
if (HasErrors)
return false;
ct.PurchaseOrder.Remove(dbObject);
var RequestsToUpdate=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 UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
await UpdateWorkOrderItemPartRequestsAsync(RequestsToUpdate);
await transaction.CommitAsync();
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Serial.ToString(), ct);
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
@@ -443,14 +446,15 @@ namespace AyaNova.Biz
await PartBiz.RemoveSerialsAsync(poItem.PartId, poItem.Serials, ct, UserId);
}
foreach (var poItem in oldObj.Items)
{
if (poItem.WorkOrderItemPartRequestId != null)
{
//De-request it
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)poItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
}
}
//Database itself will set null on delete no need to handle it in biz object
// foreach (var poItem in oldObj.Items)
// {
// if (poItem.WorkOrderItemPartRequestId != null)
// {
// //De-request it
// RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)poItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
// }
// }
return RequestsToUpdate;//done, nothing more to do here
}
@@ -532,11 +536,12 @@ namespace AyaNova.Biz
await PartBiz.RemoveSerialsAsync(oldItem.PartId, oldItem.Serials, ct, UserId);
}
//fixup woitempartrequest if any
if (oldItem.WorkOrderItemPartRequestId != null)
{
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
}
//Database itself will set null on delete no need to handle it in biz object
// //fixup woitempartrequest if any
// if (oldItem.WorkOrderItemPartRequestId != null)
// {
// RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
// }
}
}
@@ -605,11 +610,12 @@ namespace AyaNova.Biz
await PartBiz.RemoveSerialsAsync(oldItem.PartId, oldItem.Serials, ct, UserId);
//change of serial or part invalidates the workorderitempartrequest as it has specific part and warehouse so remove it here
if (oldItem.WorkOrderItemPartRequestId != null)
{
RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
}
//Database itself will set null on delete no need to handle it in biz object
// //change of serial or part invalidates the workorderitempartrequest as it has specific part and warehouse so remove it here
// if (oldItem.WorkOrderItemPartRequestId != null)
// {
// RequestsToUpdate.Add(new RequestUpdate { PartRequestId = (long)oldItem.WorkOrderItemPartRequestId, POItemId = null, ReceivedQuantity = 0 });
// }
}
if (newItem.QuantityReceived > 0)
@@ -706,18 +712,16 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
//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
//
//save changes to part requests now that we have the ID's required
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;
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();
}
}

View File

@@ -4629,6 +4629,13 @@ namespace AyaNova.Biz
if (proposedObj.Quantity < 0)//negative quantities are not allowed
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Quantity");
//UGLY workaround kind of, in order to avoid some poitem fuckery related to the dual reciprocal link between woitempartrequests adn poitems
//set the new item received quantity to zero if there is no poitemid (this is because the db itself will set the poitemid if the poitem is delete but not update the quantity received)
if(proposedObj.PurchaseOrderItemId==null && proposedObj.Received!=0)
proposedObj.Received=0;//not a biz rule but a biz adaptation
//Any form customizations to validate?
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.WorkOrderItemPartRequest.ToString());
if (FormCustomization != null)

View File

@@ -833,7 +833,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//WORKORDERITEM PART REQUEST
await ExecQueryAsync("CREATE TABLE aworkorderitempartrequest (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, quantity DECIMAL(19,5) NOT NULL default 0, received DECIMAL(19,5) NOT NULL default 0, "
+ "requestedbyuserid BIGINT NULL REFERENCES auser, purchaseorderitemid BIGINT NULL REFERENCES apurchaseorderitem"
+ "requestedbyuserid BIGINT NULL REFERENCES auser, purchaseorderitemid BIGINT NULL REFERENCES apurchaseorderitem ON DELETE SET NULL"
+ ")");
//WORKORDERITEM SCHEDULED USER
@@ -867,7 +867,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
+ ")");
//POITEM LINK
await ExecQueryAsync("ALTER TABLE apurchaseorderitem ADD column workorderitempartrequestid BIGINT REFERENCES aworkorderitempartrequest");
await ExecQueryAsync("ALTER TABLE apurchaseorderitem ADD column workorderitempartrequestid BIGINT REFERENCES aworkorderitempartrequest ON DELETE SET NULL");
//VPARTSONORDERCOMMITTED
await ExecQueryAsync("CREATE VIEW vpartsonordercommitted AS SELECT partid, partwarehouseid, SUM((COALESCE(apurchaseorderitem.quantityordered,0)-COALESCE(apurchaseorderitem.quantityreceived,0))) AS quantityonordercommitted "