Exemple #1
0
    def trial_balance(self, request):
        active_accounts = Account.objects.filter(is_active=True)
        nonzero_accounts = []
        debit_total = 0
        credit_total = 0

        for account in active_accounts:
            account_balance = account.get_balance()

            if account_balance != 0:
                nonzero_accounts.append({
                    'account_id':
                    account.pk,
                    'account_number':
                    account.account_number(),
                    'account_name':
                    account.name,
                    'balance':
                    format_currency(account_balance),
                    'is_debit':
                    account.is_debit(),
                })

                if account.is_debit():
                    debit_total += account_balance
                else:
                    credit_total += account_balance

        return Response({
            'accounts': nonzero_accounts,
            'debit_total': format_currency(debit_total),
            'credit_total': format_currency(credit_total),
            'as_of_date': timezone.now()
        })
Exemple #2
0
    def income_statement(self, request):
        accounts = Account.objects.filter(is_active=True,
                                          account_type__category__in=[3, 4])

        expenses = []
        revenues = []
        expenses_total = 0
        revenues_total = 0

        for account in accounts:
            account_balance = account.get_balance()
            if account_balance != 0:
                account_summary = {
                    'account_id': account.pk,
                    'account_number': account.account_number(),
                    'account_name': account.name,
                    'balance': format_currency(account_balance),
                    'is_debit': account.is_debit()
                }

                if account.account_type.category == 3:
                    revenues.append(account_summary)
                    revenues_total += account_balance
                elif account.account_type.category == 4:
                    expenses.append(account_summary)
                    expenses_total += account_balance

        return Response({
            'expenses':
            expenses,
            'revenues':
            revenues,
            'expenses_total':
            format_currency(expenses_total * -1),
            'revenues_total':
            format_currency(revenues_total),
            'net_profit':
            format_currency(revenues_total - expenses_total),
            'as_of_date':
            timezone.now()
        })
Exemple #3
0
    def retained_earnings(self, request):
        accounts = Account.objects.filter(is_active=True,
                                          account_type__category__in=[2, 3, 4])

        retained_earnings_beginning = 0
        net_profit = 0
        dividends_total = 0

        for account in accounts:
            account_balance = account.get_balance()

            if account.account_type.category == 2:
                if account.name == 'Retained Earnings':
                    retained_earnings_beginning = account_balance
                elif 'Drawing' in account.name:
                    # or account.name == "Paid in Capital in Excess of Par/Stated Value--Common Stock" \
                    # or account.name == 'Paid in Capital in Excess of Par/Stated Value--Preferred Stock' \
                    # or account.name == 'Paid in Capital from Sale of Treasury Stock':
                    # NOTE: We are only accounting for business owner equity here, not shareholders equity.
                    dividends_total += account_balance
            elif account.account_type.category == 3:
                net_profit += account_balance
            elif account.account_type.category == 4:
                net_profit -= account_balance

        return Response({
            'retained_earnings_beginning':
            format_currency(retained_earnings_beginning),
            'net_profit':
            format_currency(net_profit),
            'dividends_paid':
            format_currency(dividends_total),
            'retained_earnings_ending':
            format_currency(retained_earnings_beginning + net_profit -
                            dividends_total),
            'as_of_date':
            timezone.now()
        })
Exemple #4
0
    def get_transaction_history(self):
        transactions = []
        post_balance = self.initial_balance
        for t in self.transactions.all():
            if t.journal_entry.is_approved:
                post_balance += (t.value *
                                 pow(-1, int(self.is_debit() ^ t.is_debit)))
                transactions.append({
                    'balance':
                    format_currency(post_balance),
                    'is_debit':
                    t.is_debit,
                    'journal_entry_id':
                    t.journal_entry.id,
                    'date':
                    t.journal_entry.date,
                    'journal_entry_description':
                    t.journal_entry.description,
                    'value':
                    format_currency(t.value)
                })

        return transactions
Exemple #5
0
 def get_value(self, obj):
     return format_currency(obj.value, False)
Exemple #6
0
 def get_balance(self, obj):
     return format_currency(obj.get_balance())
Exemple #7
0
 def get_initial_balance(self, obj):
     return format_currency(obj.initial_balance)
Exemple #8
0
    def balance_sheet(self, request):
        active_accounts = Account.objects.filter(is_active=True)
        current_assets = []
        current_assets_total = 0
        noncurrent_assets = []
        noncurrent_assets_total = 0
        current_liabilities = []
        current_liabilities_total = 0
        noncurrent_liabilities = []
        noncurrent_liabilities_total = 0

        expenses_total = 0
        revenues_total = 0
        equity = []
        equity_total = 0
        for account in active_accounts:
            account_balance = account.get_balance()

            if account.is_contra:
                # Since we are calculating total valuation for each category/classification
                # of account, we need to make sure that the balances of any contra
                # accounts are subtracted from the totals.
                account_balance = account_balance * -1

            if account_balance != 0:
                account_summary = {
                    'account_id': account.pk,
                    'account_number': account.account_number(),
                    'account_name': account.name,
                    'balance': format_currency(account_balance),
                }
                if account.account_type.category == 0:
                    if account.account_type.classification == 1:
                        current_assets.append(account_summary)
                        current_assets_total += account_balance
                    else:
                        noncurrent_assets.append(account_summary)
                        noncurrent_assets_total += account_balance

                elif account.account_type.category == 2:
                    if account.account_type.classification == 1:
                        current_liabilities.append(account_summary)
                        current_liabilities_total += account_balance
                    else:
                        noncurrent_liabilities.append(account_summary)
                        noncurrent_liabilities_total += account_balance

                elif account.account_type.category == 2:
                    equity.append(account_summary)
                    equity_total += account_balance

                elif account.account_type.category == 3:
                    revenues_total += account_balance

                elif account.account_type.category == 4:
                    expenses_total += account_balance

        #Part of Cheaty Method
        # FIXME
        if revenues_total - expenses_total != 0:
            equity.append({
                'account_id':
                0,
                'account_number':
                0,
                'account_name':
                'Income Estimation',
                'balance':
                format_currency(revenues_total - expenses_total),
            })
        #####################
        hacky_equity_total = equity_total + revenues_total - expenses_total  # FIXME: THIS IS A HACKY SOLUTION DO NOT TRUST
        asset_total = current_assets_total + noncurrent_assets_total
        liability_total = equity_total + current_liabilities_total + noncurrent_liabilities_total + revenues_total - expenses_total
        response = {
            'current_assets':
            current_assets,
            'current_liabilities':
            current_liabilities,
            'noncurrent_assets':
            noncurrent_assets,
            'noncurrent_liabilities':
            noncurrent_liabilities,
            'equity':
            equity,
            'current_assets_total':
            format_currency(current_assets_total)
            if current_assets_total is not 0 else None,
            'noncurrent_assets_total':
            format_currency(noncurrent_assets_total)
            if noncurrent_assets_total is not 0 else None,
            'current_liabilities_total':
            format_currency(current_liabilities_total)
            if current_liabilities_total is not 0 else None,
            'noncurrent_liabilities_total':
            format_currency(noncurrent_liabilities_total)
            if noncurrent_liabilities_total is not 0 else None,
            'equity_total':
            format_currency(hacky_equity_total)
            if hacky_equity_total is not 0 else None,
            'asset_total':
            format_currency(asset_total),
            'liability_total':
            format_currency(liability_total),
            'as_of_date':
            timezone.now()
        }

        return Response(response)