This commit is contained in:
2021-08-23 18:34:54 +00:00
parent 80c59b44c9
commit cfdf357e36

View File

@@ -4103,16 +4103,13 @@ namespace AyaNova.Biz
{ {
foreach (var e in pib.Errors) foreach (var e in pib.Errors)
{ {
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
AddError(e.Code, "Quantity", e.Message);
else
AddError(e.Code, e.Target, e.Message); AddError(e.Code, e.Target, e.Message);
} }
} }
return; return;
} }
else else
{ //Append serial numbers from part { //Append serial numbers from part being returned
if (!string.IsNullOrWhiteSpace(newObj.Serials)) if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.AppendSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
} }
@@ -4158,11 +4155,48 @@ namespace AyaNova.Biz
//UPDATED, HANDLE INVENTORY / UPDATE SERIALS AS REQUIRED //UPDATED, HANDLE INVENTORY / UPDATE SERIALS AS REQUIRED
if (ayaEvent == AyaEvent.Modified) if (ayaEvent == AyaEvent.Modified)
{ {
//INVENTORY //QUANTITY OR PART CHANGE?
if (newObj.PartId != oldObj.PartId || newObj.Quantity != oldObj.Quantity) if (newObj.PartId != oldObj.PartId || newObj.Quantity != oldObj.Quantity)
{ {
//OUT with the old //OUT with the old object
if (oldObj.Quantity != 0)//zero quantity doesn't affect inventory or serials if (oldObj.Quantity != 0)//zero quantity doesn't affect inventory or serials
{
if (oldObj.Quantity < 0)
{
//NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Was negative so add back to inventory / serials
dtInternalPartInventory pi =
new dtInternalPartInventory
{
PartId = oldObj.PartId,
PartWarehouseId = oldObj.PartWarehouseId,
Quantity = oldObj.Quantity * -1,//was originally returned (negative) so needs to be consumed
SourceType = AyaType.WorkOrderItemPart,
SourceId = oldObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted")
};
if (await pib.CreateAsync(pi) == null)
{
if (pib.HasErrors)
{
foreach (var e in pib.Errors)
{
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
AddError(e.Code, "Quantity", e.Message);
else
AddError(e.Code, e.Target, e.Message);
}
}
return;
}
else
{ //Consume serial numbers from part
if (!string.IsNullOrWhiteSpace(oldObj.Serials))
await PartBiz.RemoveSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
}
//<<<<<<<<<<<<<<<<<<<<<< NEGATIVE BLOCK
}
else
{ {
dtInternalPartInventory piOld = new dtInternalPartInventory dtInternalPartInventory piOld = new dtInternalPartInventory
{ {
@@ -4184,10 +4218,47 @@ namespace AyaNova.Biz
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
} }
} }
}
//IN with the new object
if (newObj.Quantity != 0)//zero quantity is considered to be a placeholder and no serials will be consumed, nor inventory affected
{
if (newObj.Quantity < 0)
{
//NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//RETURN INVENTORY
dtInternalPartInventory pi =
new dtInternalPartInventory
{
PartId = newObj.PartId,
PartWarehouseId = newObj.PartWarehouseId,
Quantity = newObj.Quantity,//is negative
SourceType = AyaType.WorkOrderItemPart,
SourceId = newObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
};
if (await pib.CreateAsync(pi) == null)
{
if (pib.HasErrors)
{
foreach (var e in pib.Errors)
{
AddError(e.Code, e.Target, e.Message);
}
}
return;
}
else
{ //Append serial numbers from part being returned
if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.AppendSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
}
//<<<<<<<<<<<<<<<<<<<<<< NEGATIVE BLOCK
}
else
{
//IN with the new
if (newObj.Quantity != 0)
{//NOTE: zero quantity is considered to be a placeholder and no serials will be consumed, nor inventory affected
dtInternalPartInventory piNew = new dtInternalPartInventory dtInternalPartInventory piNew = new dtInternalPartInventory
{ {
PartId = newObj.PartId, PartId = newObj.PartId,
@@ -4210,21 +4281,34 @@ namespace AyaNova.Biz
} }
} }
} }
//SERIALS return;
else if (newObj.Serials != oldObj.Serials) }//end block for quantity or part change
else if (newObj.Serials != oldObj.Serials)//SERIALS CHANGE ONLY not quantity or partid so not handled already above
{ {
//NOTE: zero quantity is considered to be a placeholder and no serials will be consumed (hence not returned either) //NOTE: zero quantity is considered to be a placeholder and no serials will be consumed (hence not returned either)
//return serial numbers to part
if (oldObj.Quantity != 0 && !string.IsNullOrWhiteSpace(oldObj.Serials)) //Old object had serials?
if (!string.IsNullOrWhiteSpace(oldObj.Serials))
{
//Reverse old object serials transaction...
if (oldObj.Quantity > 0)
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
if (oldObj.Quantity < 0)
await PartBiz.RemoveSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
}
//Consume serial numbers from part //New object has serials?
if (newObj.Quantity != 0 && !string.IsNullOrWhiteSpace(newObj.Serials)) if (!string.IsNullOrWhiteSpace(newObj.Serials))
{
//do new object serials transaction
if (newObj.Quantity > 0)
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
if (newObj.Quantity < 0)
await PartBiz.AppendSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
} }
} }
}//end MODIFIED block
} }