{% extends "ui/report_base.html" %}
{% load url from future %}
{% load icons %}
{% load formats %}
{% load bob %}
{% load reports %}
{% load i18n %}

{% block contentarea %}
    <div class="well well-small">
        <h4>Ventures Report</h4>
        {% trans "This report provides detailed info regarding costs for all ventures within selected time frame (with the possibility to edit the ventures afterwards)." %}
    </div>
<form class="form form-inline daterange-form">
<div class="form-actions">
    {% for f in form %}
        <div style="display:inline-block; vertical-align:top" class="control-group {% if f.errors %}error{% endif %}" >
            {{ f }}
            {% if f.errors %}
                <span class="help-block">
                    {% for e in f.errors %}{{ e }}{% endfor %}
                </span>
            {% endif %}
        </div>
    {% endfor %}
    <button type="submit" class="btn">{% spaceless %}
        {% icon 'fugue-calendar-search-result' %}&nbsp;Update
        {% endspaceless %}</button>
    <button class="btn" name="invalidate-cache" value="true">{% spaceless %}
        {% icon 'fugue-arrow-circle-double' %}&nbsp;Refresh cache
    {% endspaceless %}</button>
    <button class="btn pull-right" name="export" value="csv">{% spaceless %}
        {% icon 'fugue-document-excel-csv' %}&nbsp;Export to CSV
    {% endspaceless %}</button>
</div>
</form>
</div>
<div class="row-fluid">
<div class="span12">
    {% if task_in_progress %}
        {% wait_for_results autoreload=1 reload_frequency=15 %}
    {% elif venture_data %}
        <table class="table table-striped table-bordered table-condensed">
            <tr>
                <th>Venture</th>
                <th>Department</th>
                <th>Default margin</th>
                <th>Physical device count</th>
                <th>Core count</th>
                <th>Virtual core count</th>
                <th>Cloud use</th>
                <th>Cloud cost</th>
                {% for extra_type in extra_types %}
                <th>{{ extra_type.name }}</th>
                {% endfor %}
                <th>Splunk cost</th>
                <th>Hardware cost</th>
                <th>Total cost</th>
                {% if profile.is_staff %}
                <th>Actions</th>
                {% endif %}
            </tr>
            {% for venture in venture_data %}
            <tr {% if venture.top_level %}class="table-highlight"{% endif %}>
                <td>
                    {% if not venture.top_level %}&nbsp;&nbsp;&nbsp;&nbsp;{% endif %}
                    <a href="/ui/ventures/{{ venture.symbol|slugify }}/venture/" >
                    {% icon venture.venture_icon %}
                    {{ venture.name }}
                    </a>
                </td>
                <td>{{ venture.department|default:'' }}</td>
                <td style="text-align:right">
                    {{ venture.margin|default:0 }}%
                </td>
                <td class="count">
                    {{ venture.count|default:0|floatformat:2 }}
                </td>
                <td class="count">
                    {{ venture.core_count|default:0|floatformat:2 }}
                </td>
                <td class="count">
                    {{ venture.virtual_core_count|default:0|floatformat:2 }}
                </td>
                <td style="text-align:right">
                    {{ venture.cloud_use|default:0|floatformat:2 }}%
                </td>
                <td style="currency">
                    {{ venture.cloud_cost|currency }}
                </td>
                {% for extra in venture.extras %}
                <td style="currency">
                    {{ extra|currency }}
                </td>
                {% endfor %}
                <td class="currency">
                    {{ venture.splunk_cost|currency }}
                </td>
                <td class="currency">
                    {{ venture.hardware_cost|currency }}
                </td>
                <td class="currency">
                    {{ venture.total|default:0|currency }}
                </td>
                {% if profile.is_staff %}
                <td>{% spaceless %}
                <a href="/admin/business/venture/{{ venture.id }}">
                    {% icon 'fugue-toolbox--pencil' %}&nbsp;Edit
                </a>
                {% endspaceless %}</td>
                {% endif %}
            </tr>
            {% endfor %}
        </table>
    {% endif %}
</div>
{% endblock %}
