This commit is contained in:
@@ -60,6 +60,8 @@ namespace AyaNova.Biz
|
||||
//CREATE
|
||||
//
|
||||
internal async Task<WorkOrder> WorkOrderCreateAsync(WorkOrder newObject, bool populateViz = true)
|
||||
{
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
await WorkOrderValidateAsync(newObject, null);
|
||||
if (HasErrors)
|
||||
@@ -94,13 +96,31 @@ namespace AyaNova.Biz
|
||||
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//INVENTORY ADJUSTMENTS
|
||||
foreach (WorkOrderItem wi in newObject.Items)
|
||||
{
|
||||
foreach (WorkOrderItemPart wip in wi.Parts)
|
||||
{
|
||||
await PartInventoryAdjustmentAsync(AyaEvent.Created, wip, null, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
await transaction.CommitAsync();
|
||||
if (populateViz)
|
||||
await WorkOrderPopulateVizFields(newObject, true);
|
||||
|
||||
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DUPLICATE
|
||||
@@ -3087,6 +3107,8 @@ namespace AyaNova.Biz
|
||||
//CREATE
|
||||
//
|
||||
internal async Task<WorkOrderItemPart> CreatePartAsync(WorkOrderItemPart newObject)
|
||||
{
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
await PartValidateAsync(newObject, null);
|
||||
if (HasErrors)
|
||||
@@ -3098,13 +3120,21 @@ namespace AyaNova.Biz
|
||||
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemPart.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await PartInventoryAdjustmentAsync(AyaEvent.Created, newObject, null, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||
await PartSearchIndexAsync(newObject, true);
|
||||
await transaction.CommitAsync();
|
||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
await PartPopulateVizFields(newObject);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GET
|
||||
@@ -3121,6 +3151,8 @@ namespace AyaNova.Biz
|
||||
//UPDATE
|
||||
//
|
||||
internal async Task<WorkOrderItemPart> PartPutAsync(WorkOrderItemPart putObject)
|
||||
{
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
WorkOrderItemPart dbObject = await PartGetAsync(putObject.Id, false);
|
||||
if (dbObject == null)
|
||||
@@ -3144,6 +3176,12 @@ namespace AyaNova.Biz
|
||||
try
|
||||
{
|
||||
await ct.SaveChangesAsync();
|
||||
await PartInventoryAdjustmentAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
@@ -3157,25 +3195,35 @@ namespace AyaNova.Biz
|
||||
await PartSearchIndexAsync(putObject, false);
|
||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
await PartHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
await transaction.CommitAsync();
|
||||
await PartPopulateVizFields(putObject);
|
||||
return putObject;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> PartDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
// var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
using (var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbObject = await PartGetAsync(id, false);
|
||||
PartValidateCanDelete(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
await PartBizActionsAsync(AyaEvent.Modified, null, dbObject, transaction);
|
||||
await PartBizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
ct.WorkOrderItemPart.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await PartInventoryAdjustmentAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||
if (HasErrors)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
return false;
|
||||
}
|
||||
//Log event
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, dbObject.AyaType, ct);
|
||||
@@ -3190,6 +3238,7 @@ namespace AyaNova.Biz
|
||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3330,6 +3379,50 @@ namespace AyaNova.Biz
|
||||
private async Task PartBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemPart newObj, WorkOrderItemPart oldObj, IDbContextTransaction transaction)
|
||||
{
|
||||
|
||||
|
||||
//SNAPSHOT PRICING IF NECESSARY
|
||||
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
return;
|
||||
|
||||
//SNAPSHOT PRICING
|
||||
bool SnapshotPricing = true;
|
||||
|
||||
//if modifed, see what has changed and should be re-applied
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
//If it wasn't a complete part change there is no need to set pricing
|
||||
if (newObj.PartId == oldObj.PartId)
|
||||
{
|
||||
SnapshotPricing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Pricing
|
||||
if (SnapshotPricing)
|
||||
{
|
||||
//default in case nothing to apply
|
||||
newObj.Cost = 0;
|
||||
newObj.ListPrice = 0;
|
||||
|
||||
|
||||
var s = await ct.Part.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.PartId);
|
||||
if (s != null)
|
||||
{
|
||||
newObj.Cost = s.Cost;
|
||||
newObj.ListPrice = s.Retail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//BIZ ACTIONS
|
||||
//
|
||||
//
|
||||
private async Task PartInventoryAdjustmentAsync(AyaEvent ayaEvent, WorkOrderItemPart newObj, WorkOrderItemPart oldObj, IDbContextTransaction transaction)
|
||||
{
|
||||
|
||||
|
||||
if (AyaNova.Util.ServerGlobalBizSettings.UseInventory)
|
||||
{
|
||||
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||
@@ -3453,57 +3546,8 @@ namespace AyaNova.Biz
|
||||
|
||||
}
|
||||
|
||||
//SNAPSHOT PRICING IF NECESSARY
|
||||
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
return;
|
||||
|
||||
//SNAPSHOT PRICING
|
||||
bool SnapshotPricing = true;
|
||||
|
||||
//if modifed, see what has changed and should be re-applied
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
//If it wasn't a complete part change there is no need to set pricing
|
||||
if (newObj.PartId == oldObj.PartId)
|
||||
{
|
||||
SnapshotPricing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Pricing
|
||||
if (SnapshotPricing)
|
||||
{
|
||||
//default in case nothing to apply
|
||||
newObj.Cost = 0;
|
||||
newObj.ListPrice = 0;
|
||||
|
||||
|
||||
var s = await ct.Part.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.PartId);
|
||||
if (s != null)
|
||||
{
|
||||
newObj.Cost = s.Cost;
|
||||
newObj.ListPrice = s.Retail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// // SET PER UNIT LIST PRICE
|
||||
// //
|
||||
// //(called by woitempart save and also by header save on change of contract)
|
||||
// private static void PartSetListPrice(WorkOrderItemPart o, Contract c)
|
||||
// {
|
||||
// if (c == null || c.ServiceRatesOverridePct == 0)
|
||||
// {
|
||||
// o.Price = o.ListPrice;//default with no contract
|
||||
// return;
|
||||
// }
|
||||
// if (c.ServiceRatesOverrideType == ContractOverrideType.CostMarkup)
|
||||
// o.Price = o.Cost + (o.Cost * c.ServiceRatesOverridePct);
|
||||
// else if (c.ServiceRatesOverrideType == ContractOverrideType.PriceDiscount)
|
||||
// o.Price = o.ListPrice - (o.ListPrice * c.ServiceRatesOverridePct);
|
||||
// }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user