This commit is contained in:
2021-05-11 17:50:22 +00:00
parent fc4b84ae85
commit 25b224c704

View File

@@ -1553,6 +1553,7 @@ namespace AyaNova.Biz
return null;
else
{
await LaborBizActionsAsync(AyaEvent.Created, newObject, null, null);
//newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
await ct.WorkOrderItemLabor.AddAsync(newObject);
@@ -1598,6 +1599,7 @@ namespace AyaNova.Biz
await LaborValidateAsync(putObject, dbObject);
if (HasErrors) return null;
await LaborBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
ct.Replace(dbObject, putObject);
try
{
@@ -1680,14 +1682,43 @@ namespace AyaNova.Biz
//
private async Task LaborPopulateVizFields(WorkOrderItemLabor o)
{
if (o.UserId != null)
if (o.UserId != null)
o.UserViz = await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync();
if (o.ServiceRateId != null)
o.ServiceRateViz = await ct.ServiceRate.AsNoTracking().Where(x => x.Id == o.ServiceRateId).Select(x => x.Name).FirstOrDefaultAsync();
if (o.TaxCodeSaleId != null)
if (o.TaxCodeSaleId != null)
o.TaxCodeSaleViz = await ct.TaxCode.AsNoTracking().Where(x => x.Id == o.TaxCodeSaleId).Select(x => x.Name).FirstOrDefaultAsync();
}
////////////////////////////////////////////////////////////////////////////////////////////////
//BIZ ACTIONS
//
private async Task LaborBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemLabor newObj, WorkOrderItemLabor oldObj, IDbContextTransaction transaction)
{
//automatic actions on record change, called AFTER validation
//For now calculate totals only which could be done more simply but doing it this way in case of future needs and for consistency
//HOW PRICING WORKS
//Base price is the regular rate price for that rate regardless if it's a contract only or normal rate, it's the actual price
//manual discount is the user applying a discount above and beyond the contract discount if there is any (?? HOW IS MANUAL CALCULATED?? AFTER CONTRACT OR B4??)
//contract discount is the actual discount the contract provides for
switch (ayaEvent)
{
case AyaEvent.Created:
//get contract
//get rate
//calculate base price
//(rate price - contract discount and / or manual discount)
break;
case AyaEvent.Modified:
break;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION