This commit is contained in:
@@ -60,6 +60,8 @@ namespace AyaNova.Biz
|
|||||||
//CREATE
|
//CREATE
|
||||||
//
|
//
|
||||||
internal async Task<WorkOrder> WorkOrderCreateAsync(WorkOrder newObject, bool populateViz = true)
|
internal async Task<WorkOrder> WorkOrderCreateAsync(WorkOrder newObject, bool populateViz = true)
|
||||||
|
{
|
||||||
|
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||||
{
|
{
|
||||||
await WorkOrderValidateAsync(newObject, null);
|
await WorkOrderValidateAsync(newObject, null);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -94,13 +96,31 @@ namespace AyaNova.Biz
|
|||||||
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
||||||
}
|
}
|
||||||
await ct.SaveChangesAsync();
|
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)
|
if (populateViz)
|
||||||
await WorkOrderPopulateVizFields(newObject, true);
|
await WorkOrderPopulateVizFields(newObject, true);
|
||||||
|
|
||||||
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||||
return newObject;
|
return newObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DUPLICATE
|
//DUPLICATE
|
||||||
@@ -3087,6 +3107,8 @@ namespace AyaNova.Biz
|
|||||||
//CREATE
|
//CREATE
|
||||||
//
|
//
|
||||||
internal async Task<WorkOrderItemPart> CreatePartAsync(WorkOrderItemPart newObject)
|
internal async Task<WorkOrderItemPart> CreatePartAsync(WorkOrderItemPart newObject)
|
||||||
|
{
|
||||||
|
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||||
{
|
{
|
||||||
await PartValidateAsync(newObject, null);
|
await PartValidateAsync(newObject, null);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -3098,13 +3120,21 @@ namespace AyaNova.Biz
|
|||||||
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||||
await ct.WorkOrderItemPart.AddAsync(newObject);
|
await ct.WorkOrderItemPart.AddAsync(newObject);
|
||||||
await ct.SaveChangesAsync();
|
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 EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||||
await PartSearchIndexAsync(newObject, true);
|
await PartSearchIndexAsync(newObject, true);
|
||||||
|
await transaction.CommitAsync();
|
||||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||||
await PartPopulateVizFields(newObject);
|
await PartPopulateVizFields(newObject);
|
||||||
return newObject;
|
return newObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// GET
|
// GET
|
||||||
@@ -3121,6 +3151,8 @@ namespace AyaNova.Biz
|
|||||||
//UPDATE
|
//UPDATE
|
||||||
//
|
//
|
||||||
internal async Task<WorkOrderItemPart> PartPutAsync(WorkOrderItemPart putObject)
|
internal async Task<WorkOrderItemPart> PartPutAsync(WorkOrderItemPart putObject)
|
||||||
|
{
|
||||||
|
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||||
{
|
{
|
||||||
WorkOrderItemPart dbObject = await PartGetAsync(putObject.Id, false);
|
WorkOrderItemPart dbObject = await PartGetAsync(putObject.Id, false);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
@@ -3144,6 +3176,12 @@ namespace AyaNova.Biz
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
await PartInventoryAdjustmentAsync(AyaEvent.Modified, putObject, dbObject, transaction);
|
||||||
|
if (HasErrors)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@@ -3157,25 +3195,35 @@ namespace AyaNova.Biz
|
|||||||
await PartSearchIndexAsync(putObject, false);
|
await PartSearchIndexAsync(putObject, false);
|
||||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
|
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||||
await PartHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
await PartHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||||
|
await transaction.CommitAsync();
|
||||||
await PartPopulateVizFields(putObject);
|
await PartPopulateVizFields(putObject);
|
||||||
return putObject;
|
return putObject;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DELETE
|
//DELETE
|
||||||
//
|
//
|
||||||
internal async Task<bool> PartDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
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
|
try
|
||||||
{
|
{
|
||||||
var dbObject = await PartGetAsync(id, false);
|
var dbObject = await PartGetAsync(id, false);
|
||||||
PartValidateCanDelete(dbObject);
|
PartValidateCanDelete(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
await PartBizActionsAsync(AyaEvent.Modified, null, dbObject, transaction);
|
await PartBizActionsAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||||
ct.WorkOrderItemPart.Remove(dbObject);
|
ct.WorkOrderItemPart.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
await PartInventoryAdjustmentAsync(AyaEvent.Deleted, null, dbObject, transaction);
|
||||||
|
if (HasErrors)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//Log event
|
//Log event
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, dbObject.AyaType, ct);
|
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
|
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3330,6 +3379,50 @@ namespace AyaNova.Biz
|
|||||||
private async Task PartBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemPart newObj, WorkOrderItemPart oldObj, IDbContextTransaction transaction)
|
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)
|
if (AyaNova.Util.ServerGlobalBizSettings.UseInventory)
|
||||||
{
|
{
|
||||||
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
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