This commit is contained in:
@@ -1543,7 +1543,7 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
await ExpenseBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
//await ExpenseBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
// newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
// newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemExpense.AddAsync(newObject);
|
||||
@@ -1588,7 +1588,7 @@ namespace AyaNova.Biz
|
||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
||||
await ExpenseValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
await ExpenseBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
//await ExpenseBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
@@ -1674,81 +1674,88 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (o.UserId != null)
|
||||
o.UserViz = await ct.User.AsNoTracking().Where(x => x.Id == o.UserId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
// if (o.ChargeTaxCodeId != null)
|
||||
// o.ChargeTaxCodeViz = await ct.TaxCode.AsNoTracking().Where(x => x.Id == o.ChargeTaxCodeId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
|
||||
TaxCode Tax = null;
|
||||
if (o.ChargeTaxCodeId != null)
|
||||
Tax = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.ChargeTaxCodeId);
|
||||
if (Tax != null)
|
||||
o.ChargeTaxCodeViz = Tax.Name;
|
||||
|
||||
//Calculate totals and taxes
|
||||
o.TaxAViz = 0;
|
||||
o.TaxBViz = 0;
|
||||
|
||||
if (o.TaxAPct != 0)
|
||||
if (Tax != null)
|
||||
{
|
||||
o.TaxAViz = o.ChargeAmount * (o.TaxAPct / 100);
|
||||
}
|
||||
if (o.TaxBPct != 0)
|
||||
{
|
||||
if (o.TaxOnTax)
|
||||
if (Tax.TaxAPct != 0)
|
||||
{
|
||||
o.TaxBViz = (o.ChargeAmount + o.TaxAViz) * (o.TaxBPct / 100);
|
||||
o.TaxAViz = o.ChargeAmount * (Tax.TaxAPct / 100);
|
||||
}
|
||||
else
|
||||
if (Tax.TaxBPct != 0)
|
||||
{
|
||||
o.TaxBViz = o.ChargeAmount * (o.TaxBPct / 100);
|
||||
if (Tax.TaxOnTax)
|
||||
{
|
||||
o.TaxBViz = (o.ChargeAmount + o.TaxAViz) * (Tax.TaxBPct / 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
o.TaxBViz = o.ChargeAmount * (Tax.TaxBPct / 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
o.LineTotalViz = o.ChargeAmount + o.TaxAViz + o.TaxBViz;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//BIZ ACTIONS
|
||||
//
|
||||
//
|
||||
private async Task ExpenseBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemExpense newObj, WorkOrderItemExpense oldObj, IDbContextTransaction transaction)
|
||||
{
|
||||
//automatic actions on record change, called AFTER validation
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //BIZ ACTIONS
|
||||
// //
|
||||
// //
|
||||
// private async Task ExpenseBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemExpense newObj, WorkOrderItemExpense oldObj, IDbContextTransaction transaction)
|
||||
// {
|
||||
// //automatic actions on record change, called AFTER validation
|
||||
|
||||
//currently no processing required except for created or modified at this time
|
||||
if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
return;
|
||||
// //currently no processing required except for created or modified at this time
|
||||
// if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
// return;
|
||||
|
||||
//SET TAXES AND PRICING
|
||||
// //SET TAXES AND PRICING
|
||||
|
||||
//by default apply all automatic actions with further restrictions possible below
|
||||
bool ApplyTax = true;
|
||||
// //by default apply all automatic actions with further restrictions possible below
|
||||
// bool ApplyTax = true;
|
||||
|
||||
|
||||
//if modifed, see what has changed and should be re-applied
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
// //if modifed, see what has changed and should be re-applied
|
||||
// if (ayaEvent == AyaEvent.Modified)
|
||||
// {
|
||||
|
||||
//If taxes haven't change then no need to update taxes
|
||||
if (newObj.ChargeTaxCodeId == oldObj.ChargeTaxCodeId)
|
||||
ApplyTax = false;
|
||||
}
|
||||
// //If taxes haven't change then no need to update taxes
|
||||
// if (newObj.ChargeTaxCodeId == oldObj.ChargeTaxCodeId)
|
||||
// ApplyTax = false;
|
||||
// }
|
||||
|
||||
//Tax code
|
||||
if (ApplyTax)
|
||||
{
|
||||
//Default in case nothing to apply
|
||||
newObj.TaxAPct = 0;
|
||||
newObj.TaxBPct = 0;
|
||||
newObj.TaxOnTax = false;
|
||||
newObj.TaxName = "";
|
||||
// //Tax code
|
||||
// if (ApplyTax)
|
||||
// {
|
||||
// //Default in case nothing to apply
|
||||
// newObj.TaxAPct = 0;
|
||||
// newObj.TaxBPct = 0;
|
||||
// newObj.TaxOnTax = false;
|
||||
// newObj.TaxName = "";
|
||||
|
||||
if (newObj.ChargeTaxCodeId != null)
|
||||
{
|
||||
var t = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ChargeTaxCodeId);
|
||||
if (t != null)
|
||||
{
|
||||
newObj.TaxAPct = t.TaxAPct;
|
||||
newObj.TaxBPct = t.TaxBPct;
|
||||
newObj.TaxOnTax = t.TaxOnTax;
|
||||
newObj.TaxName = t.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (newObj.ChargeTaxCodeId != null)
|
||||
// {
|
||||
// var t = await ct.TaxCode.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newObj.ChargeTaxCodeId);
|
||||
// if (t != null)
|
||||
// {
|
||||
// newObj.TaxAPct = t.TaxAPct;
|
||||
// newObj.TaxBPct = t.TaxBPct;
|
||||
// newObj.TaxOnTax = t.TaxOnTax;
|
||||
// newObj.TaxName = t.Name;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -1879,7 +1886,7 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
// await LaborBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
// await LaborBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
//newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemLabor.AddAsync(newObject);
|
||||
@@ -1927,7 +1934,7 @@ namespace AyaNova.Biz
|
||||
|
||||
await LaborValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
// await LaborBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
// await LaborBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user