Example #1
0
    def Calculate(self, monthTransactions):

        self.currentTransactions = monthTransactions
        income = self.sumIncome()
        expenses = self.sumExpenses()
        spending = self.processTransactions()
        remaining = income - expenses - spending["total"]
        forcast = income - expenses - spending["projected"]

        topSpends = self.GetSortedTransactions(max_count=6)
        date = Dates(self.currentTransactions[0]["date"].month,
                     self.currentTransactions[0]["date"].year)

        result = {
            "income": income,
            "spending": spending,
            "topSpends": topSpends,
            "expenses": expenses,
            "forecast": forcast,
            "threshold": self.budgetData["savingsThreshold"],
            "remaining": remaining,
            "date": date
        }

        #if this is a past budget, lets write out the data
        if not date.isCurrentMonthAndYear():
            self.history.Store(spending['total'], remaining, date)
        return result