{% extends "base.html" %}
{% block title %}Accounts - BiweeklyBudget{% endblock %}
{% block body %}
{% include 'notifications.html' %}
            <div class="row" id="content-row">
                <div class="col-lg-12">
                    <div class="panel panel-default" id="panel-bank-accounts">
                        <div class="panel-heading">
                            <i class="fa fa-bank fa-fw"></i> Bank Accounts
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th>Account</th>
                                            <th>Balance</th>
                                            <th>Unreconciled</th>
                                            <th>Difference</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for acct in bank_accounts|sort(attribute='name') %}
                                        <tr>
                                            <td><a href="/accounts/{{ acct.id }}">{{ acct.name }}</a></td>
                                            <td>
                                                <span>{{ acct.balance.ledger|dollars }}</span>
                                                {% if acct.is_stale %}
                                                <span class="data_age text-danger">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% else %}
                                                <span class="data_age">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ acct.unreconciled_sum|dollars }}</td>
                                            <td>{{ (cast_float(acct.balance.ledger) - acct.unreconciled_sum)|reddollars }}</td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                    <div class="panel panel-default" id="panel-credit-cards">
                        <div class="panel-heading">
                            <i class="fa fa-credit-card fa-fw"></i> Credit Cards
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th>Account</th>
                                            <th>Balance</th>
                                            <th>Credit Limit</th>
                                            <th>Available</th>
                                            <th>Unreconciled</th>
                                            <th>Difference</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for acct in credit_accounts|sort(attribute='name') %}
                                        <tr>
                                            <td><a href="/accounts/{{ acct.id }}">{{ acct.name }}</a></td>
                                            <td>
                                                <span>{{ acct.balance.ledger|dollars }}</span>
                                                {% if acct.is_stale %}
                                                <span class="data_age text-danger">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% else %}
                                                <span class="data_age">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ acct.credit_limit|dollars }}</td>
                                            <td>{{ (acct.credit_limit + acct.balance.ledger)|reddollars }}</td>
                                            <td>{{ acct.unreconciled_sum|dollars }}</td>
                                            <td>{{ (cast_float(acct.credit_limit + acct.balance.ledger) - acct.unreconciled_sum)|reddollars }}</td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                    <div class="panel panel-default" id="panel-investment">
                        <div class="panel-heading">
                            <i class="glyphicon glyphicon-piggy-bank"></i> Investment Accounts
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th>Account</th>
                                            <th>Value</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for acct in investment_accounts|sort(attribute='name') %}
                                        <tr>
                                            <td><a href="/accounts/{{ acct.id }}">{{ acct.name }}</a></td>
                                            <td>
                                                <span>{{ acct.balance.ledger|dollars }}</span>
                                                {% if acct.is_stale %}
                                                <span class="data_age text-danger">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% else %}
                                                <span class="data_age">({{ acct.ofx_statement.as_of|ago }})</span>
                                                {% endif %}
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
{% endblock %}