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

View File

@@ -4097,22 +4097,19 @@ namespace AyaNova.Biz
SourceId = newObj.Id, SourceId = newObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated") Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
}; };
if (await pib.CreateAsync(pi) == null) if (await pib.CreateAsync(pi) == null)
{ {
if (pib.HasErrors) if (pib.HasErrors)
{ {
foreach (var e in pib.Errors) foreach (var e in pib.Errors)
{ {
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY) AddError(e.Code, e.Target, e.Message);
AddError(e.Code, "Quantity", e.Message);
else
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,73 +4155,160 @@ 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
{ {
dtInternalPartInventory piOld = new dtInternalPartInventory if (oldObj.Quantity < 0)
{ {
PartId = oldObj.PartId, //NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PartWarehouseId = oldObj.PartWarehouseId, //Was negative so add back to inventory / serials
Quantity = oldObj.Quantity, dtInternalPartInventory pi =
SourceType = null,//null because the po no longer exists so this is technically a manual adjustment new dtInternalPartInventory
SourceId = null,//'' {
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted") PartId = oldObj.PartId,
}; PartWarehouseId = oldObj.PartWarehouseId,
if (await pib.CreateAsync(piOld) == null) Quantity = oldObj.Quantity * -1,//was originally returned (negative) so needs to be consumed
{ SourceType = AyaType.WorkOrderItemPart,
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piOld.Description}):{pib.GetErrorsAsString()}"); SourceId = oldObj.Id,
return; 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 else
{ //return serial numbers to part {
if (!string.IsNullOrWhiteSpace(oldObj.Serials)) dtInternalPartInventory piOld = new dtInternalPartInventory
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); {
PartId = oldObj.PartId,
PartWarehouseId = oldObj.PartWarehouseId,
Quantity = oldObj.Quantity,
SourceType = null,//null because the po no longer exists so this is technically a manual adjustment
SourceId = null,//''
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted")
};
if (await pib.CreateAsync(piOld) == null)
{
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piOld.Description}):{pib.GetErrorsAsString()}");
return;
}
else
{ //return serial numbers to part
if (!string.IsNullOrWhiteSpace(oldObj.Serials))
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
}
} }
} }
//IN with the new //IN with the new object
if (newObj.Quantity != 0) if (newObj.Quantity != 0)//zero quantity is considered to be a placeholder and no serials will be consumed, nor inventory affected
{//NOTE: zero quantity is considered to be a placeholder and no serials will be consumed, nor inventory affected {
dtInternalPartInventory piNew = new dtInternalPartInventory if (newObj.Quantity < 0)
{ {
PartId = newObj.PartId, //NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PartWarehouseId = newObj.PartWarehouseId, //RETURN INVENTORY
Quantity = newObj.Quantity * -1, dtInternalPartInventory pi =
SourceType = AyaType.WorkOrderItemPart, new dtInternalPartInventory
SourceId = newObj.Id, {
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated") 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);
}
if (await pib.CreateAsync(piNew) == null) //<<<<<<<<<<<<<<<<<<<<<< NEGATIVE BLOCK
{
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
return;
} }
else else
{ //Consume serial numbers from part {
if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); dtInternalPartInventory piNew = new dtInternalPartInventory
{
PartId = newObj.PartId,
PartWarehouseId = newObj.PartWarehouseId,
Quantity = newObj.Quantity * -1,
SourceType = AyaType.WorkOrderItemPart,
SourceId = newObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
};
if (await pib.CreateAsync(piNew) == null)
{
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
return;
}
else
{ //Consume serial numbers from part
if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
}
} }
} }
} return;
//SERIALS }//end block for quantity or part change
else if (newObj.Serials != oldObj.Serials) 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))
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
//Consume serial numbers from part //Old object had serials?
if (newObj.Quantity != 0 && !string.IsNullOrWhiteSpace(newObj.Serials)) if (!string.IsNullOrWhiteSpace(oldObj.Serials))
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); {
//Reverse old object serials transaction...
if (oldObj.Quantity > 0)
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
if (oldObj.Quantity < 0)
await PartBiz.RemoveSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
}
//New object has serials?
if (!string.IsNullOrWhiteSpace(newObj.Serials))
{
//do new object serials transaction
if (newObj.Quantity > 0)
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
} }
@@ -4538,7 +4622,7 @@ namespace AyaNova.Biz
//Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
//validate users choices for required non custom fields //validate users choices for required non custom fields
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
//validate custom fields //validate custom fields
} }
} }
@@ -5190,7 +5274,7 @@ namespace AyaNova.Biz
//validate users choices for required non custom fields //validate users choices for required non custom fields
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
//validate custom fields //validate custom fields
} }
} }