def trial_balance_report(request, template_name="reports/trial_balance.html"): """ Display the state and change of all :class:`Accounts <accounts.models.Account>` over a time period. The available ``GET`` parameters are ``start_date`` and ``stop_date``. The view also provides the ``start_date``, ``stop_date`` and ``accounts`` context variables. The ``start_date`` and ``stop_date`` variables default to the first day of the year and the current date. The ``accounts`` variable is a list of dictionaries, each representing an :class:`~accounts.models.Account`. Each dictionary contains the :class:`Account's<accounts.models.Account>` number, name, balance at the beginning and end of the date range, total debits and credits and the net change. :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with start and stop dates and an ``accounts`` list. :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) accounts = [_get_account_details(x, start_date, stop_date) for x in list(Account.objects.all().order_by('full_number'))] return render(request, template_name, {'start_date': start_date, 'stop_date': stop_date, 'accounts': accounts, 'form': form})
def profit_loss_report(request, template_name="reports/profit_loss.html"): """ Display the Profit or Loss for a time period calculated using all Income and Expense :class:`Accounts<accounts.models.Account>`. The available ``GET`` parameters are ``start_date`` and ``stop_date``. They control the date range used for the calculations. This view is used to show the Total, Header and Account Net Changes over a specified date range. It uses the Net Changes to calculate various Profit amounts, passing them as context variables: * ``gross_profit``: Income - Cost of Goods Sold * ``operating_profit``: Gross Profit - Expenses * ``net_profit``: Operating Profit + Other Income - Other Expenses Also included is the ``headers`` dictionary which contains the ``income``, ``cost_of_goods_sold``, ``expenses``, ``other_income``, and ``other_expense`` keys. These keys point to the root node for the respective :attr:~accounts.models.BaseAccountModel.type`. These nodes have additional attributes appended to them, ``total``, ``accounts`` and ``descendants``. ``total`` represents the total Net Change for the node. ``accounts`` and ``descendants`` are lists of child nodes(also with a ``total`` attribute). :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with the start/stop dates, ``headers`` dictionary and Profit Totals :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) headers_and_types = _get_profit_loss_header_keys_and_types() headers = { header_key: _get_profit_loss_header_totals(header_type, start_date, stop_date) for (header_key, header_type) in headers_and_types } gross_profit, operating_profit, net_profit = _get_profit_totals(headers) return render(request, template_name, locals())
def profit_loss_report(request, template_name="reports/profit_loss.html"): """ Display the Profit or Loss for a time period calculated using all Income and Expense :class:`Accounts<accounts.models.Account>`. The available ``GET`` parameters are ``start_date`` and ``stop_date``. They control the date range used for the calculations. This view is used to show the Total, Header and Account Net Changes over a specified date range. It uses the Net Changes to calculate various Profit amounts, passing them as context variables: * ``gross_profit``: Income - Cost of Goods Sold * ``operating_profit``: Gross Profit - Expenses * ``net_profit``: Operating Profit + Other Income - Other Expenses Also included is the ``headers`` dictionary which contains the ``income``, ``cost_of_goods_sold``, ``expenses``, ``other_income``, and ``other_expense`` keys. These keys point to the root node for the respective :attr:~accounts.models.BaseAccountModel.type`. These nodes have additional attributes appended to them, ``total``, ``accounts`` and ``descendants``. ``total`` represents the total Net Change for the node. ``accounts`` and ``descendants`` are lists of child nodes(also with a ``total`` attribute). :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with the start/stop dates, ``headers`` dictionary and Profit Totals :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) headers_and_types = _get_profit_loss_header_keys_and_types() headers = { header_key: _get_profit_loss_header_totals( header_type, start_date, stop_date) for (header_key, header_type) in headers_and_types} gross_profit, operating_profit, net_profit = _get_profit_totals(headers) return render(request, template_name, locals())
def trial_balance_report(request, template_name="reports/trial_balance.html"): """ Display the state and change of all :class:`Accounts <accounts.models.Account>` over a time period. The available ``GET`` parameters are ``start_date`` and ``stop_date``. The view also provides the ``start_date``, ``stop_date`` and ``accounts`` context variables. The ``start_date`` and ``stop_date`` variables default to the first day of the year and the current date. The ``accounts`` variable is a list of dictionaries, each representing an :class:`~accounts.models.Account`. Each dictionary contains the :class:`Account's<accounts.models.Account>` number, name, balance at the beginning and end of the date range, total debits and credits and the net change. :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with start and stop dates and an ``accounts`` list. :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) accounts = [ _get_account_details(x, start_date, stop_date) for x in list(Account.objects.all().order_by('full_number')) ] return render( request, template_name, { 'start_date': start_date, 'stop_date': stop_date, 'accounts': accounts, 'form': form })
def show_account_detail(request, account_slug, template_name="accounts/account_detail.html"): """ Displays a list of :class:`Transaction` instances for the :class:`Account` with a :attr:`~Account.slug` equal to the ``account_slug`` parameter. The following ``GET`` parameters are accessible: * ``start_date`` - The starting date to filter the returned :class:`Transactions<Transaction>` by. * ``stop_date`` - The ending date to filter the returned :class:`Transactions<Transaction>` by. The ``start_date`` and ``stop_date`` variables default to the first day of the month and the current date. The view will provide ``start_balance``, ``end_balance``, ``transactions``, ``debit_total``, ``credit_total`` and ``net_change`` context variables. The :class:`Transactions<Transaction>` in the context variable ``transactions`` will have the running balance added to the instance through the ``final_balance`` attribute. If the provided ``start_date`` is before the start of the current :class:`~fiscalyears.models.FiscalYear`, the running balance and :class:`Transaction's<entries.models.Transaction>` ``final_balance`` will not be calculated. If there are no :class:`Transactions<entries.models.Transaction>` the ``start_balance`` and ``end_balance`` will both be set to the balance on the ``start_date`` :param account_slug: The :attr:`~accounts.models.Account.slug` of top \ :class:`Account` to retrieve. :type account_slug: str :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with :class:`Transactions<Transaction>` and \ balance counters. :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) account = get_object_or_404(Account, slug=account_slug) date_range_query = (Q(date__lte=stop_date) & Q(date__gte=start_date)) debit_total, credit_total, net_change = account.transaction_set.filter( date_range_query).get_totals(net_change=True) transactions = account.transaction_set.filter( date_range_query).select_related('journal_entry', 'bankspendingentry', 'bankspend_entry', 'bankreceivingentry', 'bankreceive_entry') current_fiscal_start_date = get_start_of_current_fiscal_year() show_balance = (current_fiscal_start_date is None or current_fiscal_start_date <= start_date) if not show_balance: messages.info(request, "The Balance counters are only available when " "the Start Date is in the current Fiscal Year (after " "{0})".format(current_fiscal_start_date.strftime( "%m/%d/%Y"))) if transactions.exists() and show_balance: start_balance = transactions[0].get_initial_account_balance() end_balance = start_balance # TODO: Use .get_totals() instead of looping through each for transaction in transactions: if account.flip_balance(): end_balance -= transaction.balance_delta else: end_balance += transaction.balance_delta transaction.final_balance = end_balance else: start_balance = end_balance = account.get_balance_by_date(start_date) return render(request, template_name, locals())
def show_account_detail(request, account_slug, template_name="accounts/account_detail.html"): """ Displays a list of :class:`Transaction` instances for the :class:`Account` with a :attr:`~Account.slug` equal to the ``account_slug`` parameter. The following ``GET`` parameters are accessible: * ``start_date`` - The starting date to filter the returned :class:`Transactions<Transaction>` by. * ``stop_date`` - The ending date to filter the returned :class:`Transactions<Transaction>` by. The ``start_date`` and ``stop_date`` variables default to the first day of the month and the current date. The view will provide ``start_balance``, ``end_balance``, ``transactions``, ``debit_total``, ``credit_total`` and ``net_change`` context variables. The :class:`Transactions<Transaction>` in the context variable ``transactions`` will have the running balance added to the instance through the ``final_balance`` attribute. If the provided ``start_date`` is before the start of the current :class:`~fiscalyears.models.FiscalYear`, the running balance and :class:`Transaction's<entries.models.Transaction>` ``final_balance`` will not be calculated. If there are no :class:`Transactions<entries.models.Transaction>` the ``start_balance`` and ``end_balance`` will both be set to the balance on the ``start_date`` :param account_slug: The :attr:`~accounts.models.Account.slug` of top \ :class:`Account` to retrieve. :type account_slug: str :param template_name: The template file to use to render the response. :type template_name: str :returns: HTTP Response with :class:`Transactions<Transaction>` and \ balance counters. :rtype: HttpResponse """ form, start_date, stop_date = process_year_start_date_range_form(request) account = get_object_or_404(Account, slug=account_slug) date_range_query = (Q(date__lte=stop_date) & Q(date__gte=start_date)) debit_total, credit_total, net_change = account.transaction_set.filter( date_range_query).get_totals(net_change=True) transactions = account.transaction_set.filter( date_range_query).select_related('journal_entry', 'bankspendingentry', 'bankspend_entry', 'bankreceivingentry', 'bankreceive_entry') current_fiscal_start_date = get_start_of_current_fiscal_year() show_balance = (current_fiscal_start_date is None or current_fiscal_start_date <= start_date) if not show_balance: messages.info( request, "The Balance counters are only available when " "the Start Date is in the current Fiscal Year (after " "{0})".format(current_fiscal_start_date.strftime("%m/%d/%Y"))) if transactions.exists() and show_balance: start_balance = transactions[0].get_initial_account_balance() end_balance = start_balance # TODO: Use .get_totals() instead of looping through each for transaction in transactions: if account.flip_balance(): end_balance -= transaction.balance_delta else: end_balance += transaction.balance_delta transaction.final_balance = end_balance else: start_balance = end_balance = account.get_balance_by_date(start_date) return render(request, template_name, locals())