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

{% block contentarea %}
</div>
<div class="row-fluid">
<div class="span12">
    <div class="well well-small">
        <h4>Margins Report</h4>
        {% trans "This report allows you to compare current and simulated costs for selected venture within given time frame." %}
    </div>
    <form class="form form-inline daterange-form">
        <div class="form-actions">
            {% for f in form %}
                {% if f.label %}
                <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>
                {% endif %}
            {% endfor %}
            {% spaceless %}<button class="btn pull-right">
                {% icon 'fugue-calculator' %}&nbsp;Calculate
            </button>{% endspaceless %}
        </div>
        <table class="table table-bordered table-striped table-condensed">
            <tr>
                <th>Margin kind name</th>
                <th>Device count</th>
                <th>Current margin</th>
                <th>Current cost</th>
                <th width="3em">Simulated margin</th>
                <th>Simulated cost</th>
            </tr>
            {% for f, mk in zip_margin_kinds_form %}
                <tr>
                    <td>{{ mk.name }}</td>
                    <td class="count">{{ mk.count }}</td>
                    <td class="currency">{{ mk.margin }}%</td>
                    <td class="currency">{{ mk.total|currency }}</td>
                    <td 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 %}
                    </td>
                    <td class="currency">{{ mk.sim_cost|currency }}</td>
                </tr>
            {% endfor %}
            <tr>
                <th>Total</th>
                <td class="count">{{ total_count }}</td>
                <td></td>
                <td class="currency">{{ total_cost|currency }}</td>
                <td></td>
                <td class="currency">{{ total_sim|currency }}</td>
            </tr>
        </table>
    </form>
</div>
{% endblock %}
