This commit is contained in:
2021-09-13 18:01:05 +00:00
parent 8cbbdc1c59
commit 1e5388df87

View File

@@ -14,6 +14,7 @@ namespace AyaNova.Biz
{ {
internal class PurchaseOrderBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, INotifiableObject internal class PurchaseOrderBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, INotifiableObject
{ {
internal PurchaseOrderBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) internal PurchaseOrderBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
{ {
ct = dbcontext; ct = dbcontext;
@@ -490,7 +491,7 @@ namespace AyaNova.Biz
//All new so set them all //All new so set them all
foreach (var poItem in newObj.Items) foreach (var poItem in newObj.Items)
SetPoItemDefaultPartValues(poItem, PoParts, newObj.VendorId); SetPoItemDefaultPartValues(poItem, PoParts, newObj.VendorId, true);
foreach (var poItem in newObj.Items) foreach (var poItem in newObj.Items)
{ {
@@ -554,7 +555,7 @@ namespace AyaNova.Biz
//CHANGED THE VENDOR? (this doesn't preclude other changes as well below) //CHANGED THE VENDOR? (this doesn't preclude other changes as well below)
if (oldObj.VendorId != newObj.VendorId) if (oldObj.VendorId != newObj.VendorId)
{ {
SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId); SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId, false);
} }
//NEW ITEM ADDED //NEW ITEM ADDED
@@ -579,7 +580,7 @@ namespace AyaNova.Biz
await PartBiz.AppendSerialsAsync(newItem.PartId, newItem.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(newItem.PartId, newItem.Serials, ct, UserId);
} }
SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId); SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId, false);
if (newItem.WorkOrderItemPartRequestId != null) if (newItem.WorkOrderItemPartRequestId != null)
{ {
@@ -643,7 +644,7 @@ namespace AyaNova.Biz
//Update part values into poitem if the part or vendor has changed //Update part values into poitem if the part or vendor has changed
if (oldItem.PartId != newItem.PartId || oldObj.VendorId != newObj.VendorId) if (oldItem.PartId != newItem.PartId || oldObj.VendorId != newObj.VendorId)
SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId); SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId, false);
continue;//Note: this accounts also for any change received quantities so no need to check that below continue;//Note: this accounts also for any change received quantities so no need to check that below
} }
@@ -675,7 +676,7 @@ namespace AyaNova.Biz
//Update part values into poitem if the vendor has changed //Update part values into poitem if the vendor has changed
if (oldObj.VendorId != newObj.VendorId) if (oldObj.VendorId != newObj.VendorId)
SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId); SetPoItemDefaultPartValues(newItem, PoParts, newObj.VendorId, false);
//Set received cost if appropriate but don't overwrite an existing one //Set received cost if appropriate but don't overwrite an existing one
if (newItem.QuantityReceived > 0 && newItem.ReceivedCost == 0 && newItem.PurchaseOrderCost != 0) if (newItem.QuantityReceived > 0 && newItem.ReceivedCost == 0 && newItem.PurchaseOrderCost != 0)
@@ -729,7 +730,7 @@ namespace AyaNova.Biz
//Called to update Part values into poitem like VendorNumber and costs etc //Called to update Part values into poitem like VendorNumber and costs etc
private void SetPoItemDefaultPartValues(PurchaseOrderItem poItem, List<Part> poParts, long vendorId) private void SetPoItemDefaultPartValues(PurchaseOrderItem poItem, List<Part> poParts, long vendorId, bool isNewRecord)
{ {
var ThisPart = poParts.Single(x => x.Id == poItem.PartId);//part should always be there, if it isn't we have deeper problems var ThisPart = poParts.Single(x => x.Id == poItem.PartId);//part should always be there, if it isn't we have deeper problems
//VendorPartNumber //VendorPartNumber
@@ -744,7 +745,8 @@ namespace AyaNova.Biz
} }
//Costs //Costs
poItem.PurchaseOrderCost = ThisPart.Cost; if (!isNewRecord || (isNewRecord && poItem.PurchaseOrderCost == 0))//this is an exemption for migration purposes otherwise the cost is overwritten
poItem.PurchaseOrderCost = ThisPart.Cost;
} }