public static List<dynamic> ExpenseUpdate(DateTime date, float vat, JsonArrayObjects jsonAllocation, JsonArrayObjects jsonExpense) { DictionaryToDynamicMapper mapperAllocation = new DictionaryToDynamicMapper("InvoiceAllocation"); var allocation = mapperAllocation.Map(jsonAllocation.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))); var expenses = jsonExpense != null ? (new DictionaryToDynamicMapper("InvoiceExpense")).Map(jsonExpense.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))).ToList() : new List<dynamic>(); #region Capex expenses.ForEach(c => c.AmountCAPEX = 0); var accounts = DynamicRepository.GetByView("AccountCode", FilterCriteriaSet.And.In( allocation.Where(c=>c.capexopex == 0).Select(c => (Guid)c.AccountCodeId).Distinct().ToList(), "Id")); foreach (dynamic item in allocation.Where(c => c.CapexOpex == 0)) { int usefulLife = accounts.Where(c => c.Id == item.AccountCodeId).Select(c => c.UsefulLife).FirstOrDefault() ?? 0; ExpenseUpdateAddCapex(expenses, item.Amount, vat, date, usefulLife); } ExpenseRound(expenses, allocation, true); #endregion #region Opex decimal amountOpexAllocation = allocation.Where(c => c.CapexOpex == 1).Sum(c => (decimal)c.Amount); ExpenseUpdateSyncOpex(expenses, amountOpexAllocation, date); ExpenseRound(expenses, allocation, false); #endregion expenses.RemoveAll(c => c.Amount == 0 && c.AmountCAPEX == 0); return expenses; }
public static List <dynamic> ExpenseUpdate(DateTime date, float vat, JsonArrayObjects jsonAllocation, JsonArrayObjects jsonExpense) { DictionaryToDynamicMapper mapperAllocation = new DictionaryToDynamicMapper("InvoiceAllocation"); var allocation = mapperAllocation.Map(jsonAllocation.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))); var expenses = jsonExpense != null ? (new DictionaryToDynamicMapper("InvoiceExpense")).Map(jsonExpense.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))).ToList() : new List <dynamic>(); #region Capex expenses.ForEach(c => c.AmountCAPEX = 0); var accounts = DynamicRepository.GetByView("AccountCode", FilterCriteriaSet.And.In( allocation.Where(c => c.capexopex == 0).Select(c => (Guid)c.AccountCodeId).Distinct().ToList(), "Id")); foreach (dynamic item in allocation.Where(c => c.CapexOpex == 0)) { int usefulLife = accounts.Where(c => c.Id == item.AccountCodeId).Select(c => c.UsefulLife).FirstOrDefault() ?? 0; ExpenseUpdateAddCapex(expenses, item.Amount, vat, date, usefulLife); } ExpenseRound(expenses, allocation, true); #endregion #region Opex decimal amountOpexAllocation = allocation.Where(c => c.CapexOpex == 1).Sum(c => (decimal)c.Amount); ExpenseUpdateSyncOpex(expenses, amountOpexAllocation, date); ExpenseRound(expenses, allocation, false); #endregion expenses.RemoveAll(c => c.Amount == 0 && c.AmountCAPEX == 0); return(expenses); }