This commit is contained in:
@@ -238,7 +238,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//APPEND SERIALS - called by PO ops to add serials to a part
|
//APPEND SERIALS - called by PO add and WorkOrderItemPart delete ops to add serials to a part
|
||||||
//
|
//
|
||||||
internal static async Task AppendSerialsAsync(long partId, string serialText, AyContext ct, long UserId)
|
internal static async Task AppendSerialsAsync(long partId, string serialText, AyContext ct, long UserId)
|
||||||
{
|
{
|
||||||
@@ -261,7 +261,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//REMOVE SERIALS - called by PO ops to remove serials from a part
|
//REMOVE SERIALS - called by PO delete ops and WorkorderItemPart create ops to remove serials from a part
|
||||||
//
|
//
|
||||||
internal static async Task RemoveSerialsAsync(long partId, string serialText, AyContext ct, long UserId)
|
internal static async Task RemoveSerialsAsync(long partId, string serialText, AyContext ct, long UserId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3176,6 +3176,7 @@ namespace AyaNova.Biz
|
|||||||
PartValidateCanDelete(dbObject);
|
PartValidateCanDelete(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
await PartBizActionsAsync(AyaEvent.Modified, null, dbObject, transaction);
|
||||||
ct.WorkOrderItemPart.Remove(dbObject);
|
ct.WorkOrderItemPart.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
//Log event
|
//Log event
|
||||||
@@ -3336,54 +3337,122 @@ namespace AyaNova.Biz
|
|||||||
//### TODO: make this work with inventory, also check if delete entire workorder will still call this (or delete woitem)
|
//### TODO: make this work with inventory, also check if delete entire workorder will still call this (or delete woitem)
|
||||||
// if delete wo doesn't call this, it will need to
|
// if delete wo doesn't call this, it will need to
|
||||||
|
|
||||||
|
//#### Make sure serials are handled
|
||||||
|
|
||||||
|
|
||||||
if (AyaNova.Util.ServerGlobalBizSettings.UseInventory)
|
if (AyaNova.Util.ServerGlobalBizSettings.UseInventory)
|
||||||
{
|
{
|
||||||
//create debit and credit transactions as required then insert them into inventory at the bottom
|
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||||
List<dtInternalPartInventory> adjustmentsList = new List<dtInternalPartInventory>();
|
|
||||||
|
|
||||||
|
//DELETED, HANDLE INVENTORY / RETURN SERIALS
|
||||||
|
if (ayaEvent == AyaEvent.Deleted)
|
||||||
|
|
||||||
//DELETED HANDLE INVENTORY / RETURN SERIALS
|
|
||||||
|
|
||||||
|
|
||||||
//It's a new receipt with received amounts - add to inventory
|
|
||||||
dtInternalPartInventory i = new dtInternalPartInventory();
|
|
||||||
i.PartId = newItem.PartId;
|
|
||||||
i.PartWarehouseId = newItem.PartWarehouseId;
|
|
||||||
i.Quantity = newItem.QuantityReceived;
|
|
||||||
i.SourceType = AyaType.PurchaseOrder;
|
|
||||||
i.SourceId = newObj.Id;
|
|
||||||
i.Description = await Translate("PurchaseOrder") + $" {newObj.Serial} " + await Translate("PurchaseOrderItem") + " " + await Translate("EventCreated");
|
|
||||||
if (await pib.CreateAsync(i) == null)
|
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({i.Description}):{pib.GetErrorsAsString()}");
|
dtInternalPartInventory pi =
|
||||||
return;
|
new dtInternalPartInventory
|
||||||
}
|
{
|
||||||
|
PartId = oldObj.PartId,
|
||||||
//CREATED HANDLE INVENTORY / CONSUME SERIALS
|
PartWarehouseId = oldObj.PartWarehouseId,
|
||||||
|
Quantity = oldObj.Quantity *= -1,
|
||||||
|
SourceType = null,//null because the po no longer exists so this is technically a manual adjustment
|
||||||
//UPDATED HANDLE INVENTORY / UPDATE SERIALS EITHER WAY
|
SourceId = null,//''
|
||||||
|
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted")
|
||||||
|
};
|
||||||
|
if (await pib.CreateAsync(pi) == null)
|
||||||
if (adjustmentsList.Count > 0)
|
|
||||||
{
|
|
||||||
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
|
||||||
foreach (dtInternalPartInventory pi in adjustmentsList)
|
|
||||||
{
|
{
|
||||||
if (await pib.CreateAsync(pi) == null)
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
{
|
return;
|
||||||
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
}
|
||||||
return;
|
else
|
||||||
}
|
{ //return serial numbers to part
|
||||||
|
if (!string.IsNullOrWhiteSpace(oldObj.Serials))
|
||||||
|
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//CREATED, HANDLE INVENTORY / CONSUME SERIALS
|
||||||
|
if (ayaEvent == AyaEvent.Created)
|
||||||
|
{
|
||||||
|
dtInternalPartInventory pi =
|
||||||
|
new dtInternalPartInventory
|
||||||
|
{
|
||||||
|
PartId = newObj.PartId,
|
||||||
|
PartWarehouseId = newObj.PartWarehouseId,
|
||||||
|
Quantity = newObj.Quantity,
|
||||||
|
SourceType = AyaType.WorkOrderItemPart,
|
||||||
|
SourceId = newObj.Id,
|
||||||
|
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
|
||||||
|
};
|
||||||
|
if (await pib.CreateAsync(pi) == null)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({pi.Description}):{pib.GetErrorsAsString()}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ //Consume serial numbers from part
|
||||||
|
if (!string.IsNullOrWhiteSpace(newObj.Serials))
|
||||||
|
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//UPDATED HANDLE INVENTORY / UPDATE SERIALS AS REQUIRED
|
||||||
|
if (ayaEvent == AyaEvent.Modified)
|
||||||
|
{
|
||||||
|
//determine if any changes affecting inventory
|
||||||
|
if (newObj.PartId != oldObj.PartId || newObj.Quantity != oldObj.Quantity)
|
||||||
|
{
|
||||||
|
//OUT with the old
|
||||||
|
dtInternalPartInventory piOld = new dtInternalPartInventory
|
||||||
|
{
|
||||||
|
PartId = oldObj.PartId,
|
||||||
|
PartWarehouseId = oldObj.PartWarehouseId,
|
||||||
|
Quantity = oldObj.Quantity *= -1,
|
||||||
|
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
|
||||||
|
dtInternalPartInventory piNew = new dtInternalPartInventory
|
||||||
|
{
|
||||||
|
PartId = newObj.PartId,
|
||||||
|
PartWarehouseId = newObj.PartWarehouseId,
|
||||||
|
Quantity = newObj.Quantity,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//SNAPSHOT PRICING IF NECESSARY
|
//SNAPSHOT PRICING IF NECESSARY
|
||||||
|
|||||||
Reference in New Issue
Block a user