{% extends "base.html" %}
{% block title %}BiweeklyBudget{% endblock %}
{% block extra_head_css %}
    <!-- Morris Charts CSS -->
    <link href="/static/startbootstrap-sb-admin-2/vendor/morrisjs/morris.css" rel="stylesheet">
{% endblock %}
{% block body %}
{% include 'notifications.html' %}
            <!-- /.row -->
            <div class="row" id="content-row">
                <div class="col-lg-8">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-bar-chart-o fa-fw"></i> Placeholder - Account Balances
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div id="account-balance-chart"></div>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                    <div class="col-lg-6">
                        <div class="panel panel-default" id="panel-standing-budgets">
                            <div class="panel-heading">
                                Standing Budgets
                            </div>
                            <!-- /.panel-heading -->
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover table-striped" id="table-standing-budgets">
                                        <thead>
                                            <tr>
                                                <th>Budget</th>
                                                <th>Current Balance</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        {% for b in standing_budgets %}
                                            <tr>
                                                <td><a href="/budgets/{{ b.id }}">{{ b.name }} ({{ b.id }})</a></td>
                                                <td>
                                                    <span>{{ b.current_balance|dollars }}</span>
                                                </td>
                                            </td>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                                <!-- /.table-responsive -->
                            </div>
                            <!-- /.panel-body -->
                        </div>
                        <!-- /.panel -->
                    </div>
                    <!-- /.col-lg-6 -->
                </div>
                <!-- /.col-lg-8 -->
                <div class="col-lg-4">
                    <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>Available</th>
                                            <th>Avail - Unrec</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 + acct.balance.ledger)|reddollars }}</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-4 -->
            </div>
            <!-- /.row -->
{% endblock %}
{% block extra_foot_script %}
    <!-- Morris Charts JavaScript -->
    <script src="/static/startbootstrap-sb-admin-2/vendor/raphael/raphael.min.js"></script>
    <script src="/static/startbootstrap-sb-admin-2/vendor/morrisjs/morris.min.js"></script>
    <script src="/static/js/index.js"></script>
{% endblock %}