{% extends "./layout/default" %}

{% block breadcrumbs %}
    {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, account, moment, start, end) }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">
                        {% if moment == 'all' %}
                            {{ trans('firefly.chart_all_journals_for_account', {name:account.name}) }}
                        {% else %}
                            {{ trans('firefly.chart_account_in_period', {name: account.name, start: start.formatLocalized(monthAndDayFormat), end: end.formatLocalized(monthAndDayFormat) }) }}
                        {% endif %}
                    </h3>
                    <div class="box-tools pull-right">
                        <div class="btn-group">
                            <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="{{ route('accounts.edit', account.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ 'edit'|_ }}</a></li>
                                <li><a href="{{ route('accounts.delete', account.id) }}"><i class="fa fa-trash fa-fw"></i> {{ 'delete'|_ }}</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <canvas id="overview-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expenses_by_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="account-cat-out" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expenses_by_budget'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="account-budget-out" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_by_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="account-cat-in" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% if periods.count > 0 %}
        <div class="row">
            <div class="col-lg-offset-10 col-lg-2 col-md-offset-8 col-md-4 col-sm-12 col-xs-12">
                <p class="small text-center"><a href="{{ route('accounts.show',[account.id, 'all']) }}">{{ 'showEverything'|_ }}</a></p>
            </div>
        </div>
    {% endif %}

    <div class="row">
        <div class="{% if periods.count > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'transactions'|_ }}</h3>
                </div>
                <div class="box-body">
                    {% include 'list.journals' with {sorting:true, hideBills:true, hideBudgets: true, hideCategories: true} %}
                    {% if periods.count > 0 %}
                        <p>
                            <i class="fa fa-calendar" aria-hidden="true"></i>
                            <a href="{{ route('accounts.show', [account.id, 'all']) }}">
                                {{ 'show_all_no_filter'|_ }}
                            </a>
                        </p>
                    {% else %}
                        <p>
                            <i class="fa fa-calendar" aria-hidden="true"></i>
                            <a href="{{ route('accounts.show', [account.id]) }}">
                                {{ 'show_the_current_period_and_overview'|_ }}
                            </a>
                        </p>
                    {% endif %}
                </div>
            </div>
        </div>
        {% if periods.count > 0 %}
            <div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">
                {% for period in periods %}
                    {% if (period.spent != 0 or period.earned != 0) %}
                        <div class="box {% if period.date == start %}box-solid box-primary{% endif %}">
                            <div class="box-header with-border">
                                <h3 class="box-title"><a href="{{ route('accounts.show',[account.id,period.string]) }}">{{ period.name }}</a>
                                </h3>
                            </div>
                            <div class="box-body no-padding">
                                <table class="table table-hover">
                                    {% if period.spent != 0 %}
                                        <tr>
                                            <td style="width:33%;">{{ 'spent'|_ }}</td>
                                            <td style="text-align: right;">{{ formatAmountByCurrency(currency, period.spent) }}</td>
                                        </tr>
                                    {% endif %}
                                    {% if period.earned != 0 %}
                                        <tr>
                                            <td style="width: 33%;">{{ 'earned'|_ }}</td>
                                            <td style="text-align: right;">{{ formatAmountByCurrency(currency, period.earned) }}</td>
                                        </tr>
                                    {% endif %}
                                </table>
                            </div>
                        </div>
                    {% endif %}
                {% endfor %}
                <p class="small text-center"><a href="{{ route('accounts.show',[account.id, 'all']) }}">{{ 'showEverything'|_ }}</a></p>
            </div>
        {% endif %}
    </div>



{% endblock %}

{% block scripts %}
    <script type="text/javascript">
        currencySymbol = "{{ currency.symbol }}";
        var accountID = {{ account.id }};
        // uri's for charts:
        var chartUri = '{{ chartUri }}';
        {% if start and end %}
        var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
        var expenseCategoryUri = '{{ route('chart.account.expense-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
        var expenseBudgetUri = '{{ route('chart.account.expense-budget', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
        {% else %}
        var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, 'all', 'all']) }}';
        var expenseCategoryUri = '{{ route('chart.account.expense-category', [account.id, 'all', 'all']) }}';
        var expenseBudgetUri = '{{ route('chart.account.expense-budget', [account.id, 'all', 'all']) }}';
        {% endif %}

    </script>

    <script type="text/javascript">
        {# overrule currency symbol for charts: #}

    </script>

    <script type="text/javascript" src="js/lib/Chart.bundle.min.js"></script>
    <script type="text/javascript" src="js/ff/charts.defaults.js"></script>
    <script type="text/javascript" src="js/ff/charts.js"></script>

    <script src="js/lib/jquery-ui.min.js" type="text/javascript"></script>
    <script src="js/lib/jquery.color-2.1.2.min.js" type="text/javascript"></script>
    <script src="js/ff/accounts/show.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/ff/transactions/list.js"></script>
{% endblock %}
