Exemplo n.º 1
0
    def __call__(self):

        total_income = Decimal(0.0)
        total_taxes = Decimal(0.0)

        for account_name in self.income_accounts:
            account = get_account(account_name)

            for split in get_splits(account, self._start.date, self._end.date):
                value = get_decimal(split.GetAmount()) * -1
                total_income += value

        for account_name in self.tax_accounts:
            account = get_account(account_name)
            for split in get_splits(account,  self._start.date, self._end.date):
                value = get_decimal(split.GetAmount())
                total_taxes += value

        tax_value = calculate_tax(self._tax_name, self._tax_status, total_income)

        result = self._generate_result()
        result['data']['income'] = total_income
        result['data']['tax_value'] = tax_value
        result['data']['taxes_paid'] = total_taxes

        return result
Exemplo n.º 2
0
    def __call__(self):
        balance = Decimal('0.0')

        for account in account_walker(self.account_name, self.ignore_accounts):
            split_list = get_splits(account, PeriodStart.this_month.date, PeriodEnd.today.date, debit=False)

            for split in split_list:
                balance += get_decimal(split.GetAmount())

        payload = self._generate_result()
        payload['data']['balance'] = balance
        payload['data']['month'] = PeriodEnd.today.date.month
        payload['data']['daysInMonth'] = monthrange(PeriodEnd.today.date.year,
                                                    PeriodEnd.today.date.month)[1]
        payload['data']['today'] = PeriodEnd.today.date.day
        payload['data']['budgetValue'] = self.budget_value

        if self._year_to_date:
            yearly_balance = Decimal('0.0')

            for account in account_walker(self.account_name, self.ignore_accounts):
                split_list = get_splits(account, PeriodStart.this_year.date, PeriodEnd.this_year.date, debit=False)

                for split in split_list:
                    yearly_balance += get_decimal(split.GetAmount())

            today = date.today()
            payload['data']['yearlyBalance'] = yearly_balance
            payload['data']['daysInYear'] = (date(today.year+1, 1, 1) - date(today.year, 1, 1)).days
            payload['data']['currentYearDay'] = today.timetuple().tm_yday

        return payload
    def __call__(self):

        bucket = PeriodCollate(self._start.date, self._end.date, decimal_generator, split_summation,
                               frequency=self._size.frequency, interval=self._size.interval)
        record_count = PeriodCollate(self._start.date, self._end.date, integer_generator, count,
                                     frequency=self._size.frequency, interval=self._size.interval)

        for account in account_walker(self.expenses_base, self.ignore_list):
            for split in get_splits(account, self._start.date, self._end.date):
                bucket.store_value(split)
                record_count.store_value(split)

        return_value = self._generate_result()
        sorted_results = []
        sorted_count_results = []

        for key, value in bucket.container.iteritems():
            sorted_results.append(dict(date=time.mktime(key.timetuple()), value=value))

        for key, value in record_count.container.iteritems():
            sorted_count_results.append(dict(date=time.mktime(key.timetuple()), value=value))

        return_value['data']['expenses'] = sorted(sorted_results, key=lambda s: s['date'])

        if self._show_record_count:
            return_value['data']['count'] = sorted(sorted_count_results, key=lambda s: s['date'])

        return return_value
    def __call__(self):

        start_of_trend = self._start.date
        end_of_trend = self._end.date

        data = dict()

        for account in account_walker(self._accounts):
            for split in get_splits(account, start_of_trend, end_of_trend, credit=False):

                transaction = split.parent

                for transaction_split in transaction.GetSplitList():
                    transaction_account_name = transaction_split.GetAccount().get_full_name()
                    if transaction_account_name != account.get_full_name():
                        category = get_category_for_account(transaction_account_name)
                        current_balance = data.setdefault(category,
                                                          Decimal('0.0'))
                        current_balance += get_decimal(transaction_split.GetAmount())
                        data[category] = current_balance

        result = self._generate_result()
        result['data']['categories'] = sorted([[key, value] for key, value in data.iteritems()], key=itemgetter(0))

        return result
    def __call__(self):

        bucket = PeriodCollate(
            self._period_start.date,
            self._period_end.date,
            debit_credit_generator,
            store_credit_debit,
            frequency=self._period_size.frequency,
            interval=self._period_size.interval,
        )

        for account in account_walker(self._income + self._expenses, ignore_list=self._ignore_accounts):
            for split in get_splits(account, self._period_start.date, self._period_end.date):
                bucket.store_value(split)

        return_value = self._generate_result()
        credit_values = []
        debit_values = []
        difference_value = []

        for key, value in bucket.container.iteritems():
            time_value = time.mktime(key.timetuple())

            # Have to switch the signs so that the graph will make sense.  In GNUCash the income accounts are debited
            # when paid, and the expense accounts are 'credited' when purchased.
            credit_values.append(dict(date=time_value, value=-value["credit"]))
            debit_values.append(dict(date=time_value, value=-value["debit"]))
            difference_value.append(dict(date=time_value, value=-(value["debit"] + value["credit"])))

        # Income accounts are the debits, and Expense accounts are the credits.
        return_value["data"]["expenses"] = sorted(credit_values, key=lambda s: s["date"])
        return_value["data"]["income"] = sorted(debit_values, key=lambda s: s["date"])
        return_value["data"]["net"] = sorted(difference_value, key=lambda s: s["date"])

        return return_value
    def __call__(self):

        investment_value = dict()
        buckets = PeriodCollate(self._period_start.date, self._period_end.date,
                                investment_bucket_generator, store_investment, frequency=self._period_size.frequency,
                                interval=self._period_size.interval)

        start_value = Decimal('0.0')
        start_value_date = self._period_start.date - relativedelta(days=1)
        currency = get_currency()

        for account in account_walker(self._investment_accounts, ignore_list=self._ignore_accounts):
            for split in get_splits(account, self._period_start.date, self._period_end.date):
                buckets.store_value(split)

            start_value += get_balance_on_date(account, start_value_date, currency)

            for key in buckets.container.keys():
                date_value = key + relativedelta(months=1) - relativedelta(days=1)
                investment_value[key] = investment_value.get(key, Decimal('0.0')) + get_balance_on_date(account,
                                                                                                        date_value,
                                                                                                        currency)

        results = self._generate_result()
        results['data']['start_value'] = start_value

        results['data']['income'] = sorted(
            [(time.mktime(key.timetuple()), value['income']) for key, value in buckets.container.iteritems()],
            key=itemgetter(0))

        results['data']['money_in'] = sorted(
            [(time.mktime(key.timetuple()), value['money_in']) for key, value in buckets.container.iteritems()],
            key=itemgetter(0))

        results['data']['expense'] = sorted(
            [(time.mktime(key.timetuple()), value['expense']) for key, value in buckets.container.iteritems()],
            key=itemgetter(0))

        results['data']['value'] = sorted(
            [[time.mktime(key.timetuple()), value] for key, value in investment_value.iteritems()],
        )

        results['data']['basis'] = sorted(
            [[time.mktime(key.timetuple()), Decimal('0.0')] for key in buckets.container.keys()],
            key=itemgetter(0)
        )

        monthly_start = start_value
        for index, record in enumerate(results['data']['basis']):
            record[1] += (monthly_start + results['data']['income'][index][1] + results['data']['money_in'][index][1] +
                          results['data']['expense'][index][1])
            monthly_start = record[1]

        return results
    def __call__(self):
        bucket = AccountCollate(decimal_generator, split_summation)

        for account in account_walker(self.expenses_base, self.ignore_list):
            for split in get_splits(account, self._start.date, self._end.date):
                bucket.store_value(split)

        return_value = self._generate_result()

        return_value['data']['categories'] = sorted([[key, value] for key, value in bucket.container.iteritems()],
                                                    key=itemgetter(0))

        return return_value
    def __call__(self):

        bucket = PeriodCollate(self._start.date, self._end.date, decimal_generator, split_summation,
                               frequency=self._size.frequency, interval=self._size.interval)

        for account in account_walker(self.expenses_base, self.ignore_list):
            for split in get_splits(account, self._start.date, self._end.date):
                bucket.store_value(split)

        return_value = self._generate_result()
        results = []

        for key, value in bucket.container.iteritems():
            results.append(float(value))

        return_value['data']['low'] = np.percentile(results, 0)
        return_value['data']['high'] = np.percentile(results, 100)
        return_value['data']['q1'] = np.percentile(results, 25)
        return_value['data']['q2'] = np.percentile(results, 50)
        return_value['data']['q3'] = np.percentile(results, 75)

        return return_value
    def __call__(self):
        contribution_total = Decimal("0.0")
        today = date.today()
        beginning_of_year = date(today.year, 1, 1)

        for account_name in self.income_accounts:
            account = get_account(account_name)

            for split in get_splits(account, self._start.date, self._end.date):
                parent = split.parent

                for income_split in parent.GetSplitList():

                    if income_split.GetAccount().get_full_name() in self.retirement_accounts:
                        contribution_total += get_decimal(income_split.GetAmount())

        result = self._generate_result()
        result["data"]["contributionLimit"] = self.contribution_limit
        result["data"]["contribution"] = contribution_total
        result["data"]["dayOfYear"] = (today - beginning_of_year).days + 1
        result["data"]["daysInYear"] = (date(today.year, 12, 31) - beginning_of_year).days + 1

        return result
Exemplo n.º 10
0
    def __call__(self):

        bucket = PeriodCollate(self._start.date, self._end.date, debit_credit_generator,
                               store_credit_debit, frequency=self._size.frequency, interval=self._size.interval)

        for account in account_walker(self._account_names):
            for split in get_splits(account, self._start.date, self._end.date):
                bucket.store_value(split)

        return_value = self._generate_result()
        credit_values = []
        debit_values = []
        difference_value = []

        for key, value in bucket.container.iteritems():
            credit_values.append(dict(date=time.mktime(key.timetuple()), value=value['credit']))
            debit_values.append(dict(date=time.mktime(key.timetuple()), value=value['debit']))
            difference_value.append(dict(date=time.mktime(key.timetuple()), value=value['credit'] + value['debit']))

        return_value['data']['credits'] = sorted(credit_values, key=lambda s: s['date'])
        return_value['data']['debits'] = sorted(debit_values, key=lambda s: s['date'])
        return_value['data']['gross'] = sorted(debit_values, key=lambda s: ['date'])

        return return_value