public static double CreateExtraLine(int userId, MonthAndYear monthAndYear, double @in, double tax) { if (Rules.IsJcpSpecific(userId)) { if (monthAndYear.IsLaterThan((2017, 11))) { return((@in - tax) / 2 + tax); } if (monthAndYear.IsLaterThan((2016, 11))) { return(16000.0 + 26000); } if (monthAndYear.IsLaterThan((2016, 9))) { return(19200.0 + 13900); } if (monthAndYear.IsLaterThan((2015, 6))) { return(16800.0 + 10600); } return(19590.0); } return(0.0); }
private Posting GetExistingLossPosting(int userId, MonthAndYear monthAndYear, int lossSubcategoryId) { return(_context.PostingForUser(userId) .Where(posting => posting.Date.Year == monthAndYear.Year) .Where(posting => posting.Date.Month == monthAndYear.Month) .Where(posting => posting.SubcategoryId == lossSubcategoryId) .SingleOrDefault()); }
public void CalculateLoss(int userId, MonthAndYear monthAndYear) { var(startSum, endSum) = _accountStatusQueryRepository.StartAndEndOfMonthAccountStatusSum(userId, monthAndYear); var monthlyChange = _postingQueryRepository.GetMonthlyChange(userId, monthAndYear); var loss = Math.Round(monthlyChange + startSum - endSum, 2); _lossRepository.UpdateLoss(userId, monthAndYear, loss); }
private IEnumerable <MonthAndYear> monthRange(MonthAndYear start, MonthAndYear end) { var month = start; while (month <= end) { yield return(month); month = month.AddMonths(1); } }
private static Posting CreateNewLossPosting(int userId, MonthAndYear monthAndYear, int lossSubcategoryId) { return(new Posting { UserId = userId, SubcategoryId = lossSubcategoryId, Description = null, Date = monthAndYear.LastDayOfMonth(), Latitude = null, Longitude = null, Accuracy = null, }); }
public ActionResult Put(List <LegacyAccountStatus> accountStatuses) { ValidateNotEmpty(accountStatuses); accountStatuses.ForEach(ValidatePut); var userId = HttpContext.GetUserId(); var existingAccountStatuses = _legacyAccountStatusRepository.Put(accountStatuses, userId); var monthAndYear = new MonthAndYear(accountStatuses.First().Year, accountStatuses.First().Month); _lossService.CalculateLoss(userId, monthAndYear); return(Ok(existingAccountStatuses)); }
private LocalDate AdjsutEndMonthRange(MonthAndYear endMonth) { (int month, int year) = endMonth; if (month == 12) { month = 1; year++; } else { month++; } return(new LocalDate(year, month, 1)); }
private void PopulateMonthAndYear() { // Populate Year for (int i = 2018; i < 2100; i++) { Year.Add(i.ToString()); } // Populate Month for (int i = 1; i < 13; i++) { Month.Add(DateTimeFormatInfo.CurrentInfo.GetMonthName(i)); } MonthAndYear.Add(Month); MonthAndYear.Add(Year); }
public void UpdateLoss(int userId, MonthAndYear monthAndYear, double loss) { int lossSubcategoryId = _postingQueryRepository.GetLossSubCategoryId(userId); Posting lossPosting = GetExistingLossPosting(userId, monthAndYear, lossSubcategoryId); if (lossPosting == null) { lossPosting = CreateNewLossPosting(userId, monthAndYear, lossSubcategoryId); _context.Posting.Add(lossPosting); } lossPosting.Amount = loss; lossPosting.CreatedOn = DateTime.Now; _context.SaveChanges(); }
public static double GetPensionRate(int userId, MonthAndYear monthAndYear) { if (!Rules.IsJcpSpecific(userId)) { return(0); } if (monthAndYear.IsEarlierThan(new MonthAndYear(2016, 10))) { return(0); } else if (monthAndYear.IsEarlierThan(new MonthAndYear(2018, 8))) { return(0.0525); } return(0.0625); }
public List <LegacyMonthlySumup> Sumup(int userId) { var sumup = _postingSumupService.GetSumup(userId); var accountStatusSums = _accountStatusSumupService.GetSumup(userId); foreach (var monthlySumup in sumup) { var monthAndYear = new MonthAndYear(monthlySumup.Year, monthlySumup.Month); accountStatusSums.TryGetValue(monthAndYear, out var statusSums); var invest = statusSums?.Invest ?? 0; var lastMonthSummedFortune = statusSums?.LastMonthSummedFortune ?? 0; var monthsWithoutPay = CalculateMonthsWithoutPay(lastMonthSummedFortune, monthlySumup.ExpensesLastYear); monthlySumup.Invest = Math.Round(invest, 2); monthlySumup.MonthsWithoutPay = Math.Round(monthsWithoutPay, 2); } return(sumup); }
public void GetOwnPensionSavings_DifferentScenarios_ShouldReturnCorrectValue(Dictionary <MonthAndYear, Dictionary <string, double> > dictionary, MonthAndYear monthAndYear, double expectedPension) { var sut = new MonthlyAccountCategorySums(dictionary); var ownPension = sut.GetOwnPensionSavings(monthAndYear); Assert.AreEqual(expectedPension, ownPension); }
public UnusualSpendingByCategory() { SelectedMonth = MonthAndYear.Current.AddMonths(-1); }
public (double StartSum, double EndSum) StartAndEndOfMonthAccountStatusSum(int userId, MonthAndYear monthAndYear) { var monthlyAccountStatuses = _context.AccountStatus .Where(accountStatus => accountStatus.UserId == userId) .GroupBy(accountStatus => new { accountStatus.Date.Year, accountStatus.Date.Month }) .Select(pair => new { pair.Key.Year, pair.Key.Month, Sum = pair.Sum(x => x.Amount) }) .ToDictionary(x => new MonthAndYear(x.Year, x.Month), x => x.Sum); var endSum = monthlyAccountStatuses[monthAndYear]; var startSum = monthlyAccountStatuses[monthAndYear.PreviousMonth()]; return(startSum, endSum); }
private double AverageExpensesLastYear(MonthAndYear month, Dictionary <MonthAndYear, (double pureInWithoutPension, double pureOut)> monthlyValues)
public IEnumerable <DashboardDataDTO> SalariesPerMonth(string id) { Transaction t = new Transaction() { Employee = new Employee(), Company = new Company() }; List <Transaction> outgoingTransactions = new List <Transaction>(); t.InsertDocument("FlourishDB_ARC"); Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("Company.Name", id); List <CRUDAble> w = t.SearchDocument(parameters, "FlourishDB_ARC"); w.Remove(t); t.Delete("FlourishDB_ARC"); foreach (Transaction item in w) { outgoingTransactions.Add(item); } Dictionary <string, MonthAndYear> totlSalariesPerMonth = new Dictionary <string, MonthAndYear>(); foreach (var item in outgoingTransactions) { MonthAndYear monthAndYear = new MonthAndYear() { MonthInt = item.DateCreated.Month, Month = item.DateCreated.ToString("MMM"), Year = item.DateCreated.Year, Amount = item.Amount }; string monthAndYearString = monthAndYear.Month + "-" + monthAndYear.Year; if (totlSalariesPerMonth.Keys.Contains(monthAndYearString)) { totlSalariesPerMonth[monthAndYearString].Amount += item.Amount; } else { totlSalariesPerMonth.Add(monthAndYearString, monthAndYear); } } List <DashboardDataDTO> outGoingData = new List <DashboardDataDTO>(); for (int i = 1; i < 13; i++) { foreach (var item in totlSalariesPerMonth.Values) { if (item.MonthInt == i) { outGoingData.Add(new DashboardDataDTO() { FieldName = item.Month + " - " + item.Year, Value = item.Amount }); break; } } } return(outGoingData); }
public static bool ShouldDailyPurchaseMonthBeRemoved(MonthAndYear monthAndYear, int userId) { return(Rules.IsJcpSpecific(userId) && monthAndYear.IsEarlierThan(new MonthAndYear(2014, 9))); }
private DashboardInformation CalculateDashboard(MonthAndYear currentMonthAndYear, List <double> returnRates, int currentAge, int pensionAge, int numMonths, Dictionary <MonthAndYear, Ledger> monthlyLedgers) { var ledger = CalculateAverageLedger(monthlyLedgers, numMonths, currentMonthAndYear); return(CalculateDashboard(ledger, currentAge, pensionAge, returnRates)); }
private Ledger CalculateAverageLedger(Dictionary <MonthAndYear, Ledger> monthlyLedgers, int numMonths, MonthAndYear currentMonthAndYear) { return(CalculateAverageLedgers(monthlyLedgers, numMonths)[currentMonthAndYear]); }
public void GetFortuneAndInvestmentSummed_DifferentScenarios_ShouldReturnCorrectValue(Dictionary <MonthAndYear, Dictionary <string, double> > dictionary, MonthAndYear monthAndYear, double expectedSum) { var sut = new MonthlyAccountCategorySums(dictionary); var fortune = sut.GetFortunesWithoutPension(monthAndYear); Assert.AreEqual(expectedSum, fortune); }
public AverageOverMonthsCategoryRoller(Category topLevelCategory, MonthAndYear startMonth, MonthAndYear endMonth) : base(topLevelCategory) { this.startMonth = startMonth; this.endMonth = endMonth; }